:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --panel: rgba(12, 18, 24, 0.76);
  --panel-strong: rgba(10, 14, 18, 0.9);
  --line: rgba(255, 255, 255, 0.15);
  --text: #f7fbff;
  --muted: #aeb9c5;
  --amber: #f2c94c;
  --green: #50d18d;
  --red: #ff6b6b;
  --cyan: #72d6ff;
}

* {
  box-sizing: border-box;
}

html,
body,
#game {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: #10151a;
  color: var(--text);
  font-size: calc(16px * var(--ui-scale, 1));
}

#game {
  position: relative;
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 3;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(12px);
}

.top-left {
  top: 18px;
  left: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(112px, 1fr));
  gap: 10px;
  padding: 12px;
}

.top-right {
  top: 18px;
  right: 18px;
  width: min(310px, calc(100vw - 36px));
  padding: 14px;
}

#rigHud {
  cursor: pointer;
}

#rigHud:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.bottom-left {
  bottom: 18px;
  left: 18px;
  width: min(430px, calc(100vw - 36px));
  padding: 14px 16px;
}

.bottom-right {
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
}

.controls-panel {
  width: min(150px, calc(100vw - 36px));
  padding: 8px;
}

.controls-panel button {
  min-height: 38px;
}

.top-center-stack {
  position: absolute;
  z-index: 3;
  top: 18px;
  left: 50%;
  width: min(360px, calc(100vw - 36px));
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
}

.top-center-stack .hud {
  position: static;
  padding: 12px 14px;
}

.top-center-stack .projected {
  width: min(330px, calc(100vw - 36px));
  justify-self: center;
}

.top-center-stack .projected strong {
  color: var(--cyan);
}

.readout {
  min-width: 0;
  padding: 9px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.07);
}

.readout.explainer-trigger {
  cursor: pointer;
}

.readout.explainer-trigger:hover,
.readout.explainer-trigger:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  background: rgba(255, 255, 255, 0.12);
}

.readout span,
.meter-label span,
.materials span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.readout strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
}

.meter-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.bar {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.11);
}

.bar span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--green), var(--amber));
  transition: width 160ms ease;
}

.materials {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 12px;
  margin: 12px 0;
}

.materials b {
  color: var(--text);
}

button {
  width: 100%;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 7px;
  background: #e6f5ff;
  color: #10151a;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.42;
}

.bottom-left strong {
  display: block;
  margin-bottom: 5px;
  color: var(--amber);
  font-size: 14px;
}

.bottom-left p {
  margin: 0;
  color: #dce6ee;
  font-size: 14px;
  line-height: 1.45;
}

.compact {
  font-weight: 800;
}

