/* Gruvbox dark palette */
:root {
  --bg: #1d2021;        /* bg0_h */
  --panel: #282828;     /* bg0 */
  --panel2: #3c3836;    /* bg1 */
  --ink: #ebdbb2;       /* fg */
  --muted: #a89984;     /* fg4/gray */
  --accent: #8ec07c;    /* bright aqua */
  --accent-ink: #1d2021;
  --line: #504945;      /* bg2 */
  --tile: #ebdbb2;
  --tile-ink: #282828;
  --new: #fabd2f;       /* bright yellow */
  --blank: #d3869b;     /* bright purple */
  --radio: #fe8019;     /* bright orange */
  --style: #b8bb26;     /* bright green */
  --red: #fb4934;
  --tw: #cc241d; --dw: #b16286; --tl: #458588; --dl: #83a598; --center: #fe8019;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg); color: var(--ink); min-height: 100vh;
}
.topbar {
  display: flex; align-items: center; gap: 0.8rem; padding: 0.6rem 1rem;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.2rem; margin: 0; }
.topbar .lang { border: 1px solid var(--line); border-radius: 6px; padding: 0.2rem 0.5rem; font-weight: 700; color: var(--ink); }
.conn { margin-left: auto; font-size: 0.8rem; color: var(--muted); }
.conn.ok { color: var(--accent); }

.screen { padding: 1.5rem; max-width: 1100px; margin: 0 auto; }
.hidden { display: none !important; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 1.25rem; margin: 0 auto 1rem; max-width: 460px;
}
.card h2 { margin-top: 0; }
.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 1rem; font-size: 0.85rem; color: var(--muted); }
input, select {
  background: var(--panel2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 8px; padding: 0.55rem 0.7rem; font-size: 1rem;
}
.modes { display: flex; flex-direction: column; gap: 0.6rem; }
.mode {
  text-align: left; padding: 0.8rem 1rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink); cursor: pointer; font-size: 1rem; font-weight: 600;
}
.mode:hover { border-color: var(--accent); }
.mode small { display: block; font-weight: 400; color: var(--muted); margin-top: 0.2rem; }
.mode.join { display: flex; gap: 0.5rem; align-items: center; }
.mode.join input { text-transform: uppercase; width: 6rem; }

button {
  cursor: pointer; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink); padding: 0.55rem 0.9rem; font-size: 0.95rem;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
button.link { background: none; border: none; color: var(--muted); padding: 0.4rem 0; }
.muted { color: var(--muted); font-size: 0.85rem; }
.code { font-size: 2rem; letter-spacing: 0.4rem; text-align: center; color: var(--accent); font-weight: 800; }

