@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;600;700;800&family=Space+Grotesk:wght@600;700&display=swap");

:root {
  --ink: #eee7da;
  --muted: #aaa092;
  --paper: #171612;
  --panel: #24211c;
  --line: #494239;
  --purple: #69d7c7;
  --purple-dark: #2d8e84;
  --lime: #c2dc72;
  --coral: #dc7857;
  --ochre: #d7a15f;
  --sky: #1d2a28;
  --shadow: 0 9px 0 rgba(0, 0, 0, 0.18);
  font-family: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 5% 3%, rgba(154, 116, 63, 0.16), transparent 23rem),
    radial-gradient(circle at 97% 11%, rgba(61, 154, 143, 0.12), transparent 25rem),
    var(--paper);
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.hidden { display: none !important; }

.app-shell { width: min(1500px, 100%); margin: 0 auto; padding: 0 26px 36px; }

.topbar {
  height: 78px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
}

.home-link {
  justify-self: start;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-decoration: none;
}

.home-link:hover { color: var(--purple); }

.brand { display: flex; align-items: center; gap: 10px; text-align: left; }
.brand-face { color: var(--purple); font-family: ui-monospace, monospace; font-size: 1.35rem; font-weight: 800; }
.brand strong { display: block; font-family: "Space Grotesk", sans-serif; font-size: 1.16rem; line-height: 1; }
.brand small { display: block; margin-top: 3px; color: var(--muted); font-size: 0.68rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }

.utility-button {
  justify-self: end;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--muted);
  background: rgba(255,255,255,0.035);
  font-size: 0.74rem;
  font-weight: 800;
  cursor: pointer;
}
.utility-button:hover { border-color: var(--coral); color: var(--ink); }

.resource-dock {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  min-height: 58px;
  margin-bottom: 18px;
  padding: 8px 10px 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: 17px;
  background: rgba(36, 33, 28, 0.94);
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(13px);
}
.resource-dock.expanded { position: relative; top: auto; align-items: flex-start; }

.resource-scroll {
  display: flex;
  flex: 1;
  flex-wrap: nowrap;
  gap: 5px;
  min-width: 0;
  overflow: hidden;
}
.resource-dock.expanded .resource-scroll { flex-wrap: wrap; overflow: visible; }

