:root {
  color-scheme: light;
  --bg: #eef2ef;
  --ink: #1d2325;
  --muted: #617074;
  --line: #b7c5c0;
  --panel: #fbfcf8;
  --water: #8fb9c5;
  --accent: #b53d2e;
  --accent-ink: #ffffff;
}

html {
  height: 100%;
  touch-action: manipulation;
  width: 100%;
  -webkit-text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.save-status {
  background: #fff4e8;
  border: 1px solid #c85b38;
  border-radius: 6px;
  color: #8e321f;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  margin: 8px 0 0;
  padding: 7px 10px;
}

.save-status.offline {
  background: #edf5fb;
  border-color: #5a8db4;
  color: #245579;
}

body {
  margin: 0;
  min-height: 100dvh;
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid #83948f;
  background: #ffffff;
  color: var(--ink);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #4f625d;
}

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

#endPhaseButton:disabled,
#mobileEndPhaseButton:disabled {
  background: #89918f;
  border-color: #89918f;
  color: #f2f4f3;
  cursor: not-allowed;
  opacity: 1;
}

.app-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 0 18px;
  touch-action: manipulation;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 14px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0;
  margin-bottom: 10px;
}

.topbar p {
  margin-top: 6px;
  color: var(--muted);
}

.topbar-actions {
  align-items: center;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  position: relative;
}

.user-badge {
  color: var(--muted);
  font-size: 13px;
  margin-right: 4px;
}

.auth-screen,
.start-screen,
.welcome-screen {
  display: grid;
  min-height: 520px;
  place-items: center;
}

.auth-panel,
.start-actions,
.welcome-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  width: min(100%, 380px);
}

.welcome-panel {
  display: grid;
  gap: 14px;
  width: min(100%, 560px);
}

.welcome-panel h2,
.welcome-panel p {
  margin: 0;
}

