@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700;800;900&display=swap');

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

body {
    font-family: 'Nunito', system-ui, sans-serif;
    background: linear-gradient(145deg, #2b8045 0%, #145228 100%);
    min-height: 100vh;
    color: #1e2b22;
    -webkit-font-smoothing: antialiased;
}

/* ── Return bar ──────────────────────────────────────────────────────────── */
.return-bar {
    background: rgba(0,0,0,0.2);
    text-align: center;
    padding: 10px;
}
.return-bar a {
    color: rgba(255,255,255,0.82);
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
}
.return-bar a:hover { color: #fff; text-decoration: underline; }

/* ── Screen system ───────────────────────────────────────────────────────── */
.screen {
    display: none;
    min-height: calc(100vh - 42px);
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.screen.active { display: flex; }

.card {
    background: #fff;
    border-radius: 18px;
    padding: 2.5rem 2rem;
    box-shadow: 0 16px 48px rgba(0,0,0,0.22);
    max-width: 800px;
    width: 100%;
    text-align: center;
}

/* ── Start menu ──────────────────────────────────────────────────────────── */
.game-title {
    font-size: clamp(2rem, 6vw, 3rem);
    font-weight: 900;
    margin-bottom: 0.3rem;
    background: linear-gradient(135deg, #2b8045, #145228);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.game-subtitle {
    color: #607060;
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 2rem;
}
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 240px;
    margin: 0 auto 1.5rem;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    padding: 12px 26px;
    border: none;
    border-radius: 30px;
    font-size: 0.97rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.btn-primary {
    background: linear-gradient(135deg, #3a9952, #1e6635);
    color: #fff;
}
.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(42,128,69,0.4);
}
.btn-primary:disabled {
    background: #d1d5db;
    color: #9ca3af;
    cursor: not-allowed;
}
.btn-secondary {
    background: #f0f5f1;
    color: #2b5c39;
    border: 2px solid #c5dac9;
    font-weight: 700;
}
.btn-secondary:hover { background: #e0efE5; transform: translateY(-1px); }
.btn-small { padding: 7px 14px; font-size: 0.82rem; }

/* ── Instructions ────────────────────────────────────────────────────────── */
.instructions-content {
    text-align: left;
    max-width: 560px;
    margin: 0 auto 2rem;
    color: #374151;
    line-height: 1.75;
}
.instructions-content p { margin-bottom: 0.75rem; font-weight: 600; }
.instructions-content ul { margin-left: 1.5rem; margin-bottom: 0.75rem; }
.instructions-content li { margin-bottom: 0.4rem; font-weight: 500; }

/* ── Letter selection ────────────────────────────────────────────────────── */
.selection-info {
    color: #607060;
    font-size: 0.92rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
}
.row-group {
    margin-bottom: 0.75rem;
    border: 1.5px solid #c5dac9;
    border-radius: 12px;
    overflow: hidden;
    text-align: left;
}
.row-group-header {
    background: #f3f8f4;
    padding: 7px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #c5dac9;
}
.row-group-label {
    font-size: 0.75rem;
    font-weight: 800;
    color: #607060;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}
.btn-toggle-row {
    background: none;
    border: 1.5px solid #c5dac9;
    border-radius: 20px;
    font-size: 0.7rem;
    padding: 2px 8px;
    cursor: pointer;
    color: #607060;
    font-weight: 700;
    font-family: inherit;
    transition: background 0.15s;
}
.btn-toggle-row:hover { background: #e0efE5; color: #1e3d2a; }
.row-group-chars {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 5px;
    padding: 8px;
    background: #fff;
}
.char-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 9px;
    border: 1.5px solid #e0ece2;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.char-item:hover { background: #f0faf2; border-color: #3a9952; }
.char-item input[type="checkbox"] { transform: scale(1.2); accent-color: #3a9952; }
.jp-char {
    font-size: 1.3rem;
    font-weight: 800;
    min-width: 22px;
    text-align: center;
    line-height: 1;
    color: #1e3d2a;
}
.char-name { font-size: 0.78rem; color: #607060; font-weight: 600; }

.selection-controls {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin: 0.9rem 0;
    flex-wrap: wrap;
}
.selection-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding-top: 0.9rem;
    border-top: 1.5px solid #f0f5f1;
}
.count-display {
    font-weight: 800;
    color: #3a9952;
    font-size: 0.95rem;
}

/* ── Game screen ─────────────────────────────────────────────────────────── */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding: 0.9rem 1rem;
    background: #f3f8f4;
    border-radius: 12px;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.score-display {
    font-size: 1rem;
    font-weight: 800;
    color: #2b8045;
}
.progress-display {
    font-size: 0.85rem;
    color: #607060;
    font-weight: 600;
}
.game-controls { display: flex; gap: 6px; }

.jp-letter-display {
    font-size: clamp(5rem, 15vw, 7rem);
    font-weight: 900;
    margin-bottom: 1.25rem;
    color: #1e2b22;
    text-align: center;
    padding: 1.25rem;
    background: #f3f8f4;
    border-radius: 16px;
    border: 3px solid #3a9952;
    line-height: 1.1;
}

.choices {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    max-width: 460px;
    margin: 0 auto;
}
.choice-btn {
    padding: 16px;
    border: 2px solid #c5dac9;
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 700;
    font-family: inherit;
    transition: all 0.18s;
    color: #1e2b22;
}
.choice-btn:hover:not(:disabled) {
    border-color: #3a9952;
    background: #f0faf2;
    color: #1e3d2a;
    transform: translateY(-1px);
}
.choice-btn.correct {
    background: #dcfce7;
    border-color: #16a34a;
    color: #14532d;
}
.choice-btn.incorrect {
    background: #fee2e2;
    border-color: #dc2626;
    color: #7f1d1d;
}
.choice-btn:disabled { cursor: not-allowed; }

.feedback {
    margin-top: 0.85rem;
    padding: 10px 14px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.95rem;
}
.feedback.success { background: #dcfce7; color: #14532d; border: 1.5px solid #bbf7d0; }
.feedback.error   { background: #fee2e2; color: #7f1d1d; border: 1.5px solid #fecaca; }
.feedback.info    { background: #e0f2fe; color: #0c4a6e; border: 1.5px solid #bae6fd; }
.feedback.hidden  { display: none; }

/* ── Progress bar ────────────────────────────────────────────────────────── */
.progress-bar-wrap {
    height: 7px;
    background: #e0ece2;
    border-radius: 4px;
    margin-bottom: 1.25rem;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #3a9952, #6fcf84);
    border-radius: 4px;
    transition: width 0.35s ease;
}

/* ── Results ─────────────────────────────────────────────────────────────── */
.results-content { margin-bottom: 1.75rem; }
.final-score { margin-bottom: 0.75rem; }
.score-label { display: block; font-size: 0.95rem; color: #607060; font-weight: 600; margin-bottom: 0.25rem; }
.score-value { font-size: 3.5rem; font-weight: 900; color: #2b8045; line-height: 1; }
.score-total { font-size: 1rem; color: #607060; font-weight: 600; }
.performance { font-size: 1.1rem; margin: 0.75rem 0; font-weight: 700; }
.results-actions { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal.open { display: flex; }
.modal-content {
    background: #fff;
    border-radius: 18px;
    padding: 2rem;
    max-width: 440px;
    width: 100%;
    position: relative;
    box-shadow: 0 24px 64px rgba(0,0,0,0.28);
}
.modal-close {
    position: absolute;
    top: 14px; right: 18px;
    font-size: 1.4rem;
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    line-height: 1;
}
.modal-close:hover { color: #374151; }
.modal-content h2 { margin-bottom: 1rem; font-size: 1.25rem; font-weight: 800; }
.about-text { text-align: left; line-height: 1.75; color: #374151; font-weight: 500; }
.about-text p { margin-bottom: 0.75rem; }

.copyright { margin-top: 1.5rem; font-size: 0.8rem; color: #9ca3af; font-weight: 600; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .card { padding: 1.5rem 1rem; border-radius: 14px; }
    .choices { grid-template-columns: 1fr; }
    .game-header { flex-direction: column; text-align: center; }
    .selection-footer { flex-direction: column; align-items: stretch; text-align: center; }
    .row-group-chars { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}
