:root {
  --ink: #1d1c1a;
  --ink-soft: #6a6458;
  --paper: #fbf8f0;
  --rule: #e8e1d1;
  --board: #2a2825;
  --cell: #353330;
  --cell-open: #4a453d;
  --label: #8a8477;
  --p1: #2f5d8a;
  --p1-glow: #7eaee0;
  --p2: #b4442c;
  --p2-glow: #ec8a6f;
  --amber: #d79b2b;
  --sans: "Futura", "Avenir Next", "Century Gothic", "Trebuchet MS", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: radial-gradient(ellipse at 50% 45%, #efe9dc 0%, #e4dccb 55%, #d5cbb5 100%);
}

button { font: inherit; color: inherit; touch-action: manipulation; }

/* ---------- table & layout ---------- */

#stage { position: fixed; inset: 0; }

#table {
  position: absolute;
  left: 50%;
  transform-origin: center;
}

.piece { position: absolute; transform-origin: center; }

#measure {
  position: absolute;
  left: -10000px;
  top: 0;
  width: max-content;
  visibility: hidden;
  pointer-events: none;
}

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

.board {
  position: relative;
  width: 520px;
  height: 520px;
  overflow: visible;
  background: var(--board);
  border-radius: 12px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .06),
    0 3px 8px rgba(40, 30, 10, .25),
    0 22px 48px rgba(40, 30, 10, .28);
}

.grid {
  position: absolute;
  left: 31px;
  top: 31px;
  display: grid;
  grid-template-columns: repeat(8, 52px);
  grid-template-rows: repeat(8, 52px);
  gap: 6px;
  overflow: visible;
}

.cell {
  all: unset;
  position: relative;
  overflow: visible;
  width: 52px;
  height: 52px;
  border-radius: 6px;
  background: var(--cell);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .45), inset 0 -1px 0 rgba(255, 255, 255, .04);
  cursor: pointer;
  touch-action: manipulation;
}

.cell.open { background: var(--cell-open); }
.cell.target { box-shadow: inset 0 0 0 2px var(--amber); }

.edge {
  position: absolute;
  display: grid;
  gap: 6px;
  font: 500 12px/1 var(--sans);
  letter-spacing: .06em;
  color: var(--label);
}

.edge span { display: flex; align-items: center; justify-content: center; }

