:root {
  --felt: #0f5132;
  --felt-dark: #0a3b24;
  --panel: #fffdf7;
  --ink: #1d1d1b;
  --muted: #6b6b63;
  --accent: #c0392b;
  --ok: #1e8449;
  --wait: #b9770e;
  --bad: #c0392b;
  --radius: 10px;
  --team1: #2e86de;
  --team2: #e67e22;
  --team3: #a569bd;
  --cw: clamp(38px, 12vw, 66px);
  --ch: calc(var(--cw) * 1.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, var(--felt), var(--felt-dark));
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main { max-width: 820px; margin: 0 auto; padding: 16px 16px 48px; }

header { display: flex; align-items: baseline; gap: 12px; color: #fff; margin-bottom: 16px; }
h1 { margin: 0; font-size: 2.2rem; letter-spacing: 0.02em; }
h2 { margin: 0 0 12px; font-size: 1.15rem; }
.tag { font-size: 0.8rem; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.08em; }

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

label { display: block; margin-bottom: 12px; font-weight: 500; }
input {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  font: inherit; border: 1px solid #ccc; border-radius: 6px; background: #fff;
}
.name-field { max-width: 320px; }
.code-input { text-transform: uppercase; letter-spacing: 0.2em; font-weight: 700; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 8px; }
@media (max-width: 600px) { .split { grid-template-columns: 1fr; } }

button {
  font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 6px; cursor: pointer;
  border: none; background: var(--accent); color: #fff;
}
button:disabled { opacity: 0.45; cursor: default; }
button.secondary { background: transparent; color: var(--ink); border: 1px solid #bbb; }
button.big { font-size: 1.2rem; padding: 14px 28px; touch-action: manipulation; user-select: none; }

.error { color: var(--bad); font-weight: 600; margin: 12px 0 0; }
.muted { color: var(--muted); }

.room-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between; }
.room-head p { flex-basis: 100%; margin: 0; }
.code { font-size: 1.6rem; font-weight: 800; letter-spacing: 0.2em; }
.actions { display: flex; gap: 8px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #eee; white-space: nowrap; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.status.ok { color: var(--ok); font-weight: 600; }
.status.wait { color: var(--wait); }
.status.bad { color: var(--bad); font-weight: 600; }


details.connection summary { cursor: pointer; font-weight: 600; }
details.connection[open] summary { margin-bottom: 12px; }

/* ---------- lobby ---------- */
.picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 12px 0; }
@media (max-width: 600px) { .picker { grid-template-columns: 1fr; } }
.pick { border: 2px solid #e4dfd0; border-top: 6px solid var(--team); border-radius: 8px; padding: 10px 12px; }
.pick.chosen { background: #f5f1e4; }
.pick h3 { margin: 0 0 6px; font-size: 1rem; }
.pick ul { margin: 0 0 10px; padding-left: 18px; min-height: 3em; }
.start-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.banner { border-top: 8px solid var(--team); }
.team-1 { --team: var(--team1); }
.team-2 { --team: var(--team2); }
.team-3 { --team: var(--team3); }
table.results td { white-space: normal; }
table.results tr td:first-child { border-left: 4px solid var(--team); }

/* ---------- table ---------- */
.table { color: #fff; user-select: none; -webkit-user-select: none; }
.hint { color: rgba(255, 255, 255, 0.6); font-size: 0.9rem; }
.small { font-size: 0.8rem; opacity: 0.85; }
.label { margin: 10px 0 4px; font-weight: 600; }
.label .muted, .own-head .muted { color: rgba(255, 255, 255, 0.7); }

.scorebar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.chip {
  display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline;
  padding: 6px 10px; border-radius: 8px; background: rgba(0, 0, 0, 0.25); border-left: 5px solid var(--team);
}
.chip.mine { background: rgba(0, 0, 0, 0.4); }
.chip .score { font-size: 1.2rem; font-weight: 800; }
.stuck { color: #f5b041; }
.round { margin-left: auto; opacity: 0.7; font-size: 0.9rem; }

.center {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; align-content: flex-start;
  min-height: calc(var(--ch) + 20px); padding: 10px; margin-bottom: 12px;
  border: 2px dashed rgba(255, 255, 255, 0.3); border-radius: 10px;
}

.opps { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.opp { padding: 6px 10px 10px; border-radius: 8px; background: rgba(0, 0, 0, 0.18); border-top: 4px solid var(--team); }
.opp-head { font-size: 0.85rem; margin-bottom: 4px; }
.mini { --cw: 30px; --ch: 42px; }
.mini .card .pip { display: none; }

.own { padding: 10px; border-radius: 10px; background: rgba(0, 0, 0, 0.15); border-top: 5px solid var(--team); }
.own-head { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 0.9rem; }
.own-head .buttons { display: flex; gap: 8px; }
.own-head button.secondary { color: #fff; border-color: rgba(255, 255, 255, 0.5); }
.own-head button.secondary.on { background: #f5b041; color: #1d1d1b; border-color: #f5b041; }
.nertz { background: #f1c40f; color: #1d1d1b; font-size: 1.1rem; animation: pulse 0.8s infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); } }

.work { display: flex; gap: 8px; }
.wpile { display: flex; flex-direction: column; width: var(--cw); min-height: var(--ch); }
.wpile .card + .card { margin-top: calc(var(--ch) * -0.74); }
.own .work .wpile { min-height: calc(var(--ch) * 1.8); }

.hand { display: flex; min-height: calc(var(--ch) + 8px); padding-top: 8px; }
.hand .card + .card { margin-left: min(calc((100% - var(--cw)) / 12 - var(--cw)), calc(var(--cw) * 0.05)); }
.hand .card.live { transform: translateY(-8px); box-shadow: 0 0 0 2px #f1c40f, 0 4px 8px rgba(0, 0, 0, 0.3); }

.stockrow { display: flex; gap: 24px; align-items: flex-start; margin-top: 12px; }
.stock { display: flex; flex-direction: column; gap: 4px; align-items: center; opacity: 0.6; }
.stock.can { opacity: 1; cursor: pointer; touch-action: manipulation; }
.waste { display: flex; }
.waste .card + .card { margin-left: calc(var(--cw) * -0.72); }

/* ---------- cards ---------- */
.card {
  position: relative; flex: none; width: var(--cw); height: var(--ch);
  border-radius: calc(var(--cw) * 0.1); background: #fff; border: 1px solid #b9b4a6;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), inset 0 -4px 0 var(--team, transparent);
  font-weight: 700; font-size: calc(var(--cw) * 0.27); line-height: 1;
}
.card.t1 { --team: var(--team1); }
.card.t2 { --team: var(--team2); }
.card.t3 { --team: var(--team3); }
.card .ix { position: absolute; top: 3px; left: 3px; text-align: center; min-width: 1.1em; }
.card .pip { position: absolute; right: 8%; bottom: 10%; font-size: calc(var(--cw) * 0.5); }
.card.red { color: #c0392b; }
.card.black { color: #1d1d1b; }
.card.back { background: repeating-linear-gradient(45deg, #a93226 0 5px, #922b21 5px 10px); border: 3px solid #fff; }
.card.empty {
  background: rgba(255, 255, 255, 0.08); border: 2px dashed rgba(255, 255, 255, 0.35); box-shadow: none;
  display: grid; place-items: center; color: #fff; font-size: calc(var(--cw) * 0.45);
}
.card.live { cursor: grab; touch-action: none; }
.card.selected { outline: 3px solid #f1c40f; outline-offset: 1px; z-index: 1; }
.card.dragging { visibility: hidden; }
.ghost { position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none; filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.4)); }

.overlay { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, 0.55); color: var(--ink); }
.overlay .panel { max-width: 560px; width: 100%; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translate(-50%, 20px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 8px;
  background: #1d1d1b; color: #fff; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* During a round, shrink the header so the table gets the screen. */
body.in-game header, body.in-game #settings-line { display: none; }
body.in-game main { padding-top: 8px; }
body.in-game .room-head { padding: 6px 12px; margin-bottom: 10px; }
body.in-game .room-head .code { font-size: 1.1rem; }
body.in-game .room-head button { padding: 4px 10px; font-size: 0.85rem; }

.debug-log {
  margin: 16px; padding: 10px; max-height: 40vh; overflow: auto;
  background: #111; color: #9fe39f; font: 11px/1.4 ui-monospace, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word; border-radius: 6px;
}
