/* Colours are tokens, and every pair that carries text is checked for contrast
   by scripts/contrast.mjs. One accent blue, greys, black and white; no gradients. */
:root {
  color-scheme: light dark;

  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --border: #d5dbe3;
  --border-strong: #64748b;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --on-accent: #ffffff;
  --accent-soft: #e0e9ff;
  --danger: #b91c1c;
  --toast-bg: #0f172a;
  --toast-text: #f8fafc;

  /* spacing scale */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --radius: 12px;
  --radius-lg: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14;
    --surface: #151b23;
    --text: #e6eaf0;
    --muted: #9aa7b8;
    --border: #26303c;
    --border-strong: #6b7a8f;
    --accent: #7aa7ff;
    --accent-hover: #9bbcff;
    --on-accent: #0b1220;
    --accent-soft: #18274a;
    --danger: #ff8f87;
    --toast-bg: #e6eaf0;
    --toast-text: #0b0f14;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ---- shell ---- */

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s2) var(--s4) 0 var(--s4);
}

.app-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.view {
  flex: 1;
  padding: var(--s4) var(--s4) var(--s5);
}

.tabs {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabs a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  padding: var(--s2) var(--s1);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}

.tabs a[aria-current='page'] {
  color: var(--accent);
}

.tabs svg {
  width: 24px;
  height: 24px;
}

body[data-view='review'] .tabs,
body[data-view='review'] .app-header {
  display: none;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- text ---- */

.screen-title {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

.lead {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

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

.text-link {
  color: var(--accent);
  font-weight: 600;
}

.label {
  display: block;
  margin-bottom: var(--s2);
  font-size: 14px;
  font-weight: 600;
}

.error {
  margin: 0;
  min-height: 1.5em;
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- layout helpers ---- */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}

.stack.center {
  align-items: center;
  text-align: center;
  padding-top: var(--s7);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--s3);
}

.row.wrap {
  flex-wrap: wrap;
}

.grow {
  flex: 1;
}

/* ---- controls ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 var(--s5);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.btn.big {
  min-height: 56px;
  font-size: 18px;
}

.btn.small {
  min-height: 44px;
  padding: 0 var(--s4);
}

.btn.danger {
  color: var(--danger);
}

.btn:active {
  opacity: 0.8;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (hover: hover) {
  .btn:hover:not(:disabled) {
    border-color: var(--accent);
  }

  .btn.primary:hover:not(:disabled) {
    background: var(--accent-hover);
  }

  .text-link:hover {
    text-decoration: underline;
  }
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn svg {
  width: 24px;
  height: 24px;
}

.icon-btn:active {
  background: var(--accent-soft);
}

@media (hover: hover) {
  .icon-btn:hover {
    color: var(--accent);
  }
}

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

.field {
  width: 100%;
  padding: var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit; /* 16px, so iOS does not zoom into the field */
}

.field.narrow {
  width: 120px;
}

.field.date {
  width: 220px;
}

textarea.field {
  min-height: 160px;
  resize: vertical;
}

.group {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding: var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.group-title {
  margin: 0;
  font-size: 16px;
}

.choices {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s3);
  margin: 0;
  padding: 0;
  border: 0;
}

.choice {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: 44px;
}

.choice input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

/* ---- home and statistics ---- */

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s3);
}

.tile {
  display: flex;
  flex-direction: column;
  padding: var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.tile-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
}

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

.tile-hint {
  margin-top: var(--s1);
  color: var(--muted);
  font-size: 12px;
}

/* ---- review ---- */

/* The review screen fills the height and keeps the grades at the bottom, where
   a thumb reaches them; the card takes the space in between. */
body[data-view='review'] .view {
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--s5) + env(safe-area-inset-bottom));
}

.review {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--s4);
}

.review-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
}

.card-wrap {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  perspective: 1200px;
}

.card {
  display: grid;
  flex: 1;
  min-height: 300px;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.45s ease;
  -webkit-tap-highlight-color: transparent;
}

.card[data-flipped='true'] {
  transform: rotateY(180deg);
}

.face {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  padding: var(--s6) var(--s5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  text-align: center;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.face.back {
  transform: rotateY(180deg);
}

.word {
  margin: 0;
  font-size: clamp(32px, 10vw, 44px);
  font-weight: 700;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.translation {
  margin: 0;
  font-size: clamp(26px, 8vw, 34px);
  font-weight: 700;
  line-height: 1.2;
}

.example {
  margin: 0;
  color: var(--muted);
  font-size: 18px;
  text-wrap: balance;
}

.speak {
  position: absolute;
  top: var(--s2);
  right: var(--s2);
  z-index: 2;
}

.grades {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--s2);
}

.grades[data-visible='false'] {
  visibility: hidden;
}

.grade {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 64px;
  padding: var(--s2) var(--s1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.grade.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.grade:active {
  opacity: 0.8;
}

.grade-label {
  font-weight: 700;
}

.grade-hint {
  font-size: 14px;
}

.keys {
  text-align: center;
}

@media (pointer: coarse) {
  .keys {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card {
    transition: none;
  }
}

/* ---- add words ---- */

.preview {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.preview-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--border);
}

.preview-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.preview-word {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.preview-translation,
.preview-example {
  font-size: 14px;
  overflow-wrap: anywhere;
}

.preview-example {
  color: var(--muted);
}

.badge {
  flex: none;
  padding: 2px var(--s2);
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.preview-row[data-status='new'] .badge {
  color: var(--accent);
}

.preview-row[data-status='exists'] .badge,
.preview-row[data-status='repeat'] .badge {
  color: var(--muted);
}

.preview-row[data-status='invalid'] .badge {
  color: var(--danger);
}

/* ---- word list ---- */

.word-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}

.word-list li + li {
  border-top: 1px solid var(--border);
}

.word-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  width: 100%;
  min-height: 56px;
  padding: var(--s2) var(--s4);
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.word-row:active {
  background: var(--accent-soft);
}

.wr-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.wr-word {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.wr-translation {
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.wr-meta {
  flex: none;
  color: var(--muted);
  font-size: 12px;
}

.empty {
  padding: var(--s5) var(--s4);
  color: var(--muted);
}

/* ---- dialog, toast, banners ---- */

.sheet {
  width: min(92vw, 480px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
}

/* The one literal colour: custom properties do not reach ::backdrop in older browsers. */
.sheet::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  padding: var(--s5);
}

.sheet-title {
  margin: 0;
  font-size: 20px;
}

.toast {
  position: fixed;
  right: var(--s4);
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: var(--s4);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  max-width: 528px;
  margin: 0 auto;
  padding: var(--s3) var(--s4);
  border-radius: var(--radius);
  background: var(--toast-bg);
  color: var(--toast-text);
}

.toast[hidden] {
  display: none;
}

.toast-action {
  min-height: 44px;
  padding: 0 var(--s3);
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin: var(--s2) var(--s4) 0;
  padding: var(--s3) var(--s4);
  border-radius: var(--radius);
  background: var(--accent-soft);
  font-size: 14px;
}

.banner[hidden] {
  display: none;
}

.notice-static {
  margin: var(--s4);
}
