/* ============================================================
   Defense IQ

   TWO COLOUR SYSTEMS THAT NEVER MIX.

   1. Analysis  — achromatic, plus the four NATO affiliation
      colours. Those four carry meaning: blue is friendly, red
      hostile, green neutral, yellow unknown. They appear only
      where affiliation is what is being communicated. Never
      decoratively, never as a status tint, never on a button.

   2. Progress  — one amber. Streak, XP, mission, primary
      actions. Nothing else in the interface uses it.

   Keeping gamification to a single hue is what stops the app
   drifting toward a war game. If a new colour is ever needed,
   the answer is almost always a grey step instead.
   ============================================================ */

:root {
  /* Analysis — achromatic ladder */
  --bg:        #0b0e11;
  --surface-1: #12161a;
  --surface-2: #181d23;
  --surface-3: #212830;
  --line:      #2a323b;
  --line-soft: #1e252c;

  --ink:       #e8ecef;
  --ink-2:     #9aa5b1;
  --ink-3:     #6b7683;
  --ink-4:     #48525d;

  /* Progress — the only chromatic accent in the chrome */
  --signal:      #d4922c;
  --signal-dim:  #8a5f1c;
  --signal-wash: rgba(212, 146, 44, 0.12);

  /* NATO affiliation. Reserved. */
  --aff-friendly: #7cb2e8;
  --aff-hostile:  #e8736b;
  --aff-neutral:  #7dc98f;
  --aff-unknown:  #e5c65c;

  --font: 'IBM Plex Sans JP', -apple-system, BlinkMacSystemFont,
          'Hiragino Sans', 'Noto Sans JP', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', monospace;

  --nav-h: 58px;
  --pad: 18px;
  --radius: 6px;
  --radius-lg: 10px;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  font-feature-settings: 'palt' 1;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; padding: 0; }

:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
  border-radius: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

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

#app {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px var(--pad) 40px;
}

.view > * + * { margin-top: 22px; }

/* Prose stays under 70ch even on wide screens. */
.prose { max-width: 68ch; }

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

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 18px var(--pad) 0;
  max-width: 640px;
  margin: 0 auto;
}

.topbar h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

.topbar .sub {
  font-size: 12px;
  color: var(--ink-3);
  font-family: var(--mono);
}

.langtoggle {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  flex: none;
}

.langtoggle button {
  padding: 4px 9px;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--ink-3);
}

.langtoggle button[aria-pressed='true'] {
  background: var(--surface-3);
  color: var(--ink);
}

/* ------------------------------------------------- bottom nav */

.nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(11, 14, 17, 0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line-soft);
  z-index: 40;
}

.nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--ink-4);
  font-size: 10px;
  letter-spacing: 0.02em;
}

.nav a[aria-current='page'] { color: var(--ink); }
.nav a svg { width: 20px; height: 20px; stroke-width: 1.6; }

/* ----------------------------------------------------- cards */

.card {
  background: var(--surface-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.card--flat { background: none; border-color: var(--line-soft); }

.card h2, .card h3 { margin: 0 0 10px; }

h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.005em; }
h3 { font-size: 13px; font-weight: 600; color: var(--ink-2); }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-head h2 { margin: 0; }

.section-head a, .linkish {
  font-size: 12px;
  color: var(--ink-3);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
  padding-bottom: 1px;
}

/* ------------------------------------------ mission readout
   Twenty segments, one per question. Read from an avionics
   quantity gauge rather than a percentage bar — the unit here
   is questions, and the gauge shows them as countable things. */

.mission {
  background: var(--surface-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.mission-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.mission-label { font-size: 13px; color: var(--ink-2); }

.mission-count {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-2);
}
.mission-count b { color: var(--signal); font-weight: 500; }

.gauge {
  display: flex;
  gap: 2px;
  height: 26px;
  margin-bottom: 14px;
}

.gauge i {
  flex: 1;
  background: var(--surface-3);
  border-radius: 1px;
  transition: background 240ms ease;
}

.gauge i.on { background: var(--signal); }
.gauge i.cur { background: var(--signal-dim); }

/* ---------------------------------------------------- streak */

.stats {
  display: flex;
  gap: 20px;
  align-items: baseline;
}

.stat { display: flex; align-items: baseline; gap: 6px; }

.stat-num {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 500;
  color: var(--signal);
  line-height: 1;
}

.stat-label { font-size: 11px; color: var(--ink-3); }

/* --------------------------------------------------- buttons */

.btn {
  display: block;
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius);
  background: var(--signal);
  color: #16120a;
  font-weight: 600;
  font-size: 14px;
  text-align: center;
  text-decoration: none;
  transition: filter 140ms ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn--quiet {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-weight: 500;
}
.btn--quiet:hover { border-color: var(--ink-4); filter: none; }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* --------------------------------------------------- mastery */

.mastery { display: flex; flex-direction: column; gap: 9px; }

.mastery-row {
  display: grid;
  grid-template-columns: 96px 1fr 34px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.mastery-row span:first-child { color: var(--ink-2); }

.mastery-bar {
  height: 3px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
}
.mastery-bar i { display: block; height: 100%; background: var(--ink-3); }

.mastery-pct {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  text-align: right;
}

/* ------------------------------------------------------ news */

.news-item { display: block; text-decoration: none; color: inherit; }

.news-item + .news-item {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}

.news-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--ink-3);
  font-family: var(--mono);
  margin-bottom: 5px;
}

.news-item h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
  margin: 0;
}

