:root {
  --bg: #0e0718;
  --bg-panel: #2a1848;
  --bg-panel-2: #341e58;
  --ink: #f4eefc;
  --muted: #b7a4d4;
  --line: #4a3270;
  --sand: #f0d36a;
  --water: #1a7c8c;
  --water-deep: #0e4d5c;
  --blue: #2f7fe0;
  --red: #e24b3a;
  --yellow: #f0c53a;
  --purple: #9b4fd4;
  --orange: #e67e22;
  --teal: #2aabb8;
  --green: #4caf50;
  --pink: #e85aad;
  --unowned: #f7fafc;
  --focus: #d4b3ff;
  --danger: #ff7a8a;
  --gold: #f0d36a;
  --tile: 30px;
  --gap: 3px;
  --radius: 10px;
  --font-display: "Bricolage Grotesque", "Trebuchet MS", sans-serif;
  --font-body: "Figtree", "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
}

body.goldrush-page {
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  /* site.css provides the purple TatariHub atmosphere; keep page dense/full-height */
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}

.goldrush-site-header {
  flex: 0 0 auto;
  position: relative;
  z-index: 30;
  background: rgba(14, 7, 24, 0.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.api-banner {
  background: #4a2c14;
  border-bottom: 1px solid #c47a2a;
  color: #ffe7c2;
  padding: 8px 20px;
  font-size: 13px;
}

.api-banner[hidden] {
  display: none;
}

.api-banner {
  background: #4a2c14;
  border-bottom: 1px solid #c47a2a;
  color: #ffe7c2;
  padding: 8px 20px;
  font-size: 13px;
}

.api-banner[hidden] {
  display: none;
}

.topbar,
.footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 16px;
  background: rgba(18, 8, 32, 0.72);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.footer {
  border-bottom: 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  padding: 6px 16px 8px;
}

.goldrush-page .site-footer {
  flex: 0 0 auto;
  padding: 10px 16px 14px;
  background: rgba(14, 7, 24, 0.92);
}

.goldrush-page .site-footer p {
  max-width: none;
}

#field-counts {
  text-align: right;
  max-width: 74%;
  line-height: 1.45;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.03em;
  color: var(--gold);
}

.brand p,
.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.rankings {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 160px));
  gap: 8px;
  min-width: 0;
}

.rankings.rankings--leagues {
  grid-template-columns: repeat(4, minmax(100px, 140px));
}

.rank {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.rank-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
}

.rank-swatch {
  width: 10px;
  height: 10px;
  border-radius: 99px;
  flex: 0 0 auto;
}

.rank-swatch.blue { background: var(--blue); }
.rank-swatch.red { background: var(--red); }
.rank-swatch.yellow { background: var(--yellow); }
.rank-swatch.purple { background: var(--purple); }

.rank-score,
.rank-score-input {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.rank-score-input {
  width: 100%;
  background: rgba(14, 7, 24, 0.85);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 6px;
  color: var(--ink);
}

.rank-score-input:focus {
  outline: none;
  border-color: var(--focus);
}

.rank-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.rank-output {
  color: var(--focus);
}

.rank-cells {
  opacity: 0.85;
}

.rank-cell-pct {
  margin-left: 2px;
  font-size: 10px;
  font-weight: 500;
  opacity: 0.75;
}

.rank-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}

.rank-bar {
  height: 8px;
  background: rgba(14, 7, 24, 0.9);
  border-radius: 99px;
  overflow: hidden;
}

.rank-fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  transition: width 160ms ease;
}

.rank-fill.blue { background: var(--blue); }
.rank-fill.red { background: var(--red); }
.rank-fill.yellow { background: var(--yellow); }
.rank-fill.purple { background: var(--purple); }

.workspace {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 300px;
  gap: 10px;
  padding: 8px 12px 10px;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
}