.edge.rows   { left: 0; top: 31px; width: 31px; grid-template-rows: repeat(8, 52px); }
.edge.cols   { top: 0; left: 31px; height: 31px; grid-template-columns: repeat(8, 52px); font-size: 11px; }
.edge.decode { right: 0; top: 31px; width: 31px; grid-template-rows: repeat(8, 52px); font-size: 17px; color: var(--amber); }
.edge.decode .other { color: #8d8576; font-size: 12px; }

.top-mark,
.board-foot {
  position: absolute;
  left: 31px;
  right: 31px;
  height: 31px;
  display: flex;
  align-items: center;
  font: 500 11px/1 var(--sans);
  color: var(--label);
}

.top-mark { top: 0; justify-content: center; gap: 10px; letter-spacing: .45em; }
.board-foot { bottom: 0; justify-content: space-between; letter-spacing: .24em; text-transform: uppercase; color: #77715f; }

/* ---------- tiles ---------- */

.tile {
  --edge: rgba(120, 95, 50, .25);
  --glow: transparent;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 6px;
  background: linear-gradient(160deg, #f9f2e0 0%, #eee2c5 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .85),
    inset 0 -4px 0 var(--edge),
    0 2px 0 rgba(0, 0, 0, .22),
    0 5px 9px rgba(0, 0, 0, .22);
  color: var(--ink);
  transition: transform .12s ease;
}

.tile .digit { font: 500 30px/1 var(--sans); transform: translateY(-1px); }
.tile .pv { position: absolute; right: 6px; bottom: 7px; font: 500 10px/1 var(--sans); color: #7a705f; }

.tile.by-p1 { --edge: var(--p1); --glow: var(--p1-glow); }
.tile.by-p2 { --edge: var(--p2); --glow: var(--p2-glow); }

.tile.last { outline: 2.5px solid var(--glow); outline-offset: 2px; }
.tile.last.fade-out { animation: last-fade .9s ease forwards; }
.tile.last.fade-in  { animation: last-fade .9s ease reverse both; }

@keyframes last-fade {
  from { outline-color: var(--glow); }
  to   { outline-color: transparent; }
}

.tile.pending,
.tile.selected { outline: 2.5px solid var(--amber); outline-offset: 2px; }
.tile.selected { transform: translateY(-10px); }

.tile.fresh::after {
  content: '';
  position: absolute;
  left: 7px;
  top: 7px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
}

.tile.back { background: repeating-linear-gradient(45deg, #c2b08a 0 6px, #b8a57d 6px 12px); }

.tile.drop { animation: drop .22s cubic-bezier(.2, .9, .3, 1.3); }

@keyframes drop {
  from { transform: scale(1.3); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.tile.flyer {
  position: absolute;
  left: calc(var(--col) * 58px);
  top: calc(var(--row) * 58px);
  z-index: 4;
  pointer-events: none;
}

.tile.slide {
  animation: slide-down var(--fall-ms, 400ms) cubic-bezier(.22, .82, .2, 1) both;
}

@keyframes slide-down {
  from { transform: translateY(calc(-1 * var(--fall))); }
  to   { transform: none; }
}

.shake { animation: shake .32s ease; }

@keyframes shake {
  0%, 100% { translate: 0; }
  20% { translate: -5px 0; }
  60% { translate: 5px 0; }
}

/* ---------- stations ---------- */

.station { display: flex; }
.station.p1 { --pc: var(--p1); }
.station.p2 { --pc: var(--p2); }

.station.column { flex-direction: column; gap: 16px; width: 490px; }
.station.row    { flex-direction: row; align-items: center; gap: 20px; }

.rack-group {
  width: 490px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.st-head {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 40px;
  padding: 0 4px;
}

.st-name,
.strip .st-name {
  display: flex;
  align-items: center;
  gap: 9px;
  font: 600 14px/1 var(--sans);
  letter-spacing: .2em;
  text-transform: uppercase;
  white-space: nowrap;
}

.st-name .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--pc);
}

.station.active .st-name .dot { box-shadow: 0 0 0 5px color-mix(in srgb, var(--pc) 22%, transparent); }

.st-status {
  flex: 1;
  font: 500 14px/1 var(--sans);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: nowrap;
}

.station.active .st-status { color: var(--pc); font-weight: 600; }

.flag {
  all: unset;
  cursor: pointer;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--pc);
  color: var(--pc);
  font: 600 12px/1 var(--sans);
  letter-spacing: .14em;
  text-transform: uppercase;
  white-space: nowrap;
}

.flag.on { background: var(--pc); color: #fff; }
.flag.await { box-shadow: 0 0 0 5px color-mix(in srgb, var(--pc) 22%, transparent); }
.flag:disabled { cursor: default; }
.flag:disabled:not(.on) { opacity: .35; }
.flag.off { visibility: hidden; }

.rack {
  align-self: center;
  display: flex;
  gap: 6px;
  padding: 10px 6px 12px;
  border-radius: 6px;
  background: linear-gradient(#cdb791, #b39a73);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .28),
    0 6px 0 #917955,
    0 12px 16px rgba(60, 40, 10, .28);
}

.slot {
  all: unset;
  width: 52px;
  height: 52px;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
}

.slot.empty { background: rgba(0, 0, 0, .1); box-shadow: inset 0 1px 3px rgba(0, 0, 0, .2); cursor: default; }
.station:not(.active) .slot { cursor: default; }

.st-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  height: 42px;
  margin-top: 6px;
}

.btn {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  height: 42px;
  padding: 0 20px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  font: 600 13px/1 var(--sans);
  letter-spacing: .16em;
  text-transform: uppercase;
  touch-action: manipulation;
}

.btn.primary { background: var(--ink); color: var(--paper); }
.btn:disabled { opacity: .28; cursor: default; }

/* ---------- reference card ---------- */

.card-ref {
  --edge: rgba(120, 95, 50, .28);
  width: 490px;
  display: flex;
  align-items: stretch;
  border-radius: 6px;
  background: linear-gradient(160deg, #f9f2e0 0%, #eee2c5 100%);
  color: #2b2925;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .85),
    inset 0 -4px 0 var(--edge),
    0 2px 0 rgba(0, 0, 0, .2),
    0 8px 14px rgba(40, 30, 10, .22);
}

.station.row .card-ref { width: 320px; }

.ref-rail {
  width: 32px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 0;
  border-radius: 6px 0 0 6px;
  background: linear-gradient(#cdb791, #b39a73);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .28),
    inset -1px 0 0 rgba(80, 55, 25, .18);
}

.ref-title {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font: 600 11px/1 var(--sans);
  letter-spacing: .32em;
  text-transform: uppercase;
  color: #4a4034;
}

.ref-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.panels {
  flex: 1;
  display: grid;
  padding: 12px 14px 6px;
  min-width: 0;
}

.ref-modes {
  align-self: flex-end;
  display: flex;
  margin: 2px 0 0;
  border-top: 1.5px solid rgba(120, 95, 50, .28);
  border-left: 1.5px solid rgba(120, 95, 50, .28);
  border-radius: 7px 0 6px 0;
}

.tab {
  all: unset;
  box-sizing: border-box;
  padding: 7px 11px;
  font: 600 10px/1 var(--sans);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: #b3aa98;
  cursor: pointer;
  touch-action: manipulation;
}

.tab + .tab { border-left: 1.5px solid rgba(120, 95, 50, .22); }
.tab.on { color: #4a4034; background: rgba(80, 55, 25, .07); }

.panels > * { grid-area: 1 / 1; }

.panel { min-height: 0; }
.panel:not(.on) { visibility: hidden; }

.ascii-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(9, auto);
  align-content: space-between;
  column-gap: 22px;
  font: 15px/1.2 var(--mono);
}

.ascii-grid .e { display: flex; gap: 8px; }
.ascii-grid b  { font-weight: 400; color: #8a8273; }
.ascii-grid i  { font-style: normal; color: #4a463e; }
.ascii-grid em { font-style: normal; font-weight: 700; }

.panel.binary p { margin: 0; font: 14px/1.4 var(--sans); color: #4a463e; }

.bin-eg {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  max-width: 238px;
  margin: 10px 0;
  text-align: center;
  font-family: var(--mono);
}

.bin-eg .v { padding-bottom: 5px; font-size: 12px; color: #a39b8b; }
.bin-eg .b { padding-top: 5px; border-top: 1px solid var(--rule); font-size: 19px; color: #b3ab9a; }
.bin-eg .hit { color: var(--ink); }

.sum { margin-top: 5px; font: 500 16px/1.2 var(--mono); }

/* ---------- partner strip (hand-it-over seating) ---------- */

.strip {
  width: 520px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px;
}

.strip.p1 { --pc: var(--p1); }
.strip.p2 { --pc: var(--p2); }

.minis { display: flex; gap: 4px; }

.mini {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: linear-gradient(160deg, #f9f2e0 0%, #eee2c5 100%);
  box-shadow: inset 0 -2px 0 rgba(120, 95, 50, .25), 0 2px 4px rgba(0, 0, 0, .18);
  font: 500 16px/1 var(--sans);
}

.mini.empty { background: rgba(0, 0, 0, .08); box-shadow: inset 0 1px 3px rgba(0, 0, 0, .2); }
.mini.back  { background: repeating-linear-gradient(45deg, #c2b08a 0 4px, #b8a57d 4px 8px); }
.mini.fresh { box-shadow: inset 0 -3px 0 var(--amber), 0 2px 4px rgba(0, 0, 0, .18); }

/* ---------- chrome ---------- */

#chrome {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: 10px;
  display: flex;
  gap: 6px;
  z-index: 5;
}

.chrome-btn {
  all: unset;
  cursor: pointer;
  padding: 8px 13px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .45);
  font: 600 11px/1 var(--sans);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  touch-action: manipulation;
}

.chrome-btn:hover { background: rgba(255, 255, 255, .8); color: var(--ink); }

#hush {
  position: fixed;
  left: 14px;
  bottom: 12px;
  pointer-events: none;
}

#hush img {
  display: block;
  width: 36px;
  height: 36px;
  opacity: .55;
}

/* ---------- overlay sheets ---------- */

#overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 26, 20, .42);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

#overlay[hidden] { display: none; }

.sheet {
  width: calc(100% - 48px);
  max-width: 620px;
  max-height: calc(100% - 48px);
  overflow: auto;
  padding: 36px 40px 30px;
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
  user-select: text;
  -webkit-user-select: text;
}

.sheet h1 {
  margin: 0 0 6px;
  font: 500 30px/1.1 var(--sans);
  letter-spacing: .28em;
  text-transform: uppercase;
}

.sheet h2 {
  margin: 0 0 4px;
  font: 600 13px/1.2 var(--sans);
  letter-spacing: .26em;
  text-transform: uppercase;
}

.sheet h3 {
  margin: 22px 0 4px;
  font: 600 11px/1 var(--sans);
  letter-spacing: .26em;
  text-transform: uppercase;
  color: #8a8273;
}

.sheet p, .sheet li { font-size: 15px; line-height: 1.55; color: #3a362f; }
.sheet ul { padding-left: 18px; margin: 6px 0; }
.sheet .sub { margin-top: 0; color: var(--ink-soft); font-size: 14px; }
.sheet .hush-line { font: 600 13px/1 var(--sans); letter-spacing: .4em; text-transform: uppercase; margin: 22px 0 4px; }
.sheet .byline { margin: 28px 0 0; text-align: center; font: 500 13px/1.4 var(--sans); color: var(--ink-soft); }
.sheet .byline a { color: inherit; text-underline-offset: 3px; }
.sheet kbd { font: 12px var(--mono); padding: 1px 5px; border: 1px solid #d6cdb9; border-radius: 4px; background: #fff; }

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 26px;
}

.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 11px 0;
  border-bottom: 1px solid var(--rule);
}

.set-label { font-size: 14px; }
.set-note { margin-top: 3px; font-size: 12.5px; line-height: 1.4; color: var(--ink-soft); max-width: 270px; }
.set-note.warn { color: #8a5a20; }

.pills { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }

.pill {
  all: unset;
  cursor: pointer;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid #d3cab6;
  font: 500 12.5px/1 var(--sans);
  white-space: nowrap;
}

.pill.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.pill:disabled { opacity: .35; cursor: default; }

.num {
  width: 64px;
  padding: 5px 8px;
  border: 1px solid #d3cab6;
  border-radius: 6px;
  background: #fff;
  font: 14px var(--mono);
}

.num-group { display: flex; align-items: center; gap: 8px; font-size: 13px; }

/* ---------- hand-over cover ---------- */

#overlay.handoff { background: var(--p1); backdrop-filter: none; -webkit-backdrop-filter: none; cursor: pointer; }
#overlay.handoff[data-player="2"] { background: var(--p2); }

.sheet.handoff {
  background: none;
  box-shadow: none;
  text-align: center;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
}

.ho-name {
  font: 500 46px/1.1 var(--sans);
  letter-spacing: .3em;
  text-transform: uppercase;
  margin-right: -.3em;
}

.ho-turn {
  margin: 16px 0 44px;
  font: 600 15px/1 var(--sans);
  letter-spacing: .32em;
  text-transform: uppercase;
  opacity: .8;
}

.ho-btn { border-color: #fff; color: #fff; height: 50px; padding: 0 34px; font-size: 14px; }

/* ---------- the record ---------- */

.record .reason {
  font: 600 11px/1 var(--sans);
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.record .word {
  margin: 14px 0 6px;
  font: 500 64px/1.05 var(--sans);
  letter-spacing: .14em;
  word-break: break-word;
}

.record .epitaph { margin: 0 0 20px; color: var(--ink-soft); }

.record table { width: 100%; border-collapse: collapse; }
.record td { padding: 4px 6px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.record td.rn  { width: 22px; font: 11px var(--sans); color: #a39b8b; }
.record td.val { width: 64px; font: 13px var(--mono); color: var(--ink-soft); }
.record td.ch  { width: 44px; text-align: center; font: 600 20px/1 var(--sans); }
.record tr.other td.ch { color: #a39b8b; font-size: 14px; }
.record tr.incomplete td.ch { color: #c9c0ad; }

.bits { display: flex; gap: 3px; }

.mb {
  --edge: rgba(120, 95, 50, .3);
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  background: #f1e7cf;
  box-shadow: inset 0 -2px 0 var(--edge);
  font: 600 12px/1 var(--sans);
}

.mb.by-p1 { --edge: var(--p1); }
.mb.by-p2 { --edge: var(--p2); }
.mb.empty { background: #ece6d8; box-shadow: none; }

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 18px;
  font: 600 11px/1 var(--sans);
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.stats b { color: var(--ink); font-size: 13px; margin-right: 4px; }

/* ---------- small screens ---------- */

@media (max-width: 700px) {
  #hush { display: none; }
  .chrome-btn { padding: 7px 10px; font-size: 10px; letter-spacing: .12em; }
  .sheet { width: calc(100% - 24px); max-height: calc(100% - 24px); padding: 26px 22px 22px; }
  .sheet h1 { font-size: 22px; }
  .set-row { flex-direction: column; align-items: flex-start; gap: 8px; }
  .pills { justify-content: flex-start; }
  .set-note { max-width: none; }
  .record .word { font-size: 44px; }
  .mb { width: 18px; height: 18px; font-size: 10px; }
  .ho-name { font-size: 34px; }
}
