/* Anatomy — one stylesheet, no framework.
   Used mostly on a desktop, also on iPhone and iPad. The base (dark, high
   contrast, big type, the same cards and buttons) is GeographyApp's, so the
   apps feel like siblings; the accent is violet so they're told apart. The
   diagram is the light thing on the dark page: a white worksheet.

   Two layouts for the diagram screens (quiz, practice and report):
     · wide (≥ 900px): diagram on the left, staying put while the list on the
       right scrolls past it;
     · narrow: diagram across the top, held at the top of the screen, list below. */

:root {
  --bg: #0f1b2d;
  --card: #16263d;
  --card-2: #1c3150;
  --line: #2a4366;
  --text: #eaf2fb;
  --muted: #9db1ca;
  --accent: #8b5cf6;
  --accent-2: #6d28d9;
  --good: #22c55e;
  --bad: #f87171;
  --warn: #fbbf24;
  --radius: 14px;

  /* the diagram */
  --paper: #ffffff;
  --leader: #334155;
  --hl: #f59e0b;
  --marker: #1e293b;
  --marker-used: #e2e8f0;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
[hidden] { display: none !important; } /* beats a class's display: flex */
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.center { text-align: center; }

/* ---- login ---- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-card .logo {
  width: 64px; height: 64px; margin: 0 auto 16px;
  display: grid; place-items: center;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  border-radius: 18px;
}
.login-card .logo svg { width: 38px; height: 38px; fill: none; stroke: #fff; stroke-width: 1.8; }
.login-card h1 { margin: 0 0 4px; font-size: 26px; }
.login-card form { margin-top: 20px; display: grid; gap: 10px; }
.error { color: var(--bad); font-size: 14px; min-height: 20px; }

/* ---- inputs ---- */

input, textarea, select {
  width: 100%; padding: 13px 14px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 11px;
  font-size: 16px; /* 16px stops iOS zooming the page on focus */
  font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  padding: 13px 16px;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  color: #fff; border: 0; border-radius: 11px;
  font-size: 16px; font-weight: 600; font-family: inherit;
  cursor: pointer;
}
button:disabled { opacity: .55; cursor: default; }
button.secondary { background: var(--card); border: 1px solid var(--line); color: var(--text); }
button.small { padding: 9px 13px; font-size: 14px; }
button.wide { display: block; width: calc(100% - 32px); margin: 12px 16px 0; }

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

#app { min-height: 100vh; }
#screen { padding-bottom: 90px; max-width: 760px; margin: 0 auto; }
/* The diagram screens use the whole width; the quiz also hides the nav, so
   the diagram gets the room and nothing else competes for his attention. */
body.screen-wide #screen { max-width: 1560px; }
body.screen-quiz .bottom-nav, body.screen-quiz .topbar { display: none; }
body.screen-quiz #screen { padding-bottom: 0; }

.topbar {
  display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 12px;
  border-bottom: 1px solid var(--line);
}
.date-label { font-size: 19px; font-weight: 700; }

.section-label {
  padding: 18px 16px 6px; font-size: 13px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; font-weight: 600;
}
.card {
  margin: 12px 16px; padding: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.empty { color: var(--muted); text-align: center; padding: 26px 16px; font-size: 15px; }
.msg { min-height: 20px; font-size: 14px; padding: 6px 16px 0; }
.card .msg, .sec-body .msg { padding: 0; }
.msg.ok { color: var(--good); }
.msg.bad { color: var(--bad); }
.item-meta { font-size: 14px; color: var(--muted); margin-top: 4px; }
.inline-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---- collapsibles (Settings) ---- */

.sec { margin: 12px 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.sec-head {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: none; border: 0; padding: 15px 16px; color: var(--text); font-size: 16px; font-weight: 600;
  text-align: left;
}
.sec-chevron { transition: transform .2s; color: var(--muted); font-size: 20px; }
.sec.open > .sec-head .sec-chevron { transform: rotate(90deg); }
.sec-body { display: none; padding: 0 16px 16px; gap: 10px; grid-template-columns: 1fr; }
.sec.open > .sec-body { display: grid; }

/* ---- choosing a diagram ----
   (The class names still say "map": the layout is GeographyApp's, kept
   recognisable so a fix in one app can be found in the other.) */

.resume { border-color: var(--warn); display: grid; gap: 8px; }
.resume-title { font-size: 18px; font-weight: 700; }
.resume-buttons { margin-top: 4px; }

.map-picker { display: grid; gap: 10px; padding: 0 16px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.pick-card {
  text-align: left; display: grid; gap: 4px;
  background: var(--card); border: 2px solid var(--line); color: var(--text);
  border-radius: var(--radius); padding: 15px 16px; font-weight: 400;
}
.pick-card.on { border-color: var(--accent); background: rgba(139, 92, 246, .12); }
.pick-name { font-size: 20px; font-weight: 700; }
.pick-meta { font-size: 14px; color: var(--muted); }
.pick-blurb { font-size: 14px; color: var(--text); opacity: .85; line-height: 1.35; }
.size-picker { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px; }
.chip {
  min-width: 64px; padding: 11px 16px; font-size: 17px; font-weight: 700;
  background: var(--card); border: 2px solid var(--line); color: var(--muted);
  border-radius: 99px;
}
.chip.on { background: rgba(139, 92, 246, .15); border-color: var(--accent); color: var(--text); }
.begin {
  display: block; width: calc(100% - 32px); margin: 18px 16px 10px;
  padding: 20px; font-size: 22px; font-weight: 800; border-radius: 16px;
}

/* ---- the diagram ---- */

/* The box takes the diagram's own proportions (diagram.js sets aspect-ratio),
   so a tall diagram sits narrower and centred instead of leaving strips at its
   sides. Its height is capped by the layout below; the width follows. */
.map-wrap {
  position: relative; background: var(--paper);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 0 0 1px var(--line); /* not a border: it'd skew the proportions */
  margin-inline: auto; max-width: 100%;
  max-height: calc(100svh - 150px); /* the quiz: header, the zoom row and the credit */
}
.map {
  display: block; width: 100%; height: 100%;
  touch-action: pan-y;          /* let the page scroll past an unzoomed diagram… */
  user-select: none; -webkit-user-select: none;
}
.map-wrap.zoomed .map { touch-action: none; cursor: grab; } /* …but a zoomed one is dragged */
.map-wrap.zoomed .map:active { cursor: grabbing; }

.map .paper { fill: var(--paper); }
.map .art { pointer-events: none; }

/* A line from each number to a dot on its part, like a textbook diagram. */
.map .callouts { pointer-events: none; }
.map .callouts line { stroke: var(--leader); stroke-width: 1.3; vector-effect: non-scaling-stroke; }
.map .callouts circle { fill: var(--leader); stroke: #fff; stroke-width: .8; }
.map .callouts .hover line { stroke: var(--accent-2); stroke-width: 2.2; }
.map .callouts .right line { stroke: #15803d; }
.map .callouts .right circle { fill: #15803d; }
.map .callouts .wrong line { stroke: #dc2626; }
.map .callouts .wrong circle { fill: #dc2626; }
/* Picked out: a thick amber line with a dark edge, readable on any colour. */
.map .callouts .hl line { stroke: var(--hl); stroke-width: 3; }
.map .callouts .hl circle { fill: var(--hl); stroke: #1e293b; stroke-width: 1.2; }

.map .markers { pointer-events: none; }
.map-wrap.clickable .markers { pointer-events: auto; }
.map-wrap.clickable .marker { cursor: pointer; }
.map .tags { pointer-events: none; }
.map .tag rect { fill: #0f1b2d; stroke: #fff; stroke-width: 1.5; }
.map .tag text { fill: #fff; font-size: 13px; font-weight: 800; font-family: inherit; }
.map .marker circle { fill: var(--marker); stroke: #fff; stroke-width: 1.6; }
.map .marker text { fill: #fff; font-size: 11.5px; font-weight: 800; font-family: inherit; }
/* A number he's already written somewhere: pale, so the ones left stand out. */
.map .marker.used circle { fill: var(--marker-used); stroke: var(--marker); }
.map .marker.used text { fill: var(--marker); }
.map .marker.right circle { fill: #15803d; stroke: #fff; }
.map .marker.wrong circle { fill: #dc2626; stroke: #fff; }
.map .marker.right text, .map .marker.wrong text { fill: #fff; }
.map .marker.hl circle { fill: var(--hl); stroke: #fff; }
.map .marker.hl text { fill: #fff; }

/* Who drew it: under every diagram (some licences ask for it). */
.credit { margin-top: 6px; font-size: 11px; color: var(--muted); text-align: center; line-height: 1.35; overflow-wrap: anywhere; }
.credit a { color: var(--muted); }
.credit.at-side { margin-top: 14px; }
@media (max-width: 899px) { .credit.at-map { display: none; } }
@media (min-width: 900px) { .credit.at-side { display: none; } }

/* The zoom buttons: a row under the diagram, never on it (GeographyApp
   learned that a stack in the corner covers numbers). */
.map-tools {
  display: flex; justify-content: center; gap: 8px; margin-top: 8px;
}
.map-tool {
  width: 44px; height: 34px; padding: 0;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 20px; font-weight: 700; line-height: 1;
}
.map-tool:disabled { opacity: .4; }

/* ---- diagram screens: the shared two-column layout ---- */

.mapview { display: grid; gap: 12px; padding: 12px 16px 16px; }
.mapview-map { min-width: 0; }
.mapview-side { min-width: 0; }

/* Narrow: the diagram stays at the top of the screen while the list scrolls. */
@media (max-width: 899px) {
  .mapview-map { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: calc(env(safe-area-inset-top) + 6px) 0 8px; margin: 0 -4px; }
  .mapview-map .map-wrap { max-height: 44svh; }
}

/* Wide: diagram left, list right. */
@media (min-width: 900px) {
  .mapview {
    grid-template-columns: minmax(0, 1fr) clamp(340px, 32vw, 480px);
    grid-template-areas: "head head" "map side";
    align-items: start; column-gap: 20px;
  }
  .quiz-head, .report-head { grid-area: head; }
  .mapview-map { grid-area: map; position: sticky; top: 12px; }
  .mapview-side { grid-area: side; }
  /* Outside the quiz the top bar and the nav are showing too. */
  body:not(.screen-quiz) .mapview-map .map-wrap { max-height: calc(100svh - 250px); }
}

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

.quiz { padding-top: calc(env(safe-area-inset-top) + 12px); }
.quiz-head { display: flex; align-items: center; gap: 12px; }
.quiz-title { font-size: 20px; font-weight: 800; flex: 1; }
.quiz-progress { font-size: 15px; color: var(--muted); font-weight: 600; }
.quiz-help { margin: 2px 0 10px; color: var(--muted); font-size: 15px; }

.name-grid { display: grid; gap: 6px 10px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.name-row {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 8px;
  padding: 6px 6px 6px 12px; min-height: 52px;
  background: var(--card); border: 1px solid var(--line); border-radius: 11px;
  cursor: text;
}
.name-row .name { font-size: 16px; font-weight: 600; line-height: 1.2; }
.name-row.filled { border-color: #36557f; }
.name-row:focus-within { border-color: var(--accent); background: var(--card-2); }
.num-input {
  width: 58px; padding: 8px 4px; text-align: center;
  font-size: 20px; font-weight: 800; letter-spacing: .02em;
  background: var(--bg); border-width: 2px;
}
.row-hint { grid-column: 1 / -1; font-size: 13px; color: var(--warn); }
.row-hint:empty { display: none; }
.name-row.warn { border-color: var(--warn); }

.quiz-foot {
  position: sticky; bottom: 0; z-index: 1;
  display: grid; gap: 6px; margin-top: 12px;
  padding: 12px 0 calc(env(safe-area-inset-bottom) + 12px);
  background: linear-gradient(to bottom, rgba(15, 27, 45, 0), var(--bg) 22%);
}
.check { padding: 17px; font-size: 19px; font-weight: 800; border-radius: 14px; }
.check:not(.ready) { background: var(--card-2); border: 1px solid var(--line); }
.check-msg { font-size: 15px; color: var(--warn); text-align: center; }
.check-msg:empty { display: none; }
.save-note { font-size: 12px; color: var(--muted); text-align: center; min-height: 15px; }
.save-note.bad { color: var(--warn); }

/* ---- practice (learn.js): tap a place, see its name ---- */

.learn-now {
  display: flex; align-items: center; gap: 12px; min-height: 52px;
  padding: 6px 0 4px; font-size: 26px; font-weight: 800;
}
.learn-now-num {
  min-width: 44px; height: 44px; padding: 0 8px; border-radius: 99px;
  display: grid; place-items: center; font-size: 20px;
  background: #f59e0b; color: #fff;
}
.learn-now-hint { font-size: 17px; font-weight: 600; color: var(--muted); }
.learn-tools { margin-bottom: 10px; }
/* What the part does: the line under the big name. */
.learn-job { margin: 0 0 10px; font-size: 16px; line-height: 1.45; min-height: 1.45em; }
.learn-job:empty { display: none; }
.learn-now { scroll-margin-top: 12px; }
/* Practice with the list of names hidden: on a narrow screen there's no list
   to scroll, so the diagram can have more of the height. */
@media (max-width: 899px) {
  .learn.no-list .mapview-map { position: static; }
  .learn.no-list .mapview-map .map-wrap { max-height: 62svh; }
}
.learn-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 6px 6px 12px; min-height: 52px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 11px;
  color: var(--text); font-weight: 400;
}
.learn-row .name { font-size: 16px; font-weight: 600; line-height: 1.2; }
.learn-num {
  flex: 0 0 auto; width: 44px; height: 38px; border-radius: 9px;
  display: grid; place-items: center; font-size: 18px; font-weight: 800;
  background: var(--bg); border: 2px dashed var(--line); color: var(--text);
}
.learn-row.seen .learn-num { border-style: solid; border-color: #36557f; }
.learn-row.on { border-color: var(--warn); background: var(--card-2); }
.learn-row.on .learn-num { background: #f59e0b; border-color: #f59e0b; color: #fff; }

/* ---- the report ---- */

.report-head { display: flex; align-items: center; gap: 12px; }
.report-card { margin: 0 0 12px; }
.report-map { font-size: 22px; font-weight: 800; }
.result-job { font-size: 14px; color: var(--muted); margin-top: 3px; line-height: 1.35; }
.score { display: flex; align-items: baseline; gap: 10px; margin: 12px 0 6px; }
.score-big { font-size: 42px; font-weight: 800; }
.score-big.perfect { color: var(--good); }
.score-label { color: var(--muted); font-size: 17px; }
.facts { display: flex; flex-wrap: wrap; gap: 22px; margin-top: 8px; }
.fact-value { font-size: 19px; font-weight: 700; }
.fact-label { font-size: 13px; color: var(--muted); }
.note-line { margin-top: 12px; font-size: 16px; font-weight: 700; }
.note-line.good { color: var(--good); }
.again { display: block; width: 100%; margin-top: 14px; padding: 15px; font-size: 17px; }

.result-group { margin-top: 6px; }
.group-title { padding: 10px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.group-title.wrong { color: var(--bad); }
.group-title.right { color: var(--good); }
.result-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 12px; margin-top: 6px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 11px;
  color: var(--text); font-weight: 400;
}
.result-row.on { border-color: var(--warn); background: var(--card-2); }
.result-body { flex: 1; min-width: 0; }
.result-name { font-size: 17px; font-weight: 700; }
.typed { font-size: 15px; margin-top: 3px; color: var(--muted); }
.typed-bad { color: var(--bad); font-weight: 700; text-decoration: line-through; text-decoration-thickness: 1px; }
.result-num {
  flex: 0 0 auto; min-width: 34px; height: 34px; padding: 0 6px; border-radius: 99px;
  display: grid; place-items: center; font-weight: 800; color: #fff;
}
.result-row.wrong .result-num { background: #dc2626; }
.result-row.right .result-num { background: #15803d; }

/* ---- reports history ---- */

.history-card {
  display: flex; align-items: center; gap: 14px; width: calc(100% - 32px);
  margin: 8px 16px 0; padding: 14px 16px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); font-weight: 400;
}
.history-main { flex: 1; min-width: 0; }
.history-list { font-size: 17px; font-weight: 700; }
.history-meta { font-size: 14px; color: var(--muted); margin-top: 3px; }
.history-score-big { font-size: 22px; font-weight: 800; }
.history-score.perfect { color: var(--good); }

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

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav .nav-item {
  flex: 1; background: none; border: 0; color: var(--muted); border-radius: 0;
  font-size: 12px; font-weight: 600; padding: 9px 0 8px;
  display: grid; justify-items: center; gap: 3px;
}
.bottom-nav .nav-item svg {
  width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.bottom-nav .nav-item.active { color: var(--accent); }

/* ---- desktop ---- */

@media (min-width: 900px) {
  .bottom-nav { justify-content: center; }
  .bottom-nav .nav-item { flex: 0 1 140px; }
}
@media (hover: hover) {
  button:not(:disabled):hover { filter: brightness(1.12); }
  .pick-card:hover, .history-card:hover, .result-row:hover, .chip:hover, .learn-row:hover { border-color: var(--accent); }
  .bottom-nav .nav-item:hover { color: var(--text); filter: none; }
  .map-tool:not(:disabled):hover { border-color: var(--accent); filter: none; }
}
