:root {
  --bg: #0b0f14;
  --fg: #f2f5f8;
  --muted: #7d8b99;
  --accent: #3ddc91;
  --warn: #f0b429;
  --beta: #ff8c1a;
  --line: #1d2733;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.5rem;
  /* room for the fixed BETA banner, about 2rem tall. Nothing is reserved at
   * the bottom any more: the footer is in the flow and takes its own space. */
  padding: calc(2.6rem + env(safe-area-inset-top)) 1.5rem
           max(1.5rem, env(safe-area-inset-bottom));
}

.screen[hidden] { display: none; }

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  text-align: center;
}

/* --- the answer --- */

.side {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.side-arrow {
  font-size: clamp(4rem, 22vw, 8rem);
  line-height: 1;
  color: var(--accent);
}

.side-word {
  font-size: clamp(3.5rem, 19vw, 7rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--accent);
}

.side.unknown .side-arrow,
.side.unknown .side-word { color: var(--warn); }

.side.unknown .side-word { font-size: clamp(1.75rem, 9vw, 3rem); }

.sentence {
  margin: 0;
  font-size: 1.25rem;
  max-width: 24rem;
  text-wrap: balance;
}

.sentence strong { color: var(--accent); }

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 26rem;
}

/* Waiting for a platform face to be assigned. Fills over exactly one refresh,
   so the wait is visibly finite rather than a screen that just sits there. */
.pending {
  width: 100%;
  max-width: 22rem;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.pending[hidden] { display: none; }

.pending-bar {
  display: block;
  height: 100%;
  background: var(--warn);
  transform-origin: left;
  animation: pending-fill linear forwards;
}

@keyframes pending-fill {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

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

.ask-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
}

.ask-buttons,
.actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  width: 100%;
  max-width: 22rem;
  margin: 0 auto;
}

.ask-buttons button,
.actions button {
  padding: 1.25rem 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #131a23;
  color: var(--fg);
  font: inherit;
  font-size: 1.25rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 64px;
}

.ask-buttons button:active,
.actions button:active { background: var(--line); }

.actions[hidden] { display: none; }
.actions button[hidden] { display: none; }

/* The number sits with the buttons and is styled like them, because it is one
   of the two ways to answer the same question. Set in one rule: split across
   two, `font: inherit` here outweighs a font-size on `.unit-input` alone and
   quietly flattens the digits back to body text. */
.actions .unit-input {
  width: 100%;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #131a23;
  color: var(--fg);
  font-family: inherit;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.25em;
  font-variant-numeric: tabular-nums;
  min-height: 64px;
  text-align: center;
  /* letter-spacing adds a trailing gap; pull it back so digits stay centred */
  text-indent: 0.25em;
}

/* The example is set as a number in the same hand as your typing, so the shape
   of what's wanted — four digits — is legible before you start. Firefox dims
   placeholders by default, hence the explicit opacity. */
.actions .unit-input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.actions .hint {
  font-size: 0.8rem;
  text-align: center;
}

/* the status line only takes room when it has something to say */
.actions #unit-state:empty { display: none; }

/* --- settings + footer --- */

.key-input {
  width: 100%;
  max-width: 22rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #131a23;
  color: var(--fg);
  font: inherit;
  min-height: 52px;
}

/* In the flow, not fixed to the bottom.
 *
 * Fixed stopped working once the screens grew: on a five-row list it was drawn
 * across the last row, and with the keyboard up it landed on top of the
 * carriage field, because a fixed element is positioned against the layout
 * viewport, which the keyboard doesn't shrink. In flow it occupies real space
 * and can't cover anything. It sits under the controls rather than at the
 * screen edge, which is where it belongs anyway — it's chrome for them. */
#footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 0.5rem;
  padding: 0.25rem 1rem;
}

.footer-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
}

/* the footer's own lines are secondary, so they sit tighter than a real button
   while staying big enough to hit */
#footer .linkish {
  min-height: 34px;
  padding: 0.25rem 0.75rem;
}

#footer[hidden] { display: none; }

.linkish {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  min-height: 44px;
}

/* --- train picker --- */

.choose-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
  max-width: 24rem;
}

.train-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  width: 100%;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #131a23;
  color: var(--fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
  min-height: 64px;
}

.train-row:active { background: var(--line); }


.train-label {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.25;
}

/* --- beta banner --- */

.beta {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: calc(0.35rem + env(safe-area-inset-top)) 1rem 0.35rem;
  background: var(--bg);
  border-bottom: 1px solid var(--beta);
  color: var(--beta);
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  /* letter-spacing adds a trailing gap; pull it back so BETA stays centred */
  letter-spacing: 0.4em;
  text-indent: 0.4em;
  pointer-events: none;
}

.build {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
  padding: 0.25rem 0.4rem;
  cursor: pointer;
}

/* Diagnostics: monospace and left-aligned, because it exists to be screenshot
   and read back, not to look like the rest of the app. */
.debug {
  margin: 0 auto;
  max-width: 24rem;
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0e141b;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.7rem;
  line-height: 1.5;
  text-align: left;
  white-space: pre-wrap;
  overflow-x: auto;
}

.debug[hidden] { display: none; }

/* Closes the explanation. Fixed rather than in flow, because that page is
   taller than a small phone and a button at the end of it would need scrolling
   to reach. */
.close {
  position: fixed;
  top: calc(2.5rem + env(safe-area-inset-top));
  right: 0.75rem;
  z-index: 11;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #131a23;
  color: var(--muted);
  font: inherit;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
}

.close:active { background: var(--line); }
.close[hidden] { display: none; }

.prose {
  max-width: 26rem;
  text-align: left;
  color: var(--fg);
  font-size: 0.95rem;
}

.prose p { margin: 0 0 0.85rem; }

.prose ul {
  margin: 0 0 0.85rem;
  padding-left: 1.1rem;
  color: var(--muted);
}

.prose li { margin: 0.2rem 0; }

.prose .sign-off {
  margin-top: 1.25rem;
  color: var(--muted);
}

/* --- pull to look again --- */

.pull {
  position: fixed;
  top: calc(2.1rem + env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 9;
  padding: 0.4rem 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  pointer-events: none;
}

.pull[hidden] { display: none; }

/* the train you last picked, marked but not preferred */
.train-recent {
  margin-top: 0.15rem;
  color: var(--accent);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}

.train-units {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