.welcome-kicker {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.welcome-options {
  display: grid;
  gap: 10px;
}

.welcome-options button {
  display: grid;
  gap: 4px;
  min-height: 64px;
  padding: 10px 12px;
  text-align: left;
}

.welcome-options button span {
  font-size: 12px;
  font-weight: 400;
  opacity: 0.82;
}

.auth-actions,
.start-actions {
  display: grid;
  gap: 10px;
}

.auth-actions {
  grid-template-columns: 1fr 1fr;
}

.message {
  color: var(--muted);
  font-size: 13px;
  min-height: 20px;
}

.bot-field {
  display: none !important;
  left: -10000px;
  position: absolute;
  top: auto;
}

.link-button {
  border: 0;
  color: var(--muted);
  min-height: 28px;
  padding: 0;
  text-align: left;
}

.link-button:hover {
  color: var(--ink);
}

.install-app-button {
  background: transparent;
  border: 0;
  color: var(--accent);
  font-weight: 700;
  min-height: 32px;
  padding: 0;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.welcome-options .install-primary {
  background: #1d5f73;
  border-color: #1d5f73;
  color: #ffffff;
}

.welcome-options .install-primary:hover {
  background: #174f60;
  border-color: #174f60;
}

.guide-link {
  color: var(--accent);
  font-weight: 700;
  line-height: 32px;
  text-underline-offset: 3px;
}

.guide-button {
  margin: 4px 0 8px;
  width: 100%;
}

.ai-diagnostics-snapshot {
  border-left-color: var(--accent);
  font-weight: 600;
}

.build-version {
  color: var(--muted);
  font-size: 12px;
  margin: 2px 0 0;
  text-align: center;
}

.install-dialog {
  align-items: center;
  background: rgba(16, 25, 28, 0.68);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  position: fixed;
  z-index: 70;
}

.install-dialog-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 46px rgba(16, 25, 28, 0.32);
  display: grid;
  gap: 14px;
  max-width: 420px;
  padding: 20px;
  width: 100%;
}

.install-dialog-card h2 {
  margin: 0;
}

.install-dialog-card p {
  color: var(--muted);
  line-height: 1.5;
  white-space: pre-line;
}

.icon-button {
  font-size: 22px;
  min-width: 42px;
  padding: 0;
}

.game-menu {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(29, 35, 37, 0.16);
  display: grid;
  gap: 6px;
  padding: 8px;
  position: absolute;
  right: 0;
  top: 46px;
  width: 180px;
  z-index: 10;
}

.game-menu button {
  text-align: left;
}

.macros-card { max-width: 460px; display: grid; gap: 12px; }
.macros-card label { display: grid; gap: 5px; text-align: left; }
.macros-card input[type="checkbox"] { margin-right: 8px; }
.macros-card select, .macros-card input[type="text"] { width: 100%; min-height: 38px; }
.macros-card hr { width: 100%; border: 0; border-top: 1px solid var(--line); }
.macro-enabled { background: #c0392b !important; border-color: #8f241b !important; color: #fff !important; }

.tutorial-dialog {
  align-items: center;
  background: rgba(17, 24, 22, 0.34);
  display: flex;
  inset: 0;
  justify-content: center;
  position: fixed;
  z-index: 40;
}

.tutorial-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 36px rgba(29, 35, 37, 0.22);
  display: grid;
  gap: 12px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 22px;
}

.tutorial-card h2, .tutorial-card p { margin: 0; }
.tutorial-progress { color: var(--muted); font-size: 13px; }
.tutorial-coach {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  bottom: 18px;
  box-shadow: 0 8px 24px rgba(29, 35, 37, 0.18);
  display: flex;
  gap: 10px;
  left: 18px;
  max-width: min(520px, calc(100vw - 36px));
  padding: 12px 14px;
  position: fixed;
  z-index: 35;
}
.tutorial-coach span { color: var(--muted); }
.tutorial-coach-actions { display: flex; gap: 8px; margin-left: auto; }
.tutorial-coach-actions button { white-space: nowrap; }
.tutorial-target {
  animation: tutorial-pulse 1.25s ease-in-out infinite;
  filter: drop-shadow(0 0 7px #f0c94a);
  outline: 3px solid #f0c94a;
  outline-offset: 4px;
  position: relative;
  z-index: 1;
}
.territory.tutorial-target {
  outline: none;
  animation: none;
  opacity: 1;
  filter: drop-shadow(0 0 5px #ffffff) drop-shadow(0 0 16px #f0c94a);
  stroke: #f0c94a !important;
  stroke-width: 8 !important;
}
.map-controls button.tutorial-target,
.game-hud .tutorial-target,
.mobile-end-phase.tutorial-target,
.order-panel .tutorial-target {
  background: #fff4ad;
  box-shadow: 0 0 0 4px rgba(240, 201, 74, 0.55), 0 0 18px rgba(240, 201, 74, 0.9);
}
button.primary.tutorial-target {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
@keyframes tutorial-pulse {
  0%, 100% { opacity: 0.82; }
  50% { opacity: 1; }
}

@media (max-width: 900px) {
  .tutorial-coach {
    bottom: calc(74px + env(safe-area-inset-bottom, 0px));
    left: 14px;
    max-width: calc(100vw - 28px);
    right: 14px;
    top: auto;
    z-index: 20;
  }

  .tutorial-coach span { line-height: 1.25; }
}

@media (max-width: 520px) {
  .tutorial-coach {
    align-items: start;
    display: grid;
    gap: 4px 8px;
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 9px 10px;
  }

  .tutorial-coach strong,
  .tutorial-coach span { grid-column: 1; }

  .tutorial-coach-actions {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-items: stretch;
    flex-direction: column;
    margin: 0;
  }
}

.shortcut-hint {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  max-width: 220px;
  padding: 6px 4px 0;
}

.shortcut-hint kbd {
  background: #eef1ed;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--ink);
  padding: 1px 4px;
}

.game-result {
  align-items: center;
  background: rgba(16, 25, 28, 0.62);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
  z-index: 50;
}

.game-result-dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 46px rgba(16, 25, 28, 0.3);
  max-width: 420px;
  padding: 20px;
  width: 100%;
}

.game-result-dialog h2 {
  margin: 0 0 8px;
}

.game-result-dialog p {
  color: var(--muted);
  margin: 0 0 16px;
}

.profile-manager {
  align-items: center;
  background: rgba(16, 25, 28, 0.86);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 16px;
  position: fixed;
  z-index: 60;
}

.profile-dialog {
  background: #fbfcf8;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 46px rgba(16, 25, 28, 0.32);
  max-height: calc(100dvh - 32px);
  max-width: 680px;
  overflow-y: auto;
  padding: 16px;
  width: 100%;
}

.profile-heading,
.profile-slot-actions {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.profile-heading h2 {
  margin-bottom: 2px;
}

.profile-identity {
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
  padding-bottom: 14px;
}

.profile-identity label,
.profile-identity input {
  display: block;
  width: 100%;
}

.profile-identity label {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.profile-identity input {
  margin-bottom: 8px;
}

.profile-identity button {
  width: auto;
}

#settingsDialog .profile-dialog {
  max-width: 420px;
}

#settingsDialog .profile-dialog > button:not(.profile-heading button) {
  display: block;
  margin-top: 8px;
  width: 100%;
}

#settingsDialog .settings-select-label {
  color: var(--muted);
  display: block;
  font-size: 0.92rem;
  font-weight: 700;
  margin: 16px 0 6px;
}

#settingsDialog #settingsColorSelect {
  margin: 0;
  width: 100%;
}

.multiplayer-dialog {
  align-content: start;
  display: grid;
  gap: 12px;
}

/* Multiplayer is a page-level workspace, not a dialog over the campaign menu. */
#multiplayerDialog {
  align-items: stretch;
  background: #fbfcf8;
  justify-content: stretch;
  padding: 0;
}

