/* MathKids - 전두엽 기능 저하 아동을 위한 수학 앱 CSS */

:root {
    --primary: #4A90D9;
    --primary-dark: #357ABD;
    --secondary: #F5A623;
    --success: #7ED321;
    --error: #D0021B;
    --bg: #F8F9FA;
    --card-bg: #FFFFFF;
    --text: #333333;
    --text-light: #666666;
    --border: #E0E0E0;

    /* 5단위 청킹 색상 */
    --chunk-blue: #4A90D9;
    --chunk-orange: #F5A623;

    /* Spacing */
    --gap: clamp(16px, 4vw, 24px);
    --padding: clamp(16px, 4vw, 32px);
    --radius: 16px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100dvh;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    touch-action: manipulation;
}

/* ============ Screens ============ */
.screen {
    position: fixed;
    inset: 0;
    display: none !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--padding);
    gap: var(--gap);
    overflow-y: auto;
    background: var(--bg);
    z-index: 1;
}

.screen.active {
    display: flex !important;
}

/* ============ Cards ============ */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: clamp(24px, 5vw, 32px) clamp(20px, 4vw, 28px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 400px;
}

/* ============ Forms ============ */
.form-group {
    margin-bottom: clamp(20px, 4vw, 24px);
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
    font-size: clamp(14px, 3.5vw, 16px);
}

.form-group input {
    width: 100%;
    padding: clamp(14px, 3vw, 18px) clamp(12px, 3vw, 16px);
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: clamp(16px, 4vw, 18px);
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ============ Buttons ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: clamp(12px, 3vw, 16px) clamp(20px, 4vw, 28px);
    border: none;
    border-radius: 12px;
    font-size: clamp(16px, 4vw, 18px);
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
    -webkit-user-select: none;
    user-select: none;
}

.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--border);
    color: var(--text);
}

.btn-full {
    width: 100%;
}

.btn-large {
    padding: clamp(16px, 4vw, 20px) clamp(32px, 6vw, 48px);
    font-size: clamp(18px, 4.5vw, 22px);
}

.btn-text {
    background: transparent;
    color: var(--text-light);
    padding: 8px 16px;
}

