/* =====================================================================
   Filament - fixed "night switchboard" theme.
   A dark instrument panel: slate plates, cyan filament traces, one amber
   beacon colour, brass edges on the chrome. No glass, no light mode. The
   shared base.css is loaded (back chip + resets) but glass.css deliberately
   is not: this game keeps its own chrome (.c-bar, .c-btn, .c-modal).
   ===================================================================== */

:root {
  --void: #04070c;
  --deep: #0a131c;
  --slate: #0e1b26;
  --slate-hi: #162b3b;
  --plate-a: #102230;
  --plate-b: #0a1620;

  --trace: #4fe3ff;
  --trace-hot: #d8fbff;
  --amber: #ffb347;
  --amber-hi: #ffe0ad;

  --ink: #e2f4ff;
  --dim: rgba(190, 220, 238, .62);
  --faint: rgba(190, 220, 238, .38);
  --line: rgba(79, 227, 255, .22);
  --danger: #ff7a6b;

  --font-body: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;

  /* One grid cell. The board is seven of these plus padding, and the dock
     underneath has to fit the hand as well, so the height term is the one
     that usually wins on a laptop. 78px is the "silly-big" ceiling. */
  --cell: clamp(34px, min(calc((100vw - 52px) / 7), calc((100dvh - 272px) / 7)), 78px);
}

[hidden] { display: none !important; }

/* ---------- The switchboard room ---------- */
body.fl-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background-color: var(--deep);
  background-image:
    radial-gradient(72% 46% at 50% 0%, rgba(79, 227, 255, .12), transparent 66%),
    radial-gradient(60% 40% at 50% 108%, rgba(255, 179, 71, .07), transparent 70%),
    repeating-linear-gradient(90deg, rgba(126, 196, 224, .035) 0 1px, transparent 1px 34px),
    repeating-linear-gradient(0deg, rgba(126, 196, 224, .035) 0 1px, transparent 1px 34px),
    linear-gradient(178deg, #0b1620, #070e16 62%, var(--void));
  background-attachment: fixed;
}
body.fl-page *,
body.fl-page *::before,
body.fl-page *::after { box-sizing: border-box; }

.fl-app {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- Top bar: a brass faceplate ---------- */
.c-bar {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 8px clamp(12px, 3vw, 26px) 9px;
  color: var(--ink);
  background: linear-gradient(180deg, #14232f, #0d1a24 60%, #0a141d);
  border-bottom: 1px solid rgba(79, 227, 255, .28);
  box-shadow: 0 8px 26px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .06);
}
/* A second, dimmer rule under the first, like a machined groove. */
.c-bar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 3px;
  height: 1px;
  background: rgba(79, 227, 255, .12);
  pointer-events: none;
}
.c-bar__brand { display: flex; align-items: center; gap: 9px; }
.c-bar__brand svg { display: block; }
.c-bar__title {
  margin: 0;
  font-size: clamp(19px, 3vw, 26px);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #d9f4ff;
  text-shadow: 0 0 18px rgba(79, 227, 255, .45);
}
.c-bar__stats { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.stat { font-size: 12.5px; letter-spacing: .02em; color: var(--dim); white-space: nowrap; }
.stat b {
  font-family: var(--font-mono);
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
/* Cards left turns amber when the deck is nearly done. */
.stat b.is-thin { color: var(--amber); }
.c-bar__controls { display: flex; align-items: center; gap: 6px; margin-left: auto; }

/* Buttons: dark plates with a lit lower edge. */
.c-btn {
  appearance: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .01em;
  padding: 7px 13px;
  border-radius: 4px;
  color: #cfe9f7;
  background: linear-gradient(180deg, #17303f, #0f2130);
  border: 1px solid rgba(79, 227, 255, .26);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .05);
  cursor: pointer;
  transition: filter .12s ease, transform .06s ease, box-shadow .12s ease;
}
.c-btn:hover { filter: brightness(1.14); }
.c-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(0, 0, 0, .5); }
.c-btn:focus-visible { outline: 2px solid var(--trace); outline-offset: 2px; }
.c-btn:disabled { opacity: .42; cursor: default; transform: none; }
.c-btn--primary {
  color: #23160a;
  background: linear-gradient(180deg, var(--amber-hi), var(--amber));
  border-color: #c9862c;
  box-shadow: 0 2px 0 #9c6417, 0 6px 16px rgba(255, 179, 71, .22);
  text-shadow: none;
}

/* ---------- The table ---------- */
.fl-table {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.4vh, 14px);
  padding: clamp(6px, 1.4vh, 14px) 8px clamp(4px, 1vh, 10px);
  /* Safety valve on very short windows: the table scrolls, no page scrollbar. */
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.fl-table::-webkit-scrollbar { width: 0; height: 0; }

/* ---------- The grid ---------- */
.fl-board {
  display: grid;
  grid-template-columns: repeat(7, var(--cell));
  grid-template-rows: repeat(7, var(--cell));
  padding: 6px;
  border-radius: 14px;
  background:
    radial-gradient(120% 130% at 50% 0%, rgba(79, 227, 255, .07), transparent 62%),
    linear-gradient(180deg, #0a1520, #060d15);
  box-shadow:
    inset 0 0 0 1px rgba(79, 227, 255, .16),
    inset 0 0 46px rgba(0, 0, 0, .7),
    0 18px 44px rgba(0, 0, 0, .5);
}
.fl-cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  background:
    linear-gradient(180deg, rgba(120, 190, 220, .05), rgba(120, 190, 220, .02));
  box-shadow: inset 0 0 0 1px rgba(120, 190, 220, .05);
}
.fl-cell.is-wall {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .05) 0 3px, transparent 3px 7px),
    #0a0f14;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .04);
}
.fl-cell.is-wall::after {
  content: "";
  position: absolute;
  inset: 34%;
  border-radius: 2px;
  background: rgba(150, 176, 190, .18);
  transform: rotate(45deg);
}

