/* === DESIGN TOKENS === */
:root {
  --font-display: 'Zodiak', Georgia, serif;
  --font-body: 'Satoshi', 'Inter', sans-serif;

  /* Historical / Maritime palette */
  --color-bg: #1a1914;
  --color-surface: #211e18;
  --color-surface-2: #2a261f;
  --color-surface-3: #332e26;
  --color-border: #3d3629;
  --color-border-light: #4a4235;
  --color-text: #d4c9b0;
  --color-text-muted: #9a8d78;
  --color-text-faint: #6b6052;
  --color-primary: #c9a96e;
  --color-primary-hover: #dbb87a;
  --color-primary-dim: rgba(201, 169, 110, 0.12);
  --color-danger: #a44040;
  --color-danger-light: #c45555;
  --color-success: #5a8a3e;
  --color-warning: #c4873a;
  --color-water: #2a4a5a;
  --color-water-light: #3a6a7e;
  --color-land: #4a6b3a;
  --color-land-light: #5a7e4a;
  --color-dike: #8b7355;
  --color-dike-strong: #a08860;

  /* Players */
  --player-1: #c9a96e;
  --player-2: #6ea0c9;
  --player-3: #c96e6e;
  --player-4: #6ec96e;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Type */
  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 15px;
  --text-lg: 20px;
  --text-xl: 28px;
  --text-2xl: 40px;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --transition-ui: 200ms ease;

  /* Panel treatment */
  --panel-shadow: 0 2px 12px rgba(0,0,0,0.35), 0 1px 3px rgba(0,0,0,0.2);
  --panel-inset-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

/* === BASE RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  overflow: hidden;
}

img { display: block; max-width: 100%; height: auto; }
button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }

/* === SCREENS === */
.screen { display: none; width: 100vw; height: 100dvh; position: relative; }
.screen.active { display: flex; }

/* === TITLE SCREEN === */
#title-screen {
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.title-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.title-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.title-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg,
    rgba(26,25,20,0.3) 0%,
    rgba(26,25,20,0.6) 40%,
    rgba(26,25,20,0.92) 70%,
    rgba(26,25,20,1) 100%
  );
}

.title-content {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: var(--space-8);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  margin-top: 15vh;
}

.title-logo {
  width: min(400px, 80vw);
  height: auto;
}

.title-subtitle {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--color-text-muted);
  letter-spacing: 2px;
  margin-top: -8px;
}

.title-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: 500px;
  line-height: 1.6;
}

.title-setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.setup-label {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.player-select {
  display: flex;
  gap: var(--space-2);
}

.player-btn, .round-btn {
  width: 48px;
  height: 40px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  background: var(--color-surface);
  transition: all var(--transition-ui);
}

.player-btn:hover, .round-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-text);
}

.player-btn.selected, .round-btn.selected {
  background: var(--color-primary);
  color: var(--color-bg);
  border-color: var(--color-primary);
}

.btn-primary {
  padding: var(--space-3) var(--space-8);
  background: var(--color-primary);
  color: var(--color-bg);
  font-weight: 700;
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: all var(--transition-ui);
  border: none;
  margin-top: var(--space-4);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-small {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: all var(--transition-ui);
}

.btn-small:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

/* ====================================
   TEAM SELECT SCREEN
   ==================================== */
#team-screen {
  align-items: center;
  justify-content: flex-start;
  flex-direction: column;
  overflow-y: auto;
}

.team-content {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: var(--space-3) var(--space-6) var(--space-6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin-top: 1vh;
  width: 100%;
  max-width: 960px;
}

.team-heading {
  font-family: var(--font-display);
  font-size: clamp(20px, 2.5vw, 28px);
  color: var(--color-primary);
  letter-spacing: 1px;
}

.team-subtitle {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* Player slots row */
.team-slots {
  display: flex;
  gap: var(--space-4);
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

.team-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 180px;
}

.team-slot-label {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 2px;
}

/* Team cards list for selection */
.team-options {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
}

.team-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: linear-gradient(180deg, rgba(42,38,31,0.85) 0%, rgba(35,31,26,0.9) 100%);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 200ms ease;
  position: relative;
  overflow: hidden;
  text-align: left;
}

.team-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
}

.team-card:hover:not(.taken):not(.selected) {
  border-color: var(--color-primary);
  background: linear-gradient(180deg, rgba(201,169,110,0.08) 0%, rgba(201,169,110,0.03) 100%);
  transform: translateY(-1px);
}

