@font-face {
  font-family: 'Fredoka';
  src: url('fonts/fredoka.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
}

:root {
  /* 1950s bathroom: mint tile wall, porcelain tiles, chocolate glaze. */
  --wall: #a9d9cc;
  --grout: #95c6b8;
  --wall-deep: #7fb5a6;
  --porcelain: #fcfcf8;
  --porcelain-edge: #d9e2dd;
  --ink: #1c2b29;
  --ink-soft: #4b6560;
  --glaze: #6b3f22;
  --glaze-hi: #8c5732;
  --glaze-edge: #4a2a15;
  --mustard: #e7b03c;
  --rose: #d9707c;

  --tile: clamp(38px, 7.2vh, 58px);
  --gap: 6px;
  --radius-tile: 7px;
  --font: 'Fredoka', ui-rounded, 'Segoe UI', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background-color: var(--wall);
  /* Grout lines: a 4" tile wall behind everything. */
  background-image:
    linear-gradient(var(--grout) 2px, transparent 2px),
    linear-gradient(90deg, var(--grout) 2px, transparent 2px);
  background-size: 64px 64px;
  background-position: -1px -1px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--porcelain);
  border-bottom: 3px solid var(--wall-deep);
}

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

.wordmark span {
  text-transform: uppercase;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 5px;
  font-weight: 650;
  font-size: 16px;
  background: var(--porcelain);
  border: 2px solid var(--porcelain-edge);
}

.wordmark span.g {
  background: var(--glaze);
  border-color: var(--glaze-edge);
  color: var(--porcelain);
}

.puzzle-meta {
  font-size: 15px;
  color: var(--ink-soft);
}

.puzzle-meta b {
  color: var(--ink);
  font-weight: 600;
}

.top .spacer {
  flex: 1;
}

.tabs {
  display: none;
  gap: 4px;
  background: var(--wall);
  padding: 3px;
  border-radius: 10px;
}

.tabs button {
  white-space: nowrap;
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 8px;
  font-weight: 550;
  font-size: 14px;
}

.tabs button[aria-pressed='true'] {
  background: var(--porcelain);
}

.help-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: transparent;
  font-weight: 650;
}

/* ---------- layout ---------- */

.main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
  gap: 0;
}

.play {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 16px 12px;
}

.server {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--porcelain);
  border-left: 3px solid var(--wall-deep);
}

@media (max-width: 760px) {
  .main {
    grid-template-columns: minmax(0, 1fr);
  }
  .tabs {
    display: flex;
  }
  .main[data-tab='play'] .server,
  .main[data-tab='server'] .play {
    display: none;
  }
  .server {
    border-left: 0;
  }
  .wordmark {
    display: none;
  }
  .top {
    gap: 10px;
    padding: 10px 12px;
  }
  .puzzle-meta {
    font-size: 14px;
  }
  .puzzle-meta .to {
    display: none;
  }
}

/* ---------- ladder ---------- */

.ladder-wrap {
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  scrollbar-width: thin;
}

.ladder {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  margin: auto 0;
  padding: 6px 0;
}

.row {
  display: grid;
  grid-template-columns: 44px repeat(4, var(--tile)) 44px;
  gap: var(--gap);
  align-items: center;
}

.row .label {
  font-size: 13px;
  color: var(--ink-soft);
  text-align: right;
  padding-right: 4px;
}

.row .mark {
  font-size: 13px;
  color: var(--ink-soft);
  padding-left: 4px;
}

.tile {
  width: var(--tile);
  height: var(--tile);
  display: grid;
  place-items: center;
  border-radius: var(--radius-tile);
  font-weight: 600;
  font-size: calc(var(--tile) * 0.5);
  text-transform: uppercase;
  background: var(--porcelain);
  border: 2px solid var(--porcelain-edge);
  box-shadow:
    inset 0 -3px 0 rgba(28, 43, 41, 0.07),
    inset 0 2px 0 rgba(255, 255, 255, 0.9);
}

.tile.changed {
  background: var(--glaze);
  border-color: var(--glaze-edge);
  color: var(--porcelain);
  box-shadow:
    inset 0 -3px 0 rgba(0, 0, 0, 0.25),
    inset 0 2px 0 var(--glaze-hi);
}

.row.hinted .mark::before {
  content: '';
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--mustard);
  margin-right: 5px;
  vertical-align: 1px;
}

/* the row being typed */
.row.input .tile {
  background: rgba(252, 252, 248, 0.55);
  border: 2px dashed var(--wall-deep);
  box-shadow: none;
}

.row.input .tile.filled {
  background: var(--porcelain);
  border: 2px solid var(--ink);
}

.row.input .tile.ghost {
  color: rgba(28, 43, 41, 0.2);
}

.row.input .tile.filled.changed {
  background: var(--glaze);
  border-color: var(--glaze-edge);
  color: var(--porcelain);
}

.row.solved .tile {
  background: var(--glaze);
  border-color: var(--glaze-edge);
  color: var(--porcelain);
}

.shake {
  animation: shake 0.32s;
}

@keyframes shake {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}

.row.new .tile {
  animation: set 0.18s ease-out;
}

@keyframes set {
  from {
    transform: scale(0.88);
  }
}

/* The one big moment: the POOP row flips to glaze, tile by tile. */
.row.solved.celebrate .tile {
  animation: flush 0.5s ease-in-out both;
}
.row.solved.celebrate .tile:nth-child(3) {
  animation-delay: 0.08s;
}
.row.solved.celebrate .tile:nth-child(4) {
  animation-delay: 0.16s;
}
.row.solved.celebrate .tile:nth-child(5) {
  animation-delay: 0.24s;
}