/* A plate: the card itself, one per cell. */
.fl-plate {
  position: absolute;
  inset: 1px;
  border-radius: 9px;
  background: linear-gradient(180deg, var(--plate-a), var(--plate-b));
  box-shadow:
    inset 0 0 0 1px rgba(79, 227, 255, .22),
    0 2px 7px rgba(0, 0, 0, .55);
  overflow: visible;
}
.fl-plate svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  display: block;
}
/* Traces are drawn twice: a wide soft halo, then a bright core. */
.fl-halo { fill: none; stroke: var(--trace); stroke-width: 15; stroke-opacity: .16; stroke-linecap: round; }
.fl-core { fill: none; stroke: var(--trace); stroke-width: 4.6; stroke-linecap: round; }
.fl-sock { fill: #0a1620; stroke: var(--trace); stroke-width: 3.4; }
.fl-dot { fill: var(--trace-hot); }
.fl-plate svg { filter: drop-shadow(0 0 3px rgba(79, 227, 255, .55)); }

/* The bus: it feeds the whole grid, so it is amber and always breathing. */
.fl-plate--bus {
  background: linear-gradient(180deg, #22333c, #131f27);
  box-shadow:
    inset 0 0 0 1.5px rgba(255, 179, 71, .6),
    0 0 22px rgba(255, 179, 71, .22),
    0 2px 8px rgba(0, 0, 0, .6);
}
.fl-plate--bus .fl-halo { stroke: var(--amber); stroke-opacity: .2; }
.fl-plate--bus .fl-core { stroke: var(--amber); }
.fl-plate--bus .fl-sock { stroke: var(--amber); }
.fl-plate--bus .fl-dot { fill: var(--amber-hi); }
.fl-plate--bus svg { filter: drop-shadow(0 0 4px rgba(255, 179, 71, .6)); }
.fl-plate--bus::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 46%; height: 46%;
  margin: -23% 0 0 -23%;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 179, 71, .55);
  box-shadow: 0 0 14px rgba(255, 179, 71, .45), inset 0 0 12px rgba(255, 179, 71, .3);
  animation: flBus 3.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes flBus {
  0%, 100% { opacity: .5; transform: scale(.92); }
  50% { opacity: 1; transform: scale(1.04); }
}

/* ---------- Beacons ---------- */
.fl-beacon {
  position: absolute;
  z-index: 3;
  top: 3px; right: 3px;
  width: 8px; height: 8px;
  border: 1.5px solid var(--amber);
  border-radius: 2px;
  transform: rotate(45deg);
  pointer-events: none;
  animation: flBeacon 2.4s ease-in-out infinite;
}
@keyframes flBeacon {
  0%, 100% { opacity: .45; }
  50% { opacity: 1; }
}
.fl-cell.is-lit .fl-beacon {
  background: var(--amber);
  box-shadow: 0 0 10px rgba(255, 179, 71, .95);
  animation: none;
  opacity: 1;
}
.fl-cell.is-lit .fl-plate {
  box-shadow:
    inset 0 0 0 1.5px rgba(255, 179, 71, .85),
    0 0 16px rgba(255, 179, 71, .3),
    0 2px 7px rgba(0, 0, 0, .55);
}
/* A beacon that has just taken power throws one ring out. */
.fl-cell.is-pop::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--amber);
  pointer-events: none;
  animation: flPop .62s ease-out forwards;
  z-index: 4;
}
@keyframes flPop {
  0% { opacity: .9; transform: scale(.55); }
  100% { opacity: 0; transform: scale(1.25); }
}

