:root {
    --ink: #1a1a1a;
    --paper: #fbfaf7;
    --paper-edge: #ece8df;
    --paper-deep: #f3f0e8;
    --accent: #b14545;
    --accent-ink: #fff;
    --good: #2e7d4f;
    --bad:  #b14545;
    --muted: #6a6a6a;
    --rating-again: #c0392b;
    --rating-hard:  #d97e29;
    --rating-good:  #2e7d4f;
    --rating-easy:  #2867c1;
    --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.04);
    --shadow-lift: 0 2px 4px rgba(0,0,0,.06), 0 16px 40px rgba(0,0,0,.06);
    --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
                 "Yu Gothic UI", system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

body {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 24px;
    border-bottom: 1px solid var(--paper-edge);
}

.brand {
    font-size: 22px;
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
    letter-spacing: .02em;
}

.topnav {
    display: flex;
    align-items: center;
    gap: 18px;
}
.topnav a {
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
}
.topnav a:hover { color: var(--ink); }

.logout button {
    background: transparent;
    border: 1px solid var(--paper-edge);
    color: var(--muted);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 13px;
    cursor: pointer;
}
.logout button:hover { color: var(--ink); border-color: var(--ink); }

.container {
    flex: 1;
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    padding: 32px 20px 64px;
}

h1 { font-weight: 600; letter-spacing: -.01em; }

.card {
    background: #fff;
    border: 1px solid var(--paper-edge);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}

/* ============== Login ============== */

.login-card {
    max-width: 380px;
    margin: 48px auto;
}

.login-card label { display: block; margin-bottom: 14px; }
.login-card label span {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 4px;
}

input[type="text"], input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--paper-edge);
    border-radius: 8px;
    font-size: 16px;
    background: var(--paper);
}
input:focus { outline: none; border-color: var(--ink); }

button[type="submit"] {
    width: 100%;
    margin-top: 12px;
    padding: 12px 16px;
    background: var(--ink);
    color: var(--accent-ink);
    border: 0;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
}
button[type="submit"]:hover { background: var(--accent); }

.error {
    background: #fde9e9;
    color: #8c2020;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    margin: 0 0 14px;
}

/* ============== Dashboard ============== */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 24px 0 28px;
}

.stat {
    background: #fff;
    border: 1px solid var(--paper-edge);
    border-radius: var(--radius);
    padding: 18px;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-value { display: block; font-size: 32px; font-weight: 600; line-height: 1.1; }
.stat-label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-top: 4px;
}

.actions { display: flex; gap: 10px; margin: 8px 0 18px; }

.btn {
    flex: 1;
    padding: 14px 18px;
    border-radius: 12px;
    text-align: center;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 15px;
    font-family: inherit;
    line-height: 1.2;
}

.btn.primary { background: var(--ink); color: var(--accent-ink); width: 100%; }
.btn.primary:hover { background: var(--accent); }

.btn.ghost {
    background: transparent;
    color: var(--ink);
    border-color: var(--paper-edge);
    width: 100%;
}
.btn.ghost:hover { border-color: var(--ink); }

.btn.disabled { opacity: .4; pointer-events: none; }

.empty-note {
    margin-top: 18px;
    color: var(--muted);
    font-size: 14px;
}
.empty-note a { color: var(--ink); }

/* ============== Lessons list ============== */

.lessons h1 { margin-top: 0; }

