:root {
  color-scheme: light;
  --ink: #182720;
  --muted: #657168;
  --paper: #efe9d7;
  --panel: #f8f3e6;
  --green: #294f3e;
  --green-light: #49755e;
  --orange: #dc8c4b;
  --red: #a94743;
  --line: #cfc6ac;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 8%, rgba(255, 255, 255, .12), transparent 28%),
    #13221d;
}

button {
  font: inherit;
}

.shell {
  width: min(1480px, 100%);
  margin: auto;
  padding: 24px;
}

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  color: #f7f0dc;
  margin-bottom: 20px;
}

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

.save-status {
  margin-right: 4px;
  color: rgba(255, 255, 255, .68);
  font-size: .75rem;
}

.eyebrow,
.panel-label {
  margin: 0 0 5px;
  text-transform: uppercase;
  letter-spacing: .16em;
  font-size: .71rem;
  font-weight: 700;
}

h1,
h2,
h3 {
  font-family: Georgia, "Times New Roman", serif;
}

h1 {
  margin: 0;
  font-size: clamp(2.1rem, 5vw, 4.1rem);
  line-height: .95;
}

.quiet-button {
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: 999px;
  padding: 10px 16px;
  color: white;
  background: transparent;
  cursor: pointer;
}

.quiet-button:hover,
.quiet-button:focus-visible {
  background: rgba(255, 255, 255, .1);
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  overflow: hidden;
  margin-bottom: 12px;
  border-radius: 14px;
  background: var(--panel);
}

.dashboard div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 20px;
  border-right: 1px solid var(--line);
}

.dashboard div:last-child {
  border: 0;
}

.dashboard span {
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.dashboard strong {
  font-size: 1.2rem;
}

.dashboard strong.met {
  color: #357a51;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 12px;
}

.map-card,
.side-panel {
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 20px 70px rgba(0, 0, 0, .22);
}

.map-card {
  position: relative;
  overflow: hidden;
  min-width: 0;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  touch-action: manipulation;
}

.map-instructions {
  position: absolute;
  left: 50%;
  bottom: 18px;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 999px;
  padding: 10px 18px;
  color: white;
  background: rgba(20, 35, 29, .9);
  box-shadow: 0 8px 25px rgba(0, 0, 0, .2);
  text-align: center;
  font-size: .88rem;
  white-space: nowrap;
}

.map-instructions.error {
  background: rgba(129, 48, 46, .94);
}

.side-panel {
  overflow: hidden;
}

.side-panel section {
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.side-panel section:last-child {
  border-bottom: 0;
}

.panel-label {
  color: var(--muted);
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 11px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
}

.mode-switch.three {
  grid-template-columns: repeat(3, 1fr);
}

.mode-switch button {
  border: 0;
  border-radius: 7px;
  padding: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.mode-switch button.active {
  color: white;
  background: var(--green);
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 12px 15px;
  color: white;
  background: var(--green);
  font-weight: 700;
  cursor: pointer;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--green-light);
}

.secondary-button {
  width: 100%;
  border: 1px solid var(--green);
  border-radius: 9px;
  padding: 10px 12px;
  color: var(--green);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}

.secondary-button:hover,
.secondary-button:focus-visible {
  background: rgba(41, 79, 62, .08);
}

.secondary-button:disabled {
  border-color: var(--line);
  color: var(--muted);
  cursor: not-allowed;
}

.primary-button span {
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: 4px;
  padding: 2px 5px;
  font-size: .66rem;
  font-weight: 500;
}

.bulletin p {
  margin: 9px 0 0;
  border-left: 3px solid var(--green-light);
  padding-left: 10px;
  font-size: .86rem;
  line-height: 1.45;
}

.bulletin p.warning {
  border-color: var(--red);
}

.bulletin p.hope {
  border-color: var(--orange);
}

.selection {
  min-height: 110px;
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.45;
}

.objective-card {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.objective-card span {
  color: var(--muted);
  font-size: .82rem;
}

progress {
  width: 100%;
  height: 9px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  accent-color: var(--green-light);
}

.contracts {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.contracts p {
  display: grid;
  gap: 2px;
  margin: 0;
  border-left: 3px solid var(--orange);
  padding-left: 9px;
}

.contracts p.empty {
  border: 0;
  padding: 0;
  color: var(--muted);
  font-size: .8rem;
}

.contracts span {
  color: var(--muted);
  font-size: .76rem;
}

.promise-form {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 13px;
}

.promise-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
}

.promise-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px;
  color: var(--ink);
  background: white;
}

.tutorial-panel {
  background: #e8dec0;
}

.tutorial-panel strong {
  display: block;
  margin-top: 9px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
}

.tutorial-panel p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: .84rem;
  line-height: 1.5;
}

.route-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.route-form label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
}

.route-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px;
  color: var(--ink);
  background: white;
}

.route-form button {
  grid-column: 1 / -1;
}

.route-list {
  display: grid;
  gap: 6px;
  max-height: 180px;
  overflow: auto;
  margin-top: 12px;
  color: var(--muted);
  font-size: .78rem;
}

.route-list > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-radius: 7px;
  padding: 7px 8px;
  background: #ebe4d1;
}

.route-list > div.damaged {
  border-left: 3px dashed var(--red);
}

