/* style.css — dark, quiet, out of the way of the sky. */

:root {
  --bg: #0a0a0f;
  --panel: #12121a;
  --line: #23232f;
  --ink: #e6e6ee;
  --dim: #9a9aa2;
  --accent: #7fd8e8;
  --tray-h: 132px;
}

* { box-sizing: border-box; }

/* author display rules must not defeat the hidden attribute */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
}

/* Dragging a piece sweeps the pointer across the header, the readout and the
   tray captions; without this the browser selects that text and turns the
   chrome blue behind the drag. Prose the player might want to keep — a note,
   a citation, the help sheet — opts back in below. */
body { overflow: hidden; user-select: none; -webkit-user-select: none; }

.overlay .sheet, #noteTitle, #noteBody, #note .cite {
  user-select: text;
  -webkit-user-select: text;
}

#app {
  position: fixed;
  inset: 0;
  display: grid;
  /* minmax(0,...) on both axes: without it the 82-thumbnail tray blows the
     grid up to its max-content width and the board canvas follows it. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
}
#app > * { min-width: 0; min-height: 0; }

/* --- top bar --------------------------------------------------------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding-top: max(8px, env(safe-area-inset-top));
}

#topbar #btnBack {
  flex: 0 0 auto;
  color: var(--dim);
  text-decoration: none;
  font-size: 16px;
  line-height: 1;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #1b1b26;
}
#topbar #btnBack:hover { color: var(--ink); background: #23232f; }

/* The site mark. btnBack only appears for a player who came from the site, so
   without this a visitor arriving from a link elsewhere has no way home at
   all. 26 px, which is why it is bakx-icon-small.svg: the ring's arcs close up
   below 64 px, so at this size the mark is the spike alone. */
#topbar .sitemark {
  flex: 0 0 auto;
  display: block;
  line-height: 0;
  opacity: .8;
}

#topbar .sitemark:hover { opacity: 1; }

#topbar .sitemark img { display: block; width: 26px; height: 26px; }

#topbar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: .01em;
  white-space: nowrap;
}

#topbar h1 .sub {
  font-weight: 400;
  color: var(--dim);
  font-size: 12px;
  margin-left: 8px;
}

.spacer { flex: 1; }

#readout {
  color: var(--dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  min-width: 0;
  flex: 0 1 auto;          /* the transient message yields space first ... */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* ... and says so, instead of cutting mid-word */
}

#progress {
  font-size: 12px;
  color: var(--dim);
  flex: 0 0 auto;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#progress strong { color: var(--ink); font-size: 14px; }

/* the streak counter: quiet next to the progress, loud for a moment when a
   run ends, so a broken streak is felt without a dialog */
#streak {
  font-size: 12px;
  flex: 0 0 auto;
  color: var(--dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #16161f;
  transition: color 200ms, border-color 200ms, background 200ms;
}
#streak strong { color: #7fd8e8; font-size: 14px; }
#streak #streakBest { color: #6a6a75; }
#streak #streakBest:not(:empty)::before { content: ' \00b7 '; }
#streak.hot { border-color: #2f6f7d; background: #16232a; }
#streak.hot strong { color: #a8ecf7; }
#streak.lost { animation: streakLost 900ms ease-out; }
@keyframes streakLost {
  0%   { color: #e88f8f; border-color: #6d3333; background: #26171a; }
  100% { color: var(--dim); border-color: var(--line); background: #16161f; }
}
@media (prefers-reduced-motion: reduce) {
  #streak.lost { animation: none; }
}

#controls { display: flex; gap: 6px; flex: 0 0 auto; }

/* --- options menu --------------------------------------------------------
   The header used to carry every switch in the game, which on a laptop left
   no room for the readout and on a phone wrapped to two rows. Only the view
   toggle, help and reset stay outside; the rest live in here. */

#optWrap { position: relative; }

#options {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  min-width: 246px;
  max-width: calc(100vw - 20px);
  padding: 6px;
  background: #14141c;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55);
}

#options .grp {
  margin: 6px 8px 3px;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #6a6a75;
}
#options .grp:first-child { margin-top: 2px; }

