@import url('https://fonts.googleapis.com/css2?family=Chivo:wght@400;700&family=Newsreader:opsz,wght@6..72,600&display=swap');

:root {
  --ink: #0d1b2a;
  --sea: #1f6f8b;
  --sand: #f2efe8;
  --sun: #f4a261;
  --mint: #81b29a;
  --paper: #fbf8f2;
  --line: #d6d0c4;
  --danger: #bc4749;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: 'Chivo', sans-serif;
  background: linear-gradient(145deg, #f7f2e7 0%, #d9eee8 45%, #d6e8f2 100%);
  min-height: 100vh;
}

.page-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle at 12% 14%, rgba(244, 162, 97, 0.2), transparent 35%),
    radial-gradient(circle at 80% 8%, rgba(31, 111, 139, 0.18), transparent 40%),
    radial-gradient(circle at 60% 80%, rgba(129, 178, 154, 0.25), transparent 38%);
}

.app-shell {
  position: relative;
  max-width: 980px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  gap: 1rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
}

.kicker {
  margin: 0;
  color: var(--sea);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

h1 {
  margin: 0.25rem 0 0;
  font-family: 'Chivo', sans-serif;
  font-size: clamp(1.7rem, 4vw, 2.5rem);
}

h2 {
  margin: 0;
  font-family: 'Chivo', sans-serif;
  font-size: 1.2rem;
}

.panel {
  background: color-mix(in srgb, var(--paper) 90%, white 10%);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.setup-panel {
  display: grid;
  gap: 0.8rem;
}

.row {
  display: flex;
  gap: 0.6rem;
}

.row-gap {
  align-items: flex-start;
}

.field-block {
  flex: 1;
}

.field-block-auto {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.setup-panel .row-gap .field-block-auto {
  margin-top: 1.7rem;
}

.selected-player-tag {
  margin: 0.5rem 0 0;
  min-height: 1.2rem;
  font-size: 0.88rem;
  color: #3f546a;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.player-legend-wrap {
  display: grid;
  gap: 0.4rem;
}

.stats-legend-wrap {
  padding-top: 0.45rem;
  border-top: 1px dashed #bfd0dd;
}

.legend-title {
  margin: 0;
}

.player-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.4rem 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid #c8d3e1;
  background: rgba(255, 255, 255, 0.8);
  font-size: 0.84rem;
}

.legend-name {
  max-width: 8.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-count {
  min-width: 1.6rem;
  height: 1.2rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: #edf3f9;
  color: #2d4059;
  font-size: 0.77rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.legend-item.is-selected {
  border-color: #6f89a7;
  box-shadow: inset 0 0 0 1px #6f89a7;
  font-weight: 700;
}

.legend-item.is-selected .legend-count {
  background: #dce8f5;
}

.legend-chip {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(18, 36, 58, 0.25);
  background: var(--chip-color, #457b9d);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.8);
  flex: 0 0 auto;
}

.field-label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  color: #3b4b61;
}

.text-input,
select,
input[type="file"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid #c7cfdb;
  border-radius: 12px;
  padding: 0.6rem 0.75rem;
  background: white;
}

.btn {
  min-height: 42px;
  border: 1px solid #2d4059;
  background: white;
  color: #1a2a40;
  border-radius: 12px;
  padding: 0.55rem 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  background: var(--sea);
  border-color: var(--sea);
  color: white;
}

.btn-ghost {
  background: transparent;
}

.status-pill {
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  background: white;
  color: inherit;
  text-decoration: none;
}

.flash {
  margin: 0;
  font-size: 0.9rem;
  min-height: 1.2rem;
}

.flash.error {
  color: var(--danger);
}

.stats-panel {
  display: grid;
  gap: 0.75rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.stat-label {
  margin: 0;
  font-size: 0.8rem;
  color: #4f6277;
}

.stat-value {
  margin: 0.25rem 0 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.panel-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
}

.map-wrap {
  min-height: 55vh;
  overflow: hidden;
  border-radius: 14px;
  border: 1px dashed #b8c6d8;
  background: linear-gradient(180deg, #f9fcff 0%, #eef7f8 100%);
  padding: 0.25rem;
}

.map-wrap svg {
  width: 100%;
  height: auto;
}

.map-hint {
  margin: 1rem;
  color: #60758c;
}

.dept {
  transition: fill 0.2s ease, stroke-width 0.2s ease;
  stroke: #39536b;
  stroke-width: 0.65;
  cursor: pointer;
}

.dept:hover {
  stroke-width: 1.3;
  fill: #ffd79d;
}

.dept.claimed {
  cursor: not-allowed;
}

.dept-label {
  pointer-events: none;
  font-family: 'Chivo', sans-serif;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.95);
  stroke-width: 1.15px;
  stroke-linejoin: round;
}

.claim-dialog {
  width: min(95vw, 420px);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
}

.claim-dialog::backdrop {
  background: rgba(20, 30, 41, 0.45);
}

.dialog-actions {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.muted {
  color: #5a6b80;
  margin-top: 0;
}

.claim-details-dialog {
  width: min(95vw, 520px);
}

.claim-details-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 0.8rem;
}

.claim-details-title {
  margin: 0;
}

.icon-btn {
  width: 2rem;
  height: 2rem;
  border: 1px solid #9fb1c8;
  background: #fff;
  border-radius: 999px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: #1f344d;
}

.claim-details-list {
  margin: 0.8rem 0 0;
  display: grid;
  gap: 0.45rem;
}

.claim-details-list div {
  display: grid;
  grid-template-columns: 7.4rem 1fr;
  gap: 0.5rem;
}

.claim-details-list dt {
  margin: 0;
  font-size: 0.84rem;
  color: #4f6277;
}

.claim-details-list dd {
  margin: 0;
  color: #1a2a40;
}

.claim-details-photo-wrap {
  margin-top: 0.9rem;
}

.claim-details-photo-title {
  margin-bottom: 0.45rem;
}

.claim-photo-link {
  display: inline-block;
}

.claim-photo {
  width: 100%;
  max-width: 420px;
  max-height: 46vh;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid #ccd7e3;
}

.admin-shell {
  max-width: 1100px;
}

.admin-actions {
  align-items: end;
}

.admin-list-panel {
  display: grid;
  gap: 0.75rem;
}

.games-list {
  display: grid;
  gap: 0.8rem;
}

.admin-game-card {
  padding: 0.85rem;
}

.admin-game-card h3 {
  margin: 0;
  font-size: 1.05rem;
}

.admin-game-card .stat-label {
  margin-top: 0.2rem;
}

.admin-game-totals {
  border: 1px solid #c9d6e6;
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  font-size: 0.82rem;
  background: #f3f8fc;
  white-space: nowrap;
}

.admin-mini-stats .stat-value {
  font-size: 1.2rem;
}

.create-shell {
  max-width: 920px;
}

.create-panel {
  display: grid;
  gap: 0.85rem;
}

.preset-row {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.preset-row .btn {
  min-height: 36px;
  padding: 0.45rem 0.75rem;
}

.players {
  display: grid;
  gap: 0.6rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
}

.player {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.6rem;
  align-items: center;
  justify-content: flex-start;
  min-width: 31rem;
  padding: 0.55rem;
  border: 1px solid #d4deea;
  border-radius: 12px;
  background: #ffffff;
  position: relative;
  overflow: hidden;
}

.player::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 8px;
  background: var(--player-accent, #457b9d);
}

.player .text-input {
  min-height: 40px;
  width: auto;
}

.player .p-name {
  flex: 0 0 13rem;
  max-width: 13rem;
}

.player .p-color {
  flex: 0 0 7.5rem;
  max-width: 7.5rem;
}

.player .p-role {
  flex: 0 0 8.5rem;
}

.color-preview {
  display: block;
  flex: 0 0 2.25rem;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  border: 1px solid #c9ced6;
  background: #457b9d;
  box-sizing: border-box;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85), 0 3px 8px rgba(31, 111, 139, 0.2);
  margin-left: 0.25rem;
}

.create-actions {
  justify-content: flex-end;
}

.result-box {
  margin: 0;
  background: linear-gradient(180deg, #f9fcff 0%, #eef7f8 100%);
  border: 1px dashed #b8c6d8;
  border-radius: 12px;
  padding: 0.9rem;
  min-height: 6.5rem;
  max-height: 16rem;
  overflow: auto;
  font-size: 0.85rem;
  color: #1a334a;
}

@media (max-width: 760px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .row {
    flex-direction: column;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .create-actions {
    justify-content: stretch;
  }

  .preset-row {
    width: 100%;
    justify-content: stretch;
  }

  .preset-row .btn {
    flex: 1;
  }

  .create-actions .btn {
    width: 100%;
  }
}
