:root {
  --bg: #0d0f10;
  --line: #2a3033;
  --text: #e8ecee;
  --muted: #7f8b91;
  --dim: #5a656a;
  --paper: #fbfbfa;
  --warn: #ff6b6b;
  --pick: #4da3ff;
  /* the cell you have picked, before confirming */
  --mark: #ffb454;
  /* a cell called out from the log */
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ---- canvas ---- */
#stage {
  position: absolute;
  inset: 0;
  touch-action: none;
}

/* Clips the panned canvas. Fills the stage on desktop; on phones it stops
   above the bar so the canvas never slides under it or over the log. */
#viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

#canvas {
  position: absolute;
  top: 0;
  left: 0;
  background: var(--paper);
  cursor: crosshair;
}

#canvas.panning {
  cursor: grabbing;
}

/* ---- left column: the pitch, then the log ---- */
/* Frosted like the bar, so the canvas panned underneath reads as depth
   rather than clutter behind the text. */
#side {
  position: absolute;
  left: 14px;
  top: 14px;
  bottom: 14px;
  width: 280px;
  padding: 20px 10px 14px 16px;
  border-radius: 18px;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, 0) 45%),
    rgba(20, 24, 26, .88);
  border: 1px solid rgba(255, 255, 255, .06);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .05) inset, 0 18px 50px rgba(0, 0, 0, .45);
  /* dense enough that white paper behind it reads as a soft grey, not glare */
  backdrop-filter: blur(24px) saturate(120%) brightness(.6);
  -webkit-backdrop-filter: blur(24px) saturate(120%) brightness(.6);
  display: flex;
  flex-direction: column;
  pointer-events: none;
  /* clicks fall through to the canvas */
}

#about {
  flex: 0 0 auto;
  color: var(--muted);
}

/* the pitch and the log are prose; let people select and copy them */
#side {
  -webkit-user-select: text;
  user-select: text;
}

#about h1 {
  margin: 0 0 12px;
  font-size: 15px;
  letter-spacing: -.01em;
  color: var(--muted);
}

#about h1 span {
  color: var(--text);
}

#about p {
  margin: 0 0 11px;
  font-size: 12px;
  line-height: 1.55;
}

#about b {
  color: var(--text);
  font-weight: 600;
}

/* the log sits under the pitch and takes whatever height is left */
#logbox {
  flex: 1 1 auto;
  min-height: 90px;
  /* never collapse to nothing on short windows */
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
  pointer-events: auto;
  /* so it can be scrolled */
}

#logbox h2 {
  margin: 12px 0 8px;
  padding-left: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

#log {
  flex: 1 1 auto;
  min-height: 0;
  /* lets the flex child actually scroll */
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: #333c40 transparent;
}

#log::-webkit-scrollbar {
  width: 8px;
}

#log::-webkit-scrollbar-track {
  background: transparent;
}

#log::-webkit-scrollbar-thumb {
  background: #333c40;
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: content-box;
}

#log:hover::-webkit-scrollbar-thumb {
  background-color: #465257;
  background-clip: content-box;
}

.entry {
  font-size: 12px;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 6px;
  transition: background-color .14s ease;
}

.entry:hover {
  background: rgba(255, 255, 255, .045);
}

.entry:focus-visible {
  outline: 1px solid var(--mark);
  outline-offset: 0;
}

.entry.marked {
  background: rgba(255, 180, 84, .11);
}

.entry.marked .who {
  color: var(--mark);
}

.entry.marked .at {
  color: var(--mark);
}

.entry .line {
  color: var(--muted);
}

.entry .who {
  color: #c3cbcf;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.entry.fresh .who {
  color: var(--text);
}

.entry .at {
  font-variant-numeric: tabular-nums;
}

.entry.erased .at {
  text-decoration: line-through;
}

.entry .when {
  color: var(--dim);
  margin-top: 1px;
}

/* ---- the bar: one smooth pill, everything in a row ---- */
#bar {
  position: absolute;
  bottom: 46px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px;
  background: rgba(20, 24, 26, .94);
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 999px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  max-width: calc(100vw - 24px);
}

#tools,
#confirm {
  display: flex;
  align-items: center;
  gap: 4px;
}

#confirmtext {
  padding: 0 12px 0 10px;
  color: var(--muted);
  white-space: nowrap;
}

#confirmtext b {
  color: var(--pick);
  font-weight: 600;
}

.tool,
.aux {
  font: inherit;
  cursor: pointer;
  padding: 8px 17px;
  border: 0;
  border-radius: 999px;
  /* a faint fill so each button reads as its own target, apart from the
     plain cooldown text beside them */
  background: rgba(255, 255, 255, .06);
  color: #c3cbcf;
  white-space: nowrap;
  transition: background-color .16s ease, color .16s ease;
}

.tool:hover,
.aux:hover {
  color: var(--text);
  background: rgba(255, 255, 255, .14);
}

.tool.sel,
.tool.sel:hover {
  background: var(--text);
  color: #14181a;
  font-weight: 600;
}

/* name and save are actions, not modes, so they read quieter */
.aux {
  color: var(--muted);
}

#whoami {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* A status readout, not a control: coloured text with no fill, so it cannot
   be mistaken for one of the pills around it. */
#cooldown {
  padding: 0 14px;
  color: #5fd68a;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  min-width: 62px;
  text-align: center;
  cursor: default;
}

#cooldown.wait {
  color: var(--muted);
}

/* Quiet by design: worth being able to find, not worth reading every time. */
#build {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}

