:root {
  --bg: #05070c;
  --panel: #070b14;
  --panel-2: #0a1020;
  --fg: #c8c8d0;
  --hi: #ffe566;
  --dim: #6a6a7a;
  --cyan: #5ce1e6;
  --red: #ff6b6b;
  --green: #6dff9a;
  --blue: #5b7cff;
  --border: #2a3a6a;
  --border-soft: #1a2440;
  --font: "IBM Plex Mono", "Source Code Pro", "DejaVu Sans Mono", "Consolas", ui-monospace, monospace;
  --radius: 2px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 13px;
  overflow: hidden;
  user-select: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button, input, select, textarea, .look, .log, .panel { user-select: text; }

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  background:
    radial-gradient(ellipse 90% 70% at 50% 35%, #0b1630 0%, #05070c 62%),
    linear-gradient(180deg, #081018, #030508);
}

#topbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: linear-gradient(180deg, #0c1833, #081022);
  color: var(--hi);
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.02em;
  min-width: 0;
}

.topbar-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 0 12px;
  min-width: 0;
}

#topbar .brand {
  color: var(--cyan);
  font-weight: 600;
  letter-spacing: 0.08em;
  flex-shrink: 0;
}

#topbar .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

#bottom {
  display: flex;
  align-items: center;
  gap: 8px 12px;
  background: #081022;
  border-top: 1px solid var(--border);
  color: var(--cyan);
  font-size: 12px;
  padding: 4px 10px;
  min-width: 0;
  flex-wrap: wrap;
  min-height: 34px;
}

#commands-host {
  flex: 2 1 280px;
  min-width: 0;
  display: flex;
  justify-content: flex-end;
}

#toolbar-host:empty,
#commands-host:empty,
#toolbar-host:not(:has(.toolbar:not(.hidden))) { display: none; }

#bottom .hint-line {
  flex: 1 1 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #8adfe3;
}

#main {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 280px;
  min-height: 0;
}

#left, #right {
  padding: 10px 12px;
  overflow: auto;
  background: var(--panel);
  scrollbar-width: thin;
  scrollbar-color: #2a3a6a transparent;
}

#left { border-right: 1px solid var(--border-soft); }
#right { border-left: 1px solid var(--border-soft); }

#stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  position: relative;
  background:
    radial-gradient(ellipse at center, #000812 0%, #000000 75%);
  overflow: hidden;
}

#stage::before {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,0.45) 100%);
  z-index: 2;
}

#stage::after {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.08) 0px,
    rgba(0, 0, 0, 0.08) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 2;
  mix-blend-mode: multiply;
}

#view {
  image-rendering: pixelated;
  cursor: crosshair;
  box-shadow: 0 0 0 1px #1a2a4a, 0 12px 48px rgba(0, 40, 90, 0.35);
  position: relative;
  z-index: 1;
  outline: none;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
}

#view.is-panning { cursor: grabbing; }
#view.is-chart { cursor: grab; }
#view.is-chart.is-panning { cursor: grabbing; }

#view:focus {
  box-shadow: 0 0 0 1px var(--cyan), 0 12px 48px rgba(0, 80, 120, 0.4);
}

#left h3, #right h3 {
  margin: 12px 0 6px;
  color: var(--hi);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 4px;
}

#left h3:first-child, #right h3:first-child { margin-top: 0; }

#left ul, #right ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

#left li, #right li { margin: 2px 0; }

.squad-item, .island-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.squad-item:hover, .island-item:hover {
  background: #0e1a30;
  border-color: #243656;
}

.squad-item.sel, .island-item.sel {
  color: var(--cyan);
  background: #0a2230;
  border-color: #2a6a7a;
}

.squad-item .idx {
  color: var(--dim);
  width: 1.2em;
  flex-shrink: 0;
}

.squad-item.sel .idx { color: var(--hi); }

.warn { color: var(--red); }
.ok { color: var(--green); }

.look {
  white-space: pre-wrap;
  color: var(--green);
  font-size: 12px;
  line-height: 1.4;
  background: #06140c;
  border: 1px solid #1a3a28;
  padding: 8px;
  border-radius: var(--radius);
}

.log {
  font-size: 11px;
  line-height: 1.4;
  max-height: 200px;
  overflow: auto;
}

.log li { padding: 2px 0; border-bottom: 1px solid #101828; }

.legend {
  color: #9aa0b0;
  font-size: 11px;
  line-height: 1.45;
  background: #080c16;
  padding: 8px;
  border: 1px solid var(--border-soft);
}

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  background: #0a1428;
  border: 1px solid #1e2e50;
  padding: 2px 7px;
  border-radius: var(--radius);
  font-size: 11px;
  white-space: nowrap;
}