#multiplayerDialog > .profile-dialog {
  background: #fbfcf8;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  max-height: none;
  max-width: none;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) max(20px, env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
  width: 100%;
}

.multiplayer-section-title,
.multiplayer-section-heading h3 {
  color: var(--ink);
  font-size: 1rem;
  margin: 0;
}

.multiplayer-create-panel {
  display: grid;
  gap: 12px;
}

.multiplayer-section-heading {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.multiplayer-games-panel {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 8px;
  padding-bottom: 12px;
}

.multiplayer-games-list {
  display: grid;
  gap: 8px;
}

.multiplayer-game-card {
  background: #f4f7f3;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 5px;
  padding: 10px;
}

.multiplayer-game-card.is-current {
  border-color: var(--accent);
}

.multiplayer-game-card-heading,
.multiplayer-room-player {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.multiplayer-game-card p,
.multiplayer-game-card small,
.multiplayer-room-summary span,
.multiplayer-room-summary small,
.multiplayer-room-connection {
  color: var(--muted);
  margin: 0;
}

.multiplayer-game-status {
  font-size: 0.78rem;
  font-weight: 700;
}

.status-active { color: #2f6f45; }
.status-lobby { color: #8a6512; }

.multiplayer-empty-state {
  color: var(--muted);
  margin: 0;
}

.multiplayer-dialog > label {
  color: var(--muted);
  display: grid;
  font-size: 0.92rem;
  font-weight: 700;
  gap: 6px;
  max-width: 320px;
}

.multiplayer-dialog select,
.multiplayer-dialog input {
  min-height: 40px;
  max-width: 320px;
  width: min(100%, 320px);
}

.multiplayer-dialog select {
  max-width: 320px;
  width: min(100%, 320px);
}

.multiplayer-actions button,
#showMultiplayerCreateButton,
#showMultiplayerJoinButton {
  width: auto;
}

.multiplayer-join-panel {
  display: grid;
  gap: 12px;
}

.multiplayer-join-panel > label {
  color: var(--muted);
  display: grid;
  font-size: 0.92rem;
  font-weight: 700;
  gap: 6px;
  max-width: 320px;
}

.multiplayer-slot-list {
  display: grid;
  gap: 8px;
}

.multiplayer-slot {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) minmax(110px, 0.5fr) minmax(100px, 0.45fr) minmax(150px, 0.7fr) auto;
}

.multiplayer-slot label {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.multiplayer-slot select {
  max-width: 260px;
  margin-top: 4px;
  width: 100%;
}

.multiplayer-slot-type,
.multiplayer-slot-difficulty,
.multiplayer-slot-invite {
  color: var(--muted);
  display: grid;
  font-size: 0.78rem;
  font-weight: 700;
  gap: 4px;
}

.multiplayer-slot-difficulty[hidden] {
  display: none;
}

.multiplayer-slot-status {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

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

.multiplayer-room-status {
  background: #f4f7f3;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  min-height: 48px;
  padding: 10px;
}

.multiplayer-invitation-card {
  border: 1px solid var(--line);
  padding: 12px;
}

.multiplayer-invitation-card p {
  margin: 6px 0 10px;
}

.multiplayer-room-summary,
.multiplayer-room-players {
  display: grid;
  gap: 6px;
}

.multiplayer-room-summary {
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.multiplayer-room-players {
  margin-top: 8px;
}

.multiplayer-room-player {
  border-bottom: 1px solid rgba(120, 135, 130, 0.22);
  font-size: 0.9rem;
  padding: 4px 0;
}

.multiplayer-room-player span:last-child {
  color: var(--muted);
  font-size: 0.82rem;
}

@media (max-width: 640px) {
  .multiplayer-slot {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .multiplayer-slot-type,
  .multiplayer-slot-difficulty,
  .multiplayer-slot-invite {
    grid-column: 1 / -1;
  }

  .multiplayer-slot-status {
    grid-column: 2;
    grid-row: 1;
  }
}

.profile-save-slots {
  display: grid;
  gap: 10px;
  margin: 14px 0 8px;
}

.profile-account-link {
  display: inline-block;
  margin: 4px 0 8px;
}

#profileManager[data-mode="saves"] {
  align-items: stretch;
  background: var(--bg);
  padding: 0;
}

#profileManager[data-mode="required"] {
  align-items: stretch;
  background: var(--bg);
  padding: 0;
}

#profileManager[data-mode="required"] > .profile-dialog {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  max-height: none;
  max-width: none;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) max(20px, env(safe-area-inset-bottom, 0px));
}

#profileManager[data-mode="saves"] > .profile-dialog {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  max-height: none;
  max-width: none;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) max(20px, env(safe-area-inset-bottom, 0px));
}