/* A cell the picked plate can go in. */
.fl-cell.is-open { cursor: pointer; }
.fl-cell.is-open::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1.5px rgba(79, 227, 255, .55);
  background: rgba(79, 227, 255, .07);
  pointer-events: none;
  animation: flOpen 1.5s ease-in-out infinite;
  z-index: 1;
}
@keyframes flOpen {
  0%, 100% { opacity: .45; }
  50% { opacity: 1; }
}
.fl-cell.is-open:hover::after {
  background: rgba(79, 227, 255, .2);
  box-shadow: inset 0 0 0 2px var(--trace), 0 0 18px rgba(79, 227, 255, .35);
  animation: none;
  opacity: 1;
}
/* A plate that has just landed flashes its own seam once. */
.fl-cell.is-new .fl-plate { animation: flLand .34s ease-out both; }
@keyframes flLand {
  0% { transform: scale(.86); opacity: .2; }
  60% { transform: scale(1.03); opacity: 1; }
  100% { transform: none; opacity: 1; }
}

/* ---------- The dock ---------- */
.fl-dock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 100%;
}
.fl-say {
  margin: 0;
  min-height: 19px;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  color: var(--dim);
}
.fl-say.is-warn { color: var(--amber); }
.fl-hand { display: flex; align-items: center; justify-content: center; gap: 8px; }
.fl-card {
  position: relative;
  width: calc(var(--cell) * .94);
  height: calc(var(--cell) * .94);
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease;
}
.fl-card .fl-plate { inset: 0; }
.fl-card:hover { transform: translateY(-3px); }
.fl-card.is-pick { transform: translateY(-7px); }
.fl-card.is-pick .fl-plate {
  box-shadow:
    inset 0 0 0 1.5px var(--trace),
    0 0 20px rgba(79, 227, 255, .45),
    0 4px 12px rgba(0, 0, 0, .6);
}
.fl-card.is-pick::after {
  content: "";
  position: absolute;
  left: 50%; bottom: -6px;
  width: 5px; height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: var(--trace);
  box-shadow: 0 0 8px var(--trace);
}
/* A plate with no legal cell anywhere: still pickable, but dimmed. */
.fl-card.is-dead { filter: grayscale(.55) brightness(.62); }
.fl-card:focus-visible { outline: 2px solid var(--trace); outline-offset: 3px; }
.fl-hand.is-empty::after {
  content: "No plates left.";
  font-size: 12.5px;
  color: var(--faint);
}

.fl-tools {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 32px;
}
.fl-hint { font-size: 11.5px; color: var(--faint); }
.fl-tools .c-btn { font-size: 12px; padding: 5px 11px; }

