/* ---------- Typefaces (self-hosted): Schibsted Grotesk (headings), Inter (body), Geist Mono (examples) ---------- */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/inter-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/inter-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Geist Mono';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/geistmono-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Geist Mono';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/geistmono-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Schibsted Grotesk';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url('../fonts/schibsted-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Schibsted Grotesk';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url('../fonts/schibsted-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- Design tokens ---------- */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f7;
  --text: #1c1e26;
  --text-dim: #5b6172;
  --border: #e2e5ef;
  --accent: #4f46e5;
  --accent-soft: #eceafd;
  --accent-text: #ffffff;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 1px 3px rgba(20, 24, 40, .08), 0 4px 16px rgba(20, 24, 40, .06);
  --radius: 14px;
  --nav-h: 62px;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Yu Gothic UI", "Helvetica Neue", Arial, sans-serif;
  --font-heading: 'Schibsted Grotesk', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Hiragino Sans", monospace;
}

/* System typeface mode: SF Pro + SF Mono on Apple devices, native equivalents elsewhere */
html[data-font="system"] {
  --font-body: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Hiragino Sans", "Yu Gothic UI", "Helvetica Neue", Arial, sans-serif;
  --font-heading: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Hiragino Sans", sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --surface: #1c1f2b;
    --surface-2: #262a3a;
    --text: #e8eaf2;
    --text-dim: #9aa0b4;
    --border: #2e3345;
    --accent: #818cf8;
    --accent-soft: #2b2d4a;
    --accent-text: #12141c;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; font-size: 106.25%; } /* 17px base */
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
button { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- Layout ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 1.05rem; }
.brand-mark { font-size: 1.3rem; }
.lang-switch {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 999px; padding: 6px 14px; cursor: pointer; font-weight: 600; font-size: .9rem;
}
.lang-switch:hover { border-color: var(--accent); }

#view {
  max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
  outline: none;
}

#bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
#bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--text-dim); font-size: .78rem; font-weight: 600;
}
#bottomnav a.active { color: var(--accent); }
.nav-icon { font-size: 1.4rem; line-height: 1; }

/* ---------- Components ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 6px; font-size: 1.18rem; }
.card h3 { margin: 14px 0 6px; font-size: .95rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--text-dim); font-size: .95rem; }
.small { font-size: .875rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: var(--accent-text);
  border: none; border-radius: 10px; padding: 10px 18px;
  font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.sm { padding: 6px 12px; font-size: .85rem; border-radius: 8px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }

.pill {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 2px 10px; font-size: .82rem; font-weight: 700;
}

input[type="text"], input[type="password"], input[type="search"], select, textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
label { display: block; font-weight: 600; font-size: .92rem; margin: 12px 0 4px; }

/* language sheet */
.sheet.hidden { display: none; }
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-panel {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
  max-height: 75vh; overflow-y: auto;
}
.sheet-panel h2 { margin: 0 0 12px; font-size: 1.05rem; }
.lang-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .lang-list { grid-template-columns: 1fr; } }
.lang-option {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2); padding: 12px; cursor: pointer; text-align: left;
}
.lang-option.active { border-color: var(--accent); background: var(--accent-soft); }
.lang-option .flag { font-size: 1.5rem; }
.lang-option .native { display: block; font-size: .8rem; color: var(--text-dim); }

/* toast */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 20px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  border-radius: 10px; padding: 10px 18px; font-size: .9rem; font-weight: 600;
  z-index: 60; box-shadow: var(--shadow); max-width: 90vw;
}
.toast.hidden { display: none; }

/* ---------- Home ---------- */
.hero { text-align: left; padding: 20px 16px; }
.hero h1 { margin: 0 0 4px; font-size: 1.55rem; }
.stat-row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.stat {
  flex: 1; min-width: 90px;
  background: var(--surface-2); border-radius: 12px; padding: 10px 12px; text-align: center;
}
.stat .num { font-size: 1.5rem; font-weight: 800; color: var(--accent); }
.stat .lbl { font-size: .78rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; }
.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .home-actions { grid-template-columns: 1fr 1fr; } }
.action-tile {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; text-decoration: none; color: var(--text);
}
.action-tile .icon { font-size: 1.6rem; }
.action-tile .title { font-weight: 700; }
.action-tile .desc { font-size: .875rem; color: var(--text-dim); }
.phrase-of-day .target { font-size: 1.3rem; font-weight: 700; margin: 4px 0 2px; }