.lesson-list {
    list-style: none;
    padding: 0;
    margin: 24px 0 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.lesson-item {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    align-items: center;
    gap: 14px;
    background: #fff;
    border: 1px solid var(--paper-edge);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
}

.lesson-item.lesson-locked { opacity: .55; }
.lesson-item.lesson-completed { background: var(--paper-deep); }

.lesson-ordinal {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--muted);
    font-size: 14px;
}
.lesson-title { margin: 0; font-size: 16px; font-weight: 500; }
.lesson-meta { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.status-available { color: var(--accent); font-weight: 500; }
.status-completed { color: var(--good); }
.status-locked    { color: var(--muted); }

.lesson-action .btn { padding: 8px 16px; font-size: 14px; min-width: 88px; }
.lock-icon { font-size: 18px; opacity: .6; }

.back-link {
    display: inline-block;
    color: var(--muted);
    text-decoration: none;
    margin-bottom: 14px;
    font-size: 14px;
}
.back-link:hover { color: var(--ink); }

/* ============== Lesson detail (md body) ============== */

.lesson-body-md {
    background: #fff;
    border: 1px solid var(--paper-edge);
    border-radius: var(--radius);
    padding: 24px 28px;
    box-shadow: var(--shadow);
    margin: 24px 0;
}
.lesson-body-md p { margin: 0 0 12px; }
.lesson-body-md ul { padding-left: 22px; margin: 0 0 12px; }
.lesson-body-md li { margin: 4px 0; }
.lesson-body-md strong { font-weight: 600; }
.lesson-body-md em { font-style: italic; color: #444; }
.lesson-body-md code {
    background: var(--paper-deep);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: .92em;
}

.lesson-cta { margin-top: 20px; }
.lesson-cta .btn { width: 100%; }

/* ============== Review ============== */

.review-shell { padding-top: 8px; }

.review-card {
    box-shadow: var(--shadow-lift);
}

.kana-display {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 220px;
    margin-bottom: 24px;
    background: var(--paper-deep);
    border-radius: var(--radius);
    border: 1px dashed var(--paper-edge);
}

.kana-char {
    font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Noto Sans JP", sans-serif;
    font-size: 144px;
    font-weight: 400;
    line-height: 1;
    color: var(--ink);
    letter-spacing: -.04em;
}

.guess-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.guess-label span {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 6px;
}

.guess-label input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--paper-edge);
    border-radius: 10px;
    font-size: 22px;
    background: var(--paper);
    text-align: center;
    letter-spacing: .04em;
}

.guess-form .btn { padding: 12px 16px; font-size: 15px; width: 100%; }
.guess-form .btn.ghost { margin-top: 4px; }

.reveal { display: flex; flex-direction: column; gap: 16px; }

.verdict {
    margin: 0;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 15px;
}
.verdict.good { background: #e9f6ee; color: var(--good); }
.verdict.bad  { background: #fde9e9; color: var(--bad); }
.verdict.neutral { background: var(--paper-deep); color: var(--ink); }
.verdict strong { font-weight: 600; }

.audio-btn {
    align-self: flex-start;
    width: auto;
    background: var(--paper-deep);
    border: 1px solid var(--paper-edge);
    color: var(--ink);
    padding: 8px 14px;
    font-size: 14px;
    border-radius: 999px;
    flex: 0 0 auto;
}
.audio-btn:hover { border-color: var(--ink); }

.rating-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 4px;
}
.rating-form { margin: 0; }
.btn.rating {
    width: 100%;
    flex: 1;
    padding: 12px 8px;
    color: #fff;
    border-radius: 10px;
    border: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin: 0;
}
.btn.rating .rating-label { font-size: 14px; font-weight: 500; }
.btn.rating .rating-key {
    font-size: 11px;
    opacity: .7;
    background: rgba(255,255,255,.18);
    padding: 1px 7px;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.btn.rating-1 { background: var(--rating-again); }
.btn.rating-2 { background: var(--rating-hard);  }
.btn.rating-3 { background: var(--rating-good);  }
.btn.rating-4 { background: var(--rating-easy);  }
.btn.rating:hover { filter: brightness(1.06); }

.done-card { text-align: center; padding: 40px 28px; }
.done-card h1 { margin-top: 0; }
.done-card .actions { justify-content: center; }

/* ============== Responsive ============== */

@media (max-width: 480px) {
    .container { padding: 24px 16px 56px; }
    .stat-grid { gap: 8px; }
    .stat-value { font-size: 26px; }
    .actions { flex-direction: column; }
    .kana-char { font-size: 112px; }
    .kana-display { min-height: 180px; }
    .rating-strip { gap: 6px; }
    .btn.rating { padding: 10px 4px; }
    .btn.rating .rating-label { font-size: 13px; }
    .lesson-item { grid-template-columns: 28px 1fr auto; gap: 10px; padding: 12px; }
    .lesson-title { font-size: 15px; }
}