@keyframes flush {
  0% {
    transform: rotateX(0);
    background: var(--porcelain);
    color: var(--ink);
  }
  49% {
    transform: rotateX(90deg);
    background: var(--porcelain);
    color: var(--ink);
  }
  50% {
    transform: rotateX(90deg);
    background: var(--glaze);
    color: var(--porcelain);
  }
  100% {
    transform: rotateX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .shake,
  .row.new .tile,
  .row.solved.celebrate .tile {
    animation: none;
  }
}

/* ---------- message ---------- */

.toast {
  min-height: 26px;
  margin: 6px 0 2px;
  font-size: 15px;
  font-weight: 500;
  text-align: center;
}

.toast.error {
  color: #8e2433;
}

/* ---------- actions + keyboard ---------- */

.actions {
  display: flex;
  gap: 8px;
  margin: 4px 0 10px;
}

.action {
  border: 2px solid var(--ink);
  background: var(--porcelain);
  border-radius: 999px;
  padding: 6px 16px;
  font-weight: 550;
  font-size: 14px;
}

.action:disabled {
  opacity: 0.4;
  cursor: default;
}

.action.danger[data-armed='true'] {
  background: var(--rose);
  border-color: #8e2433;
}

.keyboard {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.krow {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.key {
  flex: 1;
  max-width: 44px;
  height: clamp(40px, 6.6vh, 54px);
  border: 0;
  border-radius: 6px;
  background: var(--porcelain);
  font-weight: 600;
  font-size: 17px;
  text-transform: uppercase;
  box-shadow: inset 0 -3px 0 rgba(28, 43, 41, 0.14);
}

.key:active {
  transform: translateY(1px);
  box-shadow: inset 0 -1px 0 rgba(28, 43, 41, 0.14);
}

.key.wide {
  max-width: 70px;
  flex: 1.5;
  font-size: 13px;
  text-transform: none;
}

/* ---------- finished ---------- */

.done {
  width: 100%;
  max-width: 460px;
  background: var(--porcelain);
  border-radius: 14px;
  border: 3px solid var(--wall-deep);
  padding: 16px 20px 18px;
  text-align: center;
}

.done h2 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 650;
}

.done p {
  margin: 0 0 12px;
  color: var(--ink-soft);
}

.answer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 6px;
  margin: 0 0 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.answer span + span::before {
  content: '›';
  margin-right: 6px;
  color: var(--ink-soft);
  font-weight: 400;
}

.stats {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-bottom: 12px;
}

.stats div {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stats b {
  font-size: 24px;
  font-weight: 650;
  line-height: 1.1;
}

.stats small {
  font-size: 12px;
  color: var(--ink-soft);
}

.next {
  font-size: 14px;
  color: var(--ink-soft);
}

/* ---------- server panel ---------- */

.server h3 {
  margin: 0;
  padding: 14px 18px 10px;
  font-size: 17px;
  font-weight: 600;
}

.server .count {
  color: var(--ink-soft);
  font-weight: 400;
  font-size: 14px;
}

.players {
  list-style: none;
  margin: 0;
  padding: 0 0 12px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.player {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 6px;
  padding: 10px 18px;
  border-top: 2px solid var(--wall);
}

.player.me {
  background: #eef7f3;
}

.avatar {
  grid-row: span 2;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--wall);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
}

.who {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.who .name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.who .status {
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
  margin-left: auto;
}

.player.won .status {
  color: var(--glaze);
  font-weight: 550;
}

/* Spoiler-free strip: one column per step, the changed letter in glaze. */
.strip {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.strip .srow {
  display: flex;
  align-items: center;
  gap: 2px;
}

.strip .srow i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--porcelain-edge);
}

.strip .srow i.c {
  background: var(--glaze);
}

.strip .srow.hint::after {
  content: '';
  width: 5px;
  height: 5px;
  margin-left: 3px;
  border-radius: 50%;
  background: var(--mustard);
}

.strip .srow.typing i {
  background: transparent;
  outline: 1px dashed var(--wall-deep);
  outline-offset: -1px;
}

.empty {
  padding: 4px 18px;
  color: var(--ink-soft);
}

/* ---------- full-screen states ---------- */

.center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
}

.center .wordmark span {
  width: 44px;
  height: 44px;
  font-size: 26px;
  border-radius: 8px;
  border-width: 3px;
}

.center p {
  margin: 0;
  max-width: 34ch;
  font-size: 17px;
}

.center form {
  display: flex;
  gap: 8px;
}

.center input {
  font: inherit;
  padding: 8px 12px;
  border-radius: 10px;
  border: 2px solid var(--ink);
  background: var(--porcelain);
  width: 180px;
  user-select: text;
}

.banner {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--glaze);
  color: var(--porcelain);
  font-weight: 500;
}

.banner button {
  border: 0;
  border-radius: 999px;
  padding: 4px 12px;
  background: var(--porcelain);
  color: var(--glaze);
  font-weight: 600;
}

/* help dialog */
.help {
  position: fixed;
  inset: 0;
  background: rgba(28, 43, 41, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 10;
}

.help-card {
  background: var(--porcelain);
  border-radius: 14px;
  padding: 20px 22px;
  max-width: 420px;
  line-height: 1.5;
}

.help-card h2 {
  margin: 0 0 8px;
  font-weight: 650;
}

.help-card p {
  margin: 0 0 10px;
}

.help-card .example {
  display: flex;
  gap: 4px;
  margin: 4px 0 12px;
}

.help-card .example .tile {
  --tile: 34px;
}
