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

:root {
    --color-bg: #fdf6e3;
    --color-primary: #e8a838;
    --color-success: #5cb85c;
    --color-wrong: #e8913a;
    --color-text: #3d3229;
    --color-card: #ffffff;
    --radius: 16px;
}

html, body {
    height: 100%;
    font-family: -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    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: var(--color-primary); color: white; }
.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: center; align-items: center; gap: 24px; }
.player-list { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; width: 100%; max-width: 600px; }
.player-card {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding: 20px 32px; background: var(--color-card); border: 3px solid #ddd;
    border-radius: var(--radius); cursor: pointer; font-size: 1.1rem;
    transition: transform 0.1s; min-width: 120px;
}
.player-card:active { transform: scale(0.95); }
.player-avatar { font-size: 2.5rem; }
.player-name { font-weight: 600; }
.new-player-form { display: flex; gap: 12px; width: 100%; max-width: 400px; }
.new-player-form input {
    flex: 1; padding: 14px 16px; border: 3px solid #ddd; border-radius: var(--radius);
    font-size: 1.1rem; background: var(--color-card);
}
.empty-hint { color: #999; font-size: 1.1rem; }

/* Stall Overview */
.stall-overview { display: flex; flex-direction: column; height: 100%; }
.stall-carousel {
    flex: 1; display: flex; 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: var(--color-card);
    border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column;
    align-items: center; gap: 12px; position: relative; border: 3px solid #eee;
}
.stall-card.recommended { border-color: var(--color-primary); }
.badge-recommended {
    position: absolute; top: -10px; right: -10px; background: var(--color-primary);
    color: white; padding: 4px 12px; border-radius: 12px; font-size: 0.8rem; font-weight: 600;
}
.stall-visual {
    width: 280px; height: 280px; background: #f5f0e0; border-radius: 12px;
    position: relative; overflow: hidden;
}
.stall-bedding {
    position: absolute; bottom: 0; left: 0; right: 0; background: #d4b87a;
    border-radius: 0 0 12px 12px; 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 { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; cursor: pointer; }
.stall-hamster-placeholder { width: 100%; height: 100%; }
.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-practice-btn { width: 100%; }
.stall-nav { display: flex; justify-content: center; padding: 12px; gap: 16px; }
.stall-back-btn { background: none; border: none; font-size: 1rem; color: var(--color-text); cursor: pointer; padding: 8px 16px; }

/* 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: 80px;
    object-fit: fill; image-rendering: pixelated;
}
.quiz-hamster {
    position: absolute;
    bottom: 40px; /* 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 (min-width: 768px) {
    .stall-card { flex: 0 0 380px; }
    .stall-visual { 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 */
@supports (padding: env(safe-area-inset-bottom)) {
    .screen { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}
