:root {
  --ink: #050505;
  --muted: #384b56;
  --paper: #fff7df;
  --panel: #fffdf2;
  --line: #050505;
  --sea: #aee6ef;
  --bird: #ffdd16;
  --cat: #a92de1;
  --reptile: #08bd19;
  --dog: #ff7615;
  --bear: #c25a00;
  --sock: #f06ee7;
  --active: #00a7bb;
  --danger: #e6002e;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family:
    Arial Rounded MT Bold, Arial, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(rgba(174, 230, 239, 0.76), rgba(255, 247, 223, 0.84)),
    url("assets/hero-circles.png") center / cover fixed;
}

body.playing {
  background:
    linear-gradient(rgba(174, 230, 239, 0.8), rgba(255, 247, 223, 0.86)),
    url("assets/hero-circles.png") center / cover fixed;
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  box-shadow: 4px 5px 0 var(--ink);
  cursor: pointer;
  transition:
    transform 120ms ease,
    background 120ms ease;
}

button:hover:not(:disabled) {
  background: #ffdd16;
}

button:active:not(:disabled) {
  box-shadow: 2px 3px 0 var(--ink);
  transform: translate(2px, 2px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.tip {
  position: relative;
}

.tip::after {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  z-index: 20;
  width: min(260px, 76vw);
  padding: 8px 10px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  color: var(--ink);
  text-align: left;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.25;
  background: #ffdd16;
  box-shadow: 4px 5px 0 var(--ink);
  content: attr(data-tip);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition:
    opacity 120ms ease,
    transform 120ms ease;
}

.tip:not(:disabled):hover::after,
.tip:not(:disabled):focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.primary {
  width: 100%;
  color: var(--ink);
  background: #08bd19;
}

.primary:hover:not(:disabled) {
  background: #ffdd16;
}

.quiet {
  width: 100%;
  margin-top: 8px;
  background: #fff;
}

.game-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

body:not(.playing) .game-shell {
  grid-template-columns: minmax(0, 720px);
  align-content: start;
  justify-content: center;
  padding: clamp(16px, 4vw, 42px);
}

body:not(.playing) .board-panel {
  min-height: 0;
}

body:not(.playing) .board-wrap,
body:not(.playing) .turn-badge {
  display: none;
}

body:not(.playing) .side-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

body:not(.playing) .setup-card {
  order: 1;
}

body:not(.playing) .guide-card {
  order: 2;
}

body:not(.playing) .side-panel > section:not(.setup-card):not(.guide-card),
body.playing .setup-card,
body.playing .guide-card {
  display: none;
}

.board-panel,
.side-panel > section {
  border: 4px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 253, 242, 0.94);
  box-shadow: 8px 10px 0 rgba(5, 5, 5, 0.92);
}

.board-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background:
    linear-gradient(rgba(255, 253, 242, 0.78), rgba(255, 253, 242, 0.88)),
    url("assets/coffee-can-alley-map.jpg") center / cover;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 12px;
}

.eyebrow {
  margin: 0 0 2px;
  color: #006472;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 4.2rem);
  line-height: 0.95;
  text-shadow: 3px 3px 0 #fff, 5px 5px 0 rgba(5, 5, 5, 0.16);
}

h2 {
  margin-bottom: 12px;
  font-size: 1rem;
  font-weight: 900;
}

.turn-badge {
  min-width: 150px;
  padding: 10px 12px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  text-align: center;
  font-weight: 800;
  background: #fff;
  box-shadow: 4px 5px 0 var(--ink);
}

.board-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 8px 16px 16px;
}

.map {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: min(76vh, 760px);
  min-height: 520px;
  border: 4px solid var(--ink);
  border-radius: 6px;
  background: var(--sea);
  box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.72);
}

.sea {
  fill: var(--sea);
}

.route {
  fill: none;
  stroke: rgba(5, 5, 5, 0.3);
  stroke-dasharray: 9 13;
  stroke-linecap: round;
  stroke-width: 7;
}

.territory {
  stroke: var(--ink);
  stroke-linejoin: round;
  stroke-width: 5;
  cursor: pointer;
  filter: drop-shadow(7px 8px 0 rgba(5, 5, 5, 0.18));
  transition:
    filter 140ms ease,
    opacity 140ms ease,
    stroke-width 140ms ease;
}

.territory:hover {
  filter: drop-shadow(8px 9px 0 rgba(5, 5, 5, 0.28));
}

.territory.selected {
  stroke: #fff;
  stroke-width: 8;
}

.territory.can-attack {
  stroke: var(--danger);
  stroke-width: 8;
}

.territory.defeated {
  opacity: 0.35;
}

.label-card {
  pointer-events: none;
}

.label-bg {
  fill: rgba(255, 253, 242, 0.94);
  stroke: var(--ink);
  stroke-width: 2;
}

.label-name {
  fill: var(--ink);
  font-size: 14px;
  font-weight: 900;
  text-anchor: middle;
}

.label-meta {
  fill: #2c3c44;
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
}

.peg {
  fill: #fbfbf5;
  stroke: var(--ink);
  stroke-width: 3;
}