.profile-save-slot {
  background: #f4f7f3;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 10px;
}

.profile-save-slot label {
  margin: 0;
}

.profile-slot-meta {
  color: var(--muted);
  font-size: 12px;
}

.profile-slot-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.game-result-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 440px) {
  .game-result-actions {
    grid-template-columns: 1fr;
  }
}

.game-hud {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto auto;
  margin-bottom: 12px;
  padding: 10px 12px;
}

.game-hud span {
  color: var(--muted);
  margin-left: 6px;
}

.game-hud,
.order-panel {
  touch-action: manipulation;
}

.selection-forces {
  font-size: 12px;
}

.game-layout {
  display: block;
}

.map-wrap {
  aspect-ratio: 2 / 1;
  background: #173f5f;
  border: 1px solid #6d98a4;
  border-radius: 8px;
  overflow: hidden;
  overscroll-behavior: contain;
  position: relative;
  touch-action: none;
}

#worldMap {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
}

.map-ocean {
  fill: #173f5f;
  pointer-events: none;
}

.map-controls {
  display: flex;
  gap: 6px;
  position: absolute;
  right: 8px;
  top: 8px;
  z-index: 5;
}

.map-controls button {
  align-items: center;
  background: rgba(251, 252, 248, 0.92);
  border-color: rgba(29, 35, 37, 0.32);
  border-radius: 999px;
  display: inline-flex;
  font-size: 20px;
  font-weight: 700;
  height: 36px;
  justify-content: center;
  min-height: 36px;
  padding: 0;
  width: 36px;
}

.map-controls #shipFinderButton {
  border-radius: 999px;
  font-size: 12px;
  min-width: 58px;
  width: auto;
}

.map-controls #spyButton {
  border-radius: 999px;
  font-size: 12px;
  min-width: 48px;
  width: auto;
}

.map-controls #shipFinderButton.active {
  background: #1d2325;
  border-color: #1d2325;
  color: #fbfcf8;
}

.ship-finder-outline {
  fill: none;
  pointer-events: none;
  stroke-linejoin: round;
  stroke-width: 5;
  vector-effect: non-scaling-stroke;
}

.territory {
  fill-opacity: 0.9;
  pointer-events: all;
  stroke: rgba(8, 12, 14, 0.82);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: fill-opacity 120ms ease, filter 120ms ease, stroke-width 120ms ease;
}