.panel {
  background: linear-gradient(180deg, rgba(42, 24, 72, 0.94), rgba(52, 30, 88, 0.96));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  overflow: auto;
  max-height: 100%;
  min-height: 0;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
}

.stack {
  display: grid;
  gap: 10px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button,
select,
input[type="number"],
input[type="text"],
input[type="password"] {
  font: inherit;
  color: var(--ink);
}

button {
  border: 1px solid var(--line);
  background: var(--bg-panel-2);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
}

button:hover,
button.active {
  border-color: var(--focus);
  color: #fff;
}

button.primary {
  background: #5a2d9a;
  border-color: var(--focus);
}

button.danger {
  border-color: #7a3030;
  color: #ffd4d4;
}

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

.plan-box {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: rgba(14, 7, 24, 0.85);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.plan-head {
  display: grid;
  gap: 6px;
}

.plan-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
  font-size: 12px;
}

.plan-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.plan-list .plan-name {
  flex: 1;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 12, 16, 0.72);
  z-index: 20;
  padding: 20px;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(460px, 100%);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.modal-card h3 {
  margin: 0;
}

.password-once {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: rgba(14, 7, 24, 0.85);
  border-radius: 8px;
  padding: 10px;
  word-break: break-all;
}

.tile.plan-official {
  box-shadow:
    inset 0 0 0 2px rgba(255, 224, 130, 0.95),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.tile.plan-draft {
  box-shadow:
    inset 0 0 0 2px rgba(126, 224, 200, 0.95),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.tile-plan {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--bg);
  border: 2px solid #ffe082;
  color: #ffe082;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.tile.plan-draft .tile-plan {
  border-color: var(--focus);
  color: var(--focus);
}

.swatch,
.obj-btn {
  min-width: 62px;
}

.swatch.blue { background: #1a4e8a; }
.swatch.red { background: #8a2a22; }
.swatch.yellow { background: #8a7014; color: #fff8d4; }
.swatch.purple { background: #5a2a80; }

.day-mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: end;
}

.day-mode-row .field {
  min-width: 0;
}

.day-mode-row select {
  font-size: 11px;
  padding: 7px 4px;
}

.field {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.field input,
.field select {
  width: 100%;
  background: rgba(14, 7, 24, 0.85);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.map-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  overflow: auto;
  min-width: 0;
  min-height: 0;
  padding: 22px 8px 8px;
  background:
    radial-gradient(700px 420px at 20% 0%, rgba(59, 29, 104, 0.45), transparent 60%),
    radial-gradient(600px 380px at 90% 100%, rgba(42, 20, 80, 0.4), transparent 55%),
    rgba(14, 7, 24, 0.55);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.map-fit {
  position: relative;
}

.map-caption {
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  margin: 0;
  padding: 0 8px;
  color: #d5f4ee;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  white-space: nowrap;
}

.map-board {
  --cols: 24;
  --rows: 26;
  display: grid;
  grid-template-columns: 32px 1fr;
  grid-template-rows: 28px 1fr;
  width: max-content;
}

.corner-gutter {
  background: transparent;
}

.col-headers,
.row-headers {
  display: grid;
  color: var(--focus);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.col-headers {
  grid-template-columns: repeat(var(--cols), var(--tile));
  gap: var(--gap);
  align-items: end;
  justify-items: center;
  padding-bottom: 4px;
}

.row-headers {
  grid-template-rows: repeat(var(--rows), var(--tile));
  gap: var(--gap);
  align-items: center;
  justify-items: end;
  padding-right: 6px;
  font-weight: 700;
}

.grid-wrap {
  position: relative;
  width: max-content;
}

.grid-guides {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile));
  grid-template-rows: repeat(var(--rows), var(--tile));
  gap: var(--gap);
  pointer-events: none;
}

.grid-guides span {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 4px;
}

.grid {
  position: relative;
  z-index: 1;
  width: calc(var(--tile) * var(--cols) + var(--gap) * (var(--cols) - 1));
  height: calc(var(--tile) * var(--rows) + var(--gap) * (var(--rows) - 1));
}

.region-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.tile {
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  padding: 0;
  border: 1px solid #1b2d38;
  border-radius: 8px;
  background: #f7fafc;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  cursor: pointer;
  overflow: hidden;
  color: #142028;
}

.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--faction, #f7fafc);
  opacity: 1;
  pointer-events: none;
}

.tile.blue { --faction: var(--blue); background: var(--blue); }
.tile.red { --faction: var(--red); background: var(--red); }
.tile.yellow { --faction: var(--yellow); background: var(--yellow); }
.tile.purple { --faction: var(--purple); background: var(--purple); }
.tile.none {
  --faction: #f7fafc;
  background: #f7fafc;
}

.tile.none .tile-coord,
.tile.none .tile-size,
.tile.none .tile-hp-label {
  color: rgba(20, 30, 36, 0.78);
}

.tile.none .tile-icon {
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.45);
}

.tile.selected {
  outline: 2px solid #fff;
  outline-offset: 1px;
  z-index: 2;
}

.tile.region-edge {
  box-shadow:
    inset 0 0 0 2px rgba(255, 236, 170, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.tile.locked {
  cursor: default;
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.92),
    0 0 0 2px currentColor;
}

.tile.locked .tile-hp,
.tile.locked .tile-hp-label {
  display: none;
}

.tile.coral-crystal {
  box-shadow:
    inset 0 0 0 2px rgba(255, 160, 210, 0.95),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.tile.clam {
  box-shadow:
    inset 0 0 0 2px rgba(255, 190, 150, 0.95),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.tile.storm-closed {
  filter: saturate(0.55) brightness(0.82);
  box-shadow:
    inset 0 0 0 2px rgba(120, 160, 190, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.tile.storm-closed .tile-hp-label::after {
  content: " closed";
  font-weight: 600;
  opacity: 0.85;
}

.threshold-list {
  display: grid;
  gap: 6px;
}

.threshold {
  background: rgba(14, 7, 24, 0.85);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
}

.threshold b {
  display: block;
}

.threshold.claimed {
  border: 1px solid var(--focus);
}

.threshold.pending {
  border: 1px solid #5a6f78;
}

.tile-hp {
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 3px;
  height: 4px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 99px;
  z-index: 1;
}

.tile-hp > span {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: #3ee0a0;
}

.tile-hp.mid > span { background: #f0c53a; }
.tile-hp.low > span { background: #ff5d5d; }

.tile-icon,
.tile-coord,
.tile-hp-label {
  position: absolute;
  z-index: 1;
  pointer-events: none;
}

.tile-icon {
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

.tile-coord {
  top: 2px;
  left: 3px;
  font-size: 8px;
  color: rgba(255, 255, 255, 0.8);
}

.tile-size {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  right: 3px;
  top: 2px;
  font-size: 8px;
  color: rgba(255, 255, 255, 0.88);
}

.tile-hp-label {
  right: 3px;
  bottom: 8px;
  font-size: 8px;
  color: #fff;
}

.hide-coords .tile-coord,
.hide-hp .tile-hp,
.hide-hp .tile-hp-label,
.hide-icons .tile-icon {
  display: none;
}

.region-label {
  position: absolute;
  pointer-events: none;
  z-index: 3;
  font-size: 10px;
  font-weight: 700;
  color: #fff8d0;
  text-shadow: 0 1px 3px #000;
  letter-spacing: 0.04em;
}

.editor-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.stat {
  background: rgba(14, 7, 24, 0.85);
  border-radius: 8px;
  padding: 8px;
}

.stat b {
  display: block;
  font-size: 16px;
}

.stat span {
  color: var(--muted);
  font-size: 11px;
}

.hp-readout {
  font-variant-numeric: tabular-nums;
  font-size: 18px;
}

.empty-state {
  color: var(--muted);
  font-size: 13px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/*
  Ad placeholders until a real AdSense account is wired up.
  Later: replace each .ad-placeholder with <ins class="adsbygoogle"> (no live
  script / publisher IDs in this repo). Visibility is CSS-only and follows the
  3-column workspace breakpoint (1100px), not user-agent sniffing.
  Desktop: fixed top overlay (does not shrink fitBoard) + in-flow 728×90 at the
  page bottom. Never in Tools or Selected tile. Top overlay and the mobile
  320×50 above the title both slide back with a Hide ad / Show ad control.
*/
.ad-slot {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 0 0 auto;
  max-width: 100%;
  padding: 0;
}

.ad-slot--mobile {
  display: none;
  padding: 6px 12px;
}

.ad-slot--mobile-bottom {
  padding: 6px 12px 10px;
}

.ad-slot--page-bottom {
  width: 100%;
  padding: 6px 12px 8px;
}

.ad-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  max-width: 100%;
  background: rgba(42, 24, 72, 0.65);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  box-sizing: border-box;
}

.ad-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}

.ad-size {
  font-size: 11px;
  color: var(--muted);
}

.ad-placeholder--728x90 {
  width: 728px;
  height: 90px;
}

.ad-placeholder--320x50 {
  width: 320px;
  height: 50px;
}

.ad-placeholder--320x50 .ad-label,
.ad-placeholder--320x50 .ad-size {
  font-size: 10px;
}

.ad-slot--mobile-top {
  flex-direction: column;
  padding: 0;
  gap: 0;
}

.ad-slot--mobile-top .ad-collapse-panel {
  width: 100%;
  padding: 6px 12px 2px;
}

.ad-collapse-panel {
  overflow: hidden;
  max-height: 140px;
  transition: max-height 0.28s ease, opacity 0.2s ease, padding 0.2s ease;
}

.ad-collapse.is-collapsed .ad-collapse-panel {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-width: 0;
  pointer-events: none;
}

.ad-collapse-toggle {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 108px;
  height: 28px;
  padding: 0 12px;
  margin: 0;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 10px 10px;
  background: rgba(18, 39, 54, 0.96);
  color: var(--focus);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.ad-collapse-toggle:hover,
.ad-collapse-toggle:focus {
  border-color: var(--focus);
  color: #fff;
}

.ad-collapse-label {
  line-height: 1;
}

.ad-collapse-arrow {
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 8px solid currentColor;
}

.ad-collapse.is-collapsed .ad-collapse-arrow {
  border-bottom: 0;
  border-top: 8px solid currentColor;
}

.ad-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  pointer-events: none;
}

.ad-overlay-panel {
  pointer-events: auto;
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 8px 12px 4px;
  background: rgba(8, 22, 30, 0.92);
  border-bottom: 1px solid var(--line);
}

.ad-collapse.is-collapsed .ad-overlay-panel {
  padding-top: 0;
  padding-bottom: 0;
  border-bottom-width: 0;
}

@media (max-width: 1100px) {
  .app {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .brand p:not(#match-status) {
    display: none;
  }

  .brand h1 {
    font-size: 16px;
  }

  .topbar {
    padding: 6px 10px;
    gap: 8px;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    overflow: visible;
    padding: 8px 8px 12px;
    gap: 8px;
  }

  .map-shell {
    order: -1;
    width: 100%;
    min-height: min(78vh, calc((100vw - 24px) * 1.12));
    padding: 6px;
  }

  .panel.tools,
  .panel.inspector {
    order: 1;
    max-height: none;
  }

  .rankings {
    min-width: 0;
    width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }

  .rank-score,
  .rank-score-input {
    font-size: 12px;
  }

  .rank-meta,
  .rank-head {
    font-size: 10px;
  }

  .ad-slot--desktop {
    display: none;
  }

  .ad-slot--mobile {
    display: flex;
  }
}

@media print {
  .ad-slot {
    display: none !important;
  }
}