.btn-icon {
    background: var(--card-bg);
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.btn-icon-small {
    background: rgba(255,255,255,0.2);
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
}

.btn-back {
    background: transparent;
    color: var(--primary);
    padding: 8px 0;
}

.btn-row {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.btn-row .btn {
    flex: 1;
}

.btn-column {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ============ Toast (TOP position) ============ */
.toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: var(--text);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 9999;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.error {
    background: var(--error);
}

.toast.success {
    background: var(--success);
}

/* ============ Loading Screen ============ */
.loading-screen {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}

.loading-content {
    text-align: center;
}

.loading-icon {
    font-size: clamp(64px, 15vw, 96px);
    margin-bottom: 16px;
    animation: bounce 1s ease infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.loading-content h1 {
    font-size: clamp(28px, 7vw, 36px);
    margin-bottom: 8px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 24px auto 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============ Auth Screen ============ */
.auth-card {
    text-align: center;
}

.auth-header {
    margin-bottom: 32px;
}

.auth-icon {
    font-size: 56px;
    margin-bottom: 12px;
}

.auth-header h1 {
    font-size: 28px;
    color: var(--primary);
}

.auth-header p {
    color: var(--text-light);
    margin-top: 8px;
}

.auth-form.hidden {
    display: none;
}

.auth-switch {
    margin-top: 24px;
    color: var(--text-light);
    font-size: 14px;
}

.auth-switch a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

/* ============ Children Grid ============ */
.children-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.child-card {
    background: var(--bg);
    border: 3px solid transparent;
    border-radius: 16px;
    padding: 20px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.1s;
}

.child-card:active {
    transform: scale(0.96);
}

.child-card.active {
    border-color: var(--primary);
}

.child-avatar {
    font-size: 48px;
    margin-bottom: 8px;
}

.child-name {
    font-weight: 600;
    font-size: 16px;
}

.child-stars {
    color: var(--secondary);
    font-size: 14px;
    margin-top: 4px;
}

/* ============ Avatar Grid ============ */
.avatar-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.avatar-option {
    font-size: 36px;
    padding: 12px;
    border: 3px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: border-color 0.2s;
    text-align: center;
}

.avatar-option.selected {
    border-color: var(--primary);
    background: rgba(74, 144, 217, 0.1);
}

/* ============ Home Screen ============ */
.home-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 400px;
    padding: 16px;
    background: var(--card-bg);
    border-radius: var(--radius);
}

.child-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-large {
    font-size: 40px;
}

.home-stats .stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 20px;
    font-weight: 600;
}

.home-content {
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
}

.daily-status {
    background: var(--card-bg);
    padding: 16px 32px;
    border-radius: var(--radius);
}

.time-remaining {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: clamp(24px, 6vw, 32px);
    font-weight: 700;
    color: var(--primary);
}

.btn-play {
    background: linear-gradient(135deg, var(--success) 0%, #6BC11A 100%);
    color: white;
    padding: clamp(24px, 5vw, 32px) clamp(48px, 10vw, 64px);
    font-size: clamp(24px, 5vw, 28px);
    border-radius: 24px;
    box-shadow: 0 8px 24px rgba(126, 211, 33, 0.4);
}

.play-icon {
    font-size: 32px;
}

.session-ended {
    text-align: center;
}

.session-ended p {
    font-size: 18px;
    margin-bottom: 12px;
}

.home-footer {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 400px;
    justify-content: center;
}

.screen-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 24px;
}

/* ============ Game Screen ============ */
#game-screen {
    background: linear-gradient(180deg, #E8F4FD 0%, var(--bg) 100%);
    padding: 0;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 16px 20px;
    background: var(--primary);
    color: white;
}

.game-timer {
    font-size: 20px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.game-progress {
    font-size: 16px;
}

.game-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--padding);
    width: 100%;
    max-width: 500px;
}

.question-text {
    font-size: clamp(20px, 5vw, 28px);
    font-weight: 600;
    text-align: center;
    margin-bottom: 24px;
    color: var(--text);
}

/* Visual Areas */
.visual-area {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 24px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: var(--radius);
    min-height: 100px;
}

.visual-item {
    font-size: clamp(28px, 7vw, 40px);
    transition: transform 0.2s;
}

.visual-item.crossed {
    opacity: 0.3;
    text-decoration: line-through;
}

/* 5단위 청킹 */
.visual-item.group-1 {
    filter: drop-shadow(0 0 2px var(--chunk-blue));
}

.visual-item.group-2 {
    filter: drop-shadow(0 0 2px var(--chunk-orange));
}

.visual-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 12px;
    border-radius: 12px;
    margin: 4px;
}

.visual-group.blue {
    background: rgba(74, 144, 217, 0.15);
    border: 2px dashed var(--chunk-blue);
}

.visual-group.orange {
    background: rgba(245, 166, 35, 0.15);
    border: 2px dashed var(--chunk-orange);
}

/* Ten Frame */
.ten-frame {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    padding: 16px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 3px solid var(--border);
}

.ten-frame-cell {
    width: clamp(36px, 8vw, 48px);
    height: clamp(36px, 8vw, 48px);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(20px, 5vw, 28px);
    border: 2px solid var(--border);
}

.ten-frame-cell.filled {
    background: var(--chunk-blue);
    border-color: var(--chunk-blue);
}

.ten-frame-cell.empty {
    background: white;
}

/* Number Line */
.numberline {
    width: 100%;
    max-width: 350px;
    padding: 20px 16px;
    background: var(--card-bg);
    border-radius: 12px;
}

.numberline-track {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    position: relative;
    margin: 30px 0;
}

.numberline-marker {
    position: absolute;
    top: -24px;
    transform: translateX(-50%);
    font-size: 24px;
}

.numberline-labels {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    color: var(--text-light);
    position: relative;
    height: 20px;
}

.numberline-labels span {
    position: absolute;
    transform: translateX(-50%);
    white-space: nowrap;
}

/* Equation Display */
.equation-display {
    font-size: clamp(32px, 8vw, 48px);
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    margin: 20px 0;
}

/* Game Options */
.game-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: clamp(12px, 3vw, 16px);
    padding: var(--padding);
    width: 100%;
    max-width: 400px;
}

.option-btn {
    padding: clamp(20px, 4vw, 28px);
    font-size: clamp(24px, 6vw, 32px);
    font-weight: 700;
    background: var(--card-bg);
    border: 3px solid var(--border);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s;
}

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

