:root {
    --ink: #1a2332;
    --ink-soft: #4a5568;
    --paper: #faf8f5;
    --paper-warm: #f3ede4;
    --accent: #c0392b;
    --accent-soft: #e8d5d3;
    --gold: #b8860b;
    --ok: #1e7e4a;
    --ok-soft: #d4edda;
    --bad: #a93226;
    --bad-soft: #f8d7da;
    --shadow: 0 4px 24px rgba(26, 35, 50, 0.08);
    --radius: 12px;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: "Source Sans 3", system-ui, sans-serif;
    background: var(--paper);
    color: var(--ink);
    line-height: 1.6;
    min-height: 100vh;
}

.bg-kanji {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.bg-kanji span {
    position: absolute;
    font-family: "Noto Sans JP", sans-serif;
    font-weight: 700;
    color: var(--ink);
    opacity: 0.04;
    user-select: none;
}

.bg-kanji span:nth-child(1) { top: 6%;  right: 8%;  font-size: clamp(5rem, 16vw, 12rem); }
.bg-kanji span:nth-child(2) { bottom: 10%; left: 5%; font-size: clamp(4rem, 12vw, 9rem); }
.bg-kanji span:nth-child(3) { top: 38%; left: 52%; font-size: clamp(3.5rem, 9vw, 7rem); opacity: 0.025; }

.page {
    position: relative;
    z-index: 1;
    max-width: 720px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid rgba(26, 35, 50, 0.08);
    margin-bottom: 2.5rem;
}

.logo {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.02em;
    color: var(--ink);
    text-decoration: none;
}

.logo em {
    font-style: normal;
    color: var(--accent);
}

.logo-jp {
    font-family: "Noto Sans JP", sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--ink-soft);
    margin-left: 0.5rem;
}

.back-link {
    font-size: 0.9rem;
    color: var(--ink-soft);
    text-decoration: none;
    transition: color 0.2s;
}

.back-link:hover { color: var(--accent); }

.hero {
    text-align: center;
    margin-bottom: 2rem;
}

.hero-badge {
    display: inline-block;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gold);
    background: rgba(184, 134, 11, 0.1);
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    margin-bottom: 1rem;
}

.hero h1 {
    font-size: clamp(1.85rem, 4.5vw, 2.5rem);
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.75rem;
    letter-spacing: -0.02em;
}

.hero p {
    font-size: 1.05rem;
    color: var(--ink-soft);
    max-width: 28rem;
    margin: 0 auto;
}

.board {
    background: #fff;
    border: 1px solid rgba(26, 35, 50, 0.07);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.75rem;
    margin-bottom: 2.5rem;
    transition: box-shadow 0.25s, transform 0.25s;
}

.board--flash-ok {
    box-shadow: 0 0 0 3px rgba(30, 126, 74, 0.25), var(--shadow);
}