@media (max-height: 520px) and (orientation: landscape) {
  body {
    overflow: hidden;
  }

  body:has(#gameScreen:not([hidden])) .topbar {
    padding: 0;
    position: fixed;
    right: max(8px, env(safe-area-inset-right));
    top: max(4px, env(safe-area-inset-top));
    z-index: 30;
  }

  body:has(#gameScreen:not([hidden])) .topbar > div:first-child,
  body:has(#gameScreen:not([hidden])) .topbar .user-badge,
  body:has(#gameScreen:not([hidden])) #logoutButton {
    display: none;
  }

  body:has(#gameScreen:not([hidden])) .topbar-actions {
    margin-top: 0;
    width: auto;
  }

  .app-shell {
    max-width: none;
    padding: max(4px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .topbar {
    gap: 8px;
    padding: 0 0 4px;
  }

  .topbar h1,
  #phaseSummary {
    display: none;
  }

  .topbar-actions {
    justify-content: flex-end;
    margin-top: 0;
    width: 100%;
  }

  .user-badge {
    font-size: 12px;
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .icon-button,
  #logoutButton,
  .game-hud #endPhaseButton {
    min-height: 30px;
  }

  .game-hud {
    align-items: center;
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) auto auto;
    margin-bottom: 4px;
    padding: 5px 52px 5px 8px;
  }

  .game-hud #endPhaseButton {
    grid-column: auto;
    justify-self: auto;
  }

  .map-controls button {
    height: 32px;
    min-height: 32px;
    width: 32px;
  }
}

.guide-shell {
  margin: 0 auto;
  max-width: 820px;
  padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(40px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.guide-back {
  color: var(--accent);
  display: inline-block;
  font-weight: 700;
  margin-bottom: 24px;
}

.guide-hero {
  margin-bottom: 24px;
}

.guide-hero h1 {
  font-size: clamp(32px, 7vw, 54px);
  margin: 4px 0 8px;
}

.guide-hero > p:last-child,
.guide-card p,
.guide-card li {
  color: var(--muted);
  line-height: 1.55;
}

.guide-kicker {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.guide-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 14px;
  padding: 18px;
}

.guide-card h2 {
  color: var(--ink);
  font-size: 16px;
  margin-bottom: 8px;
}

.guide-card ol,
.guide-card ul {
  margin: 0;
  padding-left: 22px;
}

.guide-card li + li {
  margin-top: 6px;
}

.territory:hover {
  fill-opacity: 1;
  filter: brightness(1.06);
}

.territory.owned {
  fill-opacity: 0.76;
  stroke: rgba(20, 24, 26, 0.72);
  stroke-width: 1.25;
}

.territory.owned:hover {
  fill-opacity: 0.9;
}

.territory.selected {
  fill-opacity: 0.94;
  stroke: #fff5ca;
  stroke-width: 3;
}

.territory.tutorial-target {
  fill-opacity: 0.94;
  animation: none;
  opacity: 1;
  filter: drop-shadow(0 0 5px #ffffff) drop-shadow(0 0 16px #f0c94a);
  stroke: #f0c94a !important;
  stroke-width: 8 !important;
}

.territory.chain-node {
  stroke: #fff5ca;
  stroke-width: 3;
}

.territory.chain-start {
  stroke: #ffffff;
  stroke-width: 4;
}

.territory.chain-destination {
  stroke: #e0b83f;
  stroke-width: 5;
}

.movement-chain-path,
.movement-chain-marker {
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

.movement-chain-path {
  fill: none;
  stroke: #fff5ca;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.movement-chain-underlay {
  stroke: rgba(18, 28, 32, 0.9);
  stroke-width: 8;
}

.movement-chain-marker {
  fill: #fff5ca;
  stroke: #1c2426;
  stroke-width: 4;
}

.movement-chain-marker.start {
  fill: #ffffff;
}

.movement-chain-marker.destination {
  fill: #e0b83f;
}

.territory-label {
  pointer-events: none;
  font-size: 52px;
  font-weight: 700;
  fill: #ffffff;
  paint-order: stroke;
  stroke: rgba(18, 28, 32, 0.82);
  stroke-width: 9px;
}

.unit-label {
  pointer-events: none;
  font-size: 92px;
  font-weight: 700;
  fill: #fff5ca;
  paint-order: stroke;
  stroke: rgba(18, 28, 32, 0.9);
  stroke-width: 16px;
}

.map-detail-label {
  display: none;
}

#worldMap.map-detail .map-detail-label {
  display: block;
}

.owner-label,
.queued-label {
  pointer-events: none;
  font-size: 68px;
  font-weight: 800;
  fill: #ffffff;
  paint-order: stroke;
  stroke: rgba(18, 28, 32, 0.95);
  stroke-width: 14px;
}

.queued-label {
  fill: #fff5ca;
  font-size: 14px;
}

.capital-mark {
  pointer-events: none;
  fill: #fff5ca;
  stroke: #1c2426;
  stroke-width: 5;
}

.capital-tap-target {
  cursor: pointer;
  fill: transparent;
  pointer-events: all;
  stroke: none;
}

body:has(#gameScreen:not([hidden])) {
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

.app-shell:has(#gameScreen:not([hidden])) {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: none;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  padding-left: max(6px, env(safe-area-inset-left));
  padding-right: max(6px, env(safe-area-inset-right));
  padding-top: max(6px, env(safe-area-inset-top));
}

#gameScreen:not([hidden]),
#gameScreen:not([hidden]) .game-layout,
#gameScreen:not([hidden]) .map-wrap {
  min-height: 0;
}

#gameScreen:not([hidden]) {
  display: flex;
  flex: 1;
  flex-direction: column;
}

#gameScreen:not([hidden]) .game-layout,
#gameScreen:not([hidden]) .map-wrap {
  flex: 1;
}

#gameScreen:not([hidden]) .game-layout {
  display: flex;
}

#gameScreen:not([hidden]) .map-wrap {
  aspect-ratio: auto;
}

.order-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

input,
select {
  min-height: 36px;
  border: 1px solid #aebdb8;
  border-radius: 6px;
  padding: 0 9px;
  background: #ffffff;
  color: var(--ink);
}

.order-panel {
  align-items: end;
  bottom: 18px;
  box-shadow: 0 12px 28px rgba(29, 35, 37, 0.18);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  left: 50%;
  max-width: calc(100% - 36px);
  padding: 14px;
  position: fixed;
  transform: translateX(-50%);
  width: 760px;
  z-index: 20;
}

