:root {
  --bg: #eef2f5;
  --surface: #ffffff;
  --ink: #1d2645;
  --muted: #5a6580;
  --line: #d5dde4;
  --blue: #1b5cb8;
  --blue-dark: #154a95;
  --blue-soft: #e4edf9;
  --red: #c92a25;
  --amber: #c97c06;
  --tile: #fffaf0;
  --tile-edge: #cdbd99;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.4 "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#app {
  position: relative;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
h1, h2, p { margin: 0; }
h1 { font-size: 26px; line-height: 1.15; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
button, input, select { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
input, select {
  width: 100%;
  height: 46px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid #aebbc7;
  border-radius: 8px;
}
.section-label { margin: -14px -14px -10px; padding: 9px 14px; font-size: 16px; color: #fff; background: var(--ink); border-radius: 11px 11px 0 0; }
.section-label + .choices { margin-top: 0; border-top: 0; }
.help { margin-top: 4px; font-size: 14px; color: var(--muted); }
.code-input, .pin-input { letter-spacing: .14em; font-weight: 700; }
.code-input { text-transform: uppercase; }

.panel { padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.page-head { padding: 4px 2px 2px; }

.btn {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 11px 14px;
  text-align: center;
  text-decoration: none;
  font-weight: 600;
  line-height: 24px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #aebbc7;
  border-radius: 8px;
  cursor: pointer;
}
.btn:active { background: var(--bg); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:active { background: var(--blue-dark); }
.btn.quiet { background: none; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--red); }
.btn.fit { width: auto; flex: none; }
.btn.compact { min-height: 40px; padding: 7px 10px; }
.share { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.share .wide { grid-column: 1 / -1; }

.choices { display: flex; flex-direction: column; margin: 2px -14px -14px; border-top: 1px solid var(--line); }
.game-choice {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 56px; padding: 9px 14px;
  text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); cursor: pointer;
}
.game-choice:last-child { border-bottom: 0; border-radius: 0 0 12px 12px; }
.game-choice:active { background: var(--bg); }
.game-choice b { display: block; font-weight: 700; }
.game-choice .meta { display: block; font-size: 14px; color: var(--muted); }
.game-row { display: flex; align-items: center; gap: 8px; padding-right: 14px; border-bottom: 1px solid var(--line); }
.game-row:last-child { border-bottom: 0; }
.game-row .btn { min-height: 0; padding: 5px 11px; font-size: 14px; line-height: 20px; }
.game-row .game-choice { flex: 1; min-width: 0; border-bottom: 0; }
.game-choice .go { max-width: 42%; text-align: right; color: var(--muted); font-size: 14px; font-weight: 600; flex: none; }
.game-choice .go.mine { color: var(--blue); font-weight: 800; }
.game-choice .go.action { padding: 5px 11px; line-height: 20px; color: var(--ink); background: var(--surface); border: 1px solid #aebbc7; border-radius: 8px; }
.game-choice .go.start { color: var(--blue); }
.game-choice:active .go.action { background: var(--bg); }

/* The raised tile marks the things people actually play with: the code and the board. */
.code-tiles { display: flex; gap: 8px; justify-content: center; }
.code-tiles b {
  width: 54px; height: 62px; display: grid; place-items: center;
  font-size: 34px; font-weight: 800;
  background: var(--tile); border-radius: 8px;
  box-shadow: 0 0 0 1px var(--tile-edge), 0 3px 0 1px var(--tile-edge);
}
.code-tiles b:nth-child(1) { color: var(--red); }
.code-tiles b:nth-child(2) { color: var(--blue); }
.code-tiles b:nth-child(3) { color: var(--amber); }
.code-tiles b:nth-child(4) { color: var(--ink); }

.list { list-style: none; margin: 6px 0 0; padding: 0; }
.list li { padding: 8px 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; }
.topbar h2 { flex: 1; min-width: 0; text-align: center; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-ids { display: flex; justify-content: center; gap: 18px; font-size: 14px; color: var(--muted); }
.game-ids b { color: var(--ink); letter-spacing: .04em; }
.scores { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
.score { flex: 1 0 0; min-width: 96px; padding: 7px 10px; border-right: 1px solid var(--line); border-bottom: 3px solid transparent; }
.score:last-child { border-right: 0; }
.score.active { border-bottom-color: var(--blue); }
.score .who { display: block; font-size: 15px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { padding: 9px 12px; border-radius: 8px; font-weight: 700; text-align: center; background: #dfe6ec; }
.status.mine { background: var(--blue); color: #fff; }
.status.waiting { background: #5a6580; color: #fff; }
.status.won { background: #ffe9b8; }
.board-area { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px; background: var(--surface); border: 1px solid #aebbc7; border-radius: 12px; }
.menu {
  position: absolute; z-index: 4; top: 56px; right: 16px; width: min(290px, calc(100% - 32px));
  padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(29, 38, 69, .18);
}

/* Space is reserved, so an ad loading never moves the board under a thumb. */
.ad-slot { margin-top: auto; display: flex; align-items: center; justify-content: center; min-height: 54px; overflow: hidden; flex: none; }
.ad-slot.tall { min-height: 100px; }
.ad-placeholder { width: 100%; align-self: stretch; display: grid; place-items: center; border: 1px dashed #aebbc7; border-radius: 8px; color: var(--muted); font-size: 13px; }

#toast {
  position: fixed; left: 16px; right: 16px; bottom: 76px; z-index: 5;
  max-width: 448px; margin: 0 auto; padding: 10px 14px;
  background: var(--ink); color: #fff; border-radius: 8px; text-align: center; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
#toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (max-width: 359px) { .code-tiles b { width: 48px; height: 56px; font-size: 30px; } }
