:root {
  --bg: #0a0a16;
  --card: #14142a;
  --border: #3a3a6e;
  --text: #e8e6df;
  --muted: #9a97b8;
  --accent: #6c6ce5;
  --light-gold: #ffd75e;
  --dark-violet: #b48ce8;
  --green: #3fb950;
  --red: #f85149;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(1200px 700px at 50% -10%, #1b1b3d 0%, var(--bg) 60%);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 2px solid var(--border);
  flex-wrap: nowrap;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(10, 10, 22, .96);
}
.topbar .pregman-nav { flex: 1 1 auto; min-width: 0; }
@media (max-width: 1000px) { .topbar { flex-wrap: wrap; gap: 8px; } }
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 42px; height: 42px; border-radius: 8px;
  background: linear-gradient(135deg, #f5eeda 0 50%, #23232e 50% 100%);
  border: 2px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: #7a5c00; text-shadow: 1px 1px 0 #fff;
}
.brand h1 { margin: 0; font-size: 24px; letter-spacing: .12em; text-transform: uppercase; font-family: Georgia, "Times New Roman", serif; }
.tagline { margin: 0; color: var(--muted); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, auto) 290px;
  gap: 14px;
  padding: 16px;
  justify-content: center;
  align-items: start;
  flex: 1;
  width: 100%;
}
@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr; }
  .center-col { order: -1; margin: 0 auto; }
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.panel h2 { margin: 0 0 10px; font-size: 16px; letter-spacing: .04em; }
.panel h3 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.side-light { color: var(--light-gold); }
.side-dark { color: var(--dark-violet); }

