/* Self-hosted Nunito font (DSGVO: no Google Fonts) */
@font-face {
    font-family: 'Nunito';
    font-style: normal;
    font-weight: 600 800;
    font-display: swap;
    src: url('fonts/nunito-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Nunito';
    font-style: normal;
    font-weight: 600 800;
    font-display: swap;
    src: url('fonts/nunito-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --color-bg: #f5efe6;
    --color-primary: #c47832;
    --color-accent: #7bab5e;
    --color-success: #5cb85c;
    --color-wrong: #d9534f;
    --color-text: #3d3229;
    --color-card: #fffcf7;
    --color-wood: #8B6914;
    --color-wood-light: #A0855B;
    --radius: 16px;
}

html, body {
    height: 100%;
    font-family: 'Nunito', -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
    color: var(--color-text);
    overflow: hidden;
    touch-action: pan-x;
    -webkit-user-select: none;
    user-select: none;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Shared button style */
.btn {
    display: inline-block;
    padding: 16px 32px;
    border: none;
    border-radius: var(--radius);
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.95); }
.btn-primary {
    background: url('/img/gras.png') center/contain no-repeat;
    image-rendering: pixelated;
    color: #fff;
    font-weight: 800;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5), 0 0 6px rgba(0,0,0,0.2);
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 16px 32px;
    position: relative;
}
.btn-wood {
    background: url('/img/plank-h2.png') center/contain no-repeat;
    image-rendering: pixelated;
    color: #fff8ee;
    font-weight: 800;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 16px 32px;
}
.btn-add {
    background: var(--color-card);
    color: var(--color-text);
    border: 3px solid #e0d8cc;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.btn-answer {
    background: var(--color-card);
    color: var(--color-text);
    border: 3px solid #ddd;
    font-size: 1.8rem;
    min-height: 70px;
    width: 100%;
}
.btn-answer.correct { border-color: var(--color-success); background: #eaffea; }
.btn-answer.wrong { border-color: var(--color-wrong); background: #fff3e6; }

/* Screen transitions */
.screen { height: 100%; padding: 20px; }

h1 { font-size: 1.6rem; text-align: center; margin-bottom: 20px; }

/* Player Select */
.player-select {
    display: flex; flex-direction: column; justify-content: flex-start; align-items: center;
    gap: 20px; overflow-y: auto; padding-top: 2rem;
}
.login-title {
    max-width: 320px; width: 80%; height: auto; image-rendering: pixelated;
    animation: loginFadeIn 0.6s ease-out;
}
.login-hamster {
    width: 120px; height: 120px; object-fit: contain; image-rendering: pixelated;
    animation: loginBounce 0.6s ease-out 0.2s both;
}
@keyframes loginFadeIn {
    from { opacity: 0; transform: translateY(-12px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes loginBounce {
    from { opacity: 0; transform: scale(0.7); }
    60% { transform: scale(1.08); }
    to { opacity: 1; transform: scale(1); }
}
.player-list {
    display: flex; flex-wrap: wrap; gap: 16px; justify-content: center;
    width: 100%; max-width: 600px; max-height: 45vh; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    animation: loginFadeIn 0.5s ease-out 0.3s both;
}
.player-card {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding: 16px 24px; background: var(--color-card); border: 3px solid #e0d8cc;
    border-radius: var(--radius); cursor: pointer; font-size: 1.1rem;
    transition: transform 0.1s, box-shadow 0.2s; min-width: 110px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.player-card:active { transform: scale(0.95); }
.player-avatar { width: 56px; height: 56px; object-fit: contain; image-rendering: pixelated; }
.player-name { font-weight: 600; }
.new-player-form {
    display: flex; gap: 12px; width: 100%; max-width: 400px;
    animation: loginFadeIn 0.5s ease-out 0.4s both;
}
.new-player-form input {
    flex: 1; padding: 14px 16px; border: 3px solid #e0d8cc; border-radius: var(--radius);
    font-size: 1.1rem; background: var(--color-card);
}
.empty-hint { color: #999; font-size: 1.1rem; }
.player-search {
    padding: 10px 16px; border: 3px solid #e0d8cc; border-radius: var(--radius);
    font-size: 1rem; background: var(--color-card); width: 100%; max-width: 400px;
}
.new-player-error { color: var(--color-wrong); font-size: 0.9rem; }

/* Stall Overview */
.stall-carousel {
    flex: 0 0 auto; display: flex; align-items: flex-start; overflow-x: auto; scroll-snap-type: x mandatory;
    gap: 20px; padding: 20px; -webkit-overflow-scrolling: touch;
}
.stall-card {
    scroll-snap-align: center; flex: 0 0 320px;
    background: transparent;
    border-radius: var(--radius); padding: 16px; padding-top: 28px; padding-bottom: 16px; display: flex; flex-direction: column;
    align-items: center; gap: 10px; position: relative; border: none;
    box-shadow: none;
}
.stall-card.recommended {
    box-shadow: none;
}
.badge-recommended {
    position: absolute; top: -8px; right: -8px; z-index: 4;
    width: 120px; height: 32px;
    background: url('/img/plank-h2.png') center/100% 100% no-repeat;
    image-rendering: pixelated;
    color: #fff8ee; font-size: 0.75rem; font-weight: 800;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    transform: rotate(8deg);
    padding: 0; border-radius: 0; border: none;
}
.badge-complete {
    position: absolute; top: -8px; left: -8px; z-index: 4;
    width: 120px; height: 32px;
    background: url('/img/plank-h2.png') center/100% 100% no-repeat;
    image-rendering: pixelated;
    color: #fff8ee; font-size: 0.75rem; font-weight: 800;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    transform: rotate(-6deg);
    padding: 0; border-radius: 0; border: none;
}
.stall-frame {
    position: relative; width: 280px; height: 280px;
    padding: 14px;
}
.plank {
    position: absolute; image-rendering: pixelated; z-index: 2; pointer-events: none;
}
.plank-top-wrap {
    position: absolute; top: -22px; left: -6px; right: -6px; z-index: 3;
    display: flex; align-items: center; justify-content: center;
    height: 44px;
}
.plank-top { width: 100%; height: 100%; object-fit: fill; image-rendering: pixelated; }
.stall-title {
    position: absolute; z-index: 3; color: #fff8ee; font-size: 1.15rem; font-weight: 800;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5); letter-spacing: 0.5px;
    white-space: nowrap;
}
.plank-bottom { bottom: -6px; left: -6px; right: -6px; width: calc(100% + 12px); height: 20px; object-fit: fill; }
.plank-left { top: 8px; left: -6px; bottom: 8px; width: 20px; height: calc(100% - 16px); object-fit: fill; }
.plank-right { top: 8px; right: -6px; bottom: 8px; width: 20px; height: calc(100% - 16px); object-fit: fill; transform: scaleX(-1); }
.stall-visual {
    width: 100%; height: 100%; background: #ede5d5; border-radius: 0;
    position: relative; overflow: hidden;
}
.stall-bedding {
    position: absolute; bottom: 0; left: 0; right: 0;
    background:
        repeating-linear-gradient(25deg, transparent, transparent 3px, rgba(210,180,120,0.4) 3px, rgba(210,180,120,0.4) 5px),
        repeating-linear-gradient(-15deg, transparent, transparent 4px, rgba(190,160,100,0.3) 4px, rgba(190,160,100,0.3) 6px),
        repeating-linear-gradient(45deg, transparent, transparent 2px, rgba(220,195,140,0.3) 2px, rgba(220,195,140,0.3) 4px),
        linear-gradient(180deg, #e8d5a8 0%, #dcc590 100%);
    border-radius: 0; transition: height 0.5s;
}
.stall-grid {
    position: relative; z-index: 1;
    display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
    width: 100%; height: 100%;
}
.stall-grid-cell {
    display: flex; align-items: center; justify-content: center; padding: 6px;
    overflow: hidden; min-height: 0; min-width: 0;
}
.stall-hamster {
    position: absolute; z-index: 2; width: 30%; height: 30%; object-fit: contain;
    image-rendering: pixelated; cursor: pointer;
    left: 35%; top: 35%;
    transition: left 1.5s ease-in-out, top 1.5s ease-in-out, transform 0.3s ease;
}
.stall-item { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.reward-item-img { width: 80px; height: 80px; object-fit: contain; image-rendering: pixelated; margin-top: 8px; }
.progress-bar { width: 100%; height: 8px; background: #eee; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--color-primary); border-radius: 4px; transition: width 0.5s; }
.stall-buttons { display: flex; gap: 8px; width: 100%; }
.stall-buttons .btn { flex: 1; text-align: center; }
.stall-practice-btn { width: 100%; }
.stall-nav {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 16px;
}
.stall-back-btn { background: none; border: none; font-size: 0.9rem; color: #888; cursor: pointer; padding: 8px 12px; }
.stall-player-name {
    font-size: 1.1rem; font-weight: 800; color: var(--color-text);
    background: linear-gradient(175deg, #c8884a 0%, #a06228 50%, #8b5520 100%);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Mobile section toggle */
.mobile-section-toggle {
    position: relative; height: 44px; margin: 0 20px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    -webkit-tap-highlight-color: transparent;
}
.mobile-section-toggle .toggle-plank {
    position: absolute; inset: 0; width: 100%; height: 100%;
    object-fit: fill; image-rendering: pixelated;
}
.mobile-section-toggle .toggle-label {
    position: relative; z-index: 1; color: #fff8ee; font-size: 1rem; font-weight: 800;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5); letter-spacing: 0.5px;
}
.mobile-section-toggle:active { transform: scale(0.97); }
@media (min-width: 768px) {
    .mobile-section-toggle { display: none !important; }
}

/* Stall Overview layout */
.stall-overview { display: flex; flex-direction: column; height: 100%; overflow-y: auto; }

/* Bonus Stall */
.bonus-stall-wrap { padding: 30px 20px 20px; overflow-x: auto; -webkit-overflow-scrolling: touch; flex: 0 0 auto; }
.bonus-stall {
    min-width: 700px; max-width: 1340px; margin: 0 auto; position: relative;
}
.bonus-frame {
    position: relative; width: 100%; min-height: 300px; padding: 14px;
}
.bonus-plank-top {
    position: absolute; top: -22px; left: -6px; right: -6px; z-index: 3;
    height: 44px; display: flex; align-items: center; justify-content: center;
    background: url('/img/plank-h3.png') repeat-x left/auto 100%;
    image-rendering: pixelated;
}
.bonus-title {
    position: relative; z-index: 3; color: #fff8ee; font-size: 1.15rem; font-weight: 800;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5); letter-spacing: 0.5px; white-space: nowrap;
}
.bonus-plank-bottom {
    position: absolute; bottom: -6px; left: -6px; right: -6px; height: 40px; z-index: 2;
    transform: scaleY(-1);
    background: url('/img/plank-h3.png') repeat-x left/auto 100%;
    image-rendering: pixelated;
}
.bonus-plank-left {
    position: absolute; top: 8px; left: -6px; bottom: 8px; width: 20px; z-index: 2;
    background: url('/img/plank-v.png') center/100% 100% no-repeat;
    image-rendering: pixelated;
}
.bonus-plank-right {
    position: absolute; top: 8px; right: -6px; bottom: 8px; width: 20px; z-index: 2;
    background: url('/img/plank-v.png') center/100% 100% no-repeat;
    image-rendering: pixelated; transform: scaleX(-1);
}
.bonus-visual {
    width: 100%; min-height: 280px; background: #ede5d5; border-radius: 0;
    position: relative; overflow: hidden;
}
.bonus-bedding {
    position: absolute; bottom: 0; left: 0; right: 0; height: 100%;
    background:
        repeating-linear-gradient(25deg, transparent, transparent 3px, rgba(210,180,120,0.4) 3px, rgba(210,180,120,0.4) 5px),
        repeating-linear-gradient(-15deg, transparent, transparent 4px, rgba(190,160,100,0.3) 4px, rgba(190,160,100,0.3) 6px),
        repeating-linear-gradient(45deg, transparent, transparent 2px, rgba(220,195,140,0.3) 2px, rgba(220,195,140,0.3) 4px),
        linear-gradient(180deg, #e8d5a8 0%, #dcc590 100%);
}
.bonus-item {
    position: absolute; width: 60px; height: 60px; object-fit: contain;
    image-rendering: pixelated; z-index: 1;
}
.bonus-hamster {
    position: absolute; width: 55px; height: 55px; object-fit: contain;
    image-rendering: pixelated; z-index: 2; cursor: grab;
    transition: left 1.5s ease-in-out, top 1.5s ease-in-out, transform 0.3s ease;
}
.bonus-locked-msg {
    display: flex; align-items: center; justify-content: center;
    height: 100%; min-height: 280px; font-size: 1.1rem; color: #999; text-align: center;
    padding: 20px; line-height: 1.6;
}
.bonus-empty-msg {
    display: flex; align-items: center; justify-content: center;
    height: 100%; min-height: 200px; font-size: 1.1rem; color: #b0a080;
    text-align: center; padding: 20px; z-index: 1; position: relative;
}
.bonus-stall-locked .bonus-visual { opacity: 0.5; }
.bonus-stall-locked .bonus-plank-top,
.bonus-stall-locked .bonus-plank-bottom,
.bonus-stall-locked .bonus-plank-left,
.bonus-stall-locked .bonus-plank-right { opacity: 0.5; }

/* Drag & Drop states */
.bonus-drop-hover .bonus-visual { box-shadow: inset 0 0 20px rgba(123,171,94,0.5); }
.bonus-drop-hover .bonus-plank-top,
.bonus-drop-hover .bonus-plank-bottom { filter: brightness(1.2); }
.stall-drop-hover .stall-visual { box-shadow: inset 0 0 15px rgba(123,171,94,0.5); }
.dragging { opacity: 0.4; }
.stall-hamster-draggable { cursor: grab; }
.stall-hamster-draggable:active { cursor: grabbing; }

/* Moved sign overlay */
.moved-sign {
    position: absolute; top: 50%; left: 50%; z-index: 5;
    transform: translate(-50%, -50%) rotate(-8deg);
    width: 85%; text-align: center;
}
.moved-sign-plank {
    width: 100%; height: auto; image-rendering: pixelated;
}
.moved-sign-text {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: #fff8ee; font-size: 1.05rem; font-weight: 800;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
    white-space: nowrap; line-height: 1.3;
}
.stall-moved .stall-visual { opacity: 1; }

/* Quiz */
.quiz-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; }
.quiz-header { display: flex; justify-content: space-between; align-items: center; width: 100%; max-width: 400px; font-size: 1rem; color: #888; }
.quiz-abort-btn { background: none; border: none; font-size: 1.2rem; color: #bbb; cursor: pointer; padding: 4px 8px; line-height: 1; }
.quiz-abort-btn:active { color: var(--color-text); }
.quiz-trail-container {
    position: relative; width: 100%; max-width: 500px;
    height: 130px;
}
.quiz-trail-bg {
    position: absolute; bottom: 0; left: 0; width: 100%; height: 100%;
    background-repeat: repeat-x; background-position: left bottom; background-size: auto 100%;
    image-rendering: pixelated;
}
.quiz-hamster {
    position: absolute;
    bottom: 60px; /* half on trail */
    width: 80px; height: 80px;
    object-fit: contain; image-rendering: pixelated;
    transform: translateX(-50%);
    transition: left 0.5s ease;
}
.quiz-question { font-size: 3rem; font-weight: 700; }
.quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; width: 100%; max-width: 400px; }
.quiz-feedback { font-size: 1.2rem; font-weight: 600; min-height: 2em; text-align: center; }
.feedback-correct { color: var(--color-success); }
.feedback-wrong { color: var(--color-wrong); }

/* Round End */
.round-end { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; text-align: center; }
.score-display { font-size: 3rem; font-weight: 700; }
.score-number { color: var(--color-primary); }
.reward-visuals { display: flex; align-items: center; justify-content: center; gap: 24px; }
.reward-hamster { width: 160px; height: 160px; object-fit: contain; image-rendering: pixelated; }
.reward-item-img { width: 140px; height: 140px; object-fit: contain; image-rendering: pixelated; }
.reward-message { font-size: 1.4rem; line-height: 1.8; font-weight: 600; }
.reward-perfect { color: var(--color-primary); }
.reward-great { color: var(--color-success); }
.reward-ok { color: var(--color-text); }

/* iPad landscape */
@media (max-width: 767px) {
    #toggle-stalls { margin-top: 40px; margin-bottom: 16px; }
    #toggle-bonus { margin-top: 12px; }
    .bonus-stall-wrap { overflow-x: scroll; }
}
@media (min-width: 768px) {
    .stall-card { flex: 0 0 380px; }
    .stall-frame { width: 340px; height: 340px; }
    .quiz-hamster { width: 150px; height: 150px; }
    .quiz-question { font-size: 4rem; }
    .btn-answer { font-size: 2.2rem; min-height: 90px; }
    .quiz-options { max-width: 500px; }
}

/* Safe area for notch/home indicator */
.legal-links { margin-top: 0.5rem; font-size: 0.8rem; opacity: 0.5; }
.legal-links a { color: var(--color-text); }

@supports (padding: env(safe-area-inset-bottom)) {
    .screen { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

/* Mobile: kompakteres Login-Layout damit alle Spieler sichtbar sind */
@media (max-width: 600px) {
    html, body { overflow: visible !important; height: auto !important; }
    #app { height: auto !important; min-height: 100vh; }
    .screen { height: auto !important; padding: 10px 10px 8px 10px !important; }
    .player-select { gap: 10px; padding-top: 0; flex: none !important; }
    .login-title { max-width: 200px; }
    .login-hamster { width: 70px; height: 70px; }
    .player-card { padding: 10px 16px; min-width: 90px; font-size: 0.95rem; }
    .player-avatar { width: 48px; height: 48px; }
    .new-player-form input { padding: 10px 14px; }
    .legal-links { margin-top: 0.2rem; padding-bottom: 0; }
}
@supports (padding: env(safe-area-inset-bottom)) {
    @media (max-width: 600px) {
        .legal-links { padding-bottom: env(safe-area-inset-bottom); }
    }
}
