/* Shipdle – dark HUD theme. Desktop first; mobile comes in v1.
   All colours, spacing, font sizes and component sizes are design tokens
   defined once in :root. Rules below should use the tokens, not raw values. */

:root {
  /* Colours */
  --bg: #070b10;
  --bg-glow: #0d1a26;
  --panel: #0e1620;
  --panel-raised: #142130;
  --line: #1f3446;
  --line-bright: #2f5470;
  --text: #dbe7f0;
  --text-dim: #8aa2b5;
  --accent: #4cc9f0;
  --accent-rgb: 76 201 240; /* same as --accent, for see-through versions: rgb(var(--accent-rgb) / 0.2) */
  --accent-hover: #7dd8f5;
  --accent-dim: #2a7fa0;
  --on-accent: #04131c;     /* text on an accent-coloured button */
  --backdrop: rgb(3 6 10 / 0.75);
  --shadow: rgb(0 0 0 / 0.5);

  /* Result colours */
  --match: #24864f;
  --partial: #b8892a;
  --miss: #8f2f33;
  --unknown: #2a3440;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 40px;

  /* Type scale */
  --text-xs: 0.72rem;   /* small labels, captions */
  --text-sm: 0.85rem;   /* secondary text */
  --text-md: 0.92rem;   /* cell values, buttons */
  --text-base: 1rem;
  --text-lg: 1.15rem;   /* search box, readouts */
  --text-xl: 1.4rem;    /* popup titles and big numbers */
  --text-2xl: 2rem;     /* logo */

  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-hud: "Bahnschrift", "DIN Alternate", "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;

  /* Shapes and sizes */
  --radius: 6px;
  --radius-sm: 4px;
  --page-width: 1200px;
  --search-width: 560px;
  --message-width: 720px;
  --page-gutter: var(--space-6);   /* total side margin when the window is narrower */
  --control-size: 40px;            /* square icon buttons */
  --icon-size: 22px;
  --control-size-sm: 32px;         /* popup close button */
  --cell-height: 68px;
  --grid-gap: 6px;
  --dialog-width: 460px;
  --dialog-width-wide: 620px;

  /* Guess reveal animation. main.js reads these to know when a row has
     finished revealing, so change them here only. */
  --reveal-duration: 450ms;
  --reveal-stagger: 90ms;   /* delay between one cell and the next */

  /* Ship, Manufacturer, Size, Role, Crew, Cargo, Price, Length.
     Role gets the most room: it's the longest text. */
  --columns: minmax(160px, 1.5fr) repeat(2, minmax(88px, 1fr)) minmax(130px, 1.5fr)
             minmax(72px, 0.8fr) repeat(3, minmax(88px, 1fr));
}

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

[hidden] { display: none !important; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at top, var(--bg-glow), transparent 60%),
    /* faint scanlines */
    repeating-linear-gradient(0deg, transparent 0 3px, rgb(255 255 255 / 0.012) 3px 4px),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
}

a { color: var(--accent); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Shared page column */
.topbar,
.game,
.footer {
  width: min(var(--page-width), 100% - var(--page-gutter));
  margin: 0 auto;
}

.icon {
  width: var(--icon-size);
  height: var(--icon-size);
}

/* Small uppercase HUD labels: tagline, readouts, column heads, popup labels */
.tagline,
.readout dt,
.head,
.dialog__heading,
.answer__label,
.countdown__label {
  font-family: var(--font-hud);
  font-size: var(--text-xs);
  text-transform: uppercase;
  color: var(--text-dim);
}

/* Numbers and the text result */
.readout dd,
.stat__value,
.countdown__time,
.dist__label,
.dist__bar,
.share-text {
  font-family: var(--font-mono);
}

/* Keyboard focus ring for every kind of button */
.button:focus-visible,
.icon-button:focus-visible,
.dialog__close:focus-visible,
.link-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) 0 var(--space-4);
  border-bottom: 1px solid var(--line);
}

.logo {
  margin: 0;
  font-family: var(--font-hud);
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: 0.25em;
  color: var(--text);
  text-shadow: 0 0 18px rgb(var(--accent-rgb) / 0.35);
}
.logo span { color: var(--accent); }

.tagline {
  margin: var(--space-1) 0 0;
  letter-spacing: 0.22em;
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.readout {
  display: flex;
  gap: var(--space-5);
  margin: 0 var(--space-4) 0 0;
}
.readout div { text-align: right; }
.readout dt { letter-spacing: 0.18em; }
.readout dd {
  margin: 0;
  font-size: var(--text-lg);
  color: var(--accent);
}

/* ---------- Main area ---------- */

.game {
  flex: 1;
  padding: var(--space-5) 0 var(--space-7);
}

.message {
  max-width: var(--message-width);
  margin: 0 auto var(--space-5);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--line-bright);
  border-left-width: var(--space-1);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: center;
}
.message--error,
.message--loss { border-color: var(--miss); }
.message--win { border-color: var(--match); }

/* ---------- Search ---------- */

.search {
  --bracket-size: 14px;
  --bracket-offset: -6px;
  position: relative;
  max-width: var(--search-width);
  margin: 0 auto var(--space-4);
}