.news-item .ja { color: var(--ink-2); font-size: 13px; margin-top: 3px; }

/* Verification status uses glyph + word, never colour — the
   red/amber/green a status chip wants would collide with the
   NATO affiliation palette and dilute it. */
.verif {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
}
.verif b { font-weight: 400; }
.verif[data-s='confirmed'] { color: var(--ink-2); }
.verif[data-s='disputed'] { color: var(--signal); }

.article-body { font-size: 15px; line-height: 1.7; }
.article-body h3 { margin: 22px 0 8px; color: var(--ink-2); }
.article-body p { margin: 0 0 12px; }

/* Tappable entity inside article text (§18) */
.ent {
  color: var(--ink);
  border-bottom: 1px dashed var(--ink-4);
  text-decoration: none;
  cursor: pointer;
}
.ent:hover { border-bottom-color: var(--signal); }

.sources { font-size: 12px; }
.sources li { margin-bottom: 6px; color: var(--ink-3); }
.sources a { color: var(--ink-2); }
.sources .tier {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-4);
}

/* ------------------------------------------------------ quiz */

.quiz-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-3);
  margin-bottom: 16px;
}

.quiz-prompt { font-size: 18px; font-weight: 600; line-height: 1.45; }
.quiz-prompt .ja { font-size: 14px; color: var(--ink-2); font-weight: 400; margin-top: 4px; }

.quiz-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: var(--surface-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}

.quiz-symbol {
  display: grid;
  place-items: center;
  min-height: 180px;
  background: var(--surface-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 20px;
}
.quiz-symbol svg { max-width: 100%; height: auto; }

.options { display: flex; flex-direction: column; gap: 8px; }

.option {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 13px 14px;
  text-align: left;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 120ms ease;
}
.option:hover:not(:disabled) { border-color: var(--ink-4); }

.option-key {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-4);
  flex: none;
  width: 14px;
}

.option-text { flex: 1; font-size: 14px; line-height: 1.4; }
.option-text .ja { font-size: 12px; color: var(--ink-3); }

/* Correct and wrong need colour, and green/red are exactly the
   NATO neutral/hostile hues. Resolved with weight and a rule on
   the inline edge instead of a fill, so the semantic palette
   stays undiluted. */
.option[data-r='right'] { border-color: var(--ink-2); box-shadow: inset 3px 0 0 var(--ink); }
.option[data-r='wrong'] { border-color: var(--line); opacity: 0.5; box-shadow: inset 3px 0 0 var(--ink-4); }
.option[data-r='picked-wrong'] { border-color: var(--ink-4); box-shadow: inset 3px 0 0 var(--signal); }
.option:disabled { cursor: default; }

.verdict {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}
.verdict[data-ok='0'] { color: var(--signal); }

.recog-points { margin: 0; padding-left: 18px; font-size: 13px; color: var(--ink-2); }
.recog-points li { margin-bottom: 5px; }

/* --------------------------------------------------- symbols */

.aff-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; }
.aff-legend span { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.aff-legend i { width: 10px; height: 10px; border-radius: 2px; }
.aff-legend i[data-a='F'] { background: var(--aff-friendly); }
.aff-legend i[data-a='H'] { background: var(--aff-hostile); }
.aff-legend i[data-a='N'] { background: var(--aff-neutral); }
.aff-legend i[data-a='U'] { background: var(--aff-unknown); }

.sidc {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: 0.06em;
}

/* ---------------------------------------------------- armory */

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.tile {
  display: block;
  background: var(--surface-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 13px;
  text-decoration: none;
  color: inherit;
}
.tile:hover { border-color: var(--line); }
.tile.locked { opacity: 0.42; }

.tile-name { font-size: 13px; font-weight: 600; line-height: 1.3; }
.tile-meta { font-size: 11px; color: var(--ink-3); margin-top: 3px; font-family: var(--mono); }

.count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-3);
}
.count b { color: var(--ink); font-weight: 500; }

/* ------------------------------------------------- utilities */

.muted { color: var(--ink-3); font-size: 13px; }
.tiny  { font-size: 11px; color: var(--ink-4); }
.mono  { font-family: var(--mono); }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-3);
  font-size: 14px;
}
.empty p { margin: 0 0 14px; }

.spinner {
  width: 18px; height: 18px;
  margin: 40px auto;
  border: 2px solid var(--line);
  border-top-color: var(--ink-3);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 15px;
  font-size: 13px;
  z-index: 60;
  max-width: calc(100% - 32px);
}

/* Unlock moment (§12). One orchestrated reveal, not a hover
   effect on every card. */
.unlock {
  border: 1px solid var(--signal-dim);
  background: var(--signal-wash);
  border-radius: var(--radius);
  padding: 14px;
  animation: unlock 420ms cubic-bezier(0.2, 0.8, 0.3, 1);
}
.unlock .label {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--signal);
  margin-bottom: 4px;
}
@keyframes unlock {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}

@media (min-width: 700px) {
  .grid-2 { grid-template-columns: repeat(3, 1fr); }
  .grid-3 { grid-template-columns: repeat(4, 1fr); }
}
