/* ============================================================
   Dots & Boxes — minimal "paper" theme
   ============================================================ */
:root {
  --bg: #f4f3ef;
  --paper: #ffffff;
  --ink: #24252b;
  --muted: #8a8c94;
  --hair: #e7e5df;
  --hair-2: #efeee9;
  --graphite: #3b3c43;
  --seat0: #5b63d3;   /* matches board.js accents[0] */
  --seat1: #c8663f;   /* matches board.js accents[1] */
  --shadow: 0 1px 2px rgba(20,20,30,.04), 0 8px 24px -12px rgba(20,20,30,.18);
  --ease: cubic-bezier(.22,1,.36,1);
  --pencil: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='26' viewBox='0 0 26 26'%3E%3Cg transform='rotate(0)'%3E%3Cpath d='M4 22l3-1 12-12-2-2L5 19l-1 3z' fill='%23ffcf6b' stroke='%2323252b' stroke-width='1.2' stroke-linejoin='round'/%3E%3Cpath d='M17 7l2 2 2-2-2-2-2 2z' fill='%23e59a52' stroke='%2323252b' stroke-width='1.2' stroke-linejoin='round'/%3E%3Cpath d='M4 22l3-1-2-2-1 3z' fill='%2323252b'/%3E%3C/g%3E%3C/svg%3E") 3 23;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none; -webkit-user-select: none;
}

/* ---------- screens ---------- */
.screen {
  display: none;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 18px max(14px, env(safe-area-inset-bottom));
  flex-direction: column;
}
.screen.active { display: flex; }

/* ---------- lobby ---------- */
.l-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 18px; }
.wordmark { font-size: 20px; font-weight: 800; letter-spacing: -.3px; }
.wordmark span { color: var(--muted); font-weight: 500; }
.me-chip { display: flex; align-items: center; gap: 8px; padding: 5px 10px 5px 5px; background: var(--paper); border: 1px solid var(--hair); border-radius: 999px; box-shadow: var(--shadow); }
.me-av { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; background: var(--hair); }
.me-name { font-size: 13px; font-weight: 600; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.l-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.l-listhead { display: flex; align-items: baseline; justify-content: space-between; margin: 24px 2px 10px; }
.l-listhead > span { font-size: 12px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: var(--muted); }
.link { background: none; border: none; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; }
.link:hover { color: var(--ink); }

.room-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; margin: 0 -2px; padding: 0 2px 8px; }
.room-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 12px 12px 14px;
  background: var(--paper); border: 1px solid var(--hair); border-radius: 16px;
  box-shadow: var(--shadow);
  animation: rise .28s var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.room-av { width: 42px; height: 42px; border-radius: 12px; object-fit: cover; background: var(--hair); flex-shrink: 0; }