.order-controls {
  display: grid;
  gap: 10px;
  grid-template-columns: 112px 112px auto;
  align-items: end;
}

.number-stepper {
  align-items: center;
  display: grid;
  grid-template-columns: 30px 44px 30px;
  gap: 4px;
}

.unit-picker {
  display: grid;
  gap: 2px;
}

.unit-slider {
  accent-color: var(--accent);
  height: 18px;
  margin: 0;
  min-height: 18px;
  padding: 0;
  width: 104px;
}

.number-stepper button {
  font-size: 18px;
  font-weight: 700;
  min-height: 30px;
  padding: 0;
  width: 30px;
}

.number-stepper input {
  min-height: 30px;
  padding: 0 4px;
  text-align: center;
  width: 44px;
}

.number-stepper input::-webkit-inner-spin-button,
.number-stepper input::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}

.queued-controls {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(180px, 1fr) 110px;
}

.queued-order-list {
  display: grid;
  gap: 5px;
}

.queued-order-row {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
  font-size: 12px;
}

.queued-order-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queued-order-row button,
.queued-controls > button {
  min-height: 30px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: #e8ece7;
  color: #293336;
  font-size: 12px;
  margin-right: 5px;
  margin-top: 5px;
}

@media (max-width: 900px) {
  .topbar,
  .game-hud {
    display: block;
  }

  .app-shell {
    padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }

  .topbar {
    padding: 4px 0 6px;
  }

  h1 {
    font-size: 24px;
  }

  #phaseSummary {
    font-size: 14px;
  }

  .topbar-actions {
    justify-content: flex-start;
    margin-top: 6px;
  }

  .game-hud {
    display: grid;
    gap: 6px;
    grid-template-columns: minmax(0, 1fr) auto;
    margin-bottom: 6px;
    padding: 6px 8px;
  }

  .game-hud #endPhaseButton {
    grid-column: 1 / -1;
    justify-self: start;
    min-height: 30px;
  }

  .game-hud span {
    margin-left: 4px;
  }

  .order-panel {
    bottom: 0;
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    display: grid;
    gap: 6px;
    grid-template-columns: minmax(0, 1fr);
    left: 0;
    max-height: 44vh;
    max-width: none;
    overflow-y: auto;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0));
    transform: none;
    top: auto !important;
    width: 100%;
  }

  .order-panel h2 {
    font-size: 12px;
    margin-bottom: 2px;
  }

  .order-panel .message {
    font-size: 11px;
    line-height: 1.2;
    min-height: 0;
  }

  .order-controls {
    align-items: end;
    gap: 6px;
    grid-template-columns: 112px 112px 112px;
    justify-content: start;
  }

  .order-controls label {
    font-size: 11px;
    gap: 2px;
    margin-bottom: 0;
  }

  .order-controls input {
    font-size: 16px;
    min-height: 30px;
    width: 100%;
  }

  .order-panel button {
    min-height: 30px;
  }

  .order-controls > button {
    width: 112px;
  }

  .queued-controls {
    grid-template-columns: minmax(0, 1fr) 112px;
  }

  .queued-order-list {
    max-height: 76px;
    overflow-y: auto;
  }

  #cancelOrderButton {
    justify-self: start;
  }
}

@media (max-width: 520px) {
  .profile-manager {
    align-items: flex-start;
    padding: max(52px, env(safe-area-inset-top, 0px)) 8px max(8px, env(safe-area-inset-bottom, 0px));
  }

  .profile-dialog {
    max-height: calc(100dvh - 60px);
    padding: 12px;
  }

  .profile-slot-actions button {
    flex: 1 1 40%;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .game-hud {
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) auto auto;
    padding: 5px 78px 5px 8px;
  }

  .game-hud > div:nth-child(2) {
    white-space: nowrap;
  }

  .game-hud #endPhaseButton {
    grid-column: auto;
  }

  .order-panel {
    align-items: end;
    bottom: 0;
    border-radius: 8px 8px 0 0;
    display: grid;
    gap: 6px;
    grid-template-columns: minmax(190px, 280px) auto auto;
    left: max(8px, env(safe-area-inset-left));
    max-height: none;
    max-width: none;
    height: calc(84px + env(safe-area-inset-bottom, 0px));
    min-height: 0;
    overflow: visible;
    padding: 6px max(8px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    top: auto !important;
    transform: none;
    width: auto;
  }

  .order-panel h2 {
    font-size: 11px;
    margin-bottom: 0;
    white-space: nowrap;
  }

  .order-panel .message {
    display: none;
  }

  .order-controls {
    gap: 4px;
    grid-template-columns: 108px 108px 92px;
    justify-content: start;
  }

  .order-controls label {
    font-size: 10px;
    gap: 2px;
    width: 108px;
  }

  .order-controls input,
  .order-panel button {
    min-height: 26px;
  }

  .order-controls .unit-slider {
    min-height: 18px;
  }

  .order-controls input {
    font-size: 16px;
    padding: 0 6px;
    width: 100%;
  }

  .order-controls > button {
    width: 92px;
  }

  .queued-controls {
    gap: 6px;
    grid-template-columns: minmax(150px, 1fr) 82px;
  }

  .queued-order-list {
    max-height: 34px;
    overflow-y: auto;
  }

  .queued-order-row {
    gap: 4px;
    font-size: 11px;
  }

  .queued-order-row button,
  .queued-controls > button {
    min-height: 26px;
  }

  .queued-controls > button {
    width: 82px;
  }

#cancelOrderButton {
    justify-self: end;
    min-width: 72px;
  }
}

