:root {
    --teal: #26BFBF;
    --teal-dark: #1fa5a5;
    --teal-light: #e6f7f7;
    --bg: #f5f2ea;
    --fg: #1a1a1a;
    --muted: #6b6b6b;
    --border: #e0e0e0;
    --card-bg: #fafafa;
    --paper: #fffef7;
    --paper-edge: rgba(0,0,0,0.09);
    --success: #2e7d32;
    --success-bg: #e8f5e9;
    --warn: #ef6c00;
    --warn-bg: #fff3e0;
    --error: #c62828;
    --error-bg: #ffebee;
    --shadow: 0 2px 6px rgba(0,0,0,0.08);
    --card-shadow: 0 6px 14px rgba(0,0,0,0.10), 0 1px 3px rgba(0,0,0,0.06);
    --card-shadow-sm: 0 3px 8px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    color: var(--fg);
    background: var(--bg);
    -webkit-text-size-adjust: 100%;
    min-height: 100vh;
}

#app {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: env(safe-area-inset-bottom);
    min-height: 100vh;
}

h1, h2, h3 { margin: 0 0 12px 0; font-weight: 600; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }

.brand {
    padding: 18px 0 8px 0;
}
.brand-kicker {
    font-size: 11px;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--teal-dark);
    font-weight: 600;
    margin-bottom: 4px;
}
.brand-title {
    font-size: 28px;
    letter-spacing: -0.02em;
    margin: 0;
}

.section-title {
    margin: 28px 0 12px 0;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--muted);
    font-weight: 600;
}

.hero {
    position: relative;
    background: var(--paper);
    border: 1px solid var(--paper-edge);
    border-radius: 18px;
    padding: 36px 24px 30px 24px;
    margin: 20px 0 8px 0;
    text-align: center;
    box-shadow: var(--card-shadow);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    overflow: hidden;
}
.hero::before {
    content: "";
    position: absolute;
    top: 16px; left: 22px; right: 22px;
    height: 1px;
    background: var(--teal);
    opacity: 0.4;
}
.hero::after {
    content: "";
    position: absolute;
    top: 22px; left: 22px; right: 22px;
    height: 1px;
    background: var(--teal);
    opacity: 0.15;
}
.hero:active { transform: translateY(1px); box-shadow: 0 3px 8px rgba(0,0,0,0.10); }
.hero-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.22em;
    color: var(--teal-dark);
    font-weight: 700;
    margin-bottom: 16px;
}
.hero-term {
    font-size: 40px;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.01em;
    word-break: break-word;
}
.hero-translation {
    font-size: 18px;
    color: var(--muted);
    margin-top: 10px;
}
.hero-example {
    font-size: 15px;
    font-style: italic;
    color: var(--muted);
    margin-top: 14px;
    line-height: 1.4;
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
}
.hero-source {
    font-size: 13px;
    color: var(--teal);
    margin-top: 20px;
    font-weight: 500;
    letter-spacing: 0.01em;
}
.hero-skeleton {
    min-height: 230px;
    opacity: 0.55;
    cursor: default;
}
.hero-skeleton::before, .hero-skeleton::after { display: none; }
@media (min-width: 520px) {
    .hero-term { font-size: 48px; }
    .hero { padding: 44px 28px 34px 28px; }
}

button {
    font: inherit;
    cursor: pointer;
    border: none;
    background: var(--teal);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: 600;
    min-height: 44px;
    touch-action: manipulation;
}
button:active { background: var(--teal-dark); }
button:disabled { opacity: 0.5; cursor: default; }
button.secondary { background: white; color: var(--teal); border: 1px solid var(--teal); }
button.danger { background: var(--error); }
button.ghost { background: transparent; color: var(--teal); padding: 8px 12px; }
button.small { padding: 8px 14px; font-size: 14px; min-height: 36px; }

input[type=text], input[type=password] {
    font: inherit;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 100%;
    background: white;
    color: var(--fg);
}
input:focus { outline: 2px solid var(--teal); outline-offset: -2px; }

.topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}
.topbar .spacer { flex: 1; }

.back-btn {
    background: transparent;
    color: var(--fg);
    padding: 8px 12px;
    font-size: 20px;
    min-height: auto;
}

.stripe {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin: 8px -16px 24px -16px;
    padding-left: 16px;
    padding-right: 16px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}
