/*
  Purpose: All styles for the app: theme tokens (light and dark), layout, tab bar,
           word page, flashcards, word list and forms.
  Used by: index.html
  Notes: Mobile first. The tab bar and the rating buttons respect the iPhone safe area
         (env(safe-area-inset-bottom)) because the app runs full screen from the home screen.
*/

:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #efe9dd;
  --ink: #1c1a17;
  --muted: #6b665d;
  --line: #e4ddcf;
  --accent: #b5452b;
  --accent-ink: #ffffff;
  --accent-soft: #f6e3dc;
  --mnemonic-bg: #fbf3d9;
  --mnemonic-line: #e8d48f;
  --again: #c0392b;
  --hard: #b7791f;
  --good: #2f855a;
  --easy: #2b6cb0;
  --danger: #b42318;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-word: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, ui-serif, serif;
  --radius: 14px;
  --tabbar-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --surface: #1f1d1a;
    --surface-2: #2a2723;
    --ink: #f2eee6;
    --muted: #a39d92;
    --line: #36322c;
    --accent: #e07a5f;
    --accent-ink: #1c1a17;
    --accent-soft: #3a2620;
    --mnemonic-bg: #2b2616;
    --mnemonic-line: #5c4f22;
    --again: #f0705f;
    --hard: #e0a84e;
    --good: #5fbf8a;
    --easy: #6aa7e8;
    --danger: #f0705f;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }

.view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 20px) 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- Page header ---------- */