/* ---------- Modals (the overlay scrolls, never the card) ---------- */
.c-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  padding: 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.c-modal[hidden] { display: none; }
.c-modal__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 5, 9, .78);
  cursor: pointer;
}
.c-modal__panel {
  position: relative;
  z-index: 1;
  margin: auto;
  width: min(94vw, 560px);
  color: var(--ink);
  background: linear-gradient(180deg, #13242f, #0c1822 62%, #0a141d);
  border-radius: 10px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .06),
    0 0 0 1px rgba(79, 227, 255, .34),
    0 30px 70px rgba(0, 0, 0, .72);
  animation: flPlate .24s ease-out both;
}
@keyframes flPlate {
  0% { transform: translateY(12px) scale(.985); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
.fl-rules { width: min(94vw, 640px); }
#rulesModal { z-index: 62; }
.c-modal__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px 10px;
  border-bottom: 1px solid rgba(79, 227, 255, .2);
}
.c-modal__head h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #d9f4ff;
}
.c-modal__x {
  margin-left: auto;
  position: relative;
  z-index: 2;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  border: 1px solid rgba(79, 227, 255, .3);
  background: linear-gradient(180deg, #17303f, #0f2130);
  color: #cfe9f7;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.c-modal__x:hover { filter: brightness(1.16); }
.c-modal__x[hidden] { display: none; }
.c-modal__body { padding: 14px 22px 4px; font-size: 14px; line-height: 1.6; color: rgba(214, 236, 250, .86); }
.c-modal__body b { color: #eaf9ff; }
.c-modal__body kbd {
  padding: 0 4px;
  border-radius: 3px;
  border: 1px solid rgba(79, 227, 255, .3);
  background: rgba(6, 14, 20, .8);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink);
}
.c-modal__lead { margin: 0 0 12px; font-size: 14.5px; color: rgba(214, 236, 250, .92); }
.c-modal__note { margin: 13px 0 2px; font-size: 12.5px; line-height: 1.55; color: var(--dim); }
.c-modal__foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px 15px;
}

/* The how-to list: numbered steps on inset wells. */
.fl-steps {
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
  counter-reset: step;
  display: grid;
  gap: 7px;
}
.fl-steps li {
  counter-increment: step;
  position: relative;
  padding: 8px 11px 8px 44px;
  border-radius: 5px;
  background: rgba(79, 227, 255, .05);
  box-shadow: inset 0 0 0 1px rgba(79, 227, 255, .14);
  font-size: 13.5px;
  line-height: 1.45;
}
.fl-steps li::before {
  content: counter(step);
  position: absolute;
  left: 10px;
  top: 8px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  color: #23160a;
  background: linear-gradient(180deg, var(--amber-hi), var(--amber));
}

/* ---------- Flow: intro, grid cleared, run over ---------- */
.fl-flow { width: min(94vw, 560px); }
.fl-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 2px 0 4px;
}
.fl-legend__item {
  flex: 1 1 150px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(79, 227, 255, .05);
  box-shadow: inset 0 0 0 1px rgba(79, 227, 255, .14);
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--dim);
}
.fl-legend__item b { display: block; color: var(--ink); font-size: 13px; }
.fl-legend__art { flex: 0 0 40px; width: 40px; height: 40px; position: relative; }
.fl-verdict { display: flex; align-items: baseline; gap: 12px; margin: 0 0 10px; }
.fl-verdict__num {
  font-family: var(--font-mono);
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
  color: #eaf9ff;
  font-variant-numeric: tabular-nums;
}
.fl-verdict__num small { font-size: 13px; font-weight: 600; color: var(--faint); margin-left: 4px; }
.fl-verdict__who { font-size: 13px; color: var(--dim); }
.fl-log { display: grid; gap: 3px; margin: 10px 0 2px; }
.fl-log__row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  padding: 4px 0;
  font-size: 12.5px;
  border-bottom: 1px dotted rgba(79, 227, 255, .18);
}
.fl-log__row span { color: var(--dim); }
.fl-log__row b {
  font-family: var(--font-mono);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.fl-picks { display: grid; gap: 7px; }

/* ---------- Toast ---------- */
.c-toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  z-index: 70;
  transform: translateX(-50%);
  max-width: min(92vw, 460px);
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.4;
  color: #e6f6ff;
  background: rgba(8, 18, 26, .96);
  border: 1px solid rgba(79, 227, 255, .26);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .6);
  animation: flToast .18s ease-out both;
}
.c-toast[hidden] { display: none; }
@keyframes flToast {
  0% { transform: translate(-50%, 6px); opacity: 0; }
  100% { transform: translate(-50%, 0); opacity: 1; }
}

/* ---------- Narrow screens ---------- */
@media (max-width: 780px) {
  .c-bar { gap: 6px 10px; padding: 6px 10px 7px; }
  .c-bar__title { font-size: 18px; }
  .c-bar__stats { gap: 9px; }
  .stat { font-size: 11.5px; }
  .stat b { font-size: 13px; }
  .c-bar .c-btn { font-size: 12px; padding: 5px 9px; }
  .fl-say { font-size: 12px; }
  .c-modal { padding: 10px; }
  .c-modal__body { padding: 10px 14px 2px; }
  /* The back chip is fixed bottom-left, so the tool row steps out of its way. */
  .fl-tools { padding-left: 128px; }
  .fl-hint { display: none; }
}

@media (max-width: 430px) {
  .fl-hand { gap: 6px; }
  .fl-tools { padding-left: 118px; }
  .c-bar__stats { gap: 7px; }
  .stat { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .c-modal__panel,
  .c-toast,
  .fl-cell.is-open::after,
  .fl-cell.is-new .fl-plate,
  .fl-beacon,
  .fl-plate--bus::after { animation: none; }
  .fl-cell.is-pop::before { animation: none; opacity: 0; }
  .fl-card, .c-btn { transition: none; }
}
