:root {
    /* Use site-wide primary color for consistency */
    --howmany-bg: #FFF9E6;
    --howmany-canvas: #fff;
    --howmany-dot: #FFD93D;
    --howmany-text: #333;
    --howmany-text-dim: #666;
    --color-excellent: #4CAF50;
    --color-good: #FFD93D;
    --color-poor: #FF6B6B;
    --font-main: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --radius-md: 12px;
    --radius-lg: 16px;
}

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-main);
    background-color: var(--howmany-bg);
    color: var(--howmany-text);
    -webkit-tap-highlight-color: transparent;
}

.game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
}

.content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1rem;
    width: 100%;
    max-width: 500px;
    padding-bottom: 4rem;
}

.title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--howmany-dot);
}

.canvas-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    max-width: 350px;
    margin: 0 auto 1rem;
}

#canvas {
    width: 100%;
    height: 100%;
    background-color: var(--howmany-canvas);
    border: 2px solid #ddd;
    border-radius: var(--radius-lg);
    cursor: pointer;
    touch-action: none;
}

.instruction {
    font-size: 1rem;
    color: var(--howmany-text-dim);
    margin-bottom: 0.5rem;
}

/* Guess input area */
.guess-container {
    display: none;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
    margin: 1rem 0;
}

.state-guessing .guess-container {
    display: flex;
}

.guess-input {
    width: 80px;
    padding: 0.75rem 1rem;
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    border: 2px solid var(--howmany-dot);
    border-radius: var(--radius-md);
    background: var(--howmany-canvas);
    color: var(--howmany-text);
    outline: none;
}

.guess-input:focus {
    border-color: #ffe566;
    box-shadow: 0 0 0 3px rgba(255, 217, 61, 0.2);
}

.guess-input::placeholder {
    color: var(--howmany-text-dim);
}

/* Hide spinner buttons */
.guess-input::-webkit-outer-spin-button,
.guess-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.guess-input[type=number] {
    -moz-appearance: textfield;
}

.submit-btn {
    padding: 0.75rem 1.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    background: var(--howmany-dot);
    color: #333;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.submit-btn:hover {
    background: #ffe566;
}

.submit-btn:active {
    transform: scale(0.95);
}

/* Feedback message */
.feedback {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0.5rem 0;
    opacity: 0;
}

.state-result .feedback {
    opacity: 1;
}

.feedback.correct { color: var(--color-excellent); }
.feedback.close { color: var(--howmany-dot); }
.feedback.wrong { color: var(--color-poor); }

/* Score display */
.score {
    font-size: 3rem;
    font-weight: 700;
    margin: 0.5rem 0;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.3s, transform 0.3s;
}

.state-result .score {
    opacity: 1;
    transform: scale(1);
}

.best-score {
    font-size: 1rem;
    color: var(--howmany-text-dim);
    margin-bottom: 0.25rem;
    opacity: 0;
}

.state-result .best-score {
    opacity: 1;
}

.share-container {
    margin: 0.5rem 0;
    opacity: 0;
}

.state-result .share-container {
    opacity: 1;
}

/* Share button styling */
.share-btn {
    background: var(--howmany-dot);
    color: #333;
    border-radius: var(--radius-md);
}

.share-btn:hover {
    background: #ffe566;
}

.hint {
    font-size: 0.85rem;
    color: var(--howmany-text-dim);
    margin-top: 0.25rem;
    opacity: 0;
}

.state-result .hint,
.state-guessing .hint {
    opacity: 1;
}

/* Controls styling */
.controls-inline {
    margin-bottom: 0.5rem;
}

.control-pill {
    background: rgba(255, 217, 61, 0.2);
    color: var(--howmany-text-dim);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.control-pill .touch {
    background: var(--howmany-dot);
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    display: inline-block;
}

/* Hide controls during guessing and result */
.state-guessing .controls-inline,
.state-result .controls-inline {
    display: none;
}

/* New best animation */
.state-result.new-best .score {
    animation: score-pop 0.5s ease-out;
}

@keyframes score-pop {
    0% { transform: scale(0.8); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* Home link */
.home-link {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 1rem;
    background: rgba(255, 217, 61, 0.2);
    color: var(--howmany-text);
    text-decoration: none;
    border-radius: 20px;
    font-size: 0.85rem;
    transition: background 0.2s, transform 0.1s;
    z-index: 10;
}

.home-link:hover {
    background: rgba(255, 217, 61, 0.3);
}

.home-link:active {
    transform: translateX(-50%) scale(0.95);
}

/* Responsive adjustments */
@media (max-width: 400px) {
    .title { font-size: 1.5rem; }
    .score { font-size: 2rem; }
    .canvas-wrapper { max-width: 280px; }
    .feedback { font-size: 1.2rem; }
    .guess-input { width: 70px; font-size: 1.25rem; padding: 0.6rem 0.8rem; }
    .submit-btn { font-size: 1rem; padding: 0.6rem 1.2rem; }
    .how-to-play { padding: 1.5rem; }
}

@media (max-height: 600px) {
    .title { font-size: 1.25rem; margin-bottom: 0.25rem; }
    .canvas-wrapper { max-width: 200px; margin-bottom: 0.5rem; }
    .score { font-size: 1.75rem; margin: 0.25rem 0; }
    .content { padding-bottom: 3rem; }
    .guess-container { margin: 0.5rem 0; }
    .how-to-play { display: none; } /* Hide educational content on short screens */
}

@media (min-height: 800px) {
    .canvas-wrapper { max-width: 400px; }
}

/* How-to-play section styling */
.how-to-play {
    background: rgba(255, 217, 61, 0.1);
    padding: 2rem;
    border-radius: var(--radius-lg);
    margin-top: 2rem;
    text-align: left;
}

.how-to-play h2 {
    color: var(--howmany-text);
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

.how-to-play h3 {
    color: var(--howmany-text);
    font-size: 1.25rem;
    margin: 1.5rem 0 0.75rem;
}

.how-to-play p,
.how-to-play li {
    color: var(--howmany-text-dim);
    line-height: 1.6;
}

.how-to-play ol {
    padding-left: 1.5rem;
    margin: 0.5rem 0;
}

.how-to-play li {
    margin-bottom: 0.5rem;
}

.how-to-play .fun-fact {
    background: rgba(255, 217, 61, 0.2);
    border-left: 4px solid var(--howmany-dot);
    padding: 1rem;
    margin: 1rem 0;
    border-radius: var(--radius-md);
}

.fun-fact strong {
    color: var(--howmany-text);
}

.related-games {
    border-top: 2px solid rgba(255, 217, 61, 0.3);
    padding-top: 1.5rem;
    margin-top: 1.5rem;
}

.related-games h3 {
    color: var(--howmany-text);
    font-size: 1.25rem;
    margin-bottom: 1rem;
}

.related-games-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.related-game-link {
    background: rgba(255, 217, 61, 0.2);
    color: var(--howmany-text);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.2s;
}

.related-game-link:hover {
    background: rgba(255, 217, 61, 0.3);
}

.related-game-emoji {
    font-size: 1.25rem;
}