.resource-pill {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 5px;
  min-width: 76px;
  padding: 7px 9px;
  border-radius: 11px;
  background: #332f28;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  transition: background 180ms, transform 180ms;
}
button.resource-pill { cursor: pointer; }
button.resource-pill:hover { background: #3b3830; }
.resource-pill.bump { background: #40503a; transform: translateY(-2px); }
.resource-pill .emoji { display: grid; width: 24px; height: 24px; flex: 0 0 auto; place-items: center; border-radius: 7px; background: #d8cbb7; font-family: "Apple Color Emoji", "Segoe UI Emoji", sans-serif; font-size: 1.05rem; }
.openmoji-icon { display: inline-block; width: 1.28em; height: 1.28em; object-fit: contain; vertical-align: -.28em; }
.resource-pill .openmoji-icon { width: 21px; height: 21px; vertical-align: middle; }
.objective-icon .openmoji-icon { width: 30px; height: 30px; }
.resource-pill span:last-child { overflow: hidden; }
.resource-pill strong { display: block; font-size: 0.8rem; font-variant-numeric: tabular-nums; line-height: 1; }
.resource-pill small { display: block; max-width: 74px; margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 0.56rem; font-weight: 800; letter-spacing: 0.04em; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }

.resources-toggle { flex: 0 0 auto; margin: 3px 2px 0 8px; border: 1px solid #53635d; border-radius: 999px; padding: 7px 10px; color: #b7e6de; background: #293b37; font-size: .61rem; font-weight: 800; cursor: pointer; }
.resources-toggle:hover { background: #324943; }
.save-state { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.game-grid { display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(410px, 0.92fr); gap: 20px; align-items: start; }
.world-column { display: grid; gap: 20px; min-width: 0; }
.panel { border: 1.5px solid var(--line); border-radius: 24px; background: var(--panel); box-shadow: var(--shadow); }

.ship-card { overflow: hidden; padding: 22px; }
.scene-header, .actions-heading, .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.eyebrow { margin: 0 0 4px; color: var(--ochre); font-size: 0.65rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; }
h1, h2, h3, p { overflow-wrap: anywhere; }
.scene-header h1, .actions-heading h2, .panel-heading h2 { margin: 0; font-family: "Space Grotesk", sans-serif; }
.scene-header h1 { font-size: clamp(1.35rem, 2.5vw, 2rem); }
.ship-score { display: flex; flex-direction: column; flex: 0 0 auto; align-items: flex-end; }
.ship-score strong { color: var(--purple); font-family: "Space Grotesk", sans-serif; font-size: 1.5rem; line-height: 1; }
.ship-score span { margin-top: 4px; color: var(--muted); font-size: 0.61rem; font-weight: 800; text-transform: uppercase; }

.ship-readout {
  margin: 18px 0 16px;
  padding: 15px;
  border: 1.5px solid #4d5148;
  border-radius: 18px;
  background: linear-gradient(145deg, #202d2a, #29251f 65%);
}
.vessel-summary { display: grid; grid-template-columns: 43px minmax(0, 1fr) auto; align-items: center; gap: 11px; padding: 2px 3px 13px; }
.vessel-summary img { width: 40px; height: 40px; }
.vessel-summary small { display: block; color: var(--purple); font-size: .58rem; font-weight: 800; letter-spacing: .13em; }
.vessel-summary strong { display: block; margin-top: 2px; font-family: "Space Grotesk", sans-serif; font-size: .9rem; }
.vessel-summary > span { color: var(--muted); font-size: .65rem; font-weight: 800; }
.ship-systems { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.ship-system { display: grid; grid-template-columns: 28px minmax(0, 1fr); align-items: center; gap: 8px; min-height: 48px; padding: 8px 9px; border-radius: 11px; background: rgba(0,0,0,.18); transition: background 240ms, transform 240ms; }
.ship-system b { display: grid; width: 26px; height: 26px; place-items: center; border-radius: 8px; color: #8f887c; background: #37332d; font: 700 .58rem/1 "Space Grotesk", sans-serif; }
.ship-system strong, .ship-system small { display: block; }
.ship-system strong { overflow: hidden; font-size: .68rem; text-overflow: ellipsis; white-space: nowrap; }
.ship-system small { margin-top: 2px; color: #d58a70; font-size: .56rem; font-weight: 700; }
.ship-system.repaired { background: #35432d; transform: translateY(-1px); }
.ship-system.repaired b { color: #17200f; background: var(--lime); }
.ship-system.repaired small { color: #bad078; }
.ship-system:last-child { grid-column: 1 / -1; }

.era-track { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.era-step { height: 7px; border-radius: 99px; background: #3a352e; transition: background 400ms; }
.era-step.done { background: var(--purple); }
.era-step.current { background: linear-gradient(90deg, var(--purple), var(--lime)); animation: current-era 1.3s ease-in-out infinite alternate; }
.objective-row { display: flex; align-items: flex-start; gap: 12px; margin-top: 14px; padding: 12px 13px; border-radius: 14px; background: #312d27; }
.objective-icon { display: grid; width: 38px; height: 38px; flex: 0 0 auto; place-items: center; border-radius: 10px; background: #d8cbb7; font-family: "Apple Color Emoji", "Segoe UI Emoji", sans-serif; font-size: 1.45rem; }
.objective-row small { display: block; color: var(--muted); font-size: 0.58rem; font-weight: 800; letter-spacing: 0.12em; }
.objective-row strong { display: block; margin-top: 2px; font-size: 0.78rem; }
.objective-detail { flex: 1; min-width: 0; }
.breakthrough-target { display: block; margin-top: 9px; color: var(--ochre); font-size: .55rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.breakthrough-requirements { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.breakthrough-chip { display: inline-flex; align-items: center; gap: 4px; min-height: 25px; padding: 4px 7px; border: 1px solid #554b3f; border-radius: 8px; color: #c9bfb1; background: #29251f; font-size: .56rem; }
.breakthrough-chip .openmoji-icon { width: 15px; height: 15px; }
.breakthrough-chip b { font-weight: 800; }
.breakthrough-chip em { color: #e2a17c; font-style: normal; font-weight: 800; font-variant-numeric: tabular-nums; }
.breakthrough-chip.complete { border-color: #465a3d; color: #cadd9a; background: #2d3928; }
.breakthrough-chip.complete em { color: #bcd27e; }

.lower-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(190px, .75fr); gap: 20px; }
.comms-card, .crew-card { min-height: 208px; padding: 18px; }
.panel-heading h2 { font-size: 1rem; }
.ai-face { color: var(--purple); font: 800 .9rem/1 ui-monospace, monospace; letter-spacing: -.08em; }
.event-log { display: flex; flex-direction: column-reverse; gap: 7px; max-height: 128px; margin: 15px 0 0; padding: 0; overflow: hidden; list-style: none; }
.event-log li { display: grid; grid-template-columns: 38px 1fr; color: #c3baad; font-size: 0.72rem; line-height: 1.35; }
.event-log time { color: #827a70; font-variant-numeric: tabular-nums; font-weight: 700; }
.event-log li:first-child { color: var(--ink); font-weight: 700; }
.crew-face { display: grid; width: 40px; height: 40px; place-items: center; font-family: "Apple Color Emoji", "Segoe UI Emoji", sans-serif; font-size: 2rem; }
.crew-face .openmoji-icon { width: 38px; height: 38px; }
.crew-stats { display: grid; gap: 8px; margin-top: 16px; }
.crew-stat { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 10px; background: #312d27; font-size: 0.72rem; font-weight: 800; }
.crew-stat > span { display: flex; align-items: center; gap: 6px; }
.crew-stat .openmoji-icon { width: 20px; height: 20px; }
.crew-stat strong { color: var(--purple); }
.crew-note { margin: 12px 2px 0; color: var(--muted); font-size: 0.66rem; line-height: 1.4; }

.actions-column { position: relative; min-height: 570px; padding: 20px; overflow: visible; }
.actions-heading h2 { font-size: 1.55rem; }
.queue-count { border-radius: 999px; padding: 6px 9px; color: #aeeae1; background: #293d39; font-size: 0.64rem; font-weight: 800; }
.tabs { display: flex; gap: 6px; margin: 17px -2px 14px; padding: 2px 2px 8px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab-button { flex: 0 0 auto; border: 0; border-radius: 999px; padding: 8px 12px; color: var(--muted); background: #332f29; font-size: 0.68rem; font-weight: 800; cursor: pointer; }
.tab-button:hover { color: var(--ink); }
.tab-button.active { color: #13221f; background: var(--purple); }
.tab-button.new::after { display: inline-block; width: 6px; height: 6px; margin: 0 0 5px 6px; border-radius: 50%; background: var(--coral); content: ""; }
.action-list { display: grid; gap: 10px; padding: 1px 1px 6px; overflow: visible; }

.action-card { display: grid; grid-template-columns: 51px minmax(0, 1fr); gap: 12px; padding: 13px; border: 1.5px solid #484139; border-radius: 17px; background: #29251f; transition: border-color 180ms, transform 180ms, opacity 180ms; }
.action-card:hover { border-color: #6b796f; }
.action-card.locked { opacity: 0.61; }
.action-card.running { border-color: var(--purple); box-shadow: inset 0 0 0 1px rgba(105, 215, 199, .28); }
.action-icon { display: grid; width: 51px; height: 51px; place-items: center; border-radius: 14px; background: #d8cbb7; font-family: "Apple Color Emoji", "Segoe UI Emoji", sans-serif; font-size: 1.55rem; }
.action-icon .openmoji-icon { width: 36px; height: 36px; }
.action-main { min-width: 0; }
.action-top { display: flex; align-items: start; justify-content: space-between; gap: 9px; }
.action-top h3 { margin: 0; font-family: "Space Grotesk", sans-serif; font-size: 0.88rem; line-height: 1.2; }
.action-flavor { margin: 3px 0 0; color: var(--muted); font-size: 0.62rem; line-height: 1.3; }
.action-time { flex: 0 0 auto; color: var(--muted); font-size: 0.61rem; font-weight: 800; }
.recipe-flow { display: flex; flex-wrap: wrap; gap: 4px; min-height: 20px; margin-top: 8px; }
.cost-chip { border-radius: 7px; padding: 3px 6px; color: #c1b8ab; background: #37322b; font-size: 0.59rem; font-weight: 800; }
.cost-chip.missing { color: #f0a18e; background: #4a2924; }
.cost-chip.output { color: #d1e79b; background: #35422d; }
.flow-arrow { align-self: center; color: #776f64; font-size: 0.65rem; }
.progress-track { height: 6px; margin-top: 9px; overflow: hidden; border-radius: 99px; background: #3d3831; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--purple), var(--lime)); transition: width 90ms linear; }
.running .progress-track span { background: repeating-linear-gradient(115deg, var(--purple) 0 10px, #4bb5a8 10px 20px); background-size: 30px 100%; animation: progress-stripes .7s linear infinite; }
.action-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 29px; margin-top: 7px; }
.status-copy { color: var(--muted); font-size: 0.59rem; font-weight: 700; }
.status-copy.ready { color: #bad47a; }
.action-buttons { display: flex; flex: 0 0 auto; gap: 5px; }
.action-button, .mini-button, .secondary-button, .danger-button {
  border: 0;
  border-radius: 9px;
  padding: 7px 11px;
  font-size: 0.65rem;
  font-weight: 800;
  cursor: pointer;
}
.action-button { min-width: 80px; color: #10211e; background: var(--purple); box-shadow: 0 3px 0 var(--purple-dark); }
.action-button:hover:not(:disabled) { transform: translateY(-1px); }
.action-button:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.action-button.stop { color: #281611; background: var(--coral); box-shadow: 0 3px 0 #9e4c37; }
.action-button:disabled, .mini-button:disabled { color: #777066; background: #37332d; box-shadow: none; cursor: not-allowed; }
.mini-button { min-width: 30px; padding-inline: 9px; color: #aee9e0; background: #2e4440; }
.cost-chip .openmoji-icon { width: 15px; height: 15px; }
.gather-assignment { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; padding: 8px 9px; border: 1px solid #464038; border-radius: 10px; background: #211e1a; }
.gather-assignment.active { border-color: #446d65; background: #24312d; }
.gather-assignment.starved { border-color: #805c3e; background: #36291f; }
.gather-assignment.starved .assignment-count { color: #e0ad72; }
.assignment-label { display: flex; align-items: center; gap: 7px; min-width: 0; }
.assignment-label > span { min-width: 0; }
.assignment-label strong, .assignment-label small { display: block; }
.assignment-label strong { font-size: .62rem; }
.assignment-label small { margin-top: 1px; color: var(--muted); font-size: .53rem; }
.assignment-label .emoji-fallback { font-family: "Apple Color Emoji", "Segoe UI Emoji", sans-serif; font-size: 1rem; }
.assignment-controls { display: flex; flex: 0 0 auto; align-items: center; gap: 5px; }
.assignment-count { min-width: 37px; color: #b9e9df; font-size: .61rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }
.empty-state { display: grid; height: 60%; place-content: center; padding: 40px; color: var(--muted); text-align: center; }
.empty-state span { color: var(--purple); font-family: ui-monospace, monospace; font-size: 2.5rem; }
.empty-state strong { margin-top: 10px; color: var(--ink); }
.empty-state p { max-width: 270px; margin: 7px 0 0; font-size: 0.72rem; line-height: 1.5; }

.toast { position: fixed; z-index: 80; right: 24px; bottom: 24px; max-width: min(360px, calc(100vw - 32px)); padding: 12px 16px; border: 1px solid #52645e; border-radius: 12px; color: var(--ink); background: #1e302d; box-shadow: 0 10px 35px rgba(0,0,0,.38); font-size: 0.76rem; font-weight: 800; opacity: 0; pointer-events: none; transform: translateY(14px); transition: 220ms; }
.toast.show { opacity: 1; transform: translateY(0); }

.game-dialog { width: min(470px, calc(100vw - 28px)); max-height: calc(100dvh - 28px); overflow: auto; border: 1px solid var(--line); border-radius: 24px; padding: 28px; color: var(--ink); background: var(--panel); box-shadow: 0 24px 90px rgba(0,0,0,.58); text-align: center; }
.game-dialog::backdrop { background: rgba(8,7,5,.76); backdrop-filter: blur(5px); }
.dialog-icon { margin-bottom: 12px; color: var(--purple); font-family: ui-monospace, "Apple Color Emoji", "Segoe UI Emoji", monospace; font-size: 2.5rem; font-weight: 800; }
.dialog-icon .openmoji-icon { width: 58px; height: 58px; }
.dialog-copy .openmoji-icon { width: 20px; height: 20px; }
.game-dialog h2 { margin: 3px 0 10px; font-family: "Space Grotesk", sans-serif; font-size: 1.7rem; }
.game-dialog p, .dialog-copy { color: var(--muted); font-size: 0.82rem; line-height: 1.55; }
.dialog-copy ul { display: grid; gap: 6px; margin: 14px 0; padding: 0; list-style: none; }
.dialog-copy li { padding: 7px 10px; border-radius: 9px; color: var(--ink); background: #312d27; font-weight: 800; }
.dialog-copy .people-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 16px; text-align: left; }
.people-list li { display: grid; grid-template-columns: 28px minmax(0, 1fr); align-items: center; gap: 7px; min-height: 44px; padding: 7px; }
.people-list li > span { display: grid; width: 27px; height: 27px; place-items: center; border-radius: 8px; color: #2b2114; background: var(--ochre); font: 800 .66rem/1 "Space Grotesk", sans-serif; }
.people-list li.assigned > span { color: #10211e; background: var(--purple); }
.people-list strong, .people-list small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people-list strong { font-size: .65rem; }
.people-list small { margin-top: 2px; color: var(--muted); font-size: .5rem; font-weight: 600; }
.dialog-actions { display: flex; justify-content: center; gap: 8px; margin-top: 20px; }
.dialog-actions .action-button { padding: 10px 18px; }
.secondary-button { color: var(--ink); background: #38433e; }
.danger-button { color: white; background: #b9493c; }

@keyframes progress-stripes { to { background-position: 30px 0; } }
@keyframes current-era { to { filter: brightness(1.2); transform: scaleY(1.3); } }

@media (max-width: 980px) {
  .app-shell { padding-inline: 16px; }
  .game-grid { grid-template-columns: 1fr; }
  .actions-column { min-height: 0; }
}

@media (max-width: 620px) {
  .app-shell { padding: 0 10px 22px; }
  .topbar { height: 64px; grid-template-columns: 38px 1fr 58px; }
  .home-link { font-size: 1.1rem; }
  .home-link span { display: none; }
  .brand { justify-self: center; }
  .brand-face { font-size: 1.05rem; }
  .brand strong { font-size: 1rem; }
  .brand small { font-size: .55rem; }
  .utility-button { padding: 7px 9px; font-size: .6rem; }
  .resource-dock { min-height: 53px; margin-bottom: 10px; border-radius: 14px; }
  .resource-pill { min-width: 67px; padding: 6px 7px; }
  .resource-pill small { max-width: 58px; }
  .resources-toggle { margin-left: 5px; padding-inline: 8px; }
  .save-state { display: none; }
  .game-grid, .world-column { gap: 10px; }
  .panel { border-radius: 18px; box-shadow: 0 5px 0 rgba(0,0,0,.16); }
  .ship-card { padding: 15px; }
  .ship-readout { margin-top: 13px; padding: 11px; }
  .ship-systems { grid-template-columns: 1fr; }
  .ship-system:last-child { grid-column: auto; }
  .scene-header h1 { font-size: 1.24rem; }
  .ship-score strong { font-size: 1.2rem; }
  .objective-row { padding: 10px; }
  .lower-grid { grid-template-columns: 1fr; gap: 10px; }
  .crew-card { min-height: auto; }
  .actions-column { min-height: 0; padding: 15px 12px; }
  .actions-heading { padding-inline: 3px; }
  .actions-heading h2 { font-size: 1.3rem; }
  .tabs { margin-top: 13px; }
  .action-card { grid-template-columns: 43px minmax(0,1fr); gap: 9px; padding: 11px 10px; }
  .action-icon { width: 43px; height: 43px; border-radius: 12px; font-size: 1.3rem; }
  .action-footer { align-items: end; }
  .action-button { min-width: 70px; }
  .toast { right: 16px; bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
