:root {
  --bg: #0e1726;
  --sea: #15263f;
  --card: #1b2940;
  --accent: #3a78e6;
  --text: #e8eef7;
  --muted: #93a4bd;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

.screen { position: absolute; inset: 0; }
.hidden { display: none !important; }

/* ---- Menu / lobby cards ---- */
#menu, #lobby {
  display: flex;
  align-items: center;
  justify-content: center;
}

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 28px;
  width: min(420px, 92vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

h1 { margin: 0 0 18px; font-size: 34px; }
h1 span { color: var(--accent); }
h2 { margin: 0 0 8px; }

label { display: block; margin: 10px 0; color: var(--muted); font-size: 14px; }

input {
  width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid #2c3d5c;
  background: #11192a;
  color: var(--text);
  font-size: 16px;
}

.row { display: flex; gap: 10px; margin-top: 12px; align-items: stretch; }
.row input { margin: 0; }
.row #joinCode { flex: 1; text-align: center; letter-spacing: 4px; font-size: 20px; }

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  background: #2c3d5c;
  color: var(--text);
  transition: transform 0.05s, background 0.15s;
}
button:hover { background: #36496b; }
button:active { transform: scale(0.97); }
button.primary { background: var(--accent); width: 100%; }
button.primary:hover { background: #4c87f0; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.userbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px; font-size: 13px; color: var(--muted);
}
.userbar b { color: var(--text); }
button.ghost {
  background: transparent; border: 1px solid #36496b; color: var(--muted);
  padding: 6px 12px; font-size: 13px;
}
button.ghost:hover { background: #1f2c44; }

.settings-box {
  border: 1px solid #2c3d5c; border-radius: 10px; padding: 10px 14px; margin: 14px 0;
}
.settings-box legend { color: var(--muted); font-size: 13px; padding: 0 6px; }
.settings-box label { display: flex; justify-content: space-between; align-items: center; }
.settings-box input { width: 90px; margin: 0; }
.settings-box input:disabled { opacity: 0.5; }

.divider { text-align: center; color: var(--muted); margin: 18px 0 4px; }
.settings { margin-top: 18px; color: var(--muted); }
.settings summary { cursor: pointer; }
.error { color: #ff6b6b; min-height: 18px; margin: 12px 0 0; }
.hint { color: var(--muted); font-size: 13px; }
.code { color: var(--accent); letter-spacing: 4px; }

#playerList { list-style: none; padding: 0; margin: 16px 0; }
#playerList li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; background: #11192a; margin-bottom: 6px;
}
.swatch { width: 18px; height: 18px; border-radius: 50%; display: inline-block; }
.dot-off { opacity: 0.4; }

/* ---- Game ---- */
#board { display: block; width: 100vw; height: 100vh; background: var(--sea); touch-action: none; }

#topbar {
  position: absolute; top: 10px; left: 10px; right: 10px;
  display: flex; gap: 8px; pointer-events: none;
}
.tag {
  background: rgba(13, 20, 34, 0.85);
  padding: 8px 14px; border-radius: 20px; font-size: 14px; font-weight: 600;
  backdrop-filter: blur(4px);
}

#panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(13, 20, 34, 0.92);
  backdrop-filter: blur(6px);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
}
.prov-info { font-size: 14px; color: var(--muted); min-height: 18px; }
.prov-info b { color: var(--text); }
.buttons { display: grid; grid-template-columns: repeat(auto-fit, minmax(58px, 1fr)); gap: 6px; }
.buy { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 2px; font-size: 12px; }
.buy small { color: #ffd866; font-weight: 700; font-size: 11px; }
.buy.active { background: var(--accent); }
.endturn { background: #2e7d46; flex: 1; }
.endturn:hover { background: #379a55; }
.endturn.ready { background: #e6b73a; color: #1b2940; }
.undo { background: #5a3a78; }
.undo:hover { background: #6c4690; }
.undo:disabled { opacity: 0.4; }
.action-row { display: flex; gap: 8px; }
.hand { font-size: 14px; color: #ffd866; text-align: center; }

.tagbtn { cursor: pointer; pointer-events: auto; background: rgba(160, 50, 40, 0.85); }
.tagbtn:hover { background: rgba(200, 60, 50, 0.95); }
#timerTag.warn { background: rgba(200, 60, 50, 0.9); }

.info { background: rgba(40, 90, 160, 0.85); }
.info:hover { background: rgba(50, 110, 190, 0.95); }
.chatbtn { background: rgba(60, 120, 90, 0.85); }
.chatbtn:hover { background: rgba(70, 140, 105, 0.95); }
.chatbtn.unread { background: #e6b73a; color: #1b2940; }

/* ---- kill-feed (spell / landing announcements) ---- */
.killfeed {
  position: absolute; top: 54px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none; z-index: 18; width: max-content; max-width: 92vw;
}
.kf-line {
  background: rgba(13, 20, 34, 0.92);
  border: 1px solid #2c3d5c; border-radius: 18px;
  padding: 7px 16px; font-size: 14px; font-weight: 600;
  white-space: nowrap; backdrop-filter: blur(4px);
  opacity: 0; transform: translateY(-8px) scale(0.96);
  transition: opacity 0.3s, transform 0.3s;
}
.kf-line.show { opacity: 1; transform: translateY(0) scale(1); }
.kf-arrow { color: #ff7b2a; margin: 0 4px; font-weight: 800; }

/* ---- in-game chat ---- */
.chat {
  position: absolute; left: 10px; bottom: 200px;
  width: min(320px, 70vw);
  background: rgba(13, 20, 34, 0.92);
  border: 1px solid #2c3d5c; border-radius: 12px;
  display: flex; flex-direction: column; overflow: hidden;
  backdrop-filter: blur(6px); z-index: 15;
}
.chat.collapsed { display: none; }
.chat-log {
  max-height: 34vh; min-height: 80px; overflow-y: auto;
  padding: 8px 10px; font-size: 13px; line-height: 1.4;
  display: flex; flex-direction: column; gap: 3px;
}
.chat-line { word-wrap: break-word; }
.chat-line.system { color: var(--muted); font-style: italic; font-size: 12px; }
.chat-input-row { display: flex; gap: 6px; padding: 8px; border-top: 1px solid #2c3d5c; }
.chat-input-row input { margin: 0; flex: 1; font-size: 14px; padding: 8px 10px; }
.chat-input-row button { padding: 8px 14px; background: var(--accent); }
.chat-input-row button:hover { background: #4c87f0; }

/* picker popup (opens upward, above the panel) */
.popup-menu {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  background: #11192a; border: 1px solid #2c3d5c; border-radius: 10px;
  padding: 8px; margin-bottom: 4px; max-height: 46vh; overflow-y: auto;
}
.popup-menu .full { grid-column: 1 / -1; font-size: 11px; color: var(--muted); padding: 0 4px 4px; }
.unit-opt {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-radius: 8px; background: #1b2940; cursor: pointer; font-size: 13px;
}
.unit-opt:hover { background: #26344f; }
.unit-opt[disabled] { opacity: 0.4; cursor: not-allowed; }
.unit-opt canvas { width: 30px; height: 30px; flex: none; }
.unit-opt .price { margin-left: auto; color: #ffd866; font-weight: 700; }
.unit-opt .nm { display: flex; flex-direction: column; }
.unit-opt .nm small { color: var(--muted); font-size: 10px; line-height: 1.1; }

/* bestiary */
#bestiary .card { width: min(560px, 94vw); max-height: 86vh; overflow-y: auto; text-align: left; }
#bestiary h3 { margin: 14px 0 6px; color: var(--accent); }
.bestiary-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px; border-radius: 8px; background: #11192a; margin-bottom: 6px; }
.bestiary-item canvas { width: 40px; height: 40px; flex: none; }
.bestiary-item .b-title { font-weight: 700; }
.bestiary-item .b-title .price { color: #ffd866; font-weight: 700; margin-left: 6px; font-size: 13px; }
.bestiary-item .b-desc { color: var(--muted); font-size: 13px; margin-top: 2px; }
.settings-box label select { background: #11192a; color: var(--text); border: 1px solid #2c3d5c; border-radius: 8px; padding: 6px; }
.settings input[type=checkbox], .settings-box input[type=checkbox] { width: auto; }
.settings select { background: #11192a; color: var(--text); border: 1px solid #2c3d5c; border-radius: 8px; padding: 6px; }

.toast {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%);
  background: rgba(230, 71, 58, 0.95); padding: 10px 18px; border-radius: 10px;
  font-weight: 600; z-index: 20;
}
.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(8, 12, 20, 0.8); z-index: 30; text-align: center;
}
.overlay .card { width: min(360px, 90vw); }