.stripe::-webkit-scrollbar { height: 4px; }
.stripe::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.stripe-card {
    flex: 0 0 190px;
    background: var(--paper);
    border-radius: 12px;
    padding: 14px 14px 14px 18px;
    border: 1px solid var(--paper-edge);
    border-left: 4px solid var(--teal);
    cursor: pointer;
    scroll-snap-align: start;
    box-shadow: var(--card-shadow-sm);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
    position: relative;
}
.stripe-card::after {
    content: "";
    position: absolute;
    right: 6px; top: 6px; bottom: 6px;
    width: 3px;
    background: linear-gradient(to bottom, transparent, rgba(0,0,0,0.04), transparent);
    border-radius: 2px;
    pointer-events: none;
}
.stripe-card:active { transform: translateY(1px); box-shadow: 0 2px 6px rgba(0,0,0,0.08); }
.stripe-card .title { font-weight: 600; margin-bottom: 4px; }
.stripe-card .class { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.stripe-card .progress { font-size: 13px; color: var(--teal-dark); font-weight: 500; }

.vocab-tree {
    background: var(--paper);
    border: 1px solid var(--paper-edge);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--card-shadow-sm);
}
.class-group + .class-group { border-top: 1px solid var(--paper-edge); }
.class-header {
    display: flex;
    align-items: center;
    padding: 14px 14px;
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    background: rgba(38,191,191,0.04);
}
.class-header .chev { margin-right: 10px; transition: transform 0.15s; color: var(--teal); font-size: 12px; }
.class-group.expanded .chev { transform: rotate(90deg); }
.class-header .count { margin-left: auto; color: var(--muted); font-size: 13px; font-weight: normal; }

.deck-row {
    display: none;
    align-items: center;
    padding: 14px 14px 14px 36px;
    cursor: pointer;
    border-top: 1px solid var(--paper-edge);
    transition: background 0.1s ease;
}
.class-group.expanded .deck-row { display: flex; }
.deck-row:hover { background: var(--teal-light); }
.deck-row:active { background: var(--teal-light); }
.deck-row .title { flex: 1; font-weight: 500; }
.deck-row .count-pill {
    background: rgba(38,191,191,0.12);
    color: var(--teal-dark);
    font-size: 12px;
    font-weight: 500;
    padding: 3px 9px;
    border-radius: 10px;
    margin: 0 10px;
}
.deck-row .chev-go {
    color: var(--teal);
    font-size: 22px;
    font-weight: 600;
    line-height: 1;
    transition: transform 0.18s ease;
}
.deck-row.expanded .chev-go { transform: rotate(90deg); }
.deck-row.expanded { background: rgba(38,191,191,0.06); }

.deck-body {
    padding: 14px 14px 20px 14px;
    background: rgba(0,0,0,0.015);
    border-top: 1px dashed var(--paper-edge);
    animation: expand-in 0.18s ease-out;
}
@keyframes expand-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.deck-body .deck-stack { margin: 6px auto 4px auto; }
.deck-body .deck-stack-hint { margin: 4px 0 0 0; }
.deck-body .progress-summary { margin: 0; }
.deck-body .action-row { margin: 14px 0 6px 0; }

.deck-main {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
    margin: 6px 0 8px 0;
}
.deck-left {
    flex: 0 1 340px;
    max-width: 100%;
    min-width: 260px;
}
.deck-right {
    flex: 1 1 200px;
    min-width: 200px;
}
.deck-right .progress-summary {
    padding: 14px 16px;
    font-size: 14px;
}
.progress-heading {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--teal-dark);
    font-weight: 700;
    margin-bottom: 10px;
}
.progress-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 4px 0;
    border-bottom: 1px solid rgba(38,191,191,0.18);
}
.progress-row:last-of-type { border-bottom: none; }
.progress-row .dir-label {
    font-size: 13px;
    color: var(--muted);
    letter-spacing: 0.02em;
}
.progress-row .dir-count {
    font-size: 16px;
    font-weight: 600;
    color: var(--fg);
    font-variant-numeric: tabular-nums;
}
@media (max-width: 560px) {
    .deck-main { gap: 14px; }
    .deck-left, .deck-right { flex: 1 1 100%; }
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--muted);
}
.empty-state button { margin-top: 16px; }

