:root {
    --howmany-bg: #1a1a2e;
    --howmany-canvas: #16213e;
    --howmany-dot: #FFD93D;
    --howmany-text: #fff;
    --howmany-text-dim: rgba(255, 255, 255, 0.6);
    --color-excellent: #4CAF50;
    --color-good: #FFD93D;
    --color-poor: #FF6B6B;
    --font-main: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
    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-radius: 16px;
    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: 12px;
    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: 12px;
    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;
}

/* Override share button for dark theme */
.share-btn {
    background: var(--howmany-dot);
    color: #333;
}

.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;
}

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

/* Countdown overlay */
.countdown {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    font-weight: 700;
    color: var(--howmany-dot);
    pointer-events: none;
    opacity: 0;
    z-index: 10;
}

.state-countdown .countdown {
    opacity: 1;
    animation: countdown-pulse 0.5s ease-out;
}

@keyframes countdown-pulse {
    0% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
    50% { opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* 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, 255, 255, 0.1);
    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, 255, 255, 0.2);
}

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

/* Round indicator */
.round-indicator {
    font-size: 0.9rem;
    color: var(--howmany-text-dim);
    margin-bottom: 0.25rem;
}

/* Responsive */
@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; }
}

@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; }
}

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