.chip-l { color: var(--dim); }
.chip-v { color: var(--fg); }
.chip.warn .chip-v { color: var(--red); }
.chip.ok .chip-v { color: var(--green); }
.chip.hi .chip-v { color: var(--hi); }
.chip.cyan .chip-v { color: var(--cyan); }

.omen { color: var(--hi); }
.relic-line { color: var(--cyan); }
.voyage-panel .menu button { white-space: normal; text-align: left; line-height: 1.35; }

.hpbar {
  display: inline-block;
  width: 72px;
  height: 7px;
  background: #1a1020;
  border: 1px solid #3a2040;
  vertical-align: middle;
  position: relative;
}
.hp-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #aa3030, #ff5555);
}
.hpnum { color: var(--dim); font-size: 11px; }

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 4, 10, 0.78);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: max(12px, 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));
}

#overlay.hidden { display: none; }

.panel {
  background: linear-gradient(180deg, #0a1230, #060a18);
  border: 1px solid var(--cyan);
  box-shadow: 0 0 0 1px #000, 0 20px 60px rgba(0, 0, 0, 0.55), 0 0 28px rgba(0, 180, 200, 0.12);
  max-width: 860px;
  max-height: 90vh;
  overflow: auto;
  padding: 24px 30px 26px;
  color: var(--fg);
  animation: panel-in 0.18s ease-out;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.title-panel { max-width: 980px; }

.setup-panel, .finale-panel, .settings-panel { max-width: 760px; }

.choice-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 14px;
}

.choice, .menu.works button {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  white-space: normal;
  text-align: left;
}

.choice.on, button.primary {
  border-color: var(--hi);
  background: #1a3058;
  color: #fff;
}

.forecast {
  list-style: none;
  margin: 4px 0 8px;
  padding: 0;
  color: var(--hi);
}
.forecast li { line-height: 1.45; }

.ledger {
  margin: 8px 0 16px;
  padding-left: 1.2em;
  color: var(--fg);
  line-height: 1.55;
}

body.reduce-motion .panel { animation: none; }

.ascii-logo {
  color: var(--hi);
  font-size: clamp(5px, 0.85vw, 9px);
  line-height: 1.05;
  overflow: hidden;
  margin: 0 0 10px;
  text-shadow: 0 0 18px rgba(255, 220, 80, 0.25);
}

.sub {
  color: var(--cyan);
  letter-spacing: 0.35em;
  font-size: 12px;
  margin-bottom: 10px;
}

.flavor { color: #a0a8e0; margin: 8px 0 16px; line-height: 1.5; }

.menu { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }

button, select, input {
  font-family: var(--font);
  font-size: 13px;
  background: #0a1840;
  color: var(--hi);
  border: 1px solid #3a4a8a;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  touch-action: manipulation;
}

button:hover:not(:disabled) {
  background: #123060;
  color: #ffffff;
  border-color: var(--cyan);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button:focus-visible, .squad-item:focus-visible, #view:focus-visible {
  outline: 1px solid var(--cyan);
  outline-offset: 2px;
}

.menu button {
  text-align: left;
  display: flex;
  gap: 10px;
  align-items: center;
}

.menu button kbd, .panel kbd, kbd {
  display: inline-block;
  min-width: 1.4em;
  text-align: center;
  padding: 1px 5px;
  border: 1px solid #4a5a9a;
  background: #101830;
  color: var(--cyan);
  border-radius: 2px;
  font-size: 11px;
  box-shadow: 0 1px 0 #000;
}

.hint { color: var(--dim); font-size: 12px; line-height: 1.45; }

.preview-panel .mini {
  color: #6dff9a;
  font-size: 9px;
  line-height: 1.05;
  background: #041008;
  border: 1px solid #1a3a28;
  padding: 10px;
  overflow: auto;
  max-height: 240px;
}

.help-panel { max-width: 780px; }
.help-panel h3 { color: var(--hi); margin: 14px 0 6px; }
.keys {
  color: #6dff9a;
  font-size: 12px;
  background: #041008;
  border: 1px solid #1a3a28;
  padding: 10px;
  overflow: auto;
}

label { display: block; margin: 6px 0; color: #aaaaaa; }
label input, label select { width: 100%; margin-top: 3px; }

/* sandbox strip sits in the header, not over the island */
#sandbox-tools {
  display: none;
  position: relative;
  top: auto;
  left: auto;
  transform: none;
  z-index: 4;
  background: rgba(6, 10, 22, 0.96);
  border: none;
  border-top: 1px solid var(--border-soft);
  padding: 5px 10px;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  max-width: none;
  width: 100%;
  box-shadow: none;
  justify-content: center;
}

#sandbox-tools.visible { display: flex; }
#sandbox-tools input, #sandbox-tools select { width: auto; padding: 4px 6px; }
#sandbox-tools span { color: var(--hi); letter-spacing: 0.08em; font-size: 11px; }

/* floating chrome */
#ui-chrome { pointer-events: none; }
#ui-chrome .toolbar,
#ui-chrome .commands,
#ui-chrome .toast,
#ui-chrome .tooltip { pointer-events: auto; }

.toolbar {
  position: relative;
  top: auto;
  left: auto;
  transform: none;
  z-index: 4;
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
  background: rgba(6, 10, 22, 0.96);
  border: none;
  border-top: 1px solid var(--border-soft);
  padding: 5px 8px;
  box-shadow: none;
}

.toolbar.hidden, .commands.hidden, .tooltip.hidden { display: none !important; }

.tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  font-size: 12px;
  background: #0a1840;
  border: 1px solid #334878;
  color: var(--fg);
}

.tb-btn span { color: var(--fg); }
.tb-btn:hover:not(:disabled) { border-color: var(--cyan); }
.tb-btn.active {
  background: #123a50;
  border-color: var(--cyan);
  color: var(--cyan);
}
.tb-btn.primary {
  background: #1a3a20;
  border-color: #3a8a50;
  color: var(--green);
}
.tb-btn.danger {
  background: #2a1018;
  border-color: #8a3040;
  color: var(--red);
}
.tb-sep {
  width: 1px;
  height: 18px;
  background: #2a3a5a;
  margin: 0 2px;
}

.commands {
  position: relative;
  bottom: auto;
  left: auto;
  transform: none;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  max-width: none;
  width: 100%;
  background: transparent;
  border: none;
  padding: 2px 0;
}

.cmd-btn {
  font-size: 11px;
  padding: 4px 8px;
  color: #b0c0d8;
  background: #0a1428;
  border: 1px solid #243456;
}

.cmd-btn.active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: #0a2230;
}

