*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a12;
  color: #c8c8e8;
  font-family: 'Courier New', Courier, monospace;
  -webkit-font-smoothing: antialiased;
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

#board-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

#grid-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#grid-canvas.dragging { cursor: grabbing; }
#grid-canvas.armed    { cursor: crosshair; }

/* ── HUD (top-left) ─────────────────────────────────────────────────────── */
#hud {
  position: absolute;
  top: 14px;
  left: 14px;
  pointer-events: none;
  user-select: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 55vw;
}

#epoch-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#player-avatar {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

#epoch-label {
  font-size: 10px;
  letter-spacing: 0.15em;
  color: #44446a;
  text-transform: uppercase;
}

#epoch-number {
  font-size: 24px;
  font-weight: bold;
  color: #7070cc;
}

#mode-label {
  font-size: 9px;
  letter-spacing: 0.12em;
  color: #2e2e4a;
}
#mode-label.live { color: #c9a227; }

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-dot.connected    { background: #44aa66; }
.status-dot.connecting   { background: #aa8833; }
.status-dot.disconnected { background: #663333; }
.status-dot.hidden       { display: none; }

#block-hash {
  font-size: 9px;
  color: #2e2e4a;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#countdown-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
#countdown-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: #333358;
}
#countdown-value {
  font-size: 14px;
  color: #55557a;
  min-width: 2.5ch;
}

#season-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 10px;
  color: #4a4a78;
  letter-spacing: 0.06em;
}

#season-crown { color: #c9a227; }

#account-pill {
  align-self: flex-start;
  font-size: 10px;
  letter-spacing: 0.05em;
  color: #7a7ab8;
  text-decoration: none;
  border: 1px solid #26264a;
  border-radius: 10px;
  padding: 2px 8px;
  pointer-events: auto;
}
a#account-pill:hover { color: #b8b8ff; border-color: #3d3d7a; }
#account-pill.linked { color: #4e9a6e; border-color: #1e3a2c; cursor: default; }

/* Reward mode: live prize pool (links to the public ledger) */
#pool-pill {
  align-self: flex-start;
  font-size: 10px;
  letter-spacing: 0.05em;
  color: #f7931a;
  text-decoration: none;
  border: 1px solid #4a3210;
  border-radius: 10px;
  padding: 2px 8px;
  pointer-events: auto;
}
#pool-pill:hover { border-color: #f7931a; }

/* ── Leaderboard (top-right) ────────────────────────────────────────────── */
#leaderboard {
  position: absolute;
  top: 14px;
  right: 14px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  user-select: none;
  pointer-events: none;
  font-size: 12px;
}

#leaderboard li {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(14, 14, 28, 0.82);
  border: 1px solid #1a1a32;
  border-radius: 6px;
  padding: 3px 8px;
}

#leaderboard li.me { border-color: #3a3a70; }

.lb-swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex-shrink: 0;
}

.lb-ready { font-size: 10px; }

.lb-you {
  font-size: 9px;
  letter-spacing: 0.08em;
  color: #7a7ad0;
  text-transform: uppercase;
}

/* ── Event banner (top-center) ──────────────────────────────────────────── */
#event-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translate(-50%, -12px);
  background: rgba(18, 18, 38, 0.94);
  border: 1px solid #2c2c55;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  pointer-events: none;
  user-select: none;
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
  max-width: 90vw;
  text-align: center;
  z-index: 5;
}
#event-banner.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

#sync-status {
  position: absolute;
  top: 52px;
  left: 14px;
  pointer-events: none;
  user-select: none;
  font-size: 10px;
  color: #44664a;
  opacity: 0;
  transition: opacity 0.5s ease;
  z-index: 4;
}

/* ── Zoom / coords / selection ──────────────────────────────────────────── */
#zoom-controls {
  position: absolute;
  right: 12px;
  bottom: 44px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#zoom-controls button {
  width: 32px;
  height: 32px;
  border: 1px solid #26264a;
  border-radius: 8px;
  background: rgba(16, 16, 32, 0.9);
  color: #8888c8;
  font-size: 16px;
  cursor: pointer;
}
#zoom-controls button:active { background: #1c1c3a; }

