:root {
  --ink: #06141b;
  --panel: #166982;
  --panel-dark: #104e63;
  --line: #06141b;
  --cream: #f3eee2;
  --gold: #f6c64a;
  --wet: #b60000;
  --dry: #006fb3;
  --green: #00b85c;
  --muted: #d8e3e8;
  --road: rgba(34, 43, 47, .68);
  --dev: rgba(255,255,255,.12);
  --grass: rgba(38,126,28,.16);
}
* { box-sizing: border-box; }

/* Ensure the settings / card modal stays hidden until JavaScript opens it. */
[hidden], .modal[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; background: #eef2f3; color: var(--ink); font-family: Arial, Helvetica, sans-serif; }
button, select, input { font: inherit; }
.screen { display: none; }
.screen.active { display: block; }

.load-card {
  max-width: 920px;
  margin: 36px auto;
  background: #fff;
  border: 4px solid var(--line);
  box-shadow: 10px 10px 0 rgba(0,0,0,.16);
  padding: 28px;
}
.brand-block h1, .title-box h1 { margin: 0; font-size: 34px; line-height: .95; letter-spacing: -.04em; }
.brand-block p, .title-box p { margin: 6px 0 0; font-weight: 700; letter-spacing: -.02em; }
.load-card h2 { margin: 24px 0 6px; }
.muted { color: #50626a; }
.player-setup { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 12px; margin: 22px 0; }
.setup-slot { border: 2px solid var(--line); background: #f7fafb; padding: 12px; }
.setup-slot label { display: grid; gap: 8px; font-weight: 700; }
.setup-slot select { width: 100%; border: 2px solid var(--line); padding: 8px; background: #fff; }
.check-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.load-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 22px; }
.btn { cursor: pointer; border: 3px solid var(--line); border-radius: 12px; padding: 12px 18px; font-weight: 800; color: #fff; background: var(--green); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.btn:hover { transform: translateY(-1px); }
.btn:disabled { cursor: not-allowed; opacity: .45; transform: none; }
.btn.primary { background: var(--green); }
.btn.secondary { background: var(--panel); }

.game-shell.active {
  display: grid;
  grid-template-columns: 240px minmax(760px, 1fr) 230px;
  gap: 14px;
  min-height: 100vh;
  padding: 10px 12px;
}
.left-rail { display: flex; flex-direction: column; gap: 12px; }
.title-box { text-align: center; padding: 12px 0 6px; }
.title-box h1 { font-size: 31px; }
.small-label { font-size: 10px; font-weight: 800; margin: 0 0 6px 4px; }
.player-badges { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.player-badge {
  border: 3px solid var(--line);
  background: #77828a;
  color: #fff;
  font-size: 21px;
  font-weight: 900;
  height: 34px;
  display: grid;
  place-items: center;
  position: relative;
}
.player-badge.dry { background: var(--dry); }
.player-badge.wet { background: var(--wet); }
.player-badge.inactive { background: #7a7a7a; opacity: .45; }
.player-badge.active-turn { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(246,198,74,.55); }
.player-badge.computer::after { content: "CPU"; position: absolute; bottom: -14px; left: 50%; transform: translateX(-50%); color: var(--ink); font-size: 8px; font-weight: 900; }
.money-display {
  min-height: 59px;
  border: 3px solid var(--line);
  background: var(--panel);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 31px;
  letter-spacing: .02em;
}
.dice-row { display: grid; grid-template-columns: 72px 1fr; gap: 8px; }
.dice-face {
  height: 74px;
  border: 3px solid var(--line);
  background: var(--panel);
  color: #fff;
  display: grid;
  place-items: center;
  text-align: center;
  font-weight: 900;
  font-size: 14px;
}
.dice-face.rolled { font-size: 48px; line-height: 1; background: #fff; color: var(--ink); }
.roll-btn {
  border: 3px solid var(--line);
  border-radius: 12px;
  background: var(--green);
  color: #fff;
  font-weight: 900;
  font-size: 18px;
}
.roll-btn:disabled { opacity: .45; }
.active-card-panel { flex: 1; min-height: 300px; border: 3px solid var(--line); background: var(--panel); padding: 10px; display: grid; }
.active-character-card.placeholder { display: grid; place-items: center; color: #fff; font-size: 29px; text-align: center; line-height: 1.2; }
.active-character-card img { width: 100%; height: 100%; object-fit: contain; display: block; }

.right-area { display: grid; grid-template-rows: minmax(390px, 1fr) 178px; gap: 12px; min-width: 0; }
.board-panel { border: 3px solid var(--line); background: var(--panel); padding: 8px; display: grid; min-height: 0; }
.board-wrap { position: relative; width: 100%; max-height: 100%; aspect-ratio: 1672 / 941; display: grid; place-items: center; overflow: hidden; background: #0d2229; }
.board-wrap img { width: 100%; height: 100%; object-fit: fill; user-select: none; pointer-events: none; }
.piece-layer, .grid-overlay { position: absolute; inset: 0; margin: auto; pointer-events: none; }
.grid-overlay { display: grid; grid-template-columns: repeat(27, 1fr); grid-template-rows: repeat(15, 1fr); opacity: .0; }
.grid-cell { border: 1px solid rgba(255,255,255,.14); }
.grid-cell.road { background: var(--road); }
.grid-cell.dev { background: var(--dev); }
.grid-cell.grass { background: var(--grass); }
.grid-cell.start { background: rgba(255, 198, 74, .32); }
.highlight { position: absolute; border: 3px solid var(--gold); background: rgba(246,198,74,.22); border-radius: 8px; pointer-events: auto; cursor: pointer; }
.highlight.invalid { border-color: #f34f4f; background: rgba(243,79,79,.18); }
.token {
  position: absolute;
  width: min(30px, 2.1vw);
  height: min(30px, 2.1vw);
  border: 3px solid #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1px 2px #000;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 6px rgba(0,0,0,.55);
  pointer-events: none;
  z-index: 30;
}
.token.dry { background: var(--dry); }
.token.wet { background: var(--wet); }
.token.arrested { opacity: .25; filter: grayscale(1); }
.placed-building {
  position: absolute;
  z-index: 20;
  border: 2px solid rgba(8,16,21,.95);
  border-radius: 6px;
  background: linear-gradient(135deg, #a88d5c 0%, #5d4a30 100%);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.14), 0 5px 10px rgba(0,0,0,.45);
  overflow: hidden;
  pointer-events: none;
}
.placed-building::before {
  content: "";
  position: absolute;
  inset: 7%;
  border: 2px solid rgba(255,255,255,.34);
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,.18) 0 4px, transparent 4px 11px),
    radial-gradient(circle at 50% 50%, rgba(246,198,74,.28), transparent 45%);
}
.placed-building.wet { outline: 4px solid rgba(182,0,0,.72); }
.placed-building.dry { outline: 4px solid rgba(0,111,179,.72); }
.placed-building.speakeasy { box-shadow: inset 0 0 0 2px rgba(255,255,255,.14), 0 0 0 5px rgba(182,0,0,.42), 0 5px 10px rgba(0,0,0,.45); }
.placed-building .building-label {
  position: absolute;
  inset: auto 4px 4px 4px;
  background: rgba(6,20,27,.78);
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  text-align: center;
  padding: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fire-marker { position: absolute; top: 2px; right: 3px; font-size: 18px; z-index: 2; }

.lower-area { display: grid; grid-template-columns: minmax(460px, 1fr) 330px; gap: 12px; min-height: 0; }
.action-hand-panel, .building-hand-panel { border: 3px solid var(--line); background: var(--panel); color: #fff; padding: 10px; min-width: 0; overflow: hidden; }
.action-hand-panel header, .building-hand-panel header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.action-hand-panel h2, .building-hand-panel h2 { margin: 0; font-size: 29px; font-weight: 500; text-align: center; flex: 1; }
.building-hand-panel h2 { font-size: 28px; }
.pill { border: 2px solid #fff; border-radius: 999px; padding: 3px 8px; font-weight: 800; font-size: 12px; }
.card-strip { display: flex; gap: 8px; overflow-x: auto; padding: 10px 2px 2px; height: 118px; }
.card-strip.vertical { height: 78px; }
.hand-card { flex: 0 0 66px; height: 96px; border: 2px solid #041015; border-radius: 6px; background: #f6efe4; color: var(--ink); cursor: pointer; overflow: hidden; position: relative; box-shadow: 0 3px 5px rgba(0,0,0,.28); }
.hand-card:hover { transform: translateY(-3px); }
.hand-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hand-card .fallback-title { display: grid; place-items: center; text-align: center; font-size: 9px; font-weight: 900; padding: 4px; height: 100%; }
.hand-card .mini-badge { position: absolute; left: 2px; right: 2px; bottom: 2px; background: rgba(6,20,27,.78); color: #fff; text-align: center; font-size: 8px; padding: 2px; font-weight: 900; }
.turn-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 10px; }
.btn.control { min-height: 61px; padding: 8px; font-size: 12px; }

.log-panel { border: 3px solid var(--line); background: #f9fbfc; min-width: 0; max-height: calc(100vh - 20px); overflow: hidden; display: flex; flex-direction: column; }
.log-title { background: var(--panel); color: #fff; padding: 10px; font-weight: 900; border-bottom: 3px solid var(--line); }
#game-log { padding: 10px; overflow-y: auto; font-size: 12px; line-height: 1.4; }
.log-entry { border-bottom: 1px solid #d9e1e4; padding: 6px 0; }
.log-entry strong { color: var(--panel-dark); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.48); display: grid; place-items: center; z-index: 999; padding: 22px; }
.modal-card { background: #fff; border: 4px solid var(--line); max-width: 680px; width: min(680px, 100%); max-height: 88vh; overflow-y: auto; padding: 22px; position: relative; box-shadow: 12px 12px 0 rgba(0,0,0,.24); }
.modal-close { position: absolute; right: 10px; top: 8px; background: transparent; border: 0; font-size: 34px; cursor: pointer; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.modal-card table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.modal-card td, .modal-card th { border: 1px solid #cbd5da; padding: 7px; text-align: left; vertical-align: top; }
.choice-list { display: grid; gap: 8px; margin-top: 10px; }
.choice-list button { text-align: left; border: 2px solid var(--line); background: #f7fafb; padding: 10px; cursor: pointer; }
.choice-list button:hover { background: #e8f2f5; }

@media (max-width: 1180px) {
  .game-shell.active { grid-template-columns: 210px 1fr; }
  .log-panel { display: none; }
  .lower-area { grid-template-columns: 1fr 300px; }
  .action-hand-panel h2, .building-hand-panel h2 { font-size: 22px; }
}