.cmd-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.toasts {
  position: fixed;
  top: 52px;
  right: 16px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(320px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  background: #0c1830;
  border: 1px solid #3a5a8a;
  color: var(--fg);
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.4;
  opacity: 0;
  transform: translateX(12px);
  transition: opacity 0.22s, transform 0.22s;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}

.toast.show { opacity: 1; transform: none; }
.toast-ok { border-color: #3a8a50; color: var(--green); }
.toast-warn { border-color: #8a6a20; color: var(--hi); }
.toast-bad { border-color: #8a3040; color: var(--red); }

.tooltip {
  position: fixed;
  z-index: 55;
  max-width: 260px;
  background: rgba(6, 10, 20, 0.96);
  border: 1px solid #3a5a8a;
  color: var(--fg);
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.4;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.tooltip .tt-title { color: var(--hi); margin-bottom: 3px; }
.tooltip .tt-sub { color: #8a9ab8; }

.phase-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
  color: var(--hi);
  letter-spacing: 0.2em;
  font-size: 12px;
  background: rgba(0,0,0,0.55);
  border: 1px solid #4a4a20;
  padding: 4px 12px;
}

.phase-banner.hidden { display: none !important; }

.menu.row { flex-direction: row; flex-wrap: wrap; }

.pause-panel, .save-panel, .confirm-panel { max-width: 520px; }

.slot-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}

.slot-btn {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  background: #0a1428;
  border: 1px solid #2a3a60;
  color: var(--fg);
}

.slot-btn:hover:not(:disabled) {
  border-color: var(--cyan);
  background: #102040;
}

.slot-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.slot-name {
  color: var(--hi);
  font-weight: 600;
  letter-spacing: 0.06em;
}

.slot-meta {
  color: #8a9ab8;
  font-size: 11px;
}

.slot-empty {
  color: var(--dim);
  font-size: 12px;
}

button.danger-outline {
  border-color: #8a3040;
  color: var(--red);
  background: #1a0810;
}

.phase-banner.paused {
  border-color: #8a6a20;
  color: var(--hi);
}

#dock {
  display: none;
}

#dock.under-overlay { display: none !important; }

#sheet-scrim {
  position: fixed;
  inset: 0;
  background: rgba(2, 4, 10, 0.55);
  z-index: 33;
}

.is-compact #sheet-scrim {
  bottom: calc(56px + env(safe-area-inset-bottom));
}

#sheet-scrim.hidden { display: none; }

@media (max-width: 1100px) {
  #main { grid-template-columns: 220px minmax(0, 1fr) 230px; }
}

@media (max-width: 900px) {
  #main { grid-template-columns: 0 1fr 0; }
  #left, #right { display: none; }
  .ascii-logo { font-size: 5px; }
}

/* compact / touch (class set by GS.util.device.apply) */
.is-compact #app {
  grid-template-rows: auto minmax(0, 1fr);
}