.option-btn.correct {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

.option-btn.wrong {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

.hint-area {
    padding: 16px;
}

.btn-hint {
    background: rgba(74, 144, 217, 0.1);
    color: var(--primary);
    border: 2px solid var(--primary);
}

.hint-text {
    background: rgba(245, 166, 35, 0.1);
    padding: 12px 20px;
    border-radius: 12px;
    color: var(--secondary);
    font-size: 16px;
    text-align: center;
    margin-top: 8px;
}

/* ============ Result Screen ============ */
#result-screen {
    background: linear-gradient(180deg, #E8F4FD 0%, var(--bg) 100%);
}

.result-content {
    text-align: center;
}

.result-icon {
    font-size: clamp(80px, 20vw, 120px);
    margin-bottom: 16px;
    animation: pop 0.5s ease;
}

@keyframes pop {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.result-content h2 {
    font-size: clamp(28px, 7vw, 36px);
    margin-bottom: 12px;
}

.result-content p {
    color: var(--text-light);
    font-size: 18px;
    margin-bottom: 32px;
}

.reward-area {
    background: linear-gradient(135deg, #FFF9E6 0%, #FFF3CC 100%);
    padding: 20px;
    border-radius: 16px;
    margin-bottom: 24px;
}

.reward-sticker {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 600;
}

#reward-emoji {
    font-size: 40px;
    animation: bounce 0.5s ease;
}

/* ============ Stickers Screen ============ */
.screen-header {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    max-width: 400px;
    margin-bottom: 16px;
}

.screen-header h2 {
    flex: 1;
    text-align: center;
    margin-right: 40px;
}

.stickers-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    width: 100%;
    max-width: 400px;
}

.sticker-item {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--card-bg);
    border-radius: 12px;
    padding: 12px;
    font-size: 32px;
}

.sticker-item.locked {
    opacity: 0.3;
    filter: grayscale(1);
}

.sticker-name {
    font-size: 11px;
    margin-top: 4px;
    color: var(--text-light);
}

/* ============ Progress Screen ============ */
.progress-content {
    width: 100%;
    max-width: 400px;
}

.progress-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.progress-card h3 {
    font-size: 16px;
    color: var(--text-light);
    margin-bottom: 12px;
}

.progress-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.progress-stat:last-child {
    border-bottom: none;
}

.progress-bar-container {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* ============ Settings Screen ============ */
.time-buttons {
    display: flex;
    gap: 12px;
}

.time-btn {
    flex: 1;
    padding: 16px;
    background: var(--bg);
    border: 2px solid var(--border);
}

.time-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ============ Modals ============ */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 32px 28px;
    width: 100%;
    max-width: 320px;
    text-align: center;
}

.modal-content h3 {
    margin-bottom: 20px;
    font-size: 20px;
}

.modal-content input {
    width: 100%;
    padding: 16px;
    font-size: 24px;
    text-align: center;
    letter-spacing: 8px;
    border: 2px solid var(--border);
    border-radius: 12px;
    margin-bottom: 20px;
}

/* ============ Help Screen ============ */
.help-content {
    width: 100%;
    max-width: 500px;
    padding: 0 16px 32px;
    overflow-y: auto;
}

.help-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 16px;
}

.help-section h3 {
    font-size: 18px;
    color: var(--primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.help-section p {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    margin-bottom: 8px;
}

.help-section ol,
.help-section ul {
    padding-left: 24px;
    margin: 12px 0;
}

.help-section li {
    font-size: 15px;
    line-height: 1.8;
    color: var(--text);
    margin-bottom: 6px;
}

.help-section strong {
    color: var(--primary-dark);
}

.help-section a {
    color: var(--primary);
    text-decoration: none;
}

.help-section a:hover {
    text-decoration: underline;
}

/* ============ Utilities ============ */
.hidden {
    display: none !important;
}

/* ============ Small Phones ============ */
@media (max-height: 667px) {
    .loading-icon {
        font-size: 56px;
    }

    .btn-play {
        padding: 20px 40px;
    }

    .game-content {
        padding: 12px;
    }

    .visual-item {
        font-size: 28px;
    }

    .option-btn {
        padding: 16px;
        font-size: 24px;
    }
}

@media (max-height: 568px) {
    .home-content {
        gap: 16px;
    }

    .daily-status {
        padding: 12px 24px;
    }

    .time-remaining {
        font-size: 24px;
    }

    .btn-play {
        padding: 16px 32px;
        font-size: 20px;
    }

    .result-icon {
        font-size: 64px;
    }
}

/* Safe Area (notch) */
@supports (padding: max(0px)) {
    .game-header {
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .home-footer {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}
