/* Four — minimal, quiet, no external assets. */

/* Nebula Sans, self-hosted (SIL OFL — see fonts/license.txt). */
@font-face {
  font-family: "Nebula Sans";
  src: url("/fonts/NebulaSans-Book.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Nebula Sans";
  src: url("/fonts/NebulaSans-Semibold.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "Nebula Sans";
  src: url("/fonts/NebulaSans-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

/* Theme: OKLCH everywhere, one palette via light-dark(). The default
   follows the system scheme; the manual toggle pins color-scheme. */
:root {
  color-scheme: light dark;

  --bg: light-dark(oklch(96% 0.01 90), oklch(21% 0.01 255));
  --fg: light-dark(oklch(24% 0.01 80), oklch(92% 0.01 90));
  --muted: light-dark(oklch(56% 0.02 85), oklch(66% 0.02 90));
  --surface: light-dark(oklch(99% 0.005 95), oklch(25% 0.012 255));
  --edge: light-dark(oklch(86% 0.015 90), oklch(33% 0.015 255));
  --board: light-dark(oklch(44% 0.08 258), oklch(37% 0.07 258));
  --red: light-dark(oklch(60% 0.19 27), oklch(65% 0.17 27));
  --yellow: light-dark(oklch(79% 0.16 90), oklch(82% 0.155 92));
  --shadow: light-dark(oklch(20% 0.02 90 / 0.14), oklch(0% 0 0 / 0.5));
}
:root[data-theme="light"] {
  color-scheme: light;
}
:root[data-theme="dark"] {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/* display:flex on the views would otherwise beat the hidden attribute */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Nebula Sans", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 0.55rem;
  padding: 0.5rem 1.1rem;
  cursor: pointer;
}
button.primary {
  background: var(--fg);
  color: var(--bg);
  border-color: transparent;
}
button:active {
  transform: translateY(1px);
}

#theme-toggle {
  position: fixed;
  top: 0.65rem;
  right: 0.65rem;
  z-index: 1;
  background: none;
  border: none;
  padding: 0.35rem;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--muted);
}

.wordmark {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--fg);
  text-decoration: none;
}

.chip {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 50%;
  vertical-align: -0.05rem;
}
.chip.red { background: var(--red); }
.chip.yellow { background: var(--yellow); }
.chip.spectator { background: var(--muted); }
.chip.you { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--muted); }

/* ---------------- landing ---------------- */

#landing {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  padding: 2rem 1.25rem;
  text-align: center;
}
#landing .wordmark {
  font-size: 3.2rem;
  margin: 0;
}
.tagline {
  margin: 0;
  color: var(--muted);
}
#landing .primary {
  padding: 0.7rem 1.8rem;
  font-size: 1.05rem;
}

#recent {
  margin-top: 1.5rem;
  width: min(22rem, 100%);
}
#recent h2 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.4rem;
}
#recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
#recent-list a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  border-radius: 0.55rem;
  color: var(--fg);
  text-decoration: none;
}
#recent-list a:hover {
  background: var(--surface);
}
#recent-list code {
  font-size: 0.95rem;
}
.recent-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge {
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 0.06rem 0.45rem;
  white-space: nowrap;
}
#recent-list time {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------------- game ---------------- */

#game {
  /* Cell size from the viewport's limiting dimension: the whole board
     always fits with the chrome around it, no scrolling anywhere. */
  --cell: min(calc((100dvw - 3rem) / 7), calc((100dvh - 13rem) / 6), 78px);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.5rem, 2dvh, 1.1rem);
  padding: 1rem;
  overflow: hidden;
}

/* Short landscape (phones): controls beside the board, height drives cells. */
@media (orientation: landscape) and (max-height: 480px) {
  #game {
    --cell: min(calc((100dvh - 3.5rem) / 6), calc((100dvw - 19rem) / 7), 78px);
    display: grid;
    grid-template-columns: max-content auto;
    grid-template-rows: 1fr auto 1fr;
    align-content: center;
    justify-content: center;
    column-gap: clamp(1.2rem, 4dvw, 2.5rem);
    row-gap: 0.8rem;
  }
  #game .board { grid-column: 2; grid-row: 1 / 4; align-self: center; }
  #game .hud { grid-column: 1; grid-row: 1; align-self: end; }
  #game .status { grid-column: 1; grid-row: 2; }
  #game .actions { grid-column: 1; grid-row: 3; align-self: start; }
}

.hud {
  display: flex;
  align-items: baseline;
  gap: 1.1rem;
  max-width: 100%;
}
.hud .wordmark {
  font-size: 1.15rem;
}

/* Game name: quiet next to the wordmark, truncates before it can wrap. */
.game-name {
  min-width: 0;
  color: var(--muted);
}
.game-name > span,
.name-edit {
  display: block;
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.name-edit {
  background: none;
  border: none;
  border-radius: 0;
  padding: 0;
  color: var(--muted);
  border-bottom: 1px dashed transparent;
}
.name-edit:hover,
.name-edit:focus-visible {
  border-bottom-color: var(--muted);
}
.name-input {
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 0.4rem;
  padding: 0 0.35rem;
  width: 11rem;
}
.score {
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
}

.status {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 1.4rem;
  font-size: 1.05rem;
}
.dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.3;
  transition: opacity 150ms;
}
.dot.on { opacity: 1; }
.dot.red.on { background: var(--red); }
.dot.yellow.on { background: var(--yellow); }

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

.board {
  display: grid;
  grid-template-columns: repeat(7, var(--cell));
  background: var(--board);
  padding: calc(var(--cell) * 0.14);
  border-radius: calc(var(--cell) * 0.22);
  /* a quiet contact shadow beneath: the board rests on the page */
  box-shadow: 0 12px 20px -14px var(--shadow);
  overflow: hidden; /* falling pieces enter from behind the frame, not over the page */
}
.col {
  display: grid;
  grid-template-rows: repeat(6, var(--cell));
}
.col.playable {
  cursor: pointer;
}
.cell {
  position: relative;
}
.cell::before {
  /* the empty slot: a recessed hole, distinguishable by depth not color */
  content: "";
  position: absolute;
  inset: 11%;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: inset 0 3px 7px var(--shadow);
}
.piece {
  position: absolute;
  inset: 11%;
  border-radius: 50%;
  /* lit from the top of the screen: soft shade on the upper inner edge */
  box-shadow: inset 0 4px 8px oklch(0% 0 0 / 0.18);
}
.piece.red { background: var(--red); }
.piece.yellow { background: var(--yellow); }

.col.playable:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: -2px;
  border-radius: calc(var(--cell) * 0.18);
}

.piece.ghost {
  opacity: 0;
  box-shadow: none;
}
@media (hover: hover) {
  .col.playable:hover .ghost {
    opacity: 0.35;
  }
}
.col.playable:focus-visible .ghost {
  opacity: 0.35;
}

.piece.win {
  box-shadow:
    inset 0 0 0 max(3px, calc(var(--cell) * 0.055)) oklch(100% 0 0 / 0.85),
    inset 0 4px 8px oklch(0% 0 0 / 0.18);
}

@keyframes drop {
  0% { transform: translateY(var(--fall)); }
  72% { transform: translateY(0); }
  86% { transform: translateY(calc(var(--cell) * -0.06)); }
  100% { transform: translateY(0); }
}
.piece.drop {
  animation: drop 220ms cubic-bezier(0.55, 0, 1, 0.45) both;
}
@media (prefers-reduced-motion: reduce) {
  .piece.drop {
    animation: none;
  }
}

.actions {
  display: flex;
  gap: 0.7rem;
}
