/* Mastermind for Kids, dressed as a 1970s boxed game: a beige plastic board
   sitting on a rust table, printed in flat inks with hard offset shadows. */

@font-face {
  font-family: 'Bowlby One SC';
  src: url('fonts/bowlby.woff2') format('woff2');
  font-display: swap;
}

@font-face {
  font-family: 'Jost';
  src: url('fonts/jost.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --ground: #6f3418;
  --ground-deep: #4d2210;
  --board: #e4d2ab;
  --board-hi: #f0e2c4;
  --board-lo: #cbb587;
  --hole: #b39d72;
  --ink: #2b1a10;
  --ink-soft: #6d5334;
  --gold: #e3a32c;
  --avocado: #6f8038;
  --teal: #2d6b66;
  --tomato: #bf3f2e;
  --cream: #f7efdc;

  /* One number drives the whole board. Height is the binding constraint on a
     phone, so ten rows plus the shield and the tray always land on one screen. */
  --peg: clamp(22px, min(10vw, 4svh), 44px);
  --gap: calc(var(--peg) * 0.2);
  --ring: max(2px, calc(var(--peg) * 0.055));

  --display: 'Bowlby One SC', 'Arial Black', system-ui, sans-serif;
  --text: 'Jost', 'Futura', 'Avenir Next', system-ui, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  background-color: var(--ground);
  background-image:
    radial-gradient(rgba(255, 236, 202, 0.055) 1px, transparent 1.3px),
    radial-gradient(120% 80% at 50% 0%, rgba(255, 190, 120, 0.14), transparent 70%);
  background-size: 7px 7px, 100% 100%;
  color: var(--ink);
  font-family: var(--text);
  font-size: 16px;
  font-weight: 500;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

h1, h2, h3 { margin: 0; font-weight: 400; font-family: var(--display); }

/* Every raised piece is printed card: an ink keyline and a hard offset shadow,
   never a blurred one. Blur reads as glass; this game is molded plastic. */
.plate {
  background: var(--board);
  border: 3px solid var(--ink);
  border-radius: 5px;
  box-shadow: 5px 6px 0 rgba(43, 26, 16, 0.55);
}

/* ---------- buttons ---------- */

button {
  font-family: var(--text);
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  background: var(--gold);
  border: 3px solid var(--ink);
  border-radius: 4px;
  padding: 11px 18px;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform 0.06s, box-shadow 0.06s;
}

button:active:not(:disabled) {
  transform: translate(4px, 4px);
  box-shadow: 0 0 0 var(--ink);
}

button:disabled {
  cursor: not-allowed;
  background: var(--board-lo);
  color: var(--ink-soft);
  box-shadow: 4px 4px 0 rgba(43, 26, 16, 0.35);
}

button.quiet { background: var(--cream); }
button.go { background: var(--avocado); color: var(--cream); }
button.danger { background: var(--tomato); color: var(--cream); }

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

input[type="text"] {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 4px;
  padding: 11px 13px;
  width: 100%;
}

input[type="text"]::placeholder { color: #a08a63; }

/* ---------- the pegs ---------- */

/* A filled peg is a die-cut sticker: cream keyline, then ink, then a flat drop
   shadow. An empty one is a hole drilled in the board. */
.peg {
  width: var(--peg);
  height: var(--peg);
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  font-size: calc(var(--peg) * 0.6);
  line-height: 1;
  border: none;
  padding: 0;
  background: var(--hole);
  box-shadow:
    inset 0 calc(var(--ring) * 0.8) 0 rgba(43, 26, 16, 0.32),
    inset 0 0 0 var(--ring) rgba(43, 26, 16, 0.14);
}

.peg.filled {
  background: var(--peg-color, #999);
  box-shadow:
    inset 0 calc(var(--peg) * -0.16) 0 rgba(43, 26, 16, 0.22),
    0 0 0 var(--ring) var(--cream),
    0 0 0 calc(var(--ring) * 2) var(--ink),
    calc(var(--ring) * 1.4) calc(var(--ring) * 1.6) 0 calc(var(--ring) * 0.6) rgba(43, 26, 16, 0.4);
}

.peg.unknown {
  color: var(--ink-soft);
  font-family: var(--display);
  font-size: calc(var(--peg) * 0.46);
}

button.peg { cursor: pointer; }
button.peg:disabled { cursor: not-allowed; filter: grayscale(0.75) opacity(0.45); }

/* The slot the next animal lands in. A dashed ring rather than a glow, so it
   reads on the beige without inventing a new colour. */
.peg.aim {
  outline: calc(var(--ring) * 1.2) dashed var(--ink);
  outline-offset: calc(var(--ring) * 0.8);
}

.peg.drop { animation: drop 0.2s cubic-bezier(0.3, 1.5, 0.5, 1); }

@keyframes drop {
  from { transform: translateY(-40%) scale(0.75); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.pegs { display: flex; gap: var(--gap); }

/* ---------- app shell ---------- */

/* Four bands on a fixed-height grid. The board band is the only flexible one,
   so nothing ever pushes the animal tray off the bottom of the screen. */
.shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
}

.shell > * { min-width: 0; }

/* ---------- rail ---------- */

.rail {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  min-width: 0;
}

.mark {
  font-family: var(--display);
  font-size: 15px;
  color: var(--cream);
  letter-spacing: 0.01em;
  text-shadow: 2px 2px 0 rgba(43, 26, 16, 0.6);
  white-space: nowrap;
  display: none;
}

@media (min-width: 560px) {
  .mark { display: block; }
}

.roomtag {
  font-family: var(--display);
  font-size: 13px;
  letter-spacing: 0.14em;
  background: var(--gold);
  border: 2px solid var(--ink);
  border-radius: 3px;
  padding: 3px 7px 2px;
  box-shadow: 2px 2px 0 var(--ink);
}

.scores {
  display: flex;
  gap: 6px;
  margin-left: auto;
  min-width: 0;
  justify-content: flex-end;
}

.score {
  display: flex;
  align-items: baseline;
  gap: 5px;
  background: rgba(43, 26, 16, 0.4);
  border: 2px solid rgba(247, 239, 220, 0.25);
  border-radius: 3px;
  padding: 3px 8px;
  color: var(--cream);
  font-size: 13px;
  font-weight: 600;
  min-width: 0;
}

.score .who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score .pts { font-family: var(--display); font-size: 14px; }
.score.you { border-color: var(--gold); }
.score.off { opacity: 0.5; }
.score.off .who::after { content: ' (away)'; font-weight: 500; }

.icon-btn {
  position: relative;
  flex: none;
  padding: 5px 9px;
  font-size: 15px;
  border-width: 2px;
  box-shadow: 2px 2px 0 var(--ink);
  background: var(--cream);
}

.icon-btn:active:not(:disabled) { transform: translate(2px, 2px); }

.icon-btn .badge {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 17px;
  height: 17px;
  border-radius: 9px;
  background: var(--tomato);
  border: 2px solid var(--ink);
  color: var(--cream);
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* ---------- shield ---------- */

/* The hidden code, parked at the top of the board the way the shield sits at
   the far end of the real one. It never scrolls away. */
.shield {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 5px;
  box-shadow: 5px 6px 0 rgba(43, 26, 16, 0.55);
  color: var(--cream);
  min-height: calc(var(--peg) + 20px);
}

.shield .peg {
  background: #48301d;
  box-shadow:
    inset 0 calc(var(--ring) * 0.9) 0 rgba(0, 0, 0, 0.55),
    0 0 0 max(1.5px, calc(var(--ring) * 0.7)) rgba(247, 239, 220, 0.28);
}

.shield .peg.unknown { color: var(--gold); }
.shield .pegs.cast { --peg: clamp(20px, 6.6vw, 32px); }
.shield .peg.aim { outline-color: var(--cream); }
/* Same die-cut ring as the board, minus the drop shadow: the shield is already
   dark and a second shadow just muddies it. */
.shield .peg.filled {
  background: var(--peg-color, #999);
  box-shadow:
    inset 0 calc(var(--peg) * -0.16) 0 rgba(43, 26, 16, 0.22),
    0 0 0 var(--ring) var(--cream);
}

.shield .caption {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  color: #c9b48f;
  min-width: 0;
  flex: 1 1 auto;
}

.shield .caption strong { display: block; color: var(--cream); font-size: 13.5px; }

.shield .pegs { margin-left: auto; }

.shield .tally {
  font-family: var(--display);
  font-size: 13px;
  text-align: center;
  line-height: 1.15;
  color: var(--gold);
  margin-left: auto;
  flex: none;
}

.shield .tally span { display: block; font-size: 21px; color: var(--cream); line-height: 1; }
.shield .pegs { flex: none; }
.shield .pegs + .tally { margin-left: 9px; }

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

.board {
  min-height: 0;
  overflow: auto;
  padding: calc(var(--gap) + 2px) 10px;
  display: flex;
  flex-direction: column;
  justify-content: safe center;
  gap: calc(var(--peg) * 0.14);
  background:
    repeating-linear-gradient(90deg, transparent 0 6px, rgba(43, 26, 16, 0.03) 6px 7px),
    var(--board);
  border: 3px solid var(--ink);
  border-radius: 5px;
  box-shadow: 5px 6px 0 rgba(43, 26, 16, 0.55);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: calc(var(--peg) * 0.09) calc(var(--peg) * 0.14);
  border-radius: 4px;
}

.row-n {
  font-family: var(--display);
  font-size: calc(var(--peg) * 0.36);
  color: var(--ink-soft);
  width: 1.6em;
  text-align: right;
  flex: none;
}

.row.todo { opacity: 0.52; }
.row.done .row-n { color: var(--ink); }

/* The row being built gets the gold band, so the eye lands on it first. */
.row.live {
  background: rgba(227, 163, 44, 0.32);
  box-shadow: inset 0 0 0 2px var(--ink);
}

.row.live .row-n { color: var(--ink); }

/* clue holes, drilled in a strip at the end of the row */
.clues {
  display: flex;
  gap: calc(var(--peg) * 0.1);
  margin-left: auto;
  padding: calc(var(--peg) * 0.12);
  background: var(--board-lo);
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(43, 26, 16, 0.25);
}

.clue {
  width: calc(var(--peg) * 0.3);
  height: calc(var(--peg) * 0.3);
  border-radius: 50%;
  background: var(--hole);
  box-shadow: inset 0 1px 2px rgba(43, 26, 16, 0.5);
  flex: none;
}

.clue.hit {
  background: var(--cream);
  box-shadow: 0 0 0 1.5px var(--ink), inset 0 calc(var(--peg) * -0.07) 0 rgba(43, 26, 16, 0.16);
}

.clue.hit.pop { animation: pop 0.28s backwards cubic-bezier(0.3, 1.6, 0.5, 1); }

@keyframes pop {
  from { transform: scale(0); }
  to { transform: none; }
}

/* ---------- tray ---------- */

.tray {
  display: grid;
  gap: 9px;
  padding: 10px;
  background: var(--board);
  border: 3px solid var(--ink);
  border-radius: 5px;
  box-shadow: 5px 6px 0 rgba(43, 26, 16, 0.55);
}

.animals {
  display: flex;
  justify-content: space-between;
  gap: var(--gap);
}

.tray .actions { display: flex; gap: 9px; }
.tray .actions button { flex: 1; }
.tray .actions button.side { flex: 0 0 auto; }

.hint {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-soft);
  text-align: center;
}

/* On a short phone the ten rows come first. The hint lives in the rules sheet
   too, so dropping it here costs nothing. */
@media (max-height: 700px) {
  .shell { gap: 7px; padding-top: 7px; }
  .tray { gap: 7px; }
  .tray .hint { display: none; }
}

/* ---------- status card, used for every "nothing to do yet" moment ---------- */

.status {
  text-align: center;
  padding: 20px 16px;
  display: grid;
  gap: 10px;
  justify-items: center;
}

.status .headline {
  font-family: var(--display);
  font-size: clamp(20px, 6vw, 32px);
  line-height: 1.05;
  max-width: 12em;
}

.status .sub { font-size: 14.5px; color: var(--ink-soft); max-width: 24em; margin: 0; }

.dots::after {
  content: '';
  animation: dots 1.4s steps(4, end) infinite;
}

@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* ---------- level picker ---------- */

.levels { display: grid; gap: 8px; }

.level {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  width: 100%;
  background: var(--cream);
  padding: 9px 12px;
}

.level .n {
  font-family: var(--display);
  font-size: 19px;
  width: 1.1em;
  flex: none;
}

.level .what { font-size: 13.5px; font-weight: 600; line-height: 1.25; min-width: 0; }
.level .what em { display: block; font-style: normal; font-weight: 500; color: var(--ink-soft); }
.level.on { background: var(--gold); }

.level .preview {
  --peg: 17px;
  --ring: 1.5px;
  margin-left: auto;
  flex: none;
}

/* ---------- sheets: chat, menu, rules ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(43, 26, 16, 0.6);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet {
  width: min(100%, 560px);
  max-height: 82dvh;
  display: flex;
  flex-direction: column;
  background: var(--board);
  border: 3px solid var(--ink);
  border-radius: 8px 8px 0 0;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  animation: rise 0.18s ease-out;
}

@keyframes rise {
  from { transform: translateY(14px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.sheet-head h3 { font-size: 19px; }
.sheet-head button { margin-left: auto; }

.sheet .menu { display: grid; gap: 9px; }
.sheet .menu button { width: 100%; }

.rules { font-size: 14.5px; line-height: 1.5; overflow: auto; }
.rules p { margin: 0 0 10px; }
.rules .sample { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.rules .sample .clues { margin-left: 0; }

/* ---------- chat ---------- */

.chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 90px;
  margin-bottom: 10px;
}

.chat-msg { font-size: 14.5px; line-height: 1.35; }
.chat-msg .who { font-family: var(--display); font-size: 12px; margin-right: 6px; }
.chat-msg.mine .who { color: var(--teal); }
.chat-empty { color: var(--ink-soft); font-size: 14px; }
.chat-form { display: flex; gap: 8px; }
.chat-form button { flex: none; }

/* ---------- lobby ---------- */

.lobby {
  min-height: 100dvh;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 16px;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
  overflow: auto;
}

.lobby-mark {
  text-align: center;
  color: var(--cream);
}

.lobby-mark .title {
  font-family: var(--display);
  font-size: clamp(30px, 11vw, 52px);
  line-height: 0.92;
  text-shadow: 4px 5px 0 rgba(43, 26, 16, 0.65);
}

.lobby-mark .title .for {
  display: block;
  font-size: 0.42em;
  letter-spacing: 0.16em;
  color: var(--gold);
  margin-top: 0.35em;
}

.tagline {
  color: #e9d3b4;
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  max-width: 22em;
  line-height: 1.4;
  margin: -4px 0 0;
}

.lobby-strip {
  display: flex;
  gap: var(--gap);
  justify-content: center;
  --peg: clamp(36px, 12vw, 52px);
}

.lobby-card {
  width: min(100%, 380px);
  padding: 16px;
  display: grid;
  gap: 11px;
}

.lobby-card button { width: 100%; }

.or {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
}

.or::before, .or::after {
  content: '';
  flex: 1;
  height: 2px;
  background: rgba(43, 26, 16, 0.2);
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.35em;
  text-align: center;
  font-family: var(--display);
  font-size: 22px;
}

.note { font-size: 13.5px; color: var(--ink-soft); text-align: center; }
.note.bad { color: var(--tomato); font-weight: 700; }

.invite {
  font-size: 13px;
  font-weight: 600;
  word-break: break-all;
  background: var(--cream);
  border: 2px dashed rgba(43, 26, 16, 0.35);
  border-radius: 4px;
  padding: 8px 10px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  background: var(--ink);
  color: var(--cream);
  border: 3px solid var(--cream);
  border-radius: 5px;
  padding: 10px 16px;
  font-size: 14.5px;
  font-weight: 600;
  box-shadow: 5px 6px 0 rgba(43, 26, 16, 0.5);
  max-width: min(90vw, 420px);
  text-align: center;
}

/* A dropped opponent or a dead socket. */
.alert {
  flex-basis: 100%;
  font-size: 13px;
  font-weight: 700;
  color: var(--cream);
  background: var(--tomato);
  border: 2px solid var(--ink);
  border-radius: 4px;
  padding: 5px 12px;
  box-shadow: 3px 3px 0 var(--ink);
}

/* ---------- wide screens: chat earns a permanent column ---------- */

@media (min-width: 700px) {
  .row, .animals, .tray .actions, .tray .hint {
    width: 100%;
    max-width: 560px;
    margin-inline: auto;
  }
}

@media (min-width: 900px) {
  .shell {
    max-width: 1080px;
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-areas:
      'rail   rail'
      'shield chat'
      'board  chat'
      'tray   chat';
  }

  .rail { grid-area: rail; }
  .shield { grid-area: shield; }
  .board { grid-area: board; }
  .tray { grid-area: tray; }

  .chat-column {
    grid-area: chat;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 12px;
  }

  .chat-column .chat-log { min-height: 0; }
  .rail .icon-btn.chat-toggle { display: none; }
}


/* A short landscape phone cannot stack four bands, so the tray moves beside
   the board instead of shrinking the pegs to nothing. */
@media (orientation: landscape) and (max-height: 560px) {
  :root { --peg: clamp(16px, 4.6svh, 34px); }

  .shell {
    max-width: none;
    grid-template-columns: minmax(0, 1fr) 210px;
    grid-template-areas:
      'rail   rail'
      'shield shield'
      'board  tray';
  }

  .rail { grid-area: rail; }
  .shield { grid-area: shield; }
  .board { grid-area: board; }
  .tray { grid-area: tray; align-content: start; }
  .animals { flex-wrap: wrap; justify-content: center; }
  .tray .actions { flex-direction: column; }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