/* army lists */
.army-list { display: flex; flex-direction: column; gap: 4px; }
.army-row {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  align-items: center;
  gap: 7px;
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 13px;
}
.army-row.here { cursor: pointer; }
.army-row.here:hover { border-color: var(--accent); background: #1d1d3d; }
.army-row.dead { opacity: .38; }
.army-row .glyph { width: 24px; height: 24px; }
.army-row .pname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.army-row .php { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hpbar { grid-column: 1 / -1; height: 5px; border-radius: 3px; background: #26263f; overflow: hidden; }
.hpbar > i { display: block; height: 100%; border-radius: 3px; }
.hp-light { background: linear-gradient(90deg, #d9a400, var(--light-gold)); }
.hp-dark { background: linear-gradient(90deg, #7b4bc4, var(--dark-violet)); }
.hp-low { background: var(--red) !important; }
.imprisoned-tag { font-size: 10px; color: #ffb3ae; border: 1px solid var(--red); border-radius: 4px; padding: 0 4px; margin-left: 5px; }
.dead-list { display: flex; flex-wrap: wrap; gap: 5px; min-height: 24px; }
.dead-chip {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px dashed #55557e; border-radius: 999px; padding: 2px 8px 2px 3px;
  font-size: 12px; color: var(--muted);
}
.dead-chip .glyph { width: 18px; height: 18px; }
.dead-chip button { background: var(--accent); color: #fff; border: 0; border-radius: 999px; font-size: 11px; padding: 1px 7px; cursor: pointer; }

/* center column */
.center-col { display: flex; flex-direction: column; gap: 12px; width: min(94vw, 620px); }
.controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.btn {
  background: #26265a; color: var(--text); border: 1px solid var(--accent);
  border-radius: 8px; padding: 8px 16px; font-size: 14px; font-weight: 700; cursor: pointer;
}
.btn:hover { background: #32327a; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #7d7df0; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.sound-off { opacity: .55; }
.mode-label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.mode-label select {
  background: #1b1b38; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font-size: 13px;
}
.turn-box { margin-left: auto; text-align: right; }
.turn-indicator { font-weight: 800; font-size: 16px; letter-spacing: .03em; }
.turn-indicator.light { color: var(--light-gold); }
.turn-indicator.dark { color: var(--dark-violet); }
.cycle-indicator { font-size: 12px; color: var(--muted); margin-top: 2px; }
.cycle-indicator .swatch { display: inline-block; width: 11px; height: 11px; border-radius: 3px; border: 1px solid #55557e; vertical-align: -1px; margin: 0 2px; }
.cycle-indicator .swatch.now { outline: 2px solid var(--light-gold); }

/* battle banner */
.battle-banner {
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 15px;
  font-weight: 600;
  border: 1px solid var(--light-gold);
  background: linear-gradient(90deg, #2c2410, #191932 55%, #241536);
  animation: bannerIn .25s ease-out;
}
.battle-banner .sub { display: block; font-weight: 400; font-size: 12.5px; color: var(--muted); margin-top: 3px; }
@keyframes bannerIn { from { transform: scale(.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* board */
.board-wrap { padding: 12px; }
.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 3px;
  aspect-ratio: 1 / 1;
  width: 100%;
}
.sq {
  position: relative;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(0,0,0,.45);
  min-height: 0;
  user-select: none;
}
.sq .coord { position: absolute; top: 1px; left: 3px; font-size: 8.5px; color: rgba(128,128,160,.85); pointer-events: none; }
.sq.pp::after {
  content: "★";
  position: absolute;
  right: 3px; top: 1px;
  font-size: 12px;
  color: #d9a400;
  text-shadow: 0 0 4px rgba(0,0,0,.6);
  pointer-events: none;
}
.sq.osc { box-shadow: inset 0 0 0 1.5px rgba(140,140,255,.35); }
.sq.move-target { cursor: pointer; }
.sq.move-target::before {
  content: ""; position: absolute; inset: 26%;
  border-radius: 50%; background: rgba(63,185,80,.55);
  border: 2px solid rgba(63,185,80,.95);
  pointer-events: none; z-index: 2;
}
.sq.capture-target::before {
  background: rgba(248,81,73,.4);
  border-color: rgba(248,81,73,.95);
  border-radius: 6px; inset: 6%;
}
.sq.spell-target { cursor: pointer; }
.sq.spell-target::before {
  content: ""; position: absolute; inset: 8%;
  border: 2px dashed #c792ea; border-radius: 6px; pointer-events: none; z-index: 2;
}
.sq.selected { outline: 3px solid var(--light-gold); outline-offset: -1px; z-index: 3; }
.piece {
  width: 86%; height: 86%;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  position: relative;
  z-index: 1;
}
.piece svg { width: 88%; height: 88%; display: block; filter: drop-shadow(0 1px 1px rgba(0,0,0,.55)); }
.piece.light { background: linear-gradient(160deg, #fdf6da, #e7d9a8); color: #4a3b12; border: 1.5px solid #8a6d1f; }
.piece.dark { background: linear-gradient(160deg, #3d3654, #1d1a2b); color: #d9c8ff; border: 1.5px solid #7a5fc0; }
.piece.mine { cursor: pointer; }
.piece.imprisoned { filter: grayscale(.55); }
.piece.imprisoned::after {
  content: ""; position: absolute; inset: 0; border-radius: 8px;
  background: repeating-linear-gradient(90deg, transparent 0 9px, rgba(10,10,10,.55) 9px 12px);
}
.piece .mini-hp {
  position: absolute; left: 8%; right: 8%; bottom: 3px; height: 4px;
  border-radius: 2px; background: rgba(0,0,0,.5); overflow: hidden;
}
.piece .mini-hp > i { display: block; height: 100%; }
.board-legend { font-size: 12px; color: var(--muted); margin-top: 9px; }

.info-bar { font-size: 13.5px; min-height: 44px; display: flex; align-items: center; }
.info-bar b { color: #fff; }

/* spells */
.spell-bar { border-color: #7a5fc0; }
.spell-head { font-weight: 700; margin-bottom: 8px; }
.spell-buttons { display: flex; flex-wrap: wrap; gap: 7px; }
.spell-btn {
  background: #241f42; color: #e6dcff; border: 1px solid #7a5fc0; border-radius: 999px;
  padding: 6px 13px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.spell-btn:hover:not(:disabled) { background: #372c66; }
.spell-btn:disabled { opacity: .38; cursor: default; text-decoration: line-through; }
.spell-btn.armed { background: #7a5fc0; color: #fff; }
.spell-prompt { margin-top: 8px; font-size: 13px; color: #e6dcff; min-height: 18px; }
.spell-prompt .cancel { margin-left: 10px; background: none; border: 1px solid var(--border); color: var(--muted); border-radius: 6px; padding: 2px 9px; cursor: pointer; }

/* log */
.log { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; max-height: 430px; overflow-y: auto; padding-right: 2px; }
.log div { border-left: 3px solid #3a3a6e; padding: 2px 0 2px 8px; color: #cfcbe8; }
.log div.battle { border-left-color: var(--light-gold); }
.log div.spell { border-left-color: #c792ea; }
.log div.system { border-left-color: var(--muted); color: var(--muted); }

/* how to */
.howto summary { cursor: pointer; font-weight: 700; }
.howto-body { font-size: 13.5px; line-height: 1.5; color: #d8d5ea; }
.howto-body p { margin: 8px 0; }

/* victory */
.victory {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 5, 14, .82);
  display: flex; align-items: center; justify-content: center;
}
.victory-box {
  background: var(--card); border: 2px solid var(--light-gold); border-radius: 14px;
  padding: 34px 44px; text-align: center; max-width: 440px;
  animation: bannerIn .3s ease-out;
}
.victory-glyph { font-size: 54px; }
.victory-box h2 { margin: 8px 0; font-size: 30px; letter-spacing: .05em; }
.victory-box p { color: var(--muted); }

footer { padding: 14px 24px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px; text-align: center; }
