:root {
  --bg: #0d1420;
  --panel: #152030;
  --panel2: #1b2a3e;
  --border: #26384f;
  --text: #e6edf5;
  --muted: #8a9bb2;
  --accent: #d4a537;
  --accent2: #f0c75e;
  --danger: #e5484d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); font-weight: normal; }
h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

input {
  background: #0b111b; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 9px 11px; font: inherit; width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:hover:not(:disabled) { background: #24364f; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1405; }
.btn.primary:hover:not(:disabled) { background: var(--accent2); }
.btn.danger { background: #5a1d22; border-color: #7a2a30; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.wide { width: 100%; }
.btn.on { background: var(--accent); color: #1a1405; border-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* ---------- home ---------- */
#welcome {
  min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(ellipse at top, #1d3150 0%, var(--bg) 70%);
}
.home-card {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.home-card label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.home-card label input { margin-top: 6px; }
.logo {
  font-family: Georgia, "Times New Roman", serif; letter-spacing: .25em; color: var(--accent);
  text-align: center; font-size: 42px; margin: 0; text-shadow: 0 2px 0 #6b4d10; letter-spacing: .12em;
}
.logo.small { font-size: 17px; text-shadow: none; white-space: nowrap; }
.home-logo { line-height: 1; }
.home-logo span { display: block; }
.logo-top { font-size: 20px; letter-spacing: .6em; margin-right: -.6em; color: var(--muted); text-shadow: none; margin-bottom: 4px; }
.logo-main { font-size: 46px; letter-spacing: .1em; margin-right: -.1em; }
@media (max-width: 440px) { .logo-main { font-size: 36px; } .logo-top { font-size: 16px; } }
.tagline { text-align: center; color: var(--muted); margin: 4px 0 24px; }
.divider { text-align: center; color: var(--muted); font-size: 12px; margin: 18px 0; position: relative; }
.divider::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid var(--border); }
.divider span { background: var(--panel); padding: 0 10px; position: relative; }
.code-input { text-transform: uppercase; letter-spacing: .3em; font-weight: 700; text-align: center; }
.code-box {
  display: flex; align-items: center; gap: 10px; background: #0b111b; border: 1px dashed var(--border);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 18px;
}
.code-box span { color: var(--muted); font-size: 12px; }
.code-box strong { font-size: 22px; letter-spacing: .25em; color: var(--accent); flex: 1; }
.wait-list { list-style: none; padding: 0; margin: 0 0 12px; }
.wait-list li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); }

select {
  background: #0b111b; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 8px; font: inherit;
}
.bot-controls { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.bot-controls .row select { flex: 1; }
label.inline { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 12px; color: var(--muted); }
label.inline select { padding: 3px 6px; font-size: 12px; }
.icon-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 0 4px; }
.icon-btn:hover { color: var(--danger); }
.tag.ai { background: #23324a; color: #9cc4ff; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(255,255,255,.15); }
.tag { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; padding: 1px 6px; border-radius: 4px; background: var(--panel2); color: var(--muted); }
.tag.off { background: #4a1f22; color: #ffb3b3; }

/* ---------- lobby & room ---------- */
#lobby, #room, #game { height: 100%; display: flex; flex-direction: column; }
.row.between { justify-content: space-between; margin-bottom: 8px; }
.row.between h3 { margin: 0; }
.row.center { justify-content: center; }
.me-name { color: var(--accent2); }
.lobby-layout, .room-layout {
  flex: 1; min-height: 0; display: grid; gap: 12px; padding: 12px 16px;
  max-width: 1300px; width: 100%; margin: 0 auto;
}
.lobby-layout { grid-template-columns: minmax(0, 1fr) 340px; }
.room-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); max-width: 1100px; align-items: start; overflow-y: auto; }
.room-map { grid-column: 1 / -1; }
.room-map .row.between { flex-wrap: wrap; gap: 8px; }
.map-name { color: var(--accent2); font-family: Georgia, serif; font-size: 16px; }
.map-blurb { margin: 2px 0 8px; color: #c8d3e0; }
.map-stats, .map-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); }
.map-legend { margin-top: 8px; }
.map-legend > span { display: inline-flex; align-items: center; gap: 5px; }
.map-legend .dot { width: 9px; height: 9px; box-shadow: none; }
.map-legend b { color: var(--text); }
.map-preview { width: 100%; max-width: 820px; aspect-ratio: 1200 / 680; display: block; margin: 8px auto 0; border-radius: 10px; }
.map-preview .cell { cursor: default; fill-opacity: .5; }
.map-preview .terr { cursor: default; }
.map-preview .terr .body { stroke-width: 1.5; }
.watch-row { margin: 0 0 12px; font-size: 13px; color: var(--text); }
.wait-list li.watching { opacity: .75; }
.s-ai { background: #23324a; color: #9cc4ff; }
.edge.portal { fill: none; stroke-width: 2.5; stroke-dasharray: 2 6; stroke-linecap: round; }
.portal-ring { fill: none; stroke-width: 2; stroke-dasharray: 3 3; opacity: .7; pointer-events: none; animation: spin 8s linear infinite; }
.lobby-main, .lobby-side { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.chat-panel { display: flex; flex-direction: column; gap: 8px; min-height: 300px; }
.chat-panel .feed { max-height: none; }
.room-layout .chat-panel { height: min(440px, calc(100vh - 90px)); }
.room-title { margin: 0 0 12px; font-family: Georgia, serif; color: var(--accent2); font-weight: 700; overflow-wrap: anywhere; }
.create-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.create-row input[type=text], .create-row #gTitle { flex: 1 1 200px; width: auto; }
label.check { font-size: 13px; color: var(--text); cursor: pointer; }
label.check input { width: auto; accent-color: var(--accent); }
.small-code { width: 96px; padding: 5px 8px; font-size: 12px; }

.game-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.game-list .empty { color: var(--muted); text-align: center; padding: 30px 10px; }
.game-item {
  display: flex; gap: 12px; align-items: center; background: var(--panel2);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
}
.game-item.mine { border-color: var(--accent); }
.gi-main { flex: 1; min-width: 0; }
.gi-title { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.gi-meta { color: var(--muted); font-size: 12px; margin: 2px 0 6px; }
.gi-players { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; }
.gi-players span { display: inline-flex; align-items: center; gap: 4px; }
.gi-players .dot { width: 9px; height: 9px; box-shadow: none; }
.gi-players .dead { opacity: .4; text-decoration: line-through; }
.status-badge { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 2px 7px; border-radius: 10px; }
.s-lobby { background: #1f4a2b; color: #8ff0a8; }
.s-playing { background: #4a3a14; color: #ffd36b; }
.s-finished { background: #2a2f3a; color: #a8b3c4; }

.online-list { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
.online-list li { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.online-list .uname { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online-list .ustatus { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
.feed .ts { color: var(--muted); font-size: 10.5px; margin-right: 5px; }

/* ---------- game layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 8px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.spacer { flex: 1; }
.mute { background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text); cursor: pointer; font-size: 15px; padding: 2px 8px; }
#turnInfo { font-weight: 600; }
.layout { flex: 1; display: flex; min-height: 0; }
.map-wrap { flex: 1; position: relative; min-width: 0; padding: 8px; }
#map { width: 100%; height: 100%; display: block; user-select: none; }
.sidebar {
  width: 340px; flex: none; display: flex; flex-direction: column; gap: 8px; padding: 8px;
  overflow-y: auto; border-left: 1px solid var(--border); background: #101926;
}
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.panel.grow { flex: 1; min-height: 220px; display: flex; flex-direction: column; }

/* ---------- map ---------- */
.land { stroke: none; }
.coast { fill: none; stroke-width: 8.8; stroke-linejoin: round; opacity: .95; pointer-events: none; }
.cell {
  fill-opacity: .58; stroke: rgba(6,12,22,.7); stroke-width: 1.4; stroke-linejoin: round;
  cursor: pointer; transition: fill .4s, fill-opacity .15s;
}
.cell:hover { fill-opacity: .78; }
.cell.hl { fill-opacity: .85; }
.edge { stroke: rgba(255,255,255,.2); stroke-width: 1.3; pointer-events: none; }
.edge.sea { stroke-dasharray: 5 5; stroke: rgba(170,210,255,.45); stroke-width: 1.5; }
.cont-label { font: 700 15px Georgia, serif; letter-spacing: .15em; text-anchor: middle; opacity: .9; pointer-events: none; paint-order: stroke; stroke: rgba(5,12,24,.8); stroke-width: 3px; }
.terr { cursor: pointer; }
.terr .body { stroke: rgba(6,12,22,.85); stroke-width: 2.2; transition: fill .3s; }
.terr:hover .body { stroke: #fff; stroke-width: 2.5; }
.terr .halo { fill: none; stroke: none; stroke-width: 3; }
.terr .count {
  font: 700 13px system-ui, sans-serif; fill: #fff; text-anchor: middle; pointer-events: none;
  paint-order: stroke; stroke: rgba(0,0,0,.7); stroke-width: 3px;
}
.terr .tlabel {
  font: 600 10.5px system-ui, sans-serif; fill: #dfe7f1; text-anchor: middle; pointer-events: none;
  paint-order: stroke; stroke: rgba(5,12,24,.9); stroke-width: 3px;
}
.terr.clickable .halo { stroke: rgba(255,255,255,.55); stroke-dasharray: 3 4; }
.terr.target .halo { stroke: #ff6b6b; stroke-width: 3; stroke-dasharray: 5 4; animation: spin 6s linear infinite; }
.terr.fort-target .halo { stroke: #7fd4ff; stroke-width: 3; stroke-dasharray: 5 4; animation: spin 6s linear infinite; }
.terr.sel-from .halo { stroke: #fff; stroke-width: 4; stroke-dasharray: none; }
.terr.sel-to .halo { stroke: #ff3b3b; stroke-width: 4; stroke-dasharray: none; }
.terr.fort-to .halo { stroke: #39b7ff; stroke-width: 4; stroke-dasharray: none; }
.terr.flash .body { animation: flash .9s ease-out; }
@keyframes spin { to { stroke-dashoffset: -90; } }
@keyframes flash { 0% { stroke: #fff; stroke-width: 8; } 100% { stroke-width: 2; } }
.arrow { stroke: #ff3b3b; stroke-width: 4; marker-end: url(#arrowhead); pointer-events: none; opacity: .9; }
.arrow.fort { stroke: #39b7ff; marker-end: url(#arrowheadBlue); }

/* ---------- dice ---------- */
.dice-panel {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(16,25,38,.94); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 16px; display: flex; gap: 22px; align-items: center; box-shadow: 0 8px 30px rgba(0,0,0,.5);
  animation: pop .25s ease-out; max-width: calc(100% - 32px);
}
.dice-panel .side { text-align: center; }
.dice-panel .who { font-size: 12px; font-weight: 700; margin-bottom: 4px; }
.die { display: inline-block; font-size: 38px; line-height: 1; margin: 0 1px; }
.die.att { color: #ff5a5a; }
.die.def { color: #f3f3f3; }
.dice-panel .vs { color: var(--muted); font-weight: 700; }
.dice-panel .result { font-size: 12px; color: var(--muted); max-width: 170px; }
.dice-panel .result b { color: var(--accent2); }
.dice-panel.rolling .die { animation: shake .35s ease-out; }
@keyframes pop { from { transform: translateX(-50%) scale(.9); opacity: 0; } }
@keyframes shake { 0% { transform: rotate(-25deg) scale(.6); } 60% { transform: rotate(12deg) scale(1.1); } 100% { transform: none; } }

/* ---------- sidebar contents ---------- */
#actions .phase { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
#actions .phase small { font-size: 12px; color: var(--muted); font-weight: 600; margin-left: 6px; }
#actions p { margin: 4px 0; color: #c8d3e0; }
#actions .big { font-size: 26px; font-weight: 800; color: var(--accent2); }
#actions .sel { background: var(--panel2); border-radius: 6px; padding: 6px 8px; margin-top: 8px; font-size: 13px; }
#actions .warn { color: #ffb15e; font-weight: 600; }
.range-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.range-row input[type=range] { flex: 1; padding: 0; accent-color: var(--accent); }
.range-row output { font-weight: 800; font-size: 18px; min-width: 28px; text-align: right; }

.player-list { list-style: none; margin: 0; padding: 0; }
.player-list li { display: flex; align-items: center; gap: 8px; padding: 6px 6px; border-radius: 6px; }
.player-list li.current { background: var(--panel2); box-shadow: inset 3px 0 0 var(--accent); }
.player-list li.dead { opacity: .4; text-decoration: line-through; }
.player-list .pname { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-list .stats { font-size: 12px; color: var(--muted); white-space: nowrap; }

.hand { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; min-height: 20px; }
.hand .empty { color: var(--muted); font-size: 12px; }
.card {
  width: 70px; height: 92px; border-radius: 7px; background: linear-gradient(160deg, #f4ead2, #d9c9a2);
  color: #3b2d12; border: 2px solid #a08850; padding: 4px; cursor: pointer; display: flex;
  flex-direction: column; align-items: center; justify-content: space-between; text-align: center;
  font-size: 9.5px; font-weight: 700; line-height: 1.1; transition: transform .1s;
}
.card .icon { font-size: 28px; }
.card .type { font-size: 9px; text-transform: uppercase; opacity: .7; }
.card.sel { transform: translateY(-5px); border-color: #e53935; box-shadow: 0 4px 12px rgba(229,57,53,.5); }
.card.wild { background: linear-gradient(160deg, #fbe7a1, #e3b94a); }

.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tab { flex: 1; background: none; border: none; border-bottom: 2px solid transparent; color: var(--muted); font: inherit; font-weight: 600; padding: 4px; cursor: pointer; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.badge { background: var(--danger); color: #fff; border-radius: 9px; font-size: 10px; padding: 0 6px; }
.feed { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 120px; max-height: 340px; font-size: 12.5px; }
.feed li { padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,.04); color: #c3cfdc; }
.feed li.turn { color: var(--accent2); font-weight: 600; padding-top: 6px; }
#chatBox { display: flex; flex-direction: column; gap: 6px; flex: 1; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.overlay-card { background: var(--panel); border: 1px solid var(--accent); border-radius: 14px; padding: 30px; text-align: center; max-width: 420px; }
.overlay-card h2 { font-family: Georgia, serif; color: var(--accent2); font-size: 30px; margin: 0 0 8px; }
.conn { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); background: var(--danger); color: #fff; padding: 6px 14px; border-radius: 6px; z-index: 30; font-weight: 600; }
.toasts { position: fixed; top: 56px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 30; width: max-content; max-width: calc(100vw - 32px); pointer-events: none; }
.toast { background: #3a1a1d; border: 1px solid #7a2a30; color: #ffd5d5; padding: 8px 12px; border-radius: 6px; animation: pop2 .2s ease-out; max-width: min(420px, calc(100vw - 32px)); text-align: center; pointer-events: auto; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.toast.info { background: #16263d; border-color: #2f5585; color: var(--text); }
.tag.spec { background: #2f5585; color: #d6e6ff; }
.spec-note { font-size: 13px; color: #9cc4ff !important; }
.watchers { margin: 8px 0 0; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.toast.chat { background: #16263d; border-color: #2f5585; color: var(--text); cursor: pointer; }
.toast.chat b { margin-right: 4px; }
.tab.flash { animation: tabflash 1s ease-in-out 2; }
@keyframes tabflash { 50% { background: rgba(229,72,77,.3); } }
@keyframes pop2 { from { opacity: 0; transform: translateY(-12px); } }

@media (max-width: 900px) {
  #lobby, #room { height: auto; min-height: 100%; }
  .lobby-layout, .room-layout { grid-template-columns: 1fr; padding: 12px 16px; }
  .room-layout .chat-panel { height: 360px; }
  .map-tag { display: none; }
  .topbar { flex-wrap: wrap; }
  .layout { flex-direction: column; overflow-y: auto; }
  .map-wrap { flex: none; height: 62vw; min-height: 260px; padding: 4px; }
  .sidebar { width: 100%; border-left: none; overflow: visible; }
  .dice-panel { bottom: 4px; padding: 6px 10px; gap: 12px; }
  .die { font-size: 28px; }
  .topbar { padding: 8px 16px; gap: 10px; font-size: 13px; }
}

/* ---------- continents legend ---------- */
.cont-list { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.cont-list li { display: flex; align-items: center; gap: 7px; padding: 3px 4px; border-radius: 5px; cursor: default; }
.cont-list li:hover { background: var(--panel2); }
.cont-list .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.cont-list .cname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cont-list b { color: var(--accent2); font-size: 12px; }
.cont-list .dot { width: 11px; height: 11px; }
.cont-list li.held .cname { font-weight: 700; }
.cell.cont-hl { fill-opacity: .9; stroke: #fff; stroke-width: 2; }