.room-main { flex: 1; min-width: 0; }
.room-top { display: flex; align-items: center; gap: 8px; }
.room-host { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { font-size: 11px; font-weight: 700; color: var(--muted); background: var(--hair-2); padding: 2px 7px; border-radius: 6px; }
.room-sub { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.status-dot.live { background: #3ba55d; box-shadow: 0 0 0 3px rgba(59,165,93,.18); }
.status-dot.wait { background: #e0a52b; box-shadow: 0 0 0 3px rgba(224,165,43,.18); }
.time { font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: 14px; text-align: center; margin-top: 30px; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--hair); background: var(--paper); color: var(--ink);
  font: 600 15px/1 system-ui; padding: 14px 16px; border-radius: 14px; cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s var(--ease), background .15s, border-color .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #34353c; }
.btn.ghost { background: transparent; box-shadow: none; }
.join-btn {
  border: 1px solid var(--ink); background: var(--ink); color: #fff;
  font: 700 13px/1 system-ui; padding: 9px 16px; border-radius: 10px; cursor: pointer; flex-shrink: 0;
  transition: transform .12s var(--ease), opacity .15s;
}
.join-btn:active { transform: scale(.94); }
.join-btn:disabled { background: var(--hair-2); color: var(--muted); border-color: var(--hair); cursor: default; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--hair);
  background: var(--paper); color: var(--ink); font-size: 18px; cursor: pointer;
  display: grid; place-items: center; box-shadow: var(--shadow);
  transition: transform .12s var(--ease);
}
.icon-btn:active { transform: scale(.92); }
.icon-btn.muted { opacity: .5; }

/* ---------- game ---------- */
.g-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: 14px; }
.g-title { font-weight: 800; font-size: 16px; letter-spacing: -.2px; }

.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: stretch; }
.sb {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--paper); border: 1px solid var(--hair);
  border-radius: 14px; box-shadow: var(--shadow); min-width: 0;
  transition: border-color .25s, box-shadow .25s, transform .25s var(--ease);
}
#sb1 { flex-direction: row-reverse; text-align: right; }
.sb-av { width: 38px; height: 38px; border-radius: 10px; object-fit: cover; background: var(--hair); flex-shrink: 0; }
.sb-meta { display: flex; flex-direction: column; min-width: 0; }
.sb-name { font-size: 12.5px; font-weight: 600; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 90px; }
.sb-score { font-size: 26px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.sb-letter {
  margin-left: auto; font-size: 22px; font-weight: 800; width: 34px; height: 34px;
  display: grid; place-items: center; border-radius: 9px; flex-shrink: 0;
  background: var(--hair-2);
}
#sb0 .sb-letter { color: var(--seat0); margin-left: auto; }
#sb1 .sb-letter { color: var(--seat1); margin-left: 0; margin-right: auto; }
#sb0.active { border-color: var(--seat0); box-shadow: 0 0 0 1px var(--seat0), var(--shadow); transform: translateY(-2px); }
#sb1.active { border-color: var(--seat1); box-shadow: 0 0 0 1px var(--seat1), var(--shadow); transform: translateY(-2px); }
.sb.me .sb-name::after { content: " · you"; color: var(--muted); font-weight: 500; }
.sb-vs { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.sb-vs > span:first-child { font-size: 11px; font-weight: 800; color: var(--muted); letter-spacing: 1px; }
.boxes-left { font-size: 10px; color: var(--muted); white-space: nowrap; }

.board-wrap { flex: 1; display: grid; place-items: center; min-height: 0; padding: 16px 0; }
.board-host {
  width: min(90vw, 62vh, 460px); aspect-ratio: 1;
  background: var(--paper); border: 1px solid var(--hair); border-radius: 18px;
  box-shadow: var(--shadow); padding: 8px;
}
.svgboard { width: 100%; height: 100%; display: block; cursor: var(--pencil), crosshair; touch-action: none; }
.svgboard.locked { cursor: default; }

.dot { fill: #cfccc2; }
.edge { stroke: var(--graphite); stroke-width: 6; stroke-linecap: round; }
.edge.draw { transition: stroke-dashoffset .18s ease-out; }
.ghost { stroke: rgba(59,60,67,.35); stroke-width: 6; stroke-linecap: round; stroke-dasharray: 1 12; pointer-events: none; }
.ghost.valid { stroke: rgba(59,60,67,.75); stroke-dasharray: none; }
.dot-active { fill: rgba(59,60,67,.16); }
.boxletter { font: 800 62px system-ui, sans-serif; transform-box: fill-box; transform-origin: center; }
.boxletter.pop { animation: pop .32s var(--ease); }
@keyframes pop { 0% { opacity: 0; transform: scale(.2); } 60% { opacity: 1; transform: scale(1.14); } 100% { transform: scale(1); } }

.g-foot { text-align: center; min-height: 22px; padding-top: 6px; }
.status { font-size: 14px; font-weight: 600; color: var(--muted); }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: end center;
  padding: 0; background: rgba(28,28,34,.34);
  opacity: 0; visibility: hidden; transition: opacity .25s, visibility .25s;
}
.modal.show { opacity: 1; visibility: visible; }
.sheet {
  width: 100%; max-width: 480px; background: var(--paper);
  border-radius: 22px 22px 0 0; padding: 24px 22px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px -14px rgba(20,20,30,.3);
  transform: translateY(12px); transition: transform .3s var(--ease);
}
.modal.show .sheet { transform: none; }
.sheet.center { text-align: center; }
.sheet h2 { font-size: 20px; font-weight: 800; margin-bottom: 16px; letter-spacing: -.2px; }
.lbl { display: block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 14px 0 8px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; padding: 5px; background: var(--hair-2); border-radius: 12px; }
.seg-btn { border: none; background: transparent; padding: 10px; border-radius: 9px; font: 700 14px system-ui; color: var(--muted); cursor: pointer; transition: background .15s, color .15s; }
.seg-btn.on { background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }
.letter-in {
  width: 84px; height: 84px; text-align: center; font: 800 40px system-ui;
  color: var(--ink); background: var(--hair-2); border: 1px solid var(--hair); border-radius: 16px;
  text-transform: uppercase; outline: none; margin: 0 auto; display: block;
}
.letter-in:focus { border-color: var(--ink); background: var(--paper); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 10px; margin-top: 22px; }
.join-info { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink); background: var(--hair-2); padding: 10px 12px; border-radius: 12px; }
.join-info img { width: 30px; height: 30px; border-radius: 8px; }
.muted { color: var(--muted); font-size: 13px; margin-top: 4px; }
.code { font: 800 22px ui-monospace, monospace; letter-spacing: 2px; margin: 4px 0 18px; }
.result-emoji { font-size: 52px; margin-bottom: 6px; animation: pop .5s var(--ease); }

.spinner {
  width: 34px; height: 34px; margin: 4px auto 14px; border-radius: 50%;
  border: 3px solid var(--hair); border-top-color: var(--ink); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(12px);
  background: var(--ink); color: #fff; font-size: 13.5px; font-weight: 600;
  padding: 11px 18px; border-radius: 12px; box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transition: opacity .2s, transform .2s var(--ease), visibility .2s; z-index: 80;
}
.toast.show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }

@media (min-width: 481px) {
  .modal { place-items: center; }
  .sheet { border-radius: 22px; max-width: 380px; }
}