#coords-display {
  position: absolute;
  bottom: 12px;
  right: 12px;
  pointer-events: none;
  user-select: none;
  font-size: 10px;
  color: #2e2e4a;
}

#selection-display {
  position: absolute;
  bottom: 12px;
  left: 12px;
  pointer-events: none;
  user-select: none;
  font-size: 12px;
  color: #6a6ab0;
}

/* ── Turn bar (bottom) ──────────────────────────────────────────────────── */
#turnbar {
  flex-shrink: 0;
  background: #0d0d1c;
  border-top: 1px solid #1c1c38;
  padding: 8px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-height: 56px;
}

#dice-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.die {
  width: 44px;
  height: 44px;
  font-size: 34px;
  line-height: 1;
  color: #c8c8e8;
  background: #14142a;
  border: 2px solid #26264a;
  border-radius: 9px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  padding: 0;
}
.die:not(:disabled):hover { transform: translateY(-2px); }
.die.locked {
  border-color: #c9a227;
  background: #1c1a10;
  box-shadow: 0 0 0 1px #c9a22744;
}
.die.one { color: #ffd76a; }
/* Committed = locked through a reroll → frozen for the turn, can't be unlocked. */
.die.committed { cursor: not-allowed; border-color: #c9a227; }
.die.committed::after {
  content: '🔒';
  position: absolute;
  top: -6px; right: -6px;
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
}
.die { position: relative; }
.die:disabled { cursor: default; opacity: 0.85; }

#turnbar button:not(.die) {
  border: 1px solid #2c2c55;
  border-radius: 8px;
  background: #16162e;
  color: #b8b8e0;
  font-family: inherit;
  font-size: 12px;
  padding: 9px 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
#turnbar button:not(.die):hover:not(:disabled) { background: #1e1e40; }
#turnbar button:not(.die):disabled { opacity: 0.45; cursor: default; }

#confirm-btn {
  border-color: #2f5a3a !important;
  background: #12281a !important;
  color: #9fd8ae !important;
}
#confirm-btn:hover:not(:disabled) { background: #17351f !important; }

#ability-btn.armed {
  border-color: #c9a227 !important;
  background: #241f0e !important;
  color: #ffd76a !important;
}

.chip {
  background: #14142a;
  border: 1px solid #26264a;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  white-space: nowrap;
}

#ap-chip { color: #ffd76a; }
#ap-chip.empty { color: #7a6a3a; }

#turn-hint {
  font-size: 11px;
  color: #55557e;
  flex: 1;
  min-width: 140px;
}

#log-btn { margin-left: auto; }

/* Phase-dependent visibility hints */
body[data-phase="idle"] #dice-row .die { opacity: 0.3; }

/* ── Help modal ─────────────────────────────────────────────────────────── */
#help-modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 12, 0.78);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}
#help-modal.show { display: flex; }

#help-card {
  background: #10101f;
  border: 1px solid #26264a;
  border-radius: 12px;
  max-width: 560px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  padding: 20px 22px;
  font-size: 13px;
  line-height: 1.55;
}

#help-card h2 {
  font-size: 16px;
  color: #9a9aff;
  margin-bottom: 10px;
}

#help-card h3 {
  font-size: 12px;
  color: #7070cc;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 14px 0 6px;
}

#help-card table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
#help-card td {
  padding: 3px 6px 3px 0;
  vertical-align: top;
  border-bottom: 1px solid #191932;
}
#help-card td:first-child { white-space: nowrap; color: #d8d8f4; }

#help-close {
  margin-top: 14px;
  width: 100%;
  border: 1px solid #2c2c55;
  border-radius: 8px;
  background: #16162e;
  color: #b8b8e0;
  font-family: inherit;
  font-size: 13px;
  padding: 9px;
  cursor: pointer;
}

/* ── History ("what happened?") modal ───────────────────────────────────── */
#log-modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 12, 0.78);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}
#log-modal.show { display: flex; }