.card-front-back {
    position: relative;
    background: var(--paper);
    border: 1px solid var(--paper-edge);
    border-radius: 16px;
    padding: 40px 24px 28px 24px;
    min-height: 240px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin: 24px 0;
    cursor: pointer;
    user-select: none;
    text-align: center;
    box-shadow: var(--card-shadow);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card-front-back::before {
    content: "";
    position: absolute;
    top: 16px; left: 20px; right: 20px;
    height: 1px;
    background: var(--teal);
    opacity: 0.35;
}
.card-front-back::after {
    content: "";
    position: absolute;
    top: 22px; left: 20px; right: 20px;
    height: 1px;
    background: var(--teal);
    opacity: 0.15;
}
.card-front-back:active { transform: translateY(1px); box-shadow: 0 3px 8px rgba(0,0,0,0.10); }
.card-front-back .term { font-size: 30px; font-weight: 600; margin-bottom: 12px; line-height: 1.2; }
.card-front-back .example { font-style: italic; color: var(--muted); margin-top: 16px; font-size: 15px; }
.card-front-back .notes { color: var(--muted); font-size: 14px; margin-top: 10px; }
.card-front-back .hint { font-size: 12px; color: var(--muted); margin-top: 18px; letter-spacing: 0.03em; }

.nav-row {
    display: flex;
    gap: 10px;
    margin: 12px 0;
}
.nav-row button { flex: 1; }

.toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0;
}

.radio-group {
    display: inline-flex;
    gap: 0;
    border: 1px solid var(--teal);
    border-radius: 8px;
    overflow: hidden;
    margin: 10px 0;
}
.radio-group label {
    padding: 8px 12px;
    text-align: center;
    cursor: pointer;
    background: white;
    color: var(--teal);
    font-weight: 500;
    font-size: 14px;
}
.radio-group.compact label {
    padding: 6px 10px;
    font-size: 13px;
    letter-spacing: 0.02em;
}
.radio-group input { display: none; }
.radio-group input:checked + label { background: var(--teal); color: white; }

.action-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 14px 0 6px 0;
    flex-wrap: wrap;
}
.action-row .radio-group { margin: 0; }
.action-row button { padding: 8px 16px; min-height: 36px; font-size: 14px; }