/* ---------- Tenses ---------- */
.tense-block .formation {
  background: var(--surface-2); border-radius: 10px; padding: 10px 12px;
  font-size: .95rem; margin: 8px 0;
}
.example { display: flex; flex-direction: column; margin: 8px 0; padding-left: 10px; border-left: 3px solid var(--accent-soft); }
.example .target { font-weight: 600; }
.example .english { color: var(--text-dim); font-size: .95rem; }

.verb-select-row { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
table.conj { width: 100%; border-collapse: collapse; font-size: 1rem; }
table.conj th, table.conj td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); }
table.conj th { color: var(--text-dim); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
table.conj td:first-child { color: var(--text-dim); white-space: nowrap; }
.conj-wrap { overflow-x: auto; }

/* ---------- Phrases ---------- */
.phrase-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.phrase-item:last-child { border-bottom: none; }
.phrase-text { flex: 1; }
.phrase-text .target { font-weight: 700; font-size: 1.08rem; }
.phrase-text .roman { color: var(--accent); font-size: .92rem; }
.phrase-text .english { color: var(--text-dim); font-size: .95rem; }
.phrase-text .note { color: var(--warn); font-size: .875rem; margin-top: 3px; }
.speak-btn {
  border: none; background: var(--surface-2); border-radius: 8px;
  width: 34px; height: 34px; cursor: pointer; font-size: 1rem; flex-shrink: 0;
}
.speak-btn:hover { background: var(--accent-soft); }
.cat-title { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.cat-title h2 { margin: 0; }

/* ---------- Flashcards ---------- */
.flashcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow); min-height: 220px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; cursor: pointer; user-select: none;
}
.flashcard .side-label { font-size: .78rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 10px; }
.flashcard .content { font-size: 1.55rem; font-weight: 700; line-height: 1.35; }
.flashcard .sub { font-size: 1.02rem; color: var(--text-dim); margin-top: 6px; }
.grade-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.grade-btn { border: none; border-radius: 10px; padding: 13px 4px; font-weight: 700; cursor: pointer; color: #fff; font-size: .95rem; }
.grade-again { background: var(--bad); }
.grade-hard { background: var(--warn); }
.grade-good { background: var(--good); }
.grade-easy { background: var(--accent); }
.grade-btn .sub { display: block; font-size: .74rem; font-weight: 500; opacity: .85; }

/* ---------- Quiz ---------- */
.quiz-prompt { text-align: center; padding: 10px 0 16px; }
.quiz-prompt .big { font-size: 1.75rem; font-weight: 800; }
.quiz-feedback { margin-top: 10px; font-weight: 700; }
.quiz-feedback.ok { color: var(--good); }
.quiz-feedback.no { color: var(--bad); }

/* ---------- Chat ---------- */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - var(--nav-h) - 150px); min-height: 380px; }
.chat-log { flex: 1; overflow-y: auto; padding: 4px 2px 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.assistant.thinking::after { content: "…"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.chat-input-row { display: flex; gap: 8px; padding-top: 10px; }
.chat-input-row textarea { resize: none; height: 48px; border-radius: 12px; flex: 1; }
.chat-hints { display: flex; gap: 8px; overflow-x: auto; padding: 6px 0; }
.chat-hints button {
  white-space: nowrap; border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 6px 13px; font-size: .85rem; cursor: pointer; color: var(--text-dim);
}

/* ---------- Settings ---------- */
.settings-link { color: var(--text-dim); font-size: .9rem; text-decoration: none; }
.danger { color: var(--bad); }

@media (min-width: 900px) {
  .hero h1 { font-size: 1.7rem; }
}

/* ---------- Typography roles ---------- */
h1, h2, .brand-name,
.action-tile .title, .quiz-prompt .big,
.phrase-of-day .target, .flashcard .content {
  font-family: var(--font-heading);
  letter-spacing: -0.012em;
}
table.conj td, .phrase-text .roman,
.example .target, #quiz-answer, .quiz-feedback {
  font-family: var(--font-mono);
  letter-spacing: -0.01em;
}
table.conj td:first-child { font-family: var(--font-body); }
table.conj td { font-size: .95rem; }