.board--flash-bad {
    animation: shake 0.35s ease;
    box-shadow: 0 0 0 3px rgba(169, 50, 38, 0.2), var(--shadow);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

.screen h2 {
    font-size: 1.25rem;
    margin-bottom: 1.25rem;
    text-align: center;
}

.start-grid {
    display: grid;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.mode-card {
    background: var(--paper-warm);
    border-radius: 10px;
    padding: 1.25rem;
}

.mode-card h3 {
    font-size: 1.05rem;
    margin-bottom: 0.35rem;
}

.mode-card p {
    font-size: 0.92rem;
    color: var(--ink-soft);
    margin-bottom: 1rem;
}

.level-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.level-legend {
    list-style: none;
    font-size: 0.88rem;
    color: var(--ink-soft);
    border-top: 1px solid rgba(26, 35, 50, 0.08);
    padding-top: 1rem;
}

.speak-option {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    padding: 1rem 1.1rem;
    background: #fff;
    border: 1px solid rgba(26, 35, 50, 0.1);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.speak-option:hover {
    border-color: rgba(192, 57, 43, 0.35);
}

.speak-option input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.speak-option-box {
    flex-shrink: 0;
    width: 1.25rem;
    height: 1.25rem;
    margin-top: 0.15rem;
    border: 2px solid rgba(26, 35, 50, 0.25);
    border-radius: 4px;
    background: #fff;
    position: relative;
    transition: background 0.15s, border-color 0.15s;
}

.speak-option input:checked + .speak-option-box {
    background: var(--accent);
    border-color: var(--accent);
}

.speak-option input:checked + .speak-option-box::after {
    content: '';
    position: absolute;
    left: 0.28rem;
    top: 0.05rem;
    width: 0.35rem;
    height: 0.65rem;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.speak-option input:disabled + .speak-option-box {
    opacity: 0.4;
}

.speak-option-text {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.speak-option-text strong {
    font-size: 0.95rem;
}

.speak-option-text small {
    font-size: 0.82rem;
    color: var(--ink-soft);
    line-height: 1.4;
}

.level-legend li + li {
    margin-top: 0.35rem;
}

.btn {
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    border-radius: 8px;
    padding: 0.6rem 1rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s, color 0.2s;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn--primary {
    background: var(--accent);
    color: #fff;
}

.btn--primary:hover { background: #a93226; }

.btn--ghost {
    background: #fff;
    color: var(--ink);
    border: 1px solid rgba(26, 35, 50, 0.12);
}

.btn--ghost:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.hud {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.hud-item {
    text-align: center;
    background: var(--paper-warm);
    border-radius: 8px;
    padding: 0.5rem 0.35rem;
}

.hud-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-soft);
}

.hud-value {
    font-size: 1.15rem;
    font-weight: 700;
}

.hud-lives {
    display: flex;
    justify-content: center;
    gap: 0.15rem;
    font-size: 1.1rem;
    line-height: 1.4;
}

.life--full { color: var(--accent); }
.life--empty { color: rgba(26, 35, 50, 0.15); }

.mode-label {
    text-align: center;
    font-size: 0.85rem;
    color: var(--ink-soft);
    margin-bottom: 1rem;
}

.question {
    text-align: center;
    margin-bottom: 1.5rem;
}

.question-char-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    min-height: 1.2em;
}

.btn-replay[hidden] {
    display: none !important;
}

.btn-replay {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border: 2px solid rgba(26, 35, 50, 0.12);
    border-radius: 50%;
    background: var(--paper-warm);
    color: var(--accent);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.btn-replay:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    transform: scale(1.05);
}

.question-prompt {
    font-size: 0.95rem;
    color: var(--ink-soft);
    margin-bottom: 0.75rem;
}

.question-char {
    font-family: "Noto Sans JP", sans-serif;
    font-size: clamp(4rem, 18vw, 6.5rem);
    font-weight: 700;
    line-height: 1.1;
    color: var(--ink);
    min-height: 1.2em;
}

.question-char--romaji {
    font-family: "Source Sans 3", system-ui, sans-serif;
    font-size: clamp(2.5rem, 10vw, 4rem);
    letter-spacing: 0.04em;
    text-transform: lowercase;
    color: var(--accent);
}

.choices {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.choice-btn {
    font: inherit;
    font-family: "Noto Sans JP", sans-serif;
    font-size: clamp(1.25rem, 4vw, 1.65rem);
    font-weight: 500;
    background: var(--paper);
    border: 2px solid rgba(26, 35, 50, 0.1);
    border-radius: 10px;
    padding: 1rem 0.75rem;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.choice-btn:hover:not(:disabled) {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.choice-btn:disabled { cursor: default; }

.choice-btn--correct {
    background: var(--ok-soft);
    border-color: var(--ok);
    color: var(--ok);
}

.choice-btn--wrong {
    background: var(--bad-soft);
    border-color: var(--bad);
    color: var(--bad);
}

.feedback {
    min-height: 1.5rem;
    text-align: center;
    font-weight: 600;
    margin-top: 1rem;
}

.feedback--ok { color: var(--ok); }
.feedback--bad { color: var(--bad); }

.play-actions {
    display: flex;
    justify-content: center;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(26, 35, 50, 0.08);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.end-score {
    text-align: center;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent);
    margin: 0.5rem 0 1rem;
}

.end-stats {
    list-style: none;
    text-align: center;
    color: var(--ink-soft);
    margin-bottom: 1rem;
}

.end-stats li + li { margin-top: 0.35rem; }

.end-missed {
    margin-bottom: 1.25rem;
    padding: 1.25rem;
    background: var(--bad-soft);
    border-radius: 10px;
    border: 1px solid rgba(169, 50, 38, 0.15);
}

.end-missed h3 {
    font-size: 0.95rem;
    text-align: center;
    color: var(--bad);
    margin-bottom: 0.85rem;
}

.missed-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.6rem;
}

.missed-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 3.5rem;
    background: #fff;
    border: 1px solid rgba(169, 50, 38, 0.2);
    border-radius: 8px;
    padding: 0.5rem 0.65rem;
}

.missed-kana {
    font-family: "Noto Sans JP", sans-serif;
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--ink);
}

.missed-romaji {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--bad);
    text-transform: lowercase;
    margin-top: 0.15rem;
}

.end-best {
    text-align: center;
    font-size: 0.92rem;
    color: var(--gold);
    font-weight: 600;
    margin-bottom: 1.25rem;
}

.end-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
}

footer {
    text-align: center;
    font-size: 0.85rem;
    color: var(--ink-soft);
    padding-top: 1.5rem;
    border-top: 1px solid rgba(26, 35, 50, 0.08);
}

footer a {
    color: var(--accent);
    text-decoration: none;
}

footer a:hover { text-decoration: underline; }

@media (max-width: 540px) {
    .hud {
        grid-template-columns: repeat(2, 1fr);
    }

    .choices {
        grid-template-columns: 1fr;
    }
}
