:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: #d9d6cf;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --ok: #1f7a3d;
  --ok-bg: #e3f3e8;
  --warn: #8a5a00;
  --warn-bg: #fdf1d6;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  --radius: 14px;
  --tap: 52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --surface: #1c1d20;
    --text: #f2f2f2;
    --muted: #9a9aa0;
    --border: #2e2f33;
    --accent: #7f9cff;
    --accent-text: #0d1430;
    --ok: #7bd99a;
    --ok-bg: #16301f;
    --warn: #f0c062;
    --warn-bg: #352a12;
    --bad: #ff8a80;
    --bad-bg: #3a1a18;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 18px/1.45 system-ui, -apple-system, sans-serif;
}

h1, h2 { margin: 0 0 12px; line-height: 1.2; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.9rem; margin: 0; }
.warn { color: var(--warn); }

.notice {
  margin: 0;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 0.85rem;
  text-align: center;
}

main {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
}

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

/* Buttons and fields: large tap targets; 18px text keeps iOS from zooming in on focus. */
button, input[type="text"], input[type="search"] {
  font: inherit;
  min-height: var(--tap);
  border-radius: var(--radius);
}

button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0 20px;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button.primary:disabled { opacity: 0.45; cursor: default; }

button.quiet {
  background: none;
  border: none;
  color: var(--muted);
  align-self: center;
}

input[type="text"], input[type="search"] {
  width: 100%;
  padding: 0 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

input:focus-visible, button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

input[readonly] { opacity: 0.8; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack > label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }

/* Language choice as two big buttons */
.segmented { display: flex; gap: 8px; border: 0; margin: 0; padding: 0; }
.segmented legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}
.segmented input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.segmented input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.toggle {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}
.toggle input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }

/* Study */
.meta { display: flex; justify-content: space-between; margin: 0; color: var(--muted); font-size: 0.9rem; }

.card {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.word {
  margin: 0;
  font-size: clamp(1.8rem, 8vw, 2.6rem);
  font-weight: 600;
  text-align: center;
  overflow-wrap: anywhere;
}

#answer-form { display: flex; flex-direction: column; gap: 12px; }
#answer { font-size: 1.3rem; }

#feedback:empty { display: none; }
#feedback { padding: 12px 14px; border-radius: var(--radius); }
#feedback p { margin: 0; }
#feedback .solution { margin-top: 4px; font-weight: 600; font-size: 1.15rem; }
#feedback.correct { background: var(--ok-bg); color: var(--ok); }
#feedback.accent, #feedback.article { background: var(--warn-bg); color: var(--warn); }
#feedback.wrong { background: var(--bad-bg); color: var(--bad); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.list .pair { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.list .pair small { display: block; color: var(--muted); }
.list button { flex: none; color: var(--bad); }

/* Bottom navigation */
nav {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  padding: 8px max(16px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
nav button { flex: 1; border: none; background: none; color: var(--muted); font-weight: 600; }
nav button[aria-current="page"] { color: var(--accent); }

/* Deck overview */
.boxes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.boxes div {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.85rem;
}
.boxes strong { color: var(--text); font-size: 1.4rem; }

.backup { margin-top: 12px; padding-top: 16px; border-top: 1px solid var(--border); }

textarea {
  width: 100%;
  min-height: 140px;
  padding: 12px 14px;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  resize: vertical;
}
textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.paste { padding-top: 16px; border-top: 1px solid var(--border); }
#paste-result p, #import-result p { margin: 0; }

/* Difficulty ticks after an answer */
.ticks { display: flex; gap: 8px; }
.ticks label { flex: 1; }
.ticks input { position: absolute; opacity: 0; pointer-events: none; }
.ticks span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.95rem;
  cursor: pointer;
}
.ticks span::before { content: "☐"; }
.ticks input:checked + span { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.ticks input:checked + span::before { content: "☑"; }
.ticks input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.list select {
  display: block;
  margin-top: 6px;
  min-height: 36px;
  padding: 0 8px;
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

/* Delete all */
.danger { margin-top: 12px; padding-top: 16px; border-top: 1px solid var(--border); }
button.danger-button { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); font-weight: 600; }
button.danger-button:disabled { opacity: 0.45; cursor: default; }
#clear-result p { margin: 0; }