#options .opt {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 7px;
  padding: 6px 8px;
  color: var(--dim);
}
#options .opt .lab { flex: 1; }
#options .opt:hover { background: #20202b; color: var(--ink); }
#options .opt kbd {
  font: inherit;
  font-size: 10px;
  color: #5f5f6b;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  min-width: 16px;
  text-align: center;
}
/* a fixed tick slot, so the labels line up whatever their state */
#options .opt::before {
  content: '';
  width: 12px;
  font-size: 11px;
  color: #7fd8e8;
}
#options .opt[aria-pressed="true"] { color: var(--ink); }
#options .opt[aria-pressed="true"]::before { content: '\2713'; }
/* the piece-set row is a choice, not a checkbox: its label carries the state */
#options .opt.cycle::before { content: '\203a'; color: #6a6a75; }
#options .opt.cycle .lab { color: var(--ink); }

button {
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  background: #1b1b26;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: #23232f; }
button:active { transform: translateY(1px); }
button[aria-pressed="true"] {
  background: #17323a;
  border-color: #2c6474;
  color: var(--accent);
}
button.warn { color: #ffb4a8; border-color: #4a2a26; }

/* --- board ------------------------------------------------------------ */

#stage { position: relative; overflow: hidden; min-width: 0; min-height: 0; }

#board {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#board.grabbing { cursor: grabbing; }
#board.dropping { cursor: none; }
#board.armed { cursor: crosshair; }   /* a piece is selected: click to place it */

#zoomctl {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
#zoomctl button {
  width: 34px;
  height: 30px;
  padding: 0;
  background: rgba(18,18,26,.85);
  backdrop-filter: blur(4px);
}

/* --- inspector -------------------------------------------------------- */

#inspector {
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: 264px;
  padding: 10px;
  background: rgba(15,15,22,.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 30px rgba(0,0,0,.55);
}

/* while a piece is being dragged the inspector must not sit over the sky */
#inspector.dragging { opacity: .18; pointer-events: none; }

#inspector .close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  padding: 0;
  line-height: 1;
  font-size: 15px;
  background: transparent;
  border-color: transparent;
  color: var(--dim);
}

#inspectorCanvas {
  display: block;
  margin: 0 auto 8px;
  border-radius: 8px;
  background: #04040a;
  cursor: grab;
  touch-action: none;
}

#inspector .name { font-weight: 650; font-size: 13px; }
#inspector .field { color: var(--dim); font-size: 11px; margin-bottom: 8px; }

.slider {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 10px;
  color: var(--dim);
}
.slider input { flex: 1; accent-color: var(--accent); min-width: 0; }

#inspector .coords {
  margin-top: 7px;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #aab3cf;
}

#inspector .tip {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--dim);
  line-height: 1.35;
}

/* --- tray -------------------------------------------------------------- */

#trayWrap {
  min-width: 0;
  overflow: hidden;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

#trayHead {
  display: flex;
  gap: 12px;
  align-items: baseline;
  padding: 6px 12px 0;
  font-size: 11px;
  color: var(--dim);
}
#trayHead .hint { opacity: .75; }

#tray {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 12px 10px;
  touch-action: pan-x;
  scrollbar-width: thin;
}