.discovery {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 8;
  width: min(430px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

.discovery.hidden {
  display: none;
}

.discovery h2 {
  margin: 0 0 8px;
  font-size: 24px;
  line-height: 1.1;
}

.discovery p {
  margin: 0 0 12px;
  color: #d6e0e8;
  line-height: 1.45;
}

.discovery #discoveryPause {
  color: var(--amber);
  font-weight: 800;
}

.discovery > div {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.discovery > div.single-action {
  grid-template-columns: 1fr;
}

.discovery > div.landing-options {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.rig-details {
  width: min(720px, calc(100vw - 32px));
}

.discovery > div.rig-columns {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
}

.rig-details fieldset {
  min-width: 0;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.rig-details legend {
  padding: 0 6px;
  color: var(--amber);
  font-weight: 800;
}

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

.choice-list label {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  align-items: start;
  color: #d6e0e8;
  font-size: 13px;
  line-height: 1.3;
}

.choice-list input {
  margin-top: 1px;
  accent-color: var(--cyan);
}

.empty-choice {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.landing-options button:last-child {
  grid-column: 1 / -1;
}

.discovery button:last-child {
  background: #27323b;
  color: var(--text);
}

.modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(2, 6, 9, 0.42);
}

.modal.hidden {
  display: none;
}

.modal > div {
  width: min(560px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.42);
}

.modal h1 {
  margin: 0 0 8px;
  font-size: 34px;
  line-height: 1.05;
  letter-spacing: 0;
}

.modal p {
  margin: 0 0 18px;
  color: #d6e0e8;
  line-height: 1.5;
}

.modal .hidden {
  display: none;
}

.replay-summary {
  margin: 0 0 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.replay-summary h2 {
  margin: 0 0 10px;
  color: var(--amber);
  font-size: 15px;
  line-height: 1.2;
}

.replay-summary dl {
  display: grid;
  grid-template-columns: minmax(130px, 0.8fr) minmax(0, 1.2fr);
  gap: 7px 12px;
  margin: 0;
  color: #d6e0e8;
  font-size: 13px;
  line-height: 1.35;
}

.replay-summary dt {
  color: var(--muted);
  font-weight: 800;
}

.replay-summary dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.reflection-panel {
  margin-bottom: 18px;
}

.reflection-panel h2 {
  margin: 0 0 8px;
  color: var(--amber);
  font-size: 22px;
  line-height: 1.1;
}

.reflection-panel textarea {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font: inherit;
  line-height: 1.45;
}

.reflection-panel textarea:focus {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.reflection-status {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--cyan);
  font-weight: 800;
}

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

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

.result-actions .secondary {
  background: #27323b;
  color: var(--text);
}

.instructions-modal {
  z-index: 12;
}

.settings-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 14px 0 18px;
}

.settings-tabs button {
  min-height: 36px;
  padding: 0 8px;
  background: #27323b;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.settings-tabs button.active {
  background: #e6f5ff;
  color: #10151a;
}

.settings-panel {
  display: none;
  min-height: 156px;
}

.settings-panel.active {
  display: grid;
  gap: 10px;
}

.setting-row,
.toggle-row {
  display: grid;
  grid-template-columns: minmax(145px, 1fr) minmax(170px, 1.1fr) minmax(78px, auto);
  align-items: center;
  gap: 12px;
  color: #d6e0e8;
  font-weight: 800;
}

.setting-row::after {
  content: attr(data-value);
  justify-self: end;
  min-width: 78px;
  color: var(--cyan);
  font-size: 13px;
  text-align: right;
}

.instructions-modal .setting-row input {
  width: 100%;
  height: auto;
}

.toggle-row {
  grid-template-columns: 24px 1fr;
}

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

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

.settings-actions .secondary {
  background: #27323b;
  color: var(--text);
}

.settings-actions .hidden {
  display: none;
}

.instructions-modal .check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 16px;
  color: #d6e0e8;
  font-weight: 700;
}

.instructions-modal .check-row.hidden {
  display: none;
}

.instructions-modal input {
  width: 18px;
  height: 18px;
  accent-color: var(--cyan);
}

.high-contrast {
  --panel: rgba(0, 0, 0, 0.88);
  --panel-strong: rgba(0, 0, 0, 0.96);
  --line: rgba(255, 255, 255, 0.38);
  --muted: #d7e7f5;
}

.colorblind-safe {
  --green: #009e73;
  --red: #d55e00;
  --amber: #f0e442;
  --cyan: #56b4e9;
}

@media (max-width: 760px) {
  .replay-summary dl {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .replay-summary dd {
    margin-bottom: 6px;
  }

  .settings-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .setting-row {
    grid-template-columns: 1fr minmax(76px, auto);
  }

  .setting-row input {
    grid-column: 1 / -1;
    grid-row: 2;
  }

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

  .top-left {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    right: 10px;
    left: 10px;
    top: 10px;
    gap: 6px;
    padding: 8px;
  }

  .top-right {
    top: auto;
    right: 10px;
    bottom: 70px;
    width: calc(100vw - 20px);
  }

  .bottom-left {
    display: none;
  }

  .bottom-right {
    right: 10px;
    bottom: 10px;
    left: 10px;
    max-width: none;
  }

  .discovery > div.rig-columns {
    grid-template-columns: 1fr;
  }

  .readout {
    padding: 7px 6px;
  }

  .readout span {
    font-size: 9px;
  }

  .readout strong {
    font-size: clamp(12px, 3.4vw, 17px);
  }
}