.btn-start {
    background: #2e9e5e;
    color: white;
    padding: 14px 26px !important;
    min-height: 52px !important;
    font-size: 17px !important;
    font-weight: 700;
    border-radius: 12px;
    letter-spacing: 0.01em;
    margin-left: auto;
    min-width: 150px;
    box-shadow: 0 4px 10px rgba(46,158,94,0.28), 0 1px 3px rgba(0,0,0,0.08);
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.btn-start:hover { background: #279554; }
.btn-start:active {
    background: #227548;
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(46,158,94,0.24);
}

.progress-summary {
    background: var(--teal-light);
    border-radius: 8px;
    padding: 12px 14px;
    margin: 12px 0;
    font-size: 14px;
}
.progress-summary div { margin: 2px 0; }
.progress-summary .reset-link {
    display: inline-block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
    text-decoration: underline;
    text-decoration-color: rgba(0,0,0,0.2);
    text-underline-offset: 2px;
}
.progress-summary .reset-link:hover,
.progress-summary .reset-link:active { color: var(--error); }

.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 16px 0;
}
.mode-buttons button { padding: 16px; font-size: 17px; }

.learn-prompt {
    position: relative;
    background: var(--paper);
    border: 1px solid var(--paper-edge);
    border-radius: 16px;
    padding: 32px 22px 26px 22px;
    text-align: center;
    margin: 18px 0;
    box-shadow: var(--card-shadow);
}
.learn-prompt::before {
    content: "";
    position: absolute;
    top: 14px; left: 18px; right: 18px;
    height: 1px;
    background: var(--teal);
    opacity: 0.35;
}
.learn-prompt .term { font-size: 30px; font-weight: 600; line-height: 1.2; }
.learn-prompt .dir { font-size: 12px; color: var(--muted); margin-bottom: 14px; text-transform: uppercase; letter-spacing: 0.08em; }

.deck-stack {
    position: relative;
    height: 280px;
    margin: 24px auto 12px auto;
    max-width: 420px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.deck-stack .stack-card {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 300px;
    height: 210px;
    margin-left: -150px;
    margin-top: -105px;
    background: var(--paper);
    border: 1px solid var(--paper-edge);
    border-radius: 16px;
    padding: 34px 18px 16px 18px;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    transition: transform 0.28s ease, box-shadow 0.28s ease, opacity 0.28s ease;
    cursor: pointer;
}
.deck-stack .stack-card::before {
    content: "";
    position: absolute;
    top: 16px; left: 18px; right: 18px;
    height: 1px;
    background: var(--teal);
    opacity: 0.4;
}
.deck-stack .stack-card::after {
    content: "";
    position: absolute;
    top: 22px; left: 18px; right: 18px;
    height: 1px;
    background: var(--teal);
    opacity: 0.15;
}
.deck-stack .stack-card .term {
    font-size: 28px;
    font-weight: 600;
    line-height: 1.2;
    word-break: break-word;
}
.deck-stack .stack-card .sub {
    font-size: 11px;
    color: var(--muted);
    margin-top: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.deck-stack .stack-card .example {
    font-size: 14px;
    font-style: italic;
    color: var(--muted);
    margin-top: 12px;
    line-height: 1.3;
    max-height: 3em;
    overflow: hidden;
}
.deck-stack .stack-card.pos-0 {
    transform: translate(0, 0) rotate(-2deg);
    z-index: 3;
}
.deck-stack .stack-card.pos-0.flipped {
    transform: translate(0, 0) rotate(0deg);
    box-shadow: 0 8px 18px rgba(0,0,0,0.14), 0 2px 4px rgba(0,0,0,0.06);
}
.deck-stack .stack-card.pos-1 {
    transform: translate(14px, -8px) rotate(4deg);
    z-index: 2;
    opacity: 0.92;
}
.deck-stack .stack-card.pos-2 {
    transform: translate(-12px, -16px) rotate(-6deg);
    z-index: 1;
    opacity: 0.82;
}
.deck-stack .stack-card.pos-3 {
    transform: translate(6px, -24px) rotate(2deg);
    z-index: 0;
    opacity: 0.7;
}
.deck-stack:active .stack-card.pos-0 {
    box-shadow: 0 3px 8px rgba(0,0,0,0.10);
}
.deck-stack .count-badge {
    position: absolute;
    right: 12px;
    bottom: 12px;
    background: var(--teal);
    color: white;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 12px;
    letter-spacing: 0.02em;
}
.deck-stack-hint {
    text-align: center;
    font-size: 12px;
    color: var(--muted);
    margin: 4px 0 20px 0;
    letter-spacing: 0.02em;
}

.answer-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
    margin: 12px 0;
}
.answer-row input {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    padding: 10px 12px;
    font-size: 17px;
}
.answer-row .answer-submit {
    flex: 0 0 auto;
    padding: 0 18px;
    min-height: auto;
    white-space: nowrap;
}

.accent-bar {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    margin: 6px 0;
    padding: 2px;
}
.accent-bar button {
    background: var(--card-bg);
    color: var(--fg);
    border: 1px solid var(--border);
    padding: 8px 12px;
    min-height: 38px;
    min-width: 38px;
    font-size: 18px;
    flex: 0 0 auto;
}

.feedback {
    padding: 14px 16px;
    border-radius: 10px;
    margin: 12px 0;
    font-size: 15px;
}
.feedback.correct { background: var(--success-bg); color: var(--success); border: 1px solid var(--success); }
.feedback.almost { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }
.feedback.wrong { background: var(--error-bg); color: var(--error); border: 1px solid var(--error); }
.feedback .canonical { font-weight: 600; font-size: 17px; margin-top: 4px; }
.feedback .example { font-style: italic; margin-top: 6px; }

.session-header {
    display: flex;
    align-items: center;
    font-size: 14px;
    color: var(--muted);
    margin-bottom: 12px;
}
.session-header .progress { flex: 1; }
.session-header button { font-size: 13px; }

.end-state {
    text-align: center;
    padding: 40px 20px;
}
.end-state .checkmark { font-size: 48px; color: var(--teal); margin-bottom: 16px; }
.end-state h2 { margin-bottom: 24px; }
.end-state button { display: block; width: 100%; margin: 10px 0; }

.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}
.confirm-dialog {
    background: white;
    border-radius: 12px;
    padding: 20px;
    max-width: 340px;
    width: 100%;
    box-shadow: var(--shadow);
}
.confirm-dialog p { margin: 0 0 16px 0; }
.confirm-dialog .buttons { display: flex; gap: 10px; }
.confirm-dialog .buttons button { flex: 1; }

.mastered-banner {
    background: var(--success-bg);
    color: var(--success);
    padding: 12px 14px;
    border-radius: 8px;
    margin: 12px 0;
    font-weight: 500;
}

.error-banner {
    background: var(--error-bg);
    color: var(--error);
    padding: 12px 14px;
    border-radius: 8px;
    margin: 12px 0;
}

.muted { color: var(--muted); font-size: 14px; }