.team-card.selected {
  border-color: var(--color-primary);
  background: linear-gradient(180deg, rgba(201,169,110,0.15) 0%, rgba(201,169,110,0.06) 100%);
  box-shadow: 0 0 12px rgba(201, 169, 110, 0.15), inset 0 0 20px rgba(201, 169, 110, 0.04);
}

.team-card.taken {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.team-card-crest {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.team-card-name {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.2;
}

.team-card-trait {
  font-size: 10px;
  color: var(--color-text-muted);
  line-height: 1.3;
}

/* Selected team preview in slot */
.team-slot-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 12px;
  background: linear-gradient(180deg, rgba(42,38,31,0.9) 0%, rgba(35,31,26,0.95) 100%);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  min-height: 60px;
  min-width: 140px;
  justify-content: center;
  transition: all var(--transition-ui);
}

.team-slot-preview.has-team {
  border-color: var(--color-primary);
}

.team-slot-preview .team-card-crest {
  width: 36px;
  height: 36px;
}

.team-slot-empty {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* Player icon in game UI */
.player-crest-inline {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  vertical-align: middle;
  margin-right: 2px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  padding-bottom: var(--space-1);
  border-bottom: 1px solid rgba(201, 169, 110, 0.1);
}

.panel-title-row .panel-title {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

/* ====================================
   GAME SCREEN — Historical Map Design
   ==================================== */
#game-screen {
  flex-direction: column;
  background: var(--color-bg);
}

#game-screen.active {
  display: flex;
}

/* --- Top Bar (parchment-style header) --- */
#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 var(--space-4);
  background: linear-gradient(180deg, #2a261f 0%, #231f1a 100%);
  border-bottom: 2px solid var(--color-border);
  flex-shrink: 0;
  height: 48px;
  position: relative;
}

#top-bar::after {
  content: '';
  position: absolute;
  bottom: -3px;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(201, 169, 110, 0.15);
}

.top-left {
  display: flex;
  gap: var(--space-6);
  align-items: center;
}

.top-right {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

#round-display {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-base);
  color: var(--color-primary);
  letter-spacing: 0.5px;
}

#phase-display {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: 3px 10px;
  background: var(--color-primary-dim);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(201, 169, 110, 0.1);
}

/* --- Game Area --- */
#game-area {
  display: flex;
  flex: 1;
  overflow: hidden;
}

#board-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #162838;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* --- Side Panel (antique parchment-style) --- */
#side-panel {
  width: 270px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  background: linear-gradient(180deg, #252119 0%, #1e1b15 100%);
  border-left: 2px solid var(--color-border);
  overflow-y: auto;
  position: relative;
}

#side-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 100%;
  background: rgba(201, 169, 110, 0.08);
}

/* Scrollbar styling */
#side-panel::-webkit-scrollbar { width: 4px; }
#side-panel::-webkit-scrollbar-track { background: transparent; }
#side-panel::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 2px; }

.panel {
  background: linear-gradient(180deg, rgba(42,38,31,0.9) 0%, rgba(35,31,26,0.95) 100%);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  box-shadow: var(--panel-inset-shadow), 0 1px 4px rgba(0,0,0,0.2);
  position: relative;
}

.panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(201,169,110,0.12), transparent);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.panel-title {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--space-2);
  letter-spacing: 0.5px;
  padding-bottom: var(--space-1);
  border-bottom: 1px solid rgba(201, 169, 110, 0.1);
}

/* --- Resources --- */
.resource-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.resource-item {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  padding: 4px 6px;
  background: rgba(255,255,255,0.02);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.03);
  transition: background var(--transition-ui);
}

.resource-item:hover {
  background: rgba(255,255,255,0.04);
}

.resource-icon {
  font-size: 14px;
  width: 20px;
  text-align: center;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

.resource-label {
  color: var(--color-text-muted);
  flex: 1;
  font-size: 11px;
}

.resource-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--color-text);
  min-width: 18px;
  text-align: right;
  font-size: var(--text-sm);
}

.fame-item {
  grid-column: 1 / -1;
  background: rgba(201, 169, 110, 0.06);
  border: 1px solid rgba(201, 169, 110, 0.12);
}

.fame-item .resource-value {
  color: var(--color-primary);
  font-size: var(--text-base);
}

