:root {
  --bg: #14213d;
  --bg2: #1d2d50;
  --felt: #1f4e3d;
  --ink: #f5f3ee;
  --muted: #a9b4c8;
  --accent: #fca311;
  --card-back: #34495e;
  --neg: #3a6ea5;
  --zero: #7fc8f8;
  --low: #6fcf97;
  --mid: #f2c94c;
  --high: #f2994a;
  --max: #eb5757;
  --act: #9b6dd6;
  --radius: 12px;
  font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg) radial-gradient(ellipse at top, var(--bg2), var(--bg) 70%) no-repeat;
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}
#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 10px 16px 12px;
}
button { font-family: inherit; }

/* ---------- home / lobby ---------- */
.home, .lobby { display: flex; flex-direction: column; gap: 14px; padding-top: 6vh; }
.logo { font-size: 46px; margin: 0; text-align: center; letter-spacing: 1px; font-weight: 700; }
.logo span { color: var(--accent); margin-left: 4px; }
.tag { text-align: center; color: var(--muted); margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.field input {
  font: inherit; font-size: 20px; padding: 12px 14px; border-radius: var(--radius);
  border: 2px solid #33456b; background: #0f1a30; color: var(--ink); outline: none;
}
.field input:focus { border-color: var(--accent); }
#code { text-transform: uppercase; letter-spacing: 8px; text-align: center; font-weight: 700; }
.panel { display: flex; flex-direction: column; gap: 10px; background: #ffffff0d; padding: 14px; border-radius: 16px; }
.or { text-align: center; color: var(--muted); font-size: 13px; }
.btn {
  font-size: 18px; font-weight: 600; padding: 14px; border-radius: var(--radius);
  border: 2px solid #3b5080; background: #26375e; color: var(--ink); cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #14213d; }
.btn.ghost { background: transparent; }
.btn.small { font-size: 15px; padding: 9px 14px; }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; color: var(--muted); font-size: 15px; padding: 6px; cursor: pointer; text-decoration: underline; }
.bigcode { font-size: 64px; font-weight: 700; text-align: center; letter-spacing: 14px; color: var(--accent); margin: -6px 0 0; }
.lobby h2 { margin: 10px 0 0; font-size: 18px; color: var(--muted); }
.plist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.plist li { display: flex; align-items: center; gap: 10px; background: #ffffff0d; padding: 10px 12px; border-radius: var(--radius); font-size: 18px; }
.plist .x { margin-left: auto; background: none; border: 0; color: var(--muted); font-size: 18px; padding: 4px 8px; cursor: pointer; }
.tag.dev { color: var(--accent); font-size: 13px; margin-top: -8px; }
.plist em { font-style: normal; font-size: 12px; color: var(--accent); border: 1px solid; border-radius: 6px; padding: 1px 6px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #14213d; display: grid; place-items: center; font-weight: 700; text-transform: uppercase; }
.hint { font-size: 14px; line-height: 1.5; }
.spinner { width: 40px; height: 40px; border: 4px solid #ffffff22; border-top-color: var(--accent); border-radius: 50%; margin: 20px auto; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- game ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 36px; }
.topbar .link { text-decoration: none; font-size: 22px; color: var(--ink); }
.lobby .topbar .link { font-size: 15px; color: var(--muted); }
.round { color: var(--muted); font-size: 14px; }
.net { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.net i { width: 8px; height: 8px; border-radius: 50%; background: var(--mid); }
.net.ok i { background: var(--low); }
.net.bad i { background: var(--max); }

.game { display: flex; flex-direction: column; gap: 10px; }
.tabs { position: relative; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 1 auto; min-width: 56px; display: inline-flex; align-items: center; gap: 5px; position: relative;
  font-size: 14px; padding: 6px 9px; border-radius: 20px; border: 2px solid #3b5080;
  background: #ffffff0a; color: var(--ink); cursor: pointer; max-width: 130px; white-space: nowrap;
}
.tab .nm { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tab.you { flex-shrink: 0; }
.tab b { flex-shrink: 0; font-size: 12px; background: #ffffff1a; border-radius: 10px; padding: 1px 6px; }
.tab.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tab.on b { background: #14213d22; }
.tab.turn::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.tab.gone { opacity: .55; }
.tab.you { cursor: default; border-style: dashed; }
.tabs .arrow { flex: 0 0 auto; align-self: center; color: var(--muted); font-size: 14px; }

.table { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--felt); border-radius: 18px; padding: 10px; box-shadow: inset 0 2px 12px #0006; }
.opp { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.grid.opp-grid { grid-template-columns: repeat(4, 36px); gap: 4px; max-width: none; margin: 0; }
.grid.opp-grid .card { width: 36px; height: 50px; aspect-ratio: auto; font-size: 18px; border-radius: 7px; border-width: 1.5px; }
.opp-grid .card small, .opp-grid .card .ico { font-size: 9px; }
.opp-grid .card .lock, .opp-grid .card .eye { display: none; }
.oscore { font-size: 12px; color: #cfe3d8; }
.oscore b { color: #fff; }
.piles { display: grid; grid-template-columns: repeat(2, auto); gap: 6px 10px; justify-items: center; }
.piles .pile:last-child { grid-column: 1 / -1; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: #cfe3d8; }
.pile .card { width: 48px; height: 66px; font-size: 24px; }

/* Prompt and action row keep fixed heights so the board never moves when they change. */
.prompt { text-align: center; font-size: 15px; line-height: 1.25; height: 2.5em; overflow: hidden; display: grid; place-items: center; color: var(--muted); padding: 0 6px; }
.prompt.mine { color: var(--accent); font-weight: 600; }
.actions { display: flex; justify-content: center; align-items: center; gap: 8px; height: 40px; }
.actions .btn.small { padding: 7px 14px; }

.me { background: #ffffff08; border: 2px solid transparent; border-radius: 18px; padding: 10px; }
.me.active { border-color: var(--accent); }
/* 4 across x 3 down, cards 5:7. Size from the height left over so the whole board fits one phone screen. */
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; max-width: clamp(220px, calc((100dvh - 520px) / 1.05 + 21px), 400px); margin: 0 auto; }
.grid .card { width: 100%; aspect-ratio: 5 / 7; font-size: 30px; }
.mescore { text-align: center; color: var(--muted); font-size: 14px; margin-top: 8px; }
.mescore b { color: var(--ink); }
.log { text-align: center; font-size: 12px; color: var(--muted); min-height: 16px; }

/* ---------- cards ---------- */
.card {
  position: relative; display: grid; place-items: center; align-content: center;
  border-radius: 10px; border: 2px solid #0003; font-weight: 700; color: #14213d;
  padding: 0; cursor: pointer; box-shadow: 0 2px 0 #0004; transition: transform .12s, box-shadow .12s;
  font-family: inherit; line-height: 1;
}
.card.down {
  background: repeating-linear-gradient(45deg, #2c3e57 0 6px, #34495e 6px 12px);
  border-color: #4a6283;
}
.card.slot { background: transparent; border: 2px dashed #ffffff33; box-shadow: none; cursor: default; }
.card.neg { background: var(--neg); color: #fff; }
.card.zero { background: var(--zero); }
.card.low { background: var(--low); }
.card.mid { background: var(--mid); }
.card.high { background: var(--high); }
.card.max { background: var(--max); color: #fff; }
.card.act { background: var(--act); color: #fff; }
.card .ico { font-size: .8em; }
.card small { font-size: 11px; letter-spacing: 1px; margin-top: 2px; }
.card.locked { filter: saturate(.35) brightness(.85); }
.card .lock { position: absolute; top: 2px; right: 3px; font-size: 12px; font-style: normal; }
.card.peeked { outline: 2px dashed #fff8; outline-offset: -5px; }
.card.peeked:not(.down) { background-image: repeating-linear-gradient(45deg, #0000 0 6px, #0002 6px 12px); }
.card .eye { position: absolute; bottom: 2px; right: 3px; font-size: 11px; font-style: normal; }
.card.target { box-shadow: 0 0 0 3px var(--accent), 0 2px 0 #0004; }
.card.picked { box-shadow: 0 0 0 4px #fff; transform: translateY(-4px); }
.card.glow { box-shadow: 0 0 0 3px var(--accent), 0 0 16px var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.card.pending { transform: rotate(4deg); }
.deck .count { position: absolute; bottom: 4px; font-size: 11px; color: #cfd9e8; font-weight: 600; }
@keyframes pulse { 50% { transform: translateY(-3px); } }
.card:active { transform: scale(.95); }

/* ---------- sheets ---------- */
.results, .modal { position: fixed; inset: 0; background: #0009; display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.results.min { background: transparent; pointer-events: none; }
.results.min .sheet { transform: translateY(calc(100% - 54px)); pointer-events: auto; }
.sheet {
  width: 100%; max-width: 520px; background: var(--bg2); border-radius: 22px 22px 0 0;
  padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 12px;
  max-height: 88dvh; transition: transform .25s;
}
.sheet h2 { margin: 0; text-align: center; }
.grab { align-self: center; text-decoration: none; font-size: 13px; }
.sheet table { width: 100%; border-collapse: collapse; font-size: 17px; }
.sheet th { color: var(--muted); font-weight: 400; font-size: 13px; text-align: right; }
.sheet th:first-child, .sheet td:first-child { text-align: left; }
.sheet td { padding: 7px 4px; border-top: 1px solid #ffffff14; text-align: right; }
.sheet tr.you td { color: var(--accent); }
.sheet .scroll { overflow: auto; }
.deck-editor .drow { display: grid; grid-template-columns: 1.3fr 0.9fr 1fr 28px; gap: 8px; align-items: center; margin-bottom: 8px; }
.deck-editor .drow.head span { color: var(--muted); font-size: 12px; }
.deck-editor .drow:has(> span:first-child + input:last-child) { grid-template-columns: 2fr 1fr; }
.deck-editor .vcell { display: flex; gap: 4px; min-width: 0; }
.deck-editor .vcell input { min-width: 0; }
.deck-editor .pm { flex: 0 0 32px; border-radius: 8px; border: 2px solid #33456b; background: #26375e; color: var(--ink); font-size: 18px; cursor: pointer; padding: 0; }
.deck-editor input[type=text], .deck-editor input[type=number] { font: inherit; font-size: 16px; width: 100%; padding: 8px; border-radius: 8px; border: 2px solid #33456b; background: #0f1a30; color: var(--ink); }
.deck-editor .swatch { position: relative; height: 40px; }
.deck-editor .swatch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.deck-editor .swatch b { display: grid; place-items: center; height: 100%; border-radius: 8px; font-size: 18px; pointer-events: none; }
.deck-editor .x { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
.deck-editor .scroll { max-height: 55dvh; }
.row2 { display: flex; gap: 8px; }
.row2 .btn { flex: 1; }
.rules p, .rules li { color: #dde3ee; line-height: 1.4; font-size: 15px; }
.rules ul { padding-left: 20px; margin: 0; }

#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 30px); opacity: 0;
  background: #000d; color: #fff; padding: 10px 16px; border-radius: 22px; font-size: 15px;
  transition: .2s; z-index: 20; pointer-events: none; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 700px) {
  .grid { gap: 5px; }
  .grid .card { font-size: 24px; }
  .prompt { font-size: 14px; }
}