.thumb {
  flex: 0 0 auto;
  width: 96px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 3px;
  background: #04040a;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.thumb canvas { display: block; border-radius: 6px; pointer-events: none; }
.thumb .cap {
  font-size: 10px;
  color: var(--dim);
  text-align: center;
  padding-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thumb.sel { border-color: var(--accent); box-shadow: 0 0 0 1px #2c6474 inset; }
.thumb.sel .cap { color: var(--accent); }
.thumb.dragging { opacity: .35; }

/* --- overlays ---------------------------------------------------------- */

#loader {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 50;
}
.lbox { text-align: center; width: min(320px, 80vw); }
.lbox p { color: var(--dim); font-size: 13px; }
.ring {
  width: 46px; height: 46px; margin: 0 auto;
  border: 3px solid #1e2b33;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 4px; background: #1a1a24; border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
#loadHint { margin-top: 14px; }
#loadHint button { margin-left: 4px; }

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(5,5,10,.78);
  backdrop-filter: blur(3px);
  z-index: 40;
  padding: 20px;
}
.overlay .sheet {
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.overlay h2 { margin: 0 0 12px; font-size: 17px; }
.overlay p { margin: 0 0 12px; color: #c9c9d4; font-size: 13.5px; }
.overlay button {
  margin-top: 6px;
  padding: 8px 16px;
  font-size: 13px;
  background: #17323a;
  border-color: #2c6474;
  color: var(--accent);
}

/* --- the completion sheet's score ---------------------------------------- */

#doneScore {
  width: 100%;
  margin: 0 0 14px;
  border-collapse: collapse;
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #aab3cf;
}
#doneScore td { padding: 3px 0; border-bottom: 1px solid #1c1c26; }
#doneScore td:nth-child(2) { color: #6a6a75; text-align: right; padding-right: 12px; }
#doneScore .pts { text-align: right; color: var(--accent); width: 4.5em; }
#doneScore .pts.neg { color: #d98a8a; }
#doneScore .total td { border-bottom: 0; border-top: 1px solid #2c3a44; padding-top: 7px; }
#doneScore .total td:first-child { color: var(--ink); letter-spacing: .08em; text-transform: uppercase; }
#doneScore .total td:last-child { color: #ffcf6b; font-size: 15px; letter-spacing: .06em; text-align: right; }

.overlay .btns { display: flex; gap: 8px; flex-wrap: wrap; }
.overlay .btns button.primary { background: #2c5d6c; border-color: #7fd8e8; color: #eafaff; }

/* --- the high-score machine ----------------------------------------------
   A pinball backglass: fixed-pitch, phosphor, three letters on wheels. The
   glow is text-shadow and the scanlines a gradient, so it costs one element
   and no image. */

#hiscore .sheet.arcade {
  position: relative;
  width: min(400px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 20px 22px 18px;
  background: #04060c;
  border: 1px solid #2b3f52;
  border-radius: 10px;
  box-shadow: 0 0 0 3px #0a0e16, 0 0 44px rgba(127, 216, 232, .10),
              inset 0 0 70px rgba(24, 60, 78, .35);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* the glass: scanlines over everything, in the way of nothing */
#hiscore .scan {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 10px;
  background: repeating-linear-gradient(
    to bottom, rgba(0, 0, 0, .28) 0 1px, transparent 1px 3px);
  opacity: .55;
}

#hiscore h2 {
  margin: 0 0 12px;
  text-align: center;
  font-size: 15px;
  letter-spacing: .34em;
  text-indent: .34em;              /* the tracking on the last letter, undone */
  text-transform: uppercase;
  color: #ffcf6b;
  text-shadow: 0 0 12px rgba(255, 176, 0, .55);
}

#hiscore .hsTabs { display: flex; gap: 6px; justify-content: center; margin-bottom: 12px; }
#hiscore .hsTab {
  margin: 0;
  padding: 3px 10px;
  font: inherit;
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  background: transparent;
  border: 1px solid #23323f;
  border-radius: 5px;
  color: #566579;
}
#hiscore .hsTab[aria-pressed="true"] {
  color: #9fe8f7;
  border-color: #35707f;
  background: #0b1c24;
}
#hiscore .hsTab:disabled { opacity: .45; }

#hiscore .hsList { list-style: none; margin: 0 0 14px; padding: 0; }
#hiscore .hsList li {
  display: grid;
  grid-template-columns: 2.2em 1fr auto 4.2em;
  gap: 8px;
  align-items: center;
  padding: 2.5px 2px;
  font-size: 13px;
  letter-spacing: .06em;
  color: #7fd8e8;
  text-shadow: 0 0 9px rgba(127, 216, 232, .35);
}
#hiscore .hsList .rk { text-align: right; color: #4d6b78; }
#hiscore .hsList .nm { white-space: pre; letter-spacing: .22em; }
#hiscore .hsList .sc { text-align: right; }
#hiscore .hsList .tm { text-align: right; font-size: 11px; color: #46626e; }
#hiscore .hsList .empty { color: #24343c; text-shadow: none; }
#hiscore .hsList .empty .rk, #hiscore .hsList .empty .tm { color: #1d2a31; }
#hiscore .hsList .fresh, #hiscore .hsList .you {
  color: #fff3cf;
  text-shadow: 0 0 14px rgba(255, 200, 90, .6);
}
#hiscore .hsList .you { animation: hsRow 1s steps(1) infinite; }
@keyframes hsRow { 50% { opacity: .35; } }

#hiscore .hsAsk {
  margin: 0 0 10px;
  text-align: center;
  font-size: 11px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: #ffcf6b;
  animation: hsRow 1.1s steps(1) infinite;
}