/* --- Action Buttons --- */
#action-buttons {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.btn-action {
  width: 100%;
  padding: 6px var(--space-3);
  font-size: var(--text-xs);
  font-weight: 500;
  text-align: left;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(42,38,31,0.6) 0%, rgba(35,31,26,0.8) 100%);
  color: var(--color-text);
  transition: all var(--transition-ui);
  position: relative;
  overflow: hidden;
}

.btn-action::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(255,255,255,0.04);
}

.btn-action:hover:not(:disabled) {
  border-color: var(--color-primary);
  background: linear-gradient(180deg, rgba(201,169,110,0.08) 0%, rgba(201,169,110,0.04) 100%);
  color: var(--color-primary-hover);
  transform: translateX(2px);
}

.btn-action:active:not(:disabled) {
  transform: translateX(2px) scale(0.98);
}

.btn-action:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-action.btn-end {
  margin-top: var(--space-2);
  background: linear-gradient(180deg, rgba(201,169,110,0.12) 0%, rgba(201,169,110,0.06) 100%);
  border-color: rgba(201, 169, 110, 0.3);
  color: var(--color-primary);
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.5px;
}

.btn-action.btn-end:hover:not(:disabled) {
  background: var(--color-primary);
  color: var(--color-bg);
  transform: none;
}

/* --- Scoreboard --- */
#scoreboard {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.score-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  transition: all var(--transition-ui);
  border: 1px solid transparent;
}

.score-row.active-player {
  background: var(--color-primary-dim);
  border: 1px solid rgba(201, 169, 110, 0.2);
  box-shadow: 0 0 8px rgba(201, 169, 110, 0.06);
}

.score-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 4px currentColor;
}

.score-name {
  flex: 1;
  font-weight: 500;
}

.score-fame {
  font-weight: 700;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}

.score-dikes {
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* ====================================
   OVERLAYS — Parchment card design
   ==================================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 8, 0.88);
  backdrop-filter: blur(6px);
  animation: fadeIn 250ms ease;
}

.overlay.hidden { display: none; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Event Card (parchment-style) --- */
.event-card {
  background: linear-gradient(180deg, #2e2a22 0%, #252119 60%, #211e18 100%);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  max-width: 480px;
  width: 90%;
  text-align: center;
  animation: cardSlideIn 300ms cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 2px 8px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.06);
  position: relative;
  overflow: hidden;
}

.event-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--color-primary), transparent);
  opacity: 0.4;
}

.event-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  pointer-events: none;
  background: radial-gradient(ellipse at center top, rgba(201,169,110,0.04) 0%, transparent 60%);
}

@keyframes cardSlideIn {
  from { opacity: 0; transform: translateY(24px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.event-type {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: var(--space-3);
  font-weight: 700;
  position: relative;
}

.event-type.positive { color: var(--color-success); }
.event-type.negative { color: var(--color-danger-light); }
.event-type.neutral { color: var(--color-warning); }

.event-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  color: var(--color-text);
  margin-bottom: var(--space-3);
  line-height: 1.2;
  position: relative;
}

.event-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
  line-height: 1.7;
}

.event-effect {
  font-size: var(--text-sm);
  color: var(--color-text);
  padding: var(--space-3) var(--space-4);
  background: rgba(201,169,110,0.06);
  border: 1px solid rgba(201,169,110,0.12);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  line-height: 1.6;
  position: relative;
}

/* --- Trade & Build Modals --- */
.trade-modal, .rules-modal {
  background: linear-gradient(180deg, #2e2a22 0%, #252119 100%);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  max-width: 420px;
  width: 90%;
  animation: cardSlideIn 300ms cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.06);
}

/* --- Build Mode Bar (replaces overlay) --- */
.build-bar {
  position: fixed;
  top: 52px;
  left: 0;
  right: 270px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: linear-gradient(180deg, rgba(40,35,25,0.96) 0%, rgba(35,30,20,0.94) 100%);
  border-bottom: 2px solid var(--color-primary);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5), 0 0 30px rgba(201,169,110,0.08);
  animation: buildBarSlide 250ms cubic-bezier(0.16, 1, 0.3, 1);
}

.build-bar.hidden { display: none; }