.peg-count {
  fill: #111;
  font-size: 20px;
  font-weight: 900;
  text-anchor: middle;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.side-panel > section {
  padding: 14px;
}

.player-config {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 800;
}

input[type="text"],
input:not([type]) {
  width: 100%;
  min-height: 40px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
}

.ai-row {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.ai-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

.phase-row,
.selected-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
  font-weight: 900;
}

.instruction {
  min-height: 44px;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.35;
}

.guide-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 20px;
  color: var(--ink);
  font-size: 0.88rem;
  line-height: 1.3;
}

.guide-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.3;
}

.dispatch-card {
  background: #ffed8a !important;
  border-color: var(--ink);
}

.dispatch-card[hidden] {
  display: none !important;
}

.dispatch-text {
  margin: 0 0 12px;
  padding: 14px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  background: #fffdf2;
  box-shadow: 4px 5px 0 rgba(5, 5, 5, 0.55);
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.35;
  white-space: pre-wrap;
}

.dispatch-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.dispatch-text--spoken {
  font-size: 1.1rem;
  line-height: 1.55;
  letter-spacing: 0.01em;
}

.dispatch-actions button[hidden] {
  display: none;
}

.dispatch-status {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
}

.recap-copy {
  min-height: 62px;
  padding: 12px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 900;
  line-height: 1.28;
  background: #ffed8a;
  box-shadow: 4px 5px 0 rgba(5, 5, 5, 0.55);
}

.dice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 32px;
  margin-top: 10px;
}

.die {
  min-width: 34px;
  padding: 5px 7px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  text-align: center;
  font-weight: 900;
  background: #ffdd16;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

#quickMoveBtn {
  grid-column: 1 / -1;
}

.scoreboard {
  display: grid;
  gap: 8px;
}

.score-row {
  display: grid;
  grid-template-columns: 12px 1fr;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  background: #fff;
}

.score-row.active {
  border-color: var(--active);
  box-shadow: 4px 5px 0 var(--ink);
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--ink);
}

.score-name {
  min-width: 0;
  overflow: hidden;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-stat {
  grid-column: 2;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.lore-copy {
  display: grid;
  gap: 4px;
  color: #35423e;
  font-size: 0.9rem;
  line-height: 1.35;
}

.lore-copy strong {
  color: var(--ink);
  font-size: 1.05rem;
}

.lore-copy span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
  text-transform: uppercase;
}

.lore-copy p {
  margin: 4px 0 0;
}

.map-link {
  display: inline-flex;
  margin-top: 10px;
  color: #007c8f;
  font-weight: 900;
  text-decoration: none;
}

.map-link:hover {
  text-decoration: underline;
}

.log-card {
  flex: 1;
  min-height: 180px;
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 180px;
  margin: 0;
  padding-left: 20px;
  overflow: auto;
  color: #35423e;
  font-size: 0.86rem;
  line-height: 1.3;
}

@media (max-width: 980px) {
  .game-shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .map {
    height: auto;
    min-height: 0;
    aspect-ratio: 1000 / 680;
  }

  .side-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .log-card {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  body {
    background: #e4f0ed;
  }

  .tip::after {
    display: none;
  }

  .game-shell {
    gap: 8px;
    padding: 0;
  }

  body:not(.playing) .game-shell {
    gap: 10px;
    padding: 10px;
  }

  body:not(.playing) .board-panel,
  body:not(.playing) .side-panel > section {
    border: 4px solid var(--ink);
    border-radius: 6px;
    box-shadow: 6px 7px 0 var(--ink);
  }

  body:not(.playing) .side-panel {
    padding-bottom: 0;
  }

  .board-panel,
  .side-panel > section {
    border-radius: 0;
    box-shadow: none;
  }

  .board-panel {
    border-width: 0 0 1px;
  }

  .topbar,
  .phase-row,
  .selected-row {
    align-items: center;
    flex-direction: row;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 4;
    padding: 10px 12px;
    background: rgba(255, 250, 240, 0.94);
    backdrop-filter: blur(10px);
  }

  .eyebrow {
    display: none;
  }

  h1 {
    font-size: 2rem;
  }

  .turn-badge {
    min-width: 118px;
    padding: 8px 10px;
  }

  .board-wrap {
    padding: 0;
  }

  .map {
    width: 100vw;
    border-width: 1px 0;
    border-radius: 0;
  }

  .side-panel {
    grid-template-columns: 1fr;
    gap: 8px;
    padding-bottom: 106px;
  }

  .setup-card {
    order: 5;
  }

  .status-card {
    order: 1;
  }

  .recap-card {
    order: 2;
  }

  .actions-card {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 5;
    order: 0;
    border-width: 1px 0 0;
    background: rgba(255, 250, 240, 0.96);
    backdrop-filter: blur(12px);
  }

  .score-card {
    order: 3;
  }

  .lore-card {
    order: 4;
  }

  .guide-card {
    order: 5;
  }

  .log-card {
    order: 6;
  }

  .button-grid {
    grid-template-columns: 1.4fr 1fr 1fr;
  }

  #resetBtn {
    display: none;
  }

  .actions-card h2,
  .selected-row span,
  .setup-card h2,
  .log-card h2 {
    display: none;
  }

  .label-name {
    font-size: 20px;
  }

  .score-row {
    grid-template-columns: 12px 1fr;
  }

  .score-stat {
    grid-column: 2;
  }
}