.mobile-end-phase {
  display: none;
}

body:has(#gameScreen:not([hidden])) .topbar {
  display: none;
}

.hud-money {
  margin-top: 4px;
}

.hud-money span {
  margin-left: 2px;
}

.combat-result {
  font-size: 13px;
  font-weight: 800;
  margin: 5px 0 0;
}

.combat-result.victory {
  color: #24723b;
}

.combat-result.defeat {
  color: #a52f25;
}

.combat-result {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.combat-result button {
  appearance: none;
  background: transparent;
  border: 0;
  color: currentColor;
  cursor: pointer;
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  padding: 0 3px;
}

.map-menu-button {
  background: rgba(251, 252, 248, 0.92);
  left: 8px;
  position: absolute;
  top: 8px;
  z-index: 6;
}

.map-game-menu {
  left: 8px;
  right: auto;
  top: 54px;
  z-index: 50;
}

.order-actions {
  display: flex;
  gap: 8px;
}

@media (max-width: 900px) {
  .shortcut-hint {
    display: none;
  }

  .game-hud {
    grid-template-columns: minmax(0, 1fr);
  }

  .selection-forces {
    white-space: nowrap;
  }

  .game-hud #endPhaseButton {
    display: none;
  }

  .mobile-end-phase {
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    display: block;
    min-height: 48px;
    position: fixed;
    right: 10px;
    z-index: 15;
  }

  .mobile-end-phase[hidden] {
    display: none;
  }

  .order-panel .target-message {
    color: var(--ink);
    font-size: 16px;
    font-weight: 700;
    line-height: 1.25;
  }

  .order-controls {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: 100%;
  }

  .order-controls label,
  .unit-picker,
  .unit-slider {
    width: 100%;
  }

  .order-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .order-actions button {
    min-height: 44px;
    width: 100%;
  }

  #cancelOrderButton {
    justify-self: stretch;
  }
}

/* Keep the primary map actions in the reachable bottom zone on phone portraits. */
@media (max-width: 900px) and (min-height: 521px) {
  .map-menu-button {
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    left: 10px;
    position: fixed;
    top: auto;
    z-index: 16;
  }

  .map-game-menu {
    bottom: calc(62px + env(safe-area-inset-bottom, 0px));
    left: 10px;
    right: auto;
    top: auto;
    z-index: 50;
  }

  .map-controls {
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 4px;
    left: 58px;
    position: fixed;
    right: auto;
    top: auto;
    z-index: 16;
  }

  .map-controls button {
    height: 40px;
    min-height: 40px;
    width: 40px;
  }

  .map-controls #shipFinderButton {
    min-width: 54px;
  }

  .map-controls .hint-trigger {
    height: 28px;
    min-height: 28px;
    width: 28px;
  }

  .map-help-hint {
    bottom: calc(62px + env(safe-area-inset-bottom, 0px));
    left: 10px;
    z-index: 17;
  }
}

@media (max-width: 380px) and (min-height: 521px) {
  .mobile-end-phase {
    font-size: 16px;
    min-height: 42px;
    padding: 0 12px;
  }

  .map-menu-button {
    min-height: 40px;
    width: 40px;
  }

  .map-controls {
    left: 54px;
  }

  .map-controls button {
    height: 36px;
    min-height: 36px;
    width: 36px;
  }

  .map-controls #shipFinderButton {
    min-width: 50px;
  }
}

.hint-trigger {
  align-items: center;
  background: #fff8d8;
  border: 1px solid #9a7a20;
  border-radius: 999px;
  color: #5f4808;
  display: none;
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 800;
  height: 24px;
  justify-content: center;
  line-height: 1;
  min-height: 24px;
  padding: 0;
  width: 24px;
  z-index: 8;
}