/* GAME */
.game-grid { display: flex; gap: 1.2rem; flex-wrap: wrap; }
.board-wrap { flex: 0 0 auto; }
.board {
  display: grid; grid-template-columns: repeat(15, 1fr); gap: 2px;
  background: var(--line); border: 2px solid var(--line); border-radius: 6px; width: min(92vw, 600px);
}
.cell {
  aspect-ratio: 1; background: var(--panel2); position: relative; display: flex;
  align-items: center; justify-content: center; font-size: clamp(8px, 1.6vw, 13px);
  color: var(--muted); cursor: pointer; user-select: none; border-radius: 2px;
}
.cell .prem { font-size: 0.7em; font-weight: 700; opacity: 0.85; }
.cell.tw { background: var(--tw); color: #fff; } .cell.dw { background: var(--dw); color: #1d2021; }
.cell.tl { background: var(--tl); color: #fff; } .cell.dl { background: var(--dl); color: #10293d; }
.cell.center { background: var(--center); color: #3a2700; }
.cell.tile { background: var(--tile); color: var(--tile-ink); cursor: default; }
.cell.tile.new { background: var(--new); cursor: pointer; }
.cell.tile.blanktile { box-shadow: inset 0 0 0 2px var(--blank); }
.cell.tile.radio { box-shadow: inset 0 0 0 2px var(--radio); }
.cell .sym { font-weight: 800; font-size: 1.25em; line-height: 1; }
.cell .pts { position: absolute; right: 2px; bottom: 1px; font-size: 0.55em; font-weight: 700; opacity: 0.7; }
.cell .decay { position: absolute; left: 1px; bottom: 0; font-size: 0.5em; font-weight: 800; color: var(--radio); }
.cell .info { position: absolute; top: 0; right: 0; width: 12px; height: 12px; min-width: 0; padding: 0; line-height: 1; font-size: 8px; font-style: italic; font-weight: 800; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--ink); display: flex; align-items: center; justify-content: center; cursor: pointer; }

.preview {
  margin-top: 0.6rem; padding: 0.6rem 0.8rem; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px;
}
.preview-total { font-size: 1.5rem; font-weight: 800; color: var(--new); }
.preview-runs { margin-top: 0.3rem; display: flex; flex-direction: column; gap: 0.2rem; }
.preview-run { display: flex; justify-content: space-between; gap: 0.6rem; font-size: 0.9rem; }
.preview-run .pf { font-weight: 700; }
.preview-run.unknown { color: var(--muted); }
.preview-run .tag { font-size: 0.72rem; color: var(--accent); }
.preview-run .tag.q { color: var(--dw); }
.preview-run .style { color: var(--style); font-weight: 700; }
.preview-error { color: var(--red); font-weight: 600; margin-top: 0.3rem; }

.side { flex: 1 1 220px; min-width: 200px; display: flex; flex-direction: column; gap: 0.8rem; }
.scores { display: flex; flex-direction: column; gap: 0.35rem; }
.score-row {
  display: flex; justify-content: space-between; padding: 0.4rem 0.6rem; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--line);
}
.score-row.current { border-color: var(--accent); }
.score-row.disconnected { opacity: 0.5; }
.score-row .pts { font-weight: 800; }
.bag { color: var(--muted); font-size: 0.9rem; }
.log { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem; flex: 1; min-height: 120px; max-height: 280px; overflow-y: auto; font-size: 0.82rem; }
.log div { padding: 0.2rem 0; border-bottom: 1px solid var(--line); }
.log .decaylog { color: var(--radio); }

.rack-area { margin-top: 1rem; }
.rack {
  display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; min-height: 56px;
  padding: 0.5rem; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.rtile {
  width: 48px; height: 48px; background: var(--tile); color: var(--tile-ink); border-radius: 6px;
  display: flex; align-items: center; justify-content: center; position: relative; cursor: pointer;
  font-weight: 800; font-size: 1.2rem; border: 2px solid transparent;
}
.rtile.blank { background: var(--blank); }
.rtile.radio { box-shadow: inset 0 0 0 2px var(--radio); }
.rtile.radio::before { content: '☢'; position: absolute; left: 2px; bottom: 1px; font-size: 0.6rem; color: var(--radio); }
.rtile.selected { border-color: var(--accent); transform: translateY(-4px); }
.rtile.exch { border-color: var(--tw); }
.rtile .info { position: absolute; top: 2px; right: 2px; width: 15px; height: 15px; min-width: 0; padding: 0; line-height: 1; font-size: 0.62rem; font-style: italic; font-weight: 800; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--ink); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.cell .info:hover, .rtile .info:hover { border-color: var(--accent); color: var(--accent); }
.rtile .pts { position: absolute; right: 3px; bottom: 1px; font-size: 0.6rem; opacity: 0.7; }
.controls { display: flex; gap: 0.5rem; justify-content: center; margin-top: 0.8rem; flex-wrap: wrap; }
.turn-info { text-align: center; margin-top: 0.6rem; color: var(--muted); min-height: 1.2rem; }

/* OVERLAYS */
.overlay {
  position: fixed; inset: 0; background: rgba(12,14,15,0.93); display: flex;
  align-items: center; justify-content: center; z-index: 20; padding: 1rem;
}
.overlay-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 1.8rem; max-width: 420px; width: 100%; text-align: center; }
.overlay-card .row { display: flex; gap: 0.6rem; justify-content: center; margin-top: 1rem; }
.formula-big { font-size: 2rem; font-weight: 800; color: var(--new); }
.blank-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.3rem; max-height: 260px; overflow-y: auto; margin: 0.8rem 0; }
.blank-grid button { padding: 0.4rem 0; font-weight: 700; }
.blank-grid button.radio { color: var(--radio); }

.rules-card { max-width: 640px; text-align: left; max-height: 88vh; display: flex; flex-direction: column; }
.rules-body { overflow-y: auto; padding-right: 0.5rem; }
.rules-body h3 { color: var(--accent); margin: 1rem 0 0.3rem; font-size: 1rem; }
.rules-body p, .rules-body li { font-size: 0.9rem; line-height: 1.45; color: var(--ink); }
.rules-body ul, .rules-body ol { padding-left: 1.2rem; margin: 0.3rem 0; }
.rules-card > button { margin-top: 1rem; align-self: center; }
.setting { display: flex; align-items: center; gap: 0.5rem; text-align: left; padding: 0.5rem 0; font-size: 0.95rem; cursor: pointer; }
.setting input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

#elSearch { width: 100%; margin-bottom: 0.6rem; }
.el-list { display: flex; flex-direction: column; }
.el-row { display: flex; gap: 0.7rem; padding: 0.45rem 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.el-sym { font-weight: 800; font-size: 1.15rem; min-width: 2.4rem; color: var(--ink); }
.el-sym.radio { color: var(--radio); }
.el-info { font-size: 0.85rem; }
.el-info .nm { font-weight: 700; }
.el-cat { color: var(--muted); }
.el-ox { color: var(--tl); font-size: 0.82rem; margin-top: 0.1rem; }
.el-decay { color: var(--radio); font-size: 0.82rem; margin-top: 0.1rem; }
.radio-text { color: var(--radio); }
.el-ox-big { font-size: 1.2rem; color: var(--tl); font-weight: 700; }
#elInfoCard h2 { margin: 0 0 0.3rem; }
.topbar .link { color: var(--muted); }

.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--accent); color: var(--ink);
  padding: 0.7rem 1.1rem; border-radius: 10px; z-index: 30; max-width: 90vw; text-align: center;
}
.toast.bad { border-color: var(--red); }

ul { list-style: none; padding: 0; }
#lobbyPlayers li, #goScores li { padding: 0.4rem 0.6rem; background: var(--panel2); border-radius: 6px; margin-bottom: 0.3rem; display: flex; justify-content: space-between; }