.route-list span,
.route-list small {
  display: block;
}

.route-list strong {
  color: var(--ink);
}

.route-list button {
  flex: 0 0 auto;
  border: 0;
  border-radius: 6px;
  padding: 6px 8px;
  color: white;
  background: var(--green);
  font-size: .7rem;
  cursor: pointer;
}

.route-list button:disabled {
  color: var(--muted);
  background: var(--line);
  cursor: not-allowed;
}

.selection h3 {
  margin: 9px 0 5px;
  color: var(--ink);
  font-size: 1.25rem;
}

.selection p {
  margin: 0 0 12px;
}

.selection dl {
  margin: 0;
}

.selection dl div {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}

.selection dt {
  color: var(--muted);
}

.selection dd {
  margin: 0;
  color: var(--ink);
  font-weight: 700;
}

.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: .75rem;
  color: var(--muted);
}

.legend span {
  display: flex;
  align-items: center;
  gap: 7px;
}

.legend i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--orange);
}

.legend .need {
  background: var(--red);
}

.legend .stable {
  background: #4f8b68;
}

.legend .line {
  height: 4px;
  border-radius: 0;
  background: #394b43;
}

.legend .storm {
  border: 2px dashed var(--red);
  background: transparent;
}

dialog {
  width: min(520px, calc(100% - 32px));
  border: 0;
  border-radius: 18px;
  padding: 0;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 30px 100px rgba(0, 0, 0, .45);
}

dialog::backdrop {
  background: rgba(9, 18, 14, .72);
  backdrop-filter: blur(4px);
}

.dialog-inner {
  padding: clamp(25px, 6vw, 44px);
}

.dialog-inner h2 {
  margin: 5px 0 16px;
  font-size: 2.2rem;
  line-height: 1.05;
}

.dialog-inner p,
.dialog-inner li {
  line-height: 1.6;
}

.dialog-inner ol {
  padding-left: 22px;
}

.dialog-inner li {
  margin-bottom: 8px;
}

.dialog-inner .primary-button {
  margin-top: 24px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 24px;
}

.dialog-actions .primary-button,
.dialog-actions .secondary-button {
  margin-top: 0;
}

.scenario-options {
  display: grid;
  gap: 9px;
  margin-top: 20px;
}

.scenario-card {
  display: block;
  cursor: pointer;
}

.scenario-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.scenario-card span {
  display: grid;
  gap: 4px;
  border: 2px solid var(--line);
  border-radius: 11px;
  padding: 13px 15px;
}

.scenario-card input:checked + span {
  border-color: var(--green);
  background: rgba(41, 79, 62, .07);
  box-shadow: 0 0 0 2px rgba(41, 79, 62, .12);
}

.scenario-card input:focus-visible + span {
  outline: 3px solid var(--orange);
  outline-offset: 2px;
}

.scenario-card small {
  color: var(--muted);
}

.scenario-card em {
  color: var(--green);
  font-size: .75rem;
  font-style: normal;
  font-weight: 700;
}

.difficulty-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0 0;
  border: 0;
  padding: 0;
}

.difficulty-options legend {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
}

.difficulty-options label {
  cursor: pointer;
}

.difficulty-options input {
  position: absolute;
  opacity: 0;
}

.difficulty-options span {
  display: grid;
  gap: 3px;
  min-height: 68px;
  border: 2px solid var(--line);
  border-radius: 9px;
  padding: 10px;
}

.difficulty-options input:checked + span {
  border-color: var(--green);
  background: rgba(41, 79, 62, .07);
}

.difficulty-options input:focus-visible + span {
  outline: 3px solid var(--orange);
  outline-offset: 2px;
}

.difficulty-options small {
  color: var(--muted);
  font-size: .68rem;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  padding: 13px 0;
}

.setting-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--green);
}

.small-print {
  color: var(--muted);
  font-size: .86rem;
}

.result {
  text-align: center;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 25px;
}

.result-stats div {
  border-radius: 10px;
  padding: 13px 6px;
  background: #e7e0cc;
}

.result-stats strong,
.result-stats span {
  display: block;
}

.result-stats strong {
  font-size: 1.25rem;
}

.result-stats span {
  color: var(--muted);
  font-size: .68rem;
  text-transform: uppercase;
}

@media (max-width: 900px) {
  .shell {
    padding: 15px;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .side-panel section {
    border-right: 1px solid var(--line);
  }
}

@media (max-width: 600px) {
  .masthead {
    align-items: flex-start;
    gap: 15px;
  }

  .header-actions {
    max-width: 160px;
  }

  .save-status {
    width: 100%;
    text-align: right;
  }

  .dashboard {
    grid-template-columns: repeat(2, 1fr);
  }

  .dashboard div:nth-child(even) {
    border-right: 0;
  }

  .dashboard div {
    border-bottom: 1px solid var(--line);
  }

  .dashboard div {
    display: block;
    padding: 10px 12px;
  }

  .dashboard strong {
    display: block;
    margin-top: 2px;
  }

  .side-panel {
    display: block;
  }

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

  .difficulty-options {
    grid-template-columns: 1fr;
  }

  .map-instructions {
    bottom: 8px;
    padding: 7px 12px;
    font-size: .72rem;
    white-space: normal;
  }

  .high-contrast .map-card {
    outline: 3px solid white;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