.hint-mode .hint-trigger {
  display: inline-flex;
}

.control-label {
  align-items: center;
  display: flex;
  gap: 5px;
}

.hinted-control {
  display: block;
  position: relative;
}

.hinted-control > button:not(.hint-trigger) {
  width: 100%;
}

.hinted-control > .hint-trigger {
  position: absolute;
  right: -5px;
  top: -9px;
  width: 24px !important;
}

.map-help-hint {
  bottom: 8px;
  left: 8px;
  position: absolute;
}

.map-controls .hint-trigger {
  align-self: center;
  display: none;
  font-size: 13px;
  height: 24px;
  min-height: 24px;
  width: 24px;
}

.hint-mode .map-controls .hint-trigger {
  display: inline-flex;
}

.hint-mode .mobile-phase-hint {
  display: none;
}

.hint-dialog,
.hint-choice-dialog,
.save-conflict-dialog,
.battle-report-dialog,
.phase-dialog,
.update-dialog {
  align-items: center;
  background: rgba(16, 25, 28, 0.62);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  position: fixed;
  z-index: 80;
}

.battle-report-heading {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.battle-report-heading button {
  min-height: 30px;
  min-width: 54px;
  padding: 3px 10px;
}

.battle-report-heading button[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}

.battle-report-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 18px 46px rgba(16, 25, 28, 0.32);
  display: grid;
  gap: 12px;
  max-height: calc(100dvh - 32px);
  max-width: 480px;
  overflow-y: auto;
  padding: 20px;
  width: 100%;
}

.battle-report-card h2,
.battle-report-card p {
  margin: 0;
}

.battle-report-kicker {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.battle-report-list {
  display: grid;
  gap: 8px;
}

.battle-report-list p {
  background: #f1f3ee;
  border-left: 4px solid var(--line);
  border-radius: 5px;
  line-height: 1.4;
  padding: 9px 10px;
}

.battle-report-list p.captured {
  border-left-color: #24723b;
}

.battle-report-list p.defended {
  border-left-color: #a77b18;
}

.ai-diagnostics-list {
  gap: 10px;
}

.ai-diagnostics-entry {
  background: #f1f3ee;
  border-left: 4px solid var(--accent);
  border-radius: 5px;
  display: grid;
  gap: 4px;
  line-height: 1.35;
  padding: 9px 10px;
}

.ai-diagnostics-entry strong {
  color: var(--ink);
}

.ai-diagnostics-entry span {
  color: #53605d;
  font-size: 13px;
}

.attack-history-card {
  max-width: 620px;
}

.attack-history-list {
  max-height: 58dvh;
  overflow-y: auto;
}

.attack-history-entry {
  background: #f1f3ee;
  border-left: 4px solid var(--line);
  border-radius: 5px;
  display: grid;
  gap: 4px;
  line-height: 1.35;
  padding: 9px 10px;
}

.attack-history-entry.captured {
  border-left-color: #24723b;
}

.attack-history-entry.defended {
  border-left-color: #a77b18;
}

.attack-history-entry p {
  background: transparent;
  border: 0;
  padding: 0;
}

.attack-history-entry p:first-child {
  color: var(--ink);
  font-weight: 800;
}

.report-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.report-actions-top {
  margin-bottom: -4px;
}

.hint-choice-label {
  color: #7a5c08;
  font-size: 13px;
  font-weight: 800;
  margin-bottom: -6px !important;
  text-transform: uppercase;
}

.hint-choice-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.hint-dialog-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 18px 46px rgba(16, 25, 28, 0.32);
  display: grid;
  gap: 12px;
  max-width: 400px;
  padding: 20px;
  width: 100%;
}

.hint-dialog-card h2,
.hint-dialog-card p {
  margin: 0;
}

.hint-dialog-card > p:not(.hint-dialog-kicker) {
  color: var(--muted);
  line-height: 1.5;
}

.hint-dialog-kicker {
  color: #7a5c08;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

@media (max-width: 900px) {
  .desktop-phase-hint {
    display: none !important;
  }

  .hint-mode .mobile-phase-hint {
    bottom: calc(22px + env(safe-area-inset-bottom, 0px));
    display: inline-flex;
    position: fixed;
    right: 126px;
    z-index: 16;
  }

  body:has(#orderPanel:not([hidden])) .mobile-phase-hint {
    display: none !important;
  }

  .control-label .hint-trigger {
    height: 22px;
    min-height: 22px;
    width: 22px;
  }
}

[hidden] {
  display: none !important;
}