/* HUD corner brackets around the search box */
.search::before,
.search::after {
  content: "";
  position: absolute;
  width: var(--bracket-size);
  height: var(--bracket-size);
  border: 2px solid var(--accent);
  pointer-events: none;
}
.search::before { top: var(--bracket-offset); left: var(--bracket-offset); border-right: 0; border-bottom: 0; }
.search::after { bottom: var(--bracket-offset); right: var(--bracket-offset); border-left: 0; border-top: 0; }

.search__input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--line-bright);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: var(--text-lg);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search__input::placeholder { color: var(--text-dim); }
.search__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(var(--accent-rgb) / 0.18);
}

.suggestions {
  position: absolute;
  z-index: 10;
  top: calc(100% + var(--space-1));
  left: 0;
  right: 0;
  max-height: 340px; /* about eight suggestions */
  overflow-y: auto;
  margin: 0;
  padding: var(--space-1);
  list-style: none;
  border: 1px solid var(--line-bright);
  border-radius: var(--radius);
  background: var(--panel-raised);
  box-shadow: 0 12px 32px var(--shadow);
}

.suggestion {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.suggestion.is-active,
.suggestion:hover { background: rgb(var(--accent-rgb) / 0.14); }
.suggestion__maker { color: var(--text-dim); font-size: var(--text-md); }
.suggestion--empty { color: var(--text-dim); cursor: default; }
.suggestion--empty:hover { background: none; }

/* ---------- Hint ---------- */

.hint {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  margin: 0 auto var(--space-5);
  color: var(--text-dim);
}
.hint__text {
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--partial);
  border-radius: var(--radius);
  color: var(--text);
}
.button--hint {
  border-style: dashed;
  background: transparent;
  color: var(--text);
  font-weight: 500;
}
.button--hint:disabled {
  color: var(--text-dim);
  border-color: var(--line);
  cursor: default;
}

/* ---------- Board ---------- */

.board {
  display: grid;
  gap: var(--grid-gap);
  overflow-x: auto;
}

.row,
#rows {
  display: grid;
  gap: var(--grid-gap);
}
.row { grid-template-columns: var(--columns); }

.head {
  padding: var(--space-2) var(--space-1);
  border-bottom: 2px solid var(--accent-dim);
  letter-spacing: 0.16em;
  text-align: center;
}
.head[title] { cursor: help; }

#rows:empty::before {
  content: "Awaiting first scan… type a ship name above.";
  padding: var(--space-6) 0;
  color: var(--text-dim);
  text-align: center;
  font-style: italic;
}

.cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: var(--cell-height);
  /* extra room at the top keeps wrapped text clear of the corner icon */
  padding: var(--space-4) var(--space-3) var(--space-3);
  border: 1px solid rgb(255 255 255 / 0.08);
  border-radius: var(--radius);
  text-align: center;
  font-weight: 600;
  text-shadow: 0 1px 2px var(--shadow);
}

.cell__value { font-size: var(--text-md); }
.cell__sub {
  margin-top: 2px;
  font-size: var(--text-xs);
  font-weight: 400;
  opacity: 0.8;
}
.cell__icon {
  position: absolute;
  top: var(--space-1);
  right: var(--space-2);
  font-size: var(--text-xs);
  opacity: 0.75;
}

.cell--match,
.cell--name-match { background: var(--match); }
.cell--partial { background: var(--partial); }
.cell--miss,
.cell--higher,
.cell--lower { background: var(--miss); }
.cell--unknown { background: var(--unknown); color: var(--text-dim); }

/* Up/down arrows sit just above the value, so both stay readable. */
.cell--higher .cell__icon,
.cell--lower .cell__icon {
  position: static;
  margin-bottom: var(--space-1);
  font-size: var(--text-sm);
  line-height: 1;
  opacity: 0.95;
}

.cell--name {
  align-items: flex-start;
  text-align: left;
  padding-left: var(--space-4);
  background: var(--panel-raised);
  border-color: var(--line-bright);
}
.cell--name-partial {
  border-color: var(--partial);
  box-shadow: inset var(--space-1) 0 0 var(--partial);
}

/* Reveal animation for new guesses (timing tokens are in :root) */
.cell--reveal {
  animation: reveal var(--reveal-duration) ease-out both;
}
@keyframes reveal {
  from { opacity: 0; transform: rotateX(80deg); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .cell--reveal,
  .dialog[open] { animation: none; }
}

/* ---------- Buttons ---------- */

.button {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line-bright);
  border-radius: var(--radius);
  background: var(--panel-raised);
  color: var(--text);
  font: inherit;
  font-size: var(--text-md);
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.button:hover { border-color: var(--accent); }

.button--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}
.button--primary:hover { background: var(--accent-hover); }
.button--large { padding: var(--space-3) var(--space-5); font-size: var(--text-base); }

.icon-button {
  display: grid;
  place-items: center;
  width: var(--control-size);
  height: var(--control-size);
  padding: 0;
  border: 1px solid var(--line-bright);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--accent);
  cursor: pointer;
}
.icon-button:hover { border-color: var(--accent); }