.page-head { margin-bottom: 20px; }
.page-head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.page-title { font-size: 1.6rem; margin: 0; line-height: 1.2; }
.eyebrow { margin: 0; color: var(--muted); font-size: 0.85rem; letter-spacing: 0.02em; }
.back-link { display: inline-block; margin-bottom: 6px; text-decoration: none; font-weight: 500; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  color: var(--muted);
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- Pills ---------- */

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.pill-level { background: var(--accent-soft); color: var(--accent); }

/* ---------- Word of the day ---------- */

.word-hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 20px 22px;
  text-align: center;
  margin-bottom: 24px;
}
.word-title {
  font-family: var(--font-word);
  font-weight: 600;
  font-size: clamp(2.1rem, 9vw, 2.9rem);
  line-height: 1.1;
  margin: 0;
  overflow-wrap: anywhere;
  hyphens: auto;
}
.article { color: var(--muted); font-weight: 400; }
.word-grammar { margin: 8px 0 0; color: var(--muted); font-size: 0.9rem; }
.word-translation { margin: 14px 0 0; font-size: 1.15rem; font-weight: 500; }
.word-meta { margin: 14px 0 0; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.block { margin-bottom: 24px; }
.block-title {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.examples { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.examples li {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.ex-de { margin: 0; font-weight: 500; }
.ex-en { margin: 2px 0 0; color: var(--muted); font-size: 0.92rem; }

.mnemonic {
  background: var(--mnemonic-bg);
  border: 1px solid var(--mnemonic-line);
  border-radius: 12px;
  padding: 14px 16px;
}
.mnemonic .block-title { color: inherit; opacity: 0.75; }
.mnemonic p { margin: 0; }
.mnemonic p + p { margin-top: 4px; }
.mnemonic.small { font-size: 0.92rem; margin-top: 12px; padding: 10px 14px; text-align: left; }
.mnemonic.small .block-title { margin-bottom: 4px; }

.deck-status { text-align: center; font-size: 0.9rem; }
.random-actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; }
.random-actions p { flex-basis: 100%; margin: 0; }

/* ---------- Flashcards ---------- */

.study-counts { display: flex; justify-content: center; gap: 16px; margin: 0 0 14px; font-size: 0.9rem; font-weight: 600; }
.count-new { color: var(--easy); }
.count-due { color: var(--good); }

.flashcard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 20px;
  min-height: 46vh;
  text-align: center;
  cursor: pointer;
  user-select: none;
}
.flashcard.is-flipped { cursor: default; user-select: text; min-height: 0; }
.card-direction { margin: 0 0 18px; color: var(--muted); font-size: 0.8rem; letter-spacing: 0.04em; }
.card-prompt { font-family: var(--font-word); font-size: clamp(1.9rem, 8vw, 2.5rem); font-weight: 600; line-height: 1.15; margin: 8vh 0 0; overflow-wrap: anywhere; }
.flashcard.is-flipped .card-prompt { margin-top: 0; }
.card-hint { margin: 10px 0 0; color: var(--muted); font-size: 0.9rem; }
.card-divider { border: 0; border-top: 1px dashed var(--line); margin: 22px 0; }
.card-answer { font-size: 1.35rem; font-weight: 600; margin: 0; font-family: var(--font-word); overflow-wrap: anywhere; }
.flashcard .examples { margin-top: 16px; text-align: left; }
.flashcard .examples li { background: var(--bg); }

.study-actions {
  position: sticky;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px);
  margin-top: 16px;
  padding-top: 8px;
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
}
.rating-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.btn-rate {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 4px;
  border-radius: 12px;
  border: 1.5px solid currentColor;
  background: var(--surface);
  font: inherit;
  cursor: pointer;
}
.btn-rate:active { transform: scale(0.97); }
.rate-label { font-weight: 700; font-size: 0.95rem; }
.rate-interval { font-size: 0.75rem; color: var(--muted); }
.rate-again { color: var(--again); }
.rate-hard { color: var(--hard); }
.rate-good { color: var(--good); }
.rate-easy { color: var(--easy); }

.done { text-align: center; padding: 18vh 12px 0; }
.done-title { font-family: var(--font-word); font-size: 1.8rem; font-weight: 600; margin: 0 0 8px; }
.done p { margin: 6px 0; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--line); }
.btn-block { display: flex; width: 100%; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
.file-btn { position: relative; }

/* ---------- Word list ---------- */

.list-tools { display: grid; gap: 10px; margin-bottom: 8px; }
.list-tools .input { width: 100%; min-width: 0; }
.list-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.list-actions .btn { padding-left: 10px; padding-right: 10px; white-space: nowrap; }
.list-count { font-size: 0.85rem; margin: 0 0 10px; }

.word-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.word-item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.word-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%;
  padding: 12px 14px;
  background: none; border: 0;
  font: inherit; color: inherit; text-align: left;
  cursor: pointer;
}
.word-row-main { display: flex; flex-direction: column; min-width: 0; }
.word-row-title { font-family: var(--font-word); font-weight: 600; font-size: 1.12rem; overflow-wrap: anywhere; }
.word-row-title .article { font-weight: 400; }
.word-row-translation { color: var(--muted); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.word-row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.word-details { padding: 0 14px 14px; }
.word-details .word-grammar { margin: 0 0 10px; }
.word-details .examples li { background: var(--bg); }
.word-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

/* ---------- Forms ---------- */

.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field-row { display: flex; gap: 10px; }
.field-article { width: 96px; flex-shrink: 0; }
.field-grow { flex: 1; min-width: 0; }
.label { font-size: 0.85rem; font-weight: 600; }
.label .muted { font-weight: 400; }
.hint { font-size: 0.8rem; color: var(--muted); }
.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 16px stops iOS from zooming into focused inputs */
}
textarea.input { resize: vertical; line-height: 1.4; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.form-error { color: var(--danger); margin: 0; font-size: 0.9rem; }

.sync-status { margin: 0 0 12px; }
.sync-status.is-error { color: var(--danger); }
.backup-status { margin: 10px 0 0; font-size: 0.9rem; }

.empty { text-align: center; color: var(--muted); padding-top: 20vh; }

/* ---------- Tab bar ---------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.72rem; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.is-active { color: var(--accent); }
.tab-icon { position: relative; display: inline-flex; }
.badge {
  position: absolute; top: -5px; left: 16px;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 0.68rem; font-weight: 700; line-height: 18px; text-align: center;
}
.badge[hidden] { display: none; }

@media (min-width: 640px) {
  .view { padding-top: 40px; }
}
