:root {
  --bg: #000;
  --fg: #e8e8e8;
  --dim: #7a7a7a;
  --line: #2c2c2c;
  --ready: #3ddc4a;
  --waiting: #e43b44;
  --font: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.4;
}

.hidden { display: none !important; }
.pixelated { image-rendering: pixelated; image-rendering: crisp-edges; }
.dim { color: var(--dim); }

h1 { font-size: 15px; font-weight: normal; margin: 0; letter-spacing: 1px; }

/* Flat, borderline-only controls */
.btn {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 4px 10px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--fg); }
.btn:disabled { opacity: 0.35; cursor: default; }
.btn:focus-visible { outline: 1px solid var(--fg); outline-offset: 1px; }
.btn.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn.primary:hover:not(:disabled) { background: #fff; }
.btn.ghost { border-color: transparent; color: var(--dim); }
.btn.ghost:hover:not(:disabled) { color: var(--fg); border-color: transparent; }

input {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 6px 8px;
  width: 100%;
  min-width: 0;
}
input:focus { outline: none; border-color: var(--fg); }

/* Home + lobby */
.screen { min-height: 100%; }
#screen-home, #screen-lobby { display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.card { width: min(340px, 100%); display: flex; flex-direction: column; gap: 10px; }
.card p { margin: 0; }
#title-art { width: 240px; max-width: 100%; height: auto; margin-bottom: 4px; }
.row { display: flex; gap: 8px; }
.row > .btn { flex: 1; }
.row input + .btn { flex: none; }
#join-code { text-transform: uppercase; letter-spacing: 4px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
select {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 4px 8px;
}
select:focus { outline: none; border-color: var(--fg); }
select:disabled { color: var(--dim); opacity: 1; }
.lobby-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.lobby-list li { display: flex; align-items: center; gap: 8px; }
.lobby-list .name { flex: 1; }
.lobby-list .btn { padding: 0 6px; }
.lobby-list .ai-version { padding: 0 4px; }
.swatch { width: 8px; height: 8px; flex: none; }

/* Top bar */
#screen-game { display: flex; flex-direction: column; height: 100%; }
#hud {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.res { display: flex; align-items: center; gap: 5px; }
.res canvas { width: 14px; height: 14px; }
.res b { font-weight: normal; }
.res small { color: var(--dim); font-size: 12px; }
.res small.neg { color: var(--waiting); }
#res-supply.full b { color: var(--waiting); }

#kingdoms { list-style: none; margin: 0; padding: 0; display: flex; gap: 14px; flex-wrap: wrap; }
#kingdoms li { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
#kingdoms li.me { text-decoration: underline; text-underline-offset: 3px; }
#kingdoms li.offline { opacity: 0.45; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--waiting); flex: none; }
.dot.ready { background: var(--ready); }
.dot.watching { background: transparent; border: 1px solid var(--dim); }

.turn-info { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.timer-bar { width: 140px; height: 8px; background: var(--bg); border: 1px solid var(--line); }
/* A white pixel checkerboard that drains as the turn runs out. */
#timer-fill {
  height: 100%;
  width: 100%;
  background-color: var(--bg);
  background-image: conic-gradient(#fff 25%, transparent 0 50%, #fff 0 75%, transparent 0);
  background-size: 4px 4px;
}
#timer { min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }

/* Map */
#map-wrap { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; }
#map { display: block; width: 100%; height: 100%; image-rendering: pixelated; cursor: pointer; }
.zoom-controls { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 4px; }
.zoom-controls .btn { width: 26px; height: 26px; padding: 0; }
#turn-banner {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  font-size: 16px; letter-spacing: 3px; pointer-events: none;
  animation: banner 1.4s steps(8) forwards;
}
@keyframes banner { 0% { opacity: 0; } 15% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }
#status-banner { position: absolute; left: 50%; top: 8px; transform: translateX(-50%); color: var(--dim); text-align: center; max-width: calc(100% - 32px); pointer-events: none; }
#status-banner.loud { color: var(--fg); letter-spacing: 2px; }

/* Floating action buttons: what the selected worker can build / castle can train */
#actions {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
}
.act {
  font: inherit;
  font-size: 11px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 3px 5px 2px;
  min-width: 38px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  cursor: pointer;
  position: relative;
}
.act .key { position: absolute; top: 0; left: 3px; font-size: 9px; color: var(--dim); }
.act canvas { width: 22px; height: 22px; image-rendering: pixelated; }
.act .glyph { height: 22px; line-height: 22px; font-size: 14px; }
.act:hover:not(:disabled) { border-color: var(--dim); }
.act.active { border-color: var(--fg); }
.act:disabled { opacity: 0.3; cursor: default; }

/* The choice popup: which unit on this hex, or what to attack (or move here)? */
#attack-menu {
  position: absolute;
  z-index: 5;
  background: var(--bg);
  border: 1px solid var(--fg);
  display: flex;
  flex-direction: column;
  min-width: 150px;
}
.menu-item {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 8px;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: #1c1c1c; outline: none; }
.menu-item canvas { width: 20px; height: 20px; image-rendering: pixelated; }

/* End-of-turn replay caption */
#replay-caption {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 4px 12px;
  white-space: nowrap;
  max-width: calc(100% - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.85); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal-card { position: relative; width: min(720px, 100%); max-height: 90vh; overflow-y: auto; background: var(--bg); border: 1px solid var(--line); padding: 18px; }
.modal-card.small { width: min(340px, 100%); display: flex; flex-direction: column; gap: 12px; }
.modal-card.small p { margin: 0; }
.modal-close { position: absolute; right: 10px; top: 10px; padding: 0 8px; }
.rules h2 { font-size: 13px; font-weight: normal; letter-spacing: 1px; margin: 18px 0 6px; color: var(--dim); text-transform: uppercase; }
.rules p { margin: 6px 0; }
.rules ul, .rules ol { padding-left: 18px; margin: 4px 0; }
.rules li { margin-bottom: 2px; }
.rules table { border-collapse: collapse; width: 100%; margin: 6px 0; font-size: 12px; }
.rules th, .rules td { border: 1px solid var(--line); padding: 3px 6px; text-align: left; vertical-align: middle; }
.rules th { color: var(--dim); font-weight: normal; }
.rules td canvas { width: 24px; height: 24px; image-rendering: pixelated; display: block; }
kbd { font: inherit; border: 1px solid var(--line); padding: 0 4px; }
#btn-resign { margin-top: 14px; }

#toast {
  position: fixed; left: 50%; bottom: 52px; transform: translateX(-50%);
  background: var(--bg); border: 1px solid var(--waiting);
  padding: 6px 12px; z-index: 20; max-width: 90vw; text-align: center;
}
#toast.info { border-color: var(--fg); }

@media (max-width: 700px) {
  #hud { gap: 10px; }
  .turn-info { margin-left: 0; flex: 1; }
  .timer-bar { flex: 1; width: auto; }
}