.is-compact .topbar-main {
  min-height: 40px;
  padding: 0 10px;
}

.is-compact #topbar {
  padding: 0;
  gap: 0;
}

.is-compact #topbar .brand { font-size: 12px; letter-spacing: 0.04em; }
.is-compact #topbar .chips { gap: 4px; max-height: 36px; }
.is-compact .chip { font-size: 10px; padding: 2px 5px; }

.is-compact #main {
  grid-template-columns: minmax(0, 1fr);
}

.is-compact #left,
.is-compact #right {
  display: block;
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(56px + env(safe-area-inset-bottom));
  top: auto;
  width: 100%;
  height: min(52vh, 400px);
  z-index: 35;
  transform: translateY(120%);
  transition: transform 0.2s ease-out;
  border-radius: 14px 14px 0 0;
  border: 1px solid var(--border);
  padding: 14px;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
  -webkit-overflow-scrolling: touch;
}

.is-compact #left.open,
.is-compact #right.open {
  transform: translateY(0);
}

.is-compact #dock {
  display: flex;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 36;
  gap: 6px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(8, 16, 34, 0.92), #081022);
  border-top: 1px solid var(--border);
  pointer-events: auto;
}

.is-compact #dock button {
  flex: 1;
  min-height: 44px;
  padding: 8px 6px;
  font-size: 12px;
  justify-content: center;
}

.is-compact #stage {
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.is-compact.has-cmd-strip #stage {
  padding-bottom: calc(156px + env(safe-area-inset-bottom));
}

.is-compact #toolbar-host { display: none !important; }

.is-compact #bottom {
  display: flex;
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(56px + env(safe-area-inset-bottom));
  z-index: 31;
  min-height: 44px;
  padding: 4px 6px;
  background: linear-gradient(180deg, rgba(8, 16, 34, 0.94), #081022);
  border-top: 1px solid var(--border);
}

.is-compact #bottom:has(.commands.hidden) { display: none; }

.is-compact .hint-line { display: none; }

.is-compact #commands-host { display: flex; width: 100%; justify-content: flex-start; }

.is-compact .toolbar {
  display: none;
}

.is-compact .commands {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  justify-content: flex-start;
  -webkit-overflow-scrolling: touch;
  gap: 6px;
  padding: 0;
  scrollbar-width: thin;
}

.is-compact .cmd-btn,
.is-compact .tb-btn {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 8px 10px;
  font-size: 12px;
}

.is-compact .toasts {
  top: 50px;
  right: 8px;
  left: 8px;
  width: auto;
}

.is-compact .phase-banner {
  top: 8px;
  font-size: 11px;
  letter-spacing: 0.08em;
  max-width: calc(100% - 24px);
  text-align: center;
}

.is-compact #sandbox-tools,
.is-compact #sandbox-tools.visible {
  display: none !important;
}

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.sheet-actions button {
  flex: 1;
  min-width: 72px;
  min-height: 40px;
  justify-content: center;
}

button.primary {
  border-color: var(--cyan);
  background: #102848;
  color: var(--hi);
}
.is-compact .panel {
  max-width: 100%;
  width: 100%;
  max-height: calc(100dvh - 24px);
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  margin: 0;
}

.is-compact .title-panel .ascii-logo {
  display: none;
}

.is-compact .menu button {
  min-height: 48px;
  font-size: 15px;
}

.is-compact .squad-item, .is-compact .island-item {
  min-height: 44px;
  padding: 10px 10px;
}

.is-touch kbd { display: none; }

.low-fx #stage::after,
.low-fx #stage::before {
  display: none;
}

.low-fx #overlay {
  backdrop-filter: none;
}

@media (max-height: 500px) and (orientation: landscape) {
  .is-compact #app { grid-template-rows: auto minmax(0, 1fr); }
  .is-compact #stage {
    padding-bottom: 8px;
    padding-right: 80px;
  }
  .is-compact.has-cmd-strip #stage {
    padding-bottom: 52px;
    padding-right: 80px;
  }
  .is-compact #bottom {
    left: 0;
    right: 72px;
    bottom: 0;
  }
  .is-compact #dock {
    left: auto;
    right: 0;
    top: 32px;
    bottom: 0;
    width: 72px;
    flex-direction: column;
    border-top: none;
    border-left: 1px solid var(--border);
    padding: 6px;
  }
  .is-compact #left, .is-compact #right {
    height: calc(100dvh - 40px);
    width: min(70vw, 360px);
    left: auto;
    right: 72px;
    border-radius: 12px 0 0 0;
  }
  .is-compact #sheet-scrim {
    bottom: 0;
    right: 72px;
  }
}