#hiscore .wheels { display: flex; gap: 14px; justify-content: center; margin-bottom: 16px; }
#hiscore .wheel { display: grid; justify-items: center; gap: 2px; }
#hiscore .wheel .step {
  margin: 0;
  padding: 0;
  width: 42px;
  height: 26px;
  line-height: 1;
  font-size: 12px;
  background: transparent;
  border: 0;
  color: #3f6a78;
}
#hiscore .wheel .step:hover { color: #9fe8f7; }
#hiscore .wheel .cell {
  width: 42px;
  height: 46px;
  display: grid;
  place-items: center;
  font-size: 24px;
  color: #9fe8f7;
  background: #071219;
  border: 1px solid #1e3a46;
  border-radius: 4px;
  text-shadow: 0 0 12px rgba(127, 216, 232, .5);
  cursor: pointer;
}
#hiscore .wheel .cell.on {
  color: #fff3cf;
  border-color: #7a6330;
  background: #16120a;
  text-shadow: 0 0 16px rgba(255, 200, 90, .7);
  animation: hsRow .95s steps(1) infinite;
}

#hiscore .tip { text-align: center; font-size: 11px; color: #4b5a68; margin-bottom: 12px; }
#hiscore .btns { justify-content: center; }
#hiscore .btns button { font: inherit; font-size: 11.5px; letter-spacing: .1em; text-transform: uppercase; }

@media (prefers-reduced-motion: reduce) {
  #hiscore .hsList .you, #hiscore .hsAsk, #hiscore .wheel .cell.on { animation: none; }
}

/* --- narrow screens ----------------------------------------------------- */

@media (max-width: 720px) {
  #topbar { flex-wrap: wrap; gap: 8px 10px; padding: 6px 10px; }
  #topbar #btnBack {
  flex: 0 0 auto;
  color: var(--dim);
  text-decoration: none;
  font-size: 16px;
  line-height: 1;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #1b1b26;
}
#topbar #btnBack:hover { color: var(--ink); background: #23232f; }

#topbar h1 { font-size: 13px; }
  #topbar h1 .sub { display: none; }
  #readout { order: 5; flex-basis: 100%; }
  #streak { font-size: 11px; padding: 1px 7px; }
  #streak strong { font-size: 13px; }
  #streak .word { display: none; }      /* just "7 · best 11" on a phone */
  #streak #streakBest:not(:empty)::before { content: ' \00b7 '; }
  #controls { gap: 5px; }
  #options { min-width: 0; }
  #controls button { padding: 5px 8px; }
  #inspector {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    display: flex;
    gap: 12px;
    align-items: center;
  }
  #inspectorCanvas { margin: 0; flex: 0 0 auto; }
  #inspector .meta { flex: 1; min-width: 0; }
  #inspector .coords {
  margin-top: 7px;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #aab3cf;
}

#inspector .tip { display: none; }
  #trayHead .hint { display: none; }
  #zoomctl { bottom: auto; top: 10px; }
}

/* --- "did you know?" note ------------------------------------------------ */
/* A card that surfaces when a galaxy with a story lands on the board. It sits
   opposite the inspector, clear of the zoom column, and fades out of the way
   while a piece is being dragged — like the inspector, it must never be the
   thing between the player and the sky. */

#note {
  position: absolute;
  right: 54px;
  bottom: 10px;
  width: 340px;
  max-height: calc(100% - 20px);
  overflow-y: auto;
  padding: 12px 14px 11px;
  background: rgba(15,15,22,.94);
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: 12px;
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 30px rgba(0,0,0,.55);
  animation: notein 260ms ease-out;
}
@keyframes notein {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
#note.dragging { opacity: .18; pointer-events: none; }

#note .close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  padding: 0;
  line-height: 1;
  font-size: 15px;
  background: transparent;
  border-color: transparent;
  color: var(--dim);
}

#note .kicker {
  margin: 0 0 3px;
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
}
#note h3 {
  margin: 0 0 6px;
  font-size: 13.5px;
  font-weight: 650;
  padding-right: 18px;
}
#note p { margin: 0 0 8px; font-size: 12.5px; color: #c9c9d4; }
#note .cite { margin: 0; font-size: 11px; color: var(--dim); }
#note .cite a { color: #9fb9c9; text-decoration: none; border-bottom: 1px dotted #4a5a63; }
#note .cite a:hover { color: var(--accent); }
#note .cite span:not(:empty)::before { content: '\00a0\00b7\00a0'; }

@media (prefers-reduced-motion: reduce) {
  #note { animation: none; }
}

@media (max-width: 720px) {
  #note {
    left: 8px;
    right: 52px;              /* the zoom column moves to the top right here */
    top: 8px;
    bottom: auto;
    width: auto;
    max-height: 46%;
  }
}
