:root {
  --parchment: #efe3c8;
  --parchment-dark: #e2d2ad;
  --ink: #2b2118;
  --ink-soft: #5a4a36;
  --patriot: #1f4e79;      /* Continental blue */
  --patriot-light: #3a6ea5;
  --crown: #8c2b2b;        /* Redcoat */
  --crown-light: #b94b4b;
  --neutral: #9a8c6e;
  --gold: #b8860b;
  --border: #6b5638;
  --shadow: rgba(40, 28, 12, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color: var(--ink);
  background: #1c140c;
}

#app { height: 100%; }

.screen {
  height: 100vh;       /* fallback */
  height: 100dvh;      /* track mobile browser chrome so the bottom isn't clipped */
  width: 100%;
}
.hidden { display: none !important; }

/* ---------- Title screen ---------- */
#title-screen, #howto-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 20%, rgba(255, 240, 200, 0.18), transparent 60%),
    linear-gradient(160deg, #3a2c18, #1c140c);
}
.title-card {
  text-align: center;
  background: var(--parchment);
  border: 3px solid var(--border);
  border-radius: 6px;
  padding: 48px 56px;
  box-shadow: 0 12px 40px var(--shadow);
  max-width: 560px;
}
.title-card h1 {
  font-size: 56px;
  margin: 0 0 8px;
  letter-spacing: 2px;
  color: var(--ink);
  text-shadow: 1px 1px 0 rgba(255,255,255,0.4);
}
.subtitle { color: var(--ink-soft); margin: 0 0 28px; font-size: 18px; }
.title-buttons { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.flavor { font-style: italic; color: var(--ink-soft); font-size: 14px; margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 16px;
  padding: 12px 20px;
  border: 2px solid var(--border);
  background: var(--parchment-dark);
  color: var(--ink);
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { background: #d8c69b; box-shadow: 0 2px 8px var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.btn-primary { background: var(--patriot); color: #f4ead2; border-color: #14385a; }
.btn-primary:hover { background: var(--patriot-light); }
.btn-crown { background: var(--crown); color: #f4ead2; border-color: #5e1d1d; }
.btn-crown:hover { background: var(--crown-light); }
.choose { color: var(--ink-soft); margin: 0 0 8px; font-size: 14px; letter-spacing: 1px; text-transform: uppercase; }
.btn-small { padding: 6px 12px; font-size: 14px; }

/* ---------- How to play ---------- */
.howto {
  max-width: 640px;
  max-height: 86vh;
  overflow-y: auto;
}
.howto h2 { margin-top: 0; }
.howto ul { line-height: 1.55; }
.howto li { margin-bottom: 8px; }

/* ---------- Panels ---------- */
.panel {
  background: var(--parchment);
  border: 2px solid var(--border);
  border-radius: 6px;
  padding: 16px 18px;
  box-shadow: 0 6px 18px var(--shadow);
}

/* ---------- Game layout ---------- */
#game-screen { display: flex; flex-direction: column; }

#topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: linear-gradient(180deg, #3a2c18, #2a2012);
  color: var(--parchment);
  border-bottom: 3px solid var(--border);
}
.brand { font-size: 22px; font-weight: bold; letter-spacing: 1px; }
.stat-group { display: flex; align-items: center; gap: 22px; flex: 1; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; line-height: 1.1; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; opacity: 0.75; }
.stat-value { font-size: 20px; font-weight: bold; }
.stat.patriot .stat-value { color: #ffe9a8; }

.morale { min-width: 120px; }
.bar {
  width: 130px; height: 14px;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 7px; overflow: hidden; margin-top: 3px;
}
.bar-fill { height: 100%; width: 100%; transition: width 0.4s ease; }
.patriot-fill { background: linear-gradient(90deg, var(--patriot-light), #6fa3d6); }
.crown-fill { background: linear-gradient(90deg, var(--crown-light), #e08a8a); }

#board { flex: 1; display: flex; min-height: 0; background: #241a0e; }

#map-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  /* same gradient family as the SVG ocean, so the inset frame reads as sea */
  background: linear-gradient(135deg, #a9c6cf, #7ba6b3);
  overflow: hidden;
}
#map { width: 100%; height: 100%; max-height: calc(100dvh - 70px); touch-action: none; }

/* The bottom-sheet grip is only used on the mobile layout (shown below). */
.sheet-grip { display: none; }

/* Zoom controls: shown only on the touch phone layout (pinch/double-tap also work). */
.zoom-controls {
  display: none; flex-direction: column; gap: 8px;
  position: absolute; left: 12px; bottom: 12px; z-index: 35;
}
.zoom-btn {
  width: 44px; height: 44px; border-radius: 8px;
  border: 2px solid var(--border); background: rgba(42, 32, 18, 0.86);
  color: var(--parchment); font-size: 24px; font-weight: bold; line-height: 1;
  cursor: pointer; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.zoom-btn:active { background: rgba(58, 44, 24, 0.95); }

/* Map elements */
.terrain { fill: #d9c79c; stroke: #b7a276; stroke-width: 0.8; }
.land-base { fill: #e3d3a8; stroke: none; }

.region-shape {
  stroke: #4a3a22; stroke-width: 1.4; cursor: pointer;
  transition: fill 0.15s ease, stroke-width 0.1s ease;
}
.region-shape:hover { fill-opacity: 0.92; stroke-width: 2; }
.region-patriot { fill: rgba(31, 78, 121, 0.74); }
.region-crown { fill: rgba(140, 43, 43, 0.76); }
.region-neutral { fill: rgba(154, 140, 110, 0.55); }
.region-shape.selected { stroke: #ffd24a; stroke-width: 3.5; }
.region-shape.movable { stroke: #43c443; stroke-width: 3.5; }
.region-shape.attackable { stroke: #ff7a3a; stroke-width: 3.5; }

.capital-star { fill: #ffd24a; stroke: #2b2118; stroke-width: 0.7; }
.general-star { fill: #fff3cf; stroke: #6b4a12; stroke-width: 0.9; }
.region-label {
  fill: #f7efd9; font-size: 11px; font-weight: bold; text-anchor: middle;
  paint-order: stroke; stroke: rgba(20, 12, 4, 0.75); stroke-width: 2.6px;
  letter-spacing: 0.2px;
}
.troop-badge { fill: #f7f2e2; stroke-width: 2; }
.troop-badge.troop-patriot { stroke: var(--patriot); }
.troop-badge.troop-crown { stroke: var(--crown); }
.troop-badge.troop-neutral { stroke: var(--neutral); }
.troop-text { fill: #2b2118; font-size: 10.5px; font-weight: bold; text-anchor: middle; }
.acted-mark { fill: rgba(20, 14, 6, 0.28); pointer-events: none; }

/* City markers: solid fortified squares, distinct from territory polygons. */
.city-marker { stroke: #14100a; stroke-width: 2; }
.region-shape.city-marker.region-patriot { fill: #1f4e79; }
.region-shape.city-marker.region-crown { fill: #8c2b2b; }
.region-shape.city-marker.region-neutral { fill: #9a8c6e; }
.city-troop { fill: #f7f2e2; stroke: rgba(15, 9, 4, 0.85); stroke-width: 3px; paint-order: stroke; }

/* Sea zones */
.sea-link { stroke-width: 1.5; stroke-dasharray: 5 5; opacity: 0.45; }
.sea-link.sea-crown { stroke: #b94b4b; }
.sea-link.sea-patriot { stroke: #3a6ea5; }
.sea-node { stroke: #14100a; stroke-width: 1.5; cursor: pointer; }
.sea-node.sea-crown { fill: #8c2b2b; }
.sea-node.sea-patriot { fill: #1f4e79; }
.sea-anchor { fill: #f7f2e2; font-size: 11px; text-anchor: middle; }
.sea-ships {
  fill: #f7efd9; font-size: 10px; font-weight: bold; text-anchor: middle;
  paint-order: stroke; stroke: rgba(20, 12, 4, 0.8); stroke-width: 2.4px;
}
.sea-ships-crown { fill: #ef9a9a; }
.sea-ships-patriot { fill: #8fc0ee; }
.sea-hit { fill: transparent; cursor: pointer; stroke: none; }
.sea-hit.movable { stroke: #f0e2b8; stroke-width: 2px; stroke-dasharray: 4 3; }
.sea-hit.selected { stroke: #ffd24a; stroke-width: 2.5px; }
.sea-label {
  fill: #21424c; font-size: 9px; font-style: italic; text-anchor: middle; font-weight: bold;
  paint-order: stroke; stroke: rgba(247, 242, 226, 0.7); stroke-width: 2px;
}

/* Cartographic decoration */
.ocean-label {
  fill: rgba(30, 60, 70, 0.55); font-size: 17px; font-style: italic;
  letter-spacing: 4px; text-anchor: middle; font-weight: bold;
}
.compass-ring { fill: rgba(247, 242, 226, 0.65); stroke: #4a3a22; stroke-width: 1.2; }
.compass-star { fill: #8c2b2b; stroke: #2b2118; stroke-width: 0.6; }
.compass-n { fill: #2b2118; font-size: 11px; font-weight: bold; text-anchor: middle; }
.sub-label {
  fill: #f7efd9; font-size: 11px; font-style: italic; text-anchor: middle;
  paint-order: stroke; stroke: rgba(20, 12, 4, 0.6); stroke-width: 2.5px;
}

/* ---------- Sidebar ---------- */
#sidebar {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  background: #2a2012;
  overflow-y: auto;
}
#region-info { position: relative; }
.ri-portrait { float: right; width: 76px; margin: 2px 0 6px 12px; }
.ri-portrait:empty { display: none; margin: 0; }
.ri-portrait .portrait-svg, .ri-portrait .portrait-img {
  width: 76px; height: auto; display: block;
}
.ri-portrait .portrait-svg {
  border-radius: 3px; box-shadow: 0 1px 4px rgba(0,0,0,0.45);
}
.ri-portrait .portrait-img {
  /* transparent around the card; shadow follows the card silhouette */
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.55));
}
#region-info h3 { margin: 0 0 4px; }
.ri-owner { margin: 0 0 10px; font-weight: bold; font-size: 14px; }
.ri-owner.patriot { color: var(--patriot); }
.ri-owner.crown { color: var(--crown); }
.ri-owner.neutral { color: var(--ink-soft); }
.ri-general { margin: -6px 0 10px; font-size: 13px; font-weight: bold; color: #8a6a14; }
.ri-general:empty { display: none; }
.ri-stats { display: flex; gap: 8px; margin-bottom: 10px; clear: both; }
.ri-stats > div {
  flex: 1; text-align: center; background: var(--parchment-dark);
  border: 1px solid var(--border); border-radius: 4px; padding: 6px 4px;
}
.ri-k { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-soft); }
.ri-v { display: block; font-size: 18px; font-weight: bold; }
.ri-hint { font-size: 13px; color: var(--ink-soft); min-height: 18px; margin: 0 0 10px; font-style: italic; }
.ri-actions { display: flex; flex-direction: column; gap: 8px; }

.log-panel { flex: 1; min-height: 120px; display: flex; flex-direction: column; }
.log-panel h3 { margin: 0 0 8px; }
#log {
  list-style: none; margin: 0; padding: 0;
  overflow-y: auto; flex: 1; font-size: 13px; line-height: 1.4;
}
#log li { padding: 4px 0; border-bottom: 1px dashed rgba(107,86,56,0.4); }
#log li.l-good { color: var(--patriot); }
#log li.l-bad { color: var(--crown); }
#log li.l-event { color: var(--gold); font-weight: bold; }
#log li.l-flavor { color: var(--ink-soft); font-style: italic; }

.btn-end { font-size: 18px; padding: 14px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20, 14, 8, 0.7);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--parchment); border: 3px solid var(--border);
  border-radius: 6px; padding: 24px 28px; max-width: 420px; width: 90%;
  box-shadow: 0 16px 50px var(--shadow);
}
.modal h3, .modal h2 { margin-top: 0; }
.slider-row { display: flex; align-items: center; gap: 14px; margin: 18px 0; }
#troop-slider { flex: 1; }
.troop-count {
  font-size: 22px; font-weight: bold; min-width: 44px; text-align: center;
  background: var(--patriot); color: #f4ead2; border-radius: 4px; padding: 4px 8px;
}
.lead-row { display: flex; align-items: center; gap: 9px; margin: 4px 0 16px; font-size: 15px; cursor: pointer; }
.lead-row input { width: 17px; height: 17px; cursor: pointer; }
.lead-row.disabled { opacity: 0.6; cursor: default; font-style: italic; }
.lead-row.disabled input { cursor: not-allowed; }
.modal-odds {
  margin: 0 0 14px; padding: 8px 10px; border-radius: 5px;
  font-size: 14px; font-weight: bold; border-left: 4px solid currentColor;
  background: rgba(0, 0, 0, 0.05);
}
.modal-odds.odds-great { color: #2f7d3a; }
.modal-odds.odds-good  { color: #4a7a2b; }
.modal-odds.odds-even  { color: #8a6a14; }
.modal-odds.odds-bad   { color: #a85a1e; }
.modal-odds.odds-grim  { color: #8c2b2b; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 10px; }
.gameover-modal { text-align: center; max-width: 540px; }
.gameover-modal h2 { font-size: 36px; }
.go-chronicle-title {
  margin: 18px 0 8px; font-size: 15px; letter-spacing: 0.5px;
  text-transform: uppercase; color: var(--ink-soft);
  border-top: 1px solid var(--border); padding-top: 14px;
}
.go-chronicle {
  list-style: none; margin: 0 0 18px; padding: 0 4px;
  text-align: left; max-height: 38vh; overflow-y: auto;
  font-size: 13.5px; line-height: 1.5;
}
.go-chronicle .ch-entry {
  display: flex; gap: 10px; padding: 5px 0;
  border-bottom: 1px dashed rgba(107, 86, 56, 0.35);
}
.go-chronicle .ch-date {
  flex: 0 0 104px; color: var(--ink-soft); font-style: italic; font-size: 12.5px;
}
.go-chronicle .ch-text { flex: 1; }
.go-chronicle .ch-entry.l-good .ch-text { color: var(--patriot); }
.go-chronicle .ch-entry.l-bad .ch-text { color: var(--crown); }
.go-chronicle .ch-entry.l-event .ch-text { color: #8a6a14; font-weight: bold; }
.go-chronicle .ch-empty { color: var(--ink-soft); font-style: italic; }

/* ---------- Banner toast ---------- */
.banner {
  position: fixed; top: 80px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--gold); border: 2px solid var(--gold);
  padding: 12px 24px; border-radius: 6px; font-size: 18px; font-weight: bold;
  z-index: 60; box-shadow: 0 8px 30px var(--shadow); text-align: center;
  transition: opacity 0.4s ease, transform 0.4s ease;
  display: flex; align-items: center; gap: 14px; max-width: 92vw;
}
.banner.hidden { opacity: 0; pointer-events: none; transform: translate(-50%, -10px); }

/* ---------- Event "moment" card (period painting for turning points) ---------- */
.moment {
  position: fixed; inset: 0; z-index: 70; cursor: pointer;
  background-size: cover; background-position: center;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 1; transition: opacity 0.5s ease;
}
.moment.hidden { opacity: 0; pointer-events: none; }
.moment-caption {
  margin-bottom: 12vh; padding: 12px 28px;
  font-family: Georgia, "Times New Roman", serif; font-size: 28px; font-weight: bold;
  color: #f7efd9; text-align: center; letter-spacing: 0.5px;
  text-shadow: 0 2px 12px rgba(0,0,0,0.9), 0 0 3px rgba(0,0,0,0.8);
}
@media (max-width: 820px) { .moment-caption { font-size: 20px; margin-bottom: 14vh; } }
.banner-portrait { flex: none; }
.banner-portrait:empty { display: none; }
.banner-portrait .portrait-img {
  width: 54px; height: auto; display: block; border-radius: 3px;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.6));
}

/* ===================== Mobile / narrow portrait layout ===================== */
@media (max-width: 820px) {
  /* Title / how-to screens fit a phone. */
  .title-card { padding: 30px 22px; max-width: 92vw; }
  .title-card h1 { font-size: 40px; }
  .subtitle { font-size: 15px; }
  .panel.howto { max-width: 92vw; }

  /* Condensed top bar: drop the brand, shrink everything, let stats wrap. */
  #topbar { gap: 10px 14px; padding: 7px 12px; flex-wrap: wrap; }
  .brand { display: none; }
  .stat-group { gap: 10px 16px; }
  .stat-value { font-size: 16px; }
  .stat-label { font-size: 10px; }
  .morale { min-width: 84px; flex: 1; }
  .btn-small { padding: 6px 10px; }

  /* The map takes the whole board; the sidebar becomes a bottom sheet. The
     bottom padding keeps the southern map clear of the collapsed sheet peek. */
  #board { flex-direction: column; position: relative; }
  #map-wrap { flex: 1; padding: 4px 4px 88px; }
  /* Show the zoom buttons here (phone layout), clear of the bottom-sheet peek. */
  body.touch .zoom-controls { display: flex; bottom: 96px; left: 10px; }

  #sidebar {
    --peek: 86px;
    position: absolute; left: 0; right: 0; bottom: 0;
    width: 100%; max-height: 70dvh;
    display: flex; flex-direction: column; gap: 8px;
    padding: 0 12px calc(12px + env(safe-area-inset-bottom)) 12px;
    background: #2a2012;
    border-top: 2px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 26px rgba(0, 0, 0, 0.5);
    transform: translateY(calc(100% - var(--peek)));
    transition: transform 0.26s ease;
    z-index: 40;
    overflow: hidden;
  }
  #sidebar.sheet-open { transform: translateY(0); overflow-y: auto; }

  /* Peek row = grip handle + End Turn, always reachable; details sit below. */
  .sheet-grip {
    order: 0; display: flex; align-items: center; gap: 10px;
    background: none; border: none; color: var(--parchment);
    padding: 10px 4px 4px; cursor: pointer; font: inherit; text-align: left;
  }
  .sheet-grip-handle { width: 34px; height: 5px; border-radius: 3px; background: var(--border); flex: none; }
  .sheet-grip-label { font-size: 14px; font-weight: bold; letter-spacing: 0.3px; }
  .sheet-grip-label::after { content: " \25B4"; opacity: 0.8; }
  #sidebar.sheet-open .sheet-grip-label::after { content: " \25BE"; }

  #btn-end-turn { order: 1; margin: 0 0 6px; }
  #region-info { order: 2; }
  .log-panel { order: 3; min-height: 90px; }
}

/* Short viewports (e.g. landscape phones): compact the top bar for more board. */
@media (max-height: 480px) {
  #topbar { padding: 5px 12px; gap: 8px 14px; }
  .brand { display: none; }
  .stat-value { font-size: 15px; }
  .stat-label { font-size: 9px; }
  .morale { min-width: 80px; }
}