#build .env {
  color: var(--warn);
  font-weight: 600;
}

/* The mute button is a glyph, because the bar is already crowded and this is
   the least important thing on it. */
#mute {
  padding-left: 11px;
  padding-right: 11px;
  font-size: 15px;
  line-height: 1;
}

#mute.off {
  color: #4a5358;
  text-decoration: line-through;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

/* Who last inked the cell under the cursor. Follows the pointer, and must
   never eat a click: the canvas underneath is the whole interface. */
#hover {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  padding: 5px 9px;
  border-radius: 7px;
  background: rgba(24, 28, 30, .78);
  border: 1px solid rgba(255, 255, 255, .06);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

#hover b {
  color: var(--text);
  font-weight: 600;
}

#hover .at {
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

/* ---------- timelapse ---------- */
/* The player takes the pill over while it runs, so it gets two rows: a caption
   naming the moment being shown, and the transport underneath. */
#player {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 4px 2px;
}

/* Two rows do not sit well in a pill, so the replay squares off: a tight
   box with small corners, and buttons to match. */
#stage.replaying #bar {
  border-radius: 10px;
}

#player .tool,
#player .aux {
  border-radius: 6px;
}

#tlcaption {
  padding: 2px 10px 0;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 18px;
}

#tlcaption b {
  color: var(--text);
  font-weight: 600;
}

#tlrow {
  display: flex;
  align-items: center;
  gap: 2px;
}

#tlcount {
  padding: 0 10px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  min-width: 68px;
  text-align: center;
}

/* The scrubber is the one control worth making big enough to grab on a phone. */
#tlscrub {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 110px;
  height: 22px;
  background: transparent;
  cursor: pointer;
}

#tlscrub::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 1px;
  background: rgba(255, 255, 255, .16);
}

#tlscrub::-moz-range-track {
  height: 4px;
  border-radius: 1px;
  background: rgba(255, 255, 255, .16);
}

#tlscrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border: 0;
  border-radius: 50%;
  background: var(--text);
}

#tlscrub::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--text);
}

#tlscrub:focus-visible {
  outline: 2px solid var(--pick);
  outline-offset: 3px;
}

/* While the replay owns the canvas, say so plainly rather than letting it look
   like the live board. */
#stage.replaying #canvas {
  cursor: default;
}

/* the warning sits just under the bar, small and red */
#status {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--warn);
  white-space: nowrap;
  pointer-events: none;
}

.hidden {
  display: none !important;
}

/* ---- name gate ---- */
#gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 15, 16, .82);
  backdrop-filter: blur(3px);
}

#gateform {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 240px;
}

#gateform label {
  color: var(--muted);
}

#gateform input {
  font: inherit;
  padding: 9px 12px;
  background: #14181a;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

#gateform input:focus {
  border-color: var(--muted);
}

#gateform button {
  font: inherit;
  cursor: pointer;
  padding: 9px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: #14181a;
  font-weight: 600;
}

/* Centre the bar and its message in the space right of the panel (14px
   inset + 280px + 14px gap), not the window, so it lines up with the canvas
   and never slides under the panel. */
@media (min-width: 900px) {
  #bar,
  #status {
    left: calc(50% + 154px);
  }

  #bar {
    max-width: calc(100vw - 332px);
  }
}

@media (max-width: 899px) {

  /* Phones get a scrolling page instead of a fixed app: the canvas owns the
     first screen, the pitch and the log follow underneath. The canvas is a
     little short of full height on purpose, so the text peeking below the
     fold tells you there is more to scroll to. */
  html,
  body {
    height: auto;
    overflow: visible;
  }

  #stage {
    position: relative;
    inset: auto;
    /* the canvas is limited by width on a phone, so a taller stage would only
       add dead space and push the text further below the fold */
    height: min(78dvh, 500px);
    min-height: 340px;
  }

  #viewport {
    bottom: 76px;
    border-bottom: 1px solid var(--line);
  }

  /* the replay player is two rows tall */
  #stage.replaying #viewport {
    bottom: 112px;
  }

  #bar {
    bottom: 22px;
  }

  .tool,
  .aux {
    padding: 9px 13px;
  }

  #cooldown {
    padding: 0 10px;
    min-width: 56px;
  }

  #whoami {
    max-width: 90px;
  }

  #status {
    bottom: 3px;
    font-size: 12px;
  }

  /* the column becomes a normal block under the canvas */
  #side {
    position: static;
    width: auto;
    padding: 22px 20px 40px;
    pointer-events: auto;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
    background: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  #about h1 {
    font-size: 17px;
  }

  #about p {
    font-size: 14px;
    line-height: 1.6;
  }

  /* the page scrolls now, so the log should not also scroll inside itself */
  #logbox {
    min-height: 0;
    margin-top: 14px;
  }

  #logbox h2 {
    font-size: 12px;
  }

  #log {
    overflow: visible;
    padding-right: 0;
    gap: 12px;
  }

  .entry {
    font-size: 14px;
  }

  .entry .when {
    font-size: 12px;
  }
}

/* Small phones: keep the canvas usable rather than letting the bar crowd it. */
@media (max-width: 380px) {

  #mute {
    padding-left: 8px;
    padding-right: 8px;
  }


  .tool,
  .aux {
    padding: 9px 10px;
  }

  #tlcount {
    min-width: 58px;
    padding: 0 6px;
  }

  #tlscrub {
    min-width: 80px;
  }

  #cooldown {
    padding: 0 7px;
    min-width: 50px;
  }

  #whoami {
    max-width: 66px;
  }
}