@keyframes buildBarSlide {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.build-bar-icon {
  font-size: 14px;
  color: var(--color-primary);
  animation: buildPulse 1.5s ease-in-out infinite;
}

@keyframes buildPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.build-bar-text {
  font-size: var(--text-sm);
  color: var(--color-text);
  font-weight: 500;
}

.build-bar-cost {
  font-size: var(--text-xs);
  color: var(--color-warning);
  padding: 2px 8px;
  background: rgba(196, 135, 58, 0.1);
  border: 1px solid rgba(196, 135, 58, 0.15);
  border-radius: var(--radius-sm);
  margin-left: auto;
}

.build-bar-cancel {
  padding: 4px 12px;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.04);
  transition: all var(--transition-ui);
}

.build-bar-cancel:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
  background: rgba(255,255,255,0.08);
}

/* Build mode cursor on canvas */
#board-container.build-mode #game-canvas {
  cursor: crosshair;
}

.modal-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--color-primary);
  margin-bottom: var(--space-2);
}

.modal-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
  line-height: 1.6;
}

.modal-cost {
  font-size: var(--text-sm);
  color: var(--color-warning);
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: rgba(196, 135, 58, 0.08);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(196, 135, 58, 0.12);
}

.trade-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.trade-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.trade-col label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.trade-col select {
  padding: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-family: var(--font-body);
}

.trade-arrow {
  font-size: var(--text-xl);
  color: var(--color-primary);
  margin-top: 16px;
}

.modal-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: center;
}

.modal-actions .btn-primary {
  margin-top: 0;
}

/* --- Rules Modal --- */
.rules-modal {
  max-width: 560px;
  max-height: 80vh;
  overflow-y: auto;
}

.rules-content {
  margin-bottom: var(--space-4);
}

.rules-content h3 {
  font-family: var(--font-display);
  font-size: var(--text-base);
  color: var(--color-primary);
  margin: var(--space-4) 0 var(--space-2);
}

.rules-content h3:first-child {
  margin-top: 0;
}

.rules-content p, .rules-content li {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.6;
}

.rules-content ul {
  padding-left: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* --- Flood overlay --- */
.flood-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background: radial-gradient(ellipse at center bottom, rgba(42,74,90,0.6) 0%, transparent 70%);
  animation: floodPulse 2s ease-in-out;
}

.flood-overlay.hidden { display: none; }

@keyframes floodPulse {
  0% { opacity: 0; }
  30% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

/* ====================================
   GAME OVER
   ==================================== */
#gameover-screen {
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}

.gameover-content {
  text-align: center;
  padding: var(--space-8);
}

.gameover-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  color: var(--color-primary);
  margin-bottom: var(--space-6);
}

#gameover-results {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  min-width: 320px;
}

.result-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: linear-gradient(180deg, rgba(42,38,31,0.9) 0%, rgba(35,31,26,0.95) 100%);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  box-shadow: var(--panel-inset-shadow);
}

.result-row.winner {
  border-color: var(--color-primary);
  background: linear-gradient(180deg, rgba(201,169,110,0.12) 0%, rgba(201,169,110,0.06) 100%);
  box-shadow: 0 0 12px rgba(201, 169, 110, 0.1);
}

.result-rank {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-primary);
  width: 30px;
}

.result-name {
  flex: 1;
  text-align: left;
  font-weight: 600;
}

.result-fame {
  font-weight: 700;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}

.result-dikes {
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* --- Message Toast --- */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-2) var(--space-4);
  background: linear-gradient(180deg, #2e2a22 0%, #252119 100%);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text);
  z-index: 200;
  animation: toastIn 300ms ease, toastOut 300ms ease 2s forwards;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* --- Global Music Toggle --- */
.music-toggle {
  position: fixed;
  bottom: 24px;
  right: 16px;
  z-index: 300;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 27, 21, 0.85);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  color: var(--color-primary);
  cursor: pointer;
  transition: all var(--transition-ui);
  backdrop-filter: blur(4px);
}

.music-toggle:hover {
  background: rgba(42, 38, 31, 0.95);
  border-color: var(--color-primary);
  transform: scale(1.08);
}

.music-toggle.muted {
  color: var(--color-text-faint);
  border-color: rgba(255,255,255,0.06);
}

.music-toggle.muted svg {
  opacity: 0.4;
}

/* --- Footer --- */
.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: var(--space-1);
  z-index: 10;
}

.site-footer a {
  font-size: 10px;
  color: var(--color-text-faint);
  text-decoration: none;
  opacity: 0.5;
}

.site-footer a:hover {
  opacity: 1;
}