.message .button { margin-left: var(--space-1); vertical-align: middle; }

/* ---------- Popups ---------- */

.dialog {
  width: min(var(--dialog-width), 100% - var(--page-gutter));
  padding: var(--space-6) var(--space-6) var(--space-5);
  border: 1px solid var(--line-bright);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 64px var(--shadow), 0 0 40px rgb(var(--accent-rgb) / 0.08);
}
.dialog--wide { width: min(var(--dialog-width-wide), 100% - var(--page-gutter)); }
.dialog::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(2px);
}
.dialog[open] { animation: dialog-in 0.2s ease-out; }
@keyframes dialog-in {
  from { opacity: 0; transform: translateY(var(--space-3)); }
}

.dialog p { margin: 0 0 var(--space-3); }

.dialog__close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: var(--control-size-sm);
  height: var(--control-size-sm);
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--text-dim);
  font-size: var(--text-base);
  cursor: pointer;
}
.dialog__close:hover { color: var(--text); background: var(--panel-raised); }

.dialog__title {
  margin: 0 0 var(--space-4);
  font-family: var(--font-hud);
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-align: center;
  color: var(--accent);
}
.dialog__title:focus { outline: none; }

.dialog__heading {
  margin: var(--space-5) 0 var(--space-3);
  font-weight: 600;
  letter-spacing: 0.18em;
}

.dialog__note { color: var(--text-dim); font-size: var(--text-sm); }
.dialog__actions { margin-top: var(--space-5); text-align: center; }

/* How to Play */

.legend {
  display: grid;
  gap: var(--grid-gap);
  margin: 0;
  padding: 0;
  list-style: none;
}
.legend li {
  display: grid;
  grid-template-columns: 110px 1fr; /* example cell, then explanation */
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-md);
}
.legend .cell {
  min-height: 38px;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
}
.legend .cell--name { padding-left: var(--space-3); }

.columns-help {
  display: grid;
  grid-template-columns: 70px 1fr; /* column name, then explanation */
  gap: var(--space-1) var(--space-3);
  margin: 0;
  font-size: var(--text-md);
}
.columns-help dt { font-weight: 700; }
.columns-help dd { margin: 0; color: var(--text-dim); }

/* Results */

.answer {
  margin-bottom: var(--space-5);
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-raised);
  text-align: center;
}
.answer p { margin: 0; }
.answer__label { letter-spacing: 0.18em; }
.answer .answer__ship { margin-top: var(--space-1); font-size: var(--text-xl); font-weight: 700; }
.answer__maker { color: var(--text-dim); font-size: var(--text-md); }
.answer .answer__summary { margin-top: var(--space-2); }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  text-align: center;
}
.stat__value {
  display: block;
  font-size: var(--text-xl);
  color: var(--text);
}
.stat__label {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-dim);
}

/* Distribution alone while playing; distribution + share preview once finished */
.results-grid {
  display: grid;
  gap: var(--space-5);
}
.results-grid--split { grid-template-columns: 1fr 1fr; }

.share-image {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.share-actions .button { flex: 1; }
.share-actions .button--primary { flex-basis: 100%; } /* main action gets its own row */

.button.is-done {
  border-color: var(--match);
  background: var(--match);
  color: var(--text);
}

/* A quiet text-style button, e.g. "Copy as text instead" */
.link-button {
  margin-top: var(--space-2);
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: var(--text-sm);
  text-decoration: underline;
  cursor: pointer;
}
.link-button.is-done { color: var(--match); text-decoration: none; }

/* Only shown when the text has to be copied by hand */
.share-text {
  display: block;
  width: 100%;
  margin-top: var(--space-2);
  padding: var(--space-2);
  resize: none;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--panel-raised);
  color: var(--text);
  font-size: var(--text-sm);
  white-space: pre;
  overflow-x: auto;
}

.share-status {
  min-height: 1.4em; /* keeps the layout still when a message appears */
  margin-top: var(--space-2);
  color: var(--text-dim);
  font-size: var(--text-sm);
}

.dist {
  display: grid;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}
.dist__row {
  display: grid;
  grid-template-columns: 18px 1fr; /* guess number, then bar */
  align-items: center;
  gap: var(--space-2);
}
.dist__label {
  font-size: var(--text-sm);
  color: var(--text-dim);
  text-align: right;
}
.dist__bar {
  min-width: 26px;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--unknown);
  font-size: var(--text-sm);
  text-align: right;
}
.dist__bar.is-today { background: var(--match); }
.dist__bar.is-today.is-loss { background: var(--miss); }

.dialog__footer {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-4);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}
.countdown__label {
  display: block;
  letter-spacing: 0.14em;
}
.countdown__time {
  font-size: var(--text-xl);
  color: var(--accent);
}

/* ---------- Footer ---------- */

.footer {
  padding: var(--space-4) 0 var(--space-5);
  border-top: 1px solid var(--line);
  color: var(--text-dim);
  font-size: var(--text-sm);
  text-align: center;
}
.footer p { margin: var(--space-1) 0; }