#log-card {
  background: #10101f;
  border: 1px solid #26264a;
  border-radius: 12px;
  max-width: 460px;
  width: 100%;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  padding: 18px 20px;
}
#log-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
#log-head h2 { font-size: 16px; color: #9a9aff; margin: 0; flex: 1; }
#log-replay {
  border: 1px solid #3a3a72;
  border-radius: 8px;
  background: #1c1c3a;
  color: #c8c8ff;
  font-family: inherit;
  font-size: 12px;
  padding: 6px 10px;
  cursor: pointer;
  white-space: nowrap;
}
#log-replay:hover { background: #26264a; }
#log-intro { font-size: 12px; color: #8a8ab0; margin: 0 0 10px; }

#log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}
.log-item {
  padding: 7px 2px;
  border-bottom: 1px solid #191932;
}
.log-line-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  color: #d8d8f4;
}
.log-epoch { margin-left: auto; font-size: 11px; color: #6a6a99; white-space: nowrap; }
.log-line-detail { font-size: 12px; color: #9a9ac0; margin-top: 2px; }
.log-line-detail.mine { color: #d8d8f4; }
.log-empty { padding: 18px 2px; text-align: center; color: #6a6a99; font-size: 13px; }

#log-close {
  margin-top: 12px;
  border: 1px solid #2c2c55;
  border-radius: 8px;
  background: #16162e;
  color: #b8b8e0;
  font-family: inherit;
  font-size: 13px;
  padding: 9px;
  cursor: pointer;
}

/* ── Offline overlay ────────────────────────────────────────────────────── */
#offline-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 12, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 30;
  font-size: 14px;
  color: #a0a0d0;
  text-align: center;
  padding: 20px;
}
#offline-overlay.show { display: flex; }

/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #hud { max-width: 46vw; }
  #block-hash { max-width: 44vw; }
  #leaderboard { font-size: 11px; max-width: 44vw; }

  #turnbar {
    padding: 6px 8px;
    gap: 6px;
  }
  .die {
    width: 40px;
    height: 40px;
    font-size: 30px;
  }
  #turnbar button:not(.die) {
    font-size: 11px;
    padding: 8px 10px;
  }
  #ability-btn {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #turn-hint { flex-basis: 100%; order: 10; min-width: 0; }
}

/* ── Season replay player ─────────────────────────────────────────────────── */
body.hg-replay #game-root {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

#rp-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9a9aff;
  font-size: 15px;
  pointer-events: none;
}

#hud #rp-epoch { font-size: 14px; font-weight: 700; }
#hud #rp-event { font-size: 12px; color: #9a9add; margin-top: 2px; }
#hud #rp-back {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  color: #7a7ab0;
  text-decoration: none;
}
#hud #rp-back:hover { color: #9a9aff; }

#rp-leaderboard {
  position: absolute;
  top: 14px;
  right: 14px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  user-select: none;
  font-size: 12px;
  max-width: 44vw;
}
#rp-leaderboard li {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(14, 14, 28, 0.82);
  border: 1px solid #1a1a32;
  border-radius: 6px;
  padding: 3px 8px;
}
#rp-leaderboard .rp-rank { width: 16px; text-align: center; flex-shrink: 0; }
#rp-leaderboard .rp-swatch { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
#rp-leaderboard .rp-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#rp-leaderboard .rp-cells { margin-left: auto; opacity: .8; }

#rp-banner {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: rgba(20, 16, 6, 0.92);
  border: 1px solid #f7931a;
  color: #ffd591;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  max-width: 92vw;
}

#rp-transport {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #0e0e1c;
  border-top: 1px solid #1a1a32;
  flex-wrap: wrap;
}
#rp-transport button {
  background: #1a1a30;
  border: 1px solid #2a2a48;
  color: #c8c8e8;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 15px;
  cursor: pointer;
}
#rp-transport button:hover { border-color: #9a9aff; }
#rp-slider { flex: 1; min-width: 140px; accent-color: #9a9aff; }
#rp-pos { font-size: 12px; color: #9a9add; min-width: 62px; text-align: center; }
#rp-speed-wrap { font-size: 12px; color: #9a9add; display: flex; align-items: center; gap: 5px; }
#rp-speed { background: #1a1a30; border: 1px solid #2a2a48; color: #c8c8e8; border-radius: 5px; padding: 3px 6px; }
