:root {
  --panel: rgba(14, 22, 36, 0.8);
  --panel-solid: #121c2c;
  --panel-hi: rgba(28, 42, 64, 0.9);
  --line: rgba(255, 255, 255, 0.08);
  --line-hi: rgba(255, 255, 255, 0.16);
  --text: #e9eff6;
  --muted: #93a3b8;
  --dim: #66768c;
  --amber: #f2c14e;
  --cyan: #5ccfe0;
  --good: #6fdc8c;
  --bad: #ff6b5e;
  --warn: #f0a43a;
  --violet: #b892f0;
  --radius: 12px;
  --font: 'Outfit', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1d4f82; }
body { font-family: var(--font); color: var(--text); font-size: 13px; user-select: none; -webkit-font-smoothing: antialiased; }
canvas#view { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; cursor: default; }
canvas#view.tool { cursor: crosshair; }
canvas#view.panning { cursor: grabbing; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
/* Overlays that only show information must never catch the mouse. */
#hud > .toasts, #hud > .banner, #hud > .tooltip, #hud > .hint { pointer-events: none; }

.glass {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

/* ------------------------------------------------------------ top bar */

#topbar {
  position: absolute; left: 12px; right: 12px; top: 10px;
  display: flex; align-items: center; gap: 14px;
  padding: 8px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  backdrop-filter: blur(12px) saturate(1.2); -webkit-backdrop-filter: blur(12px) saturate(1.2);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding-right: 12px; border-right: 1px solid var(--line); }
.logo { font-weight: 700; letter-spacing: 0.24em; font-size: 15px; background: linear-gradient(90deg, #ffe3a0, #8ee6f2); -webkit-background-clip: text; background-clip: text; color: transparent; }
.loop-tag { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }
.date-box { min-width: 170px; }
.date { font-weight: 600; font-size: 14px; }
.stormbar { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); margin: 5px 0 3px; overflow: hidden; }
.stormfill { height: 100%; width: 0; background: linear-gradient(90deg, #6fdc8c, #f2c14e 60%, #ff6b5e); border-radius: 3px; transition: width 0.4s; }
.storm-text { font-size: 11px; color: var(--muted); }

.stats { display: flex; gap: 6px; flex: 1; justify-content: center; flex-wrap: wrap; }
.stat {
  display: flex; align-items: center; gap: 8px; padding: 5px 10px 5px 8px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); border-radius: 10px; min-width: 96px;
  cursor: default;
}
.stat:hover { background: rgba(255, 255, 255, 0.07); border-color: var(--line-hi); }
.stat svg { width: 18px; height: 18px; flex: none; }
.stat .v { font-weight: 600; font-size: 14px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 10.5px; color: var(--muted); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .s.good { color: var(--good); }
.stat .s.bad { color: var(--bad); }
.stat .meter { height: 3px; border-radius: 2px; background: rgba(255, 255, 255, 0.08); margin-top: 3px; width: 64px; overflow: hidden; }
.stat .meter i { display: block; height: 100%; border-radius: 2px; }

.speed { display: flex; gap: 4px; }
.btn {
  font-family: inherit; font-size: 12px; color: var(--text);
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-radius: 9px;
  padding: 6px 10px; cursor: pointer; transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.btn:hover { background: rgba(255, 255, 255, 0.1); border-color: var(--line-hi); }
.btn:active { transform: translateY(1px); }
.btn.on { background: rgba(242, 193, 78, 0.18); border-color: rgba(242, 193, 78, 0.55); color: #ffe7ad; }
.btn.primary { background: linear-gradient(180deg, #f6cd63, #e0a838); color: #2a1d05; border-color: #f6d27a; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { border-color: rgba(255, 107, 94, 0.45); color: #ffb3ab; }
.btn.danger:hover { background: rgba(255, 107, 94, 0.15); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.speed .btn { width: 34px; padding: 6px 0; text-align: center; }
.speed .btn svg { width: 12px; height: 12px; vertical-align: -1px; }

/* ------------------------------------------------------------ stock strip */

.stock {
  position: absolute; top: 74px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px; padding: 5px 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 11px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.res { display: flex; align-items: center; gap: 6px; padding: 3px 9px 3px 6px; border-radius: 8px; cursor: default; }
.res:hover { background: rgba(255, 255, 255, 0.06); }
.res .ricon { width: 22px; height: 22px; flex: none; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0.05) 55%, transparent 72%); filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35)); }
img.ri { vertical-align: -3px; margin-right: 3px; }
.res .n { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 26px; }
.res .r { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.res .r.good { color: var(--good); }
.res .r.bad { color: var(--bad); }
.res.locked { display: none; }

/* ------------------------------------------------------------ side and goals */

.side {
  position: absolute; left: 12px; top: 84px;
  display: flex; flex-direction: column; gap: 6px; padding: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.side .btn { display: flex; align-items: center; gap: 8px; text-align: left; min-width: 132px; }
.side .btn svg { width: 15px; height: 15px; flex: none; opacity: 0.9; }
.side .sep { height: 1px; background: var(--line); margin: 2px 0; }
.side .label { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); padding: 2px 2px 0; }
.side .badge { margin-left: auto; font-size: 10px; background: var(--amber); color: #2a1d05; border-radius: 8px; padding: 0 6px; font-weight: 700; }

.goals {
  position: absolute; left: 12px; bottom: 150px; width: 260px;
  padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.goals h4 { margin: 0 0 6px; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--amber); font-weight: 600; display: flex; justify-content: space-between; }
.goals h4 span { color: var(--dim); cursor: pointer; letter-spacing: 0; text-transform: none; font-size: 11px; }
.goals .g { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; line-height: 1.35; color: #d3dce8; }
.goals .g i { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); margin-top: 6px; flex: none; box-shadow: 0 0 6px var(--amber); }
.goals.min .g { display: none; }

/* ------------------------------------------------------------ build bar */

.build {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  width: 800px; max-width: calc(100vw - 24px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.tabs { display: flex; gap: 2px; padding: 6px 8px 0; }
.tab { font-family: inherit; font-size: 12px; color: var(--muted); background: none; border: 0; padding: 6px 12px; border-radius: 8px 8px 0 0; cursor: pointer; letter-spacing: 0.03em; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); background: rgba(255, 255, 255, 0.06); box-shadow: inset 0 2px 0 var(--amber); }
.items { display: flex; gap: 6px; padding: 8px; background: rgba(255, 255, 255, 0.03); border-top: 1px solid var(--line); border-radius: 0 0 14px 14px; overflow-x: auto; }
.item {
  position: relative; width: 92px; flex: none; padding: 6px 6px 7px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; background: rgba(255, 255, 255, 0.03); text-align: center;
  transition: background 0.12s, border-color 0.12s, transform 0.12s;
}
.item:hover { background: rgba(255, 255, 255, 0.08); border-color: var(--line-hi); transform: translateY(-2px); }
.item.on { background: rgba(242, 193, 78, 0.14); border-color: rgba(242, 193, 78, 0.6); }
.item .pic { height: 52px; display: flex; align-items: flex-end; justify-content: center; }
.item .pic img { max-height: 52px; max-width: 80px; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.35)); }
.item .pic svg { width: 40px; height: 40px; margin-bottom: 6px; }
.item .nm { font-size: 11.5px; font-weight: 500; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .cost { font-size: 10.5px; color: var(--amber); font-variant-numeric: tabular-nums; }
.item .cost.cant { color: var(--bad); }
.item.locked { opacity: 0.42; }
.item.locked .cost { color: var(--muted); }
.item .key { position: absolute; top: 4px; left: 6px; font-size: 9.5px; color: var(--dim); }

/* ------------------------------------------------------------ info panel */

.info {
  position: absolute; right: 12px; top: 84px; width: 290px; max-height: calc(100vh - 250px); overflow-y: auto;
  padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.info h3 { margin: 0; font-size: 16px; font-weight: 600; }
.info .sub { color: var(--muted); font-size: 12px; margin: 2px 0 10px; }
.info .close { position: absolute; right: 10px; top: 8px; background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
.info .close:hover { color: var(--text); }
.info .row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; border-bottom: 1px dashed rgba(255, 255, 255, 0.05); gap: 8px; }
.info .row span:first-child { color: var(--muted); }
.info .row b { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.info .bar { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); overflow: hidden; margin: 4px 0 10px; }
.info .bar i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, #6fdc8c, #a6f0b8); transition: width 0.3s; }
.info .status { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; margin-bottom: 8px; }
.info .status.ok { background: rgba(111, 220, 140, 0.15); color: var(--good); }
.info .status.warn { background: rgba(240, 164, 58, 0.15); color: var(--warn); }
.info .status.bad { background: rgba(255, 107, 94, 0.15); color: var(--bad); }
.info .actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.info .desc { color: #c2cddb; line-height: 1.45; margin: 8px 0 4px; font-size: 12px; }
.info .need { display: grid; grid-template-columns: 80px 1fr 38px; align-items: center; gap: 8px; padding: 3px 0; font-size: 12px; }
.info .need .bar { margin: 0; }
.info .need b { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; color: var(--muted); }
.info .section { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); margin: 12px 0 4px; }

/* ------------------------------------------------------------ toasts, banner, tooltip */

.toasts { position: absolute; right: 12px; bottom: 150px; display: flex; flex-direction: column-reverse; gap: 6px; width: 300px; pointer-events: none; }
.toast {
  padding: 9px 12px; border-radius: 10px; background: var(--panel-hi); border: 1px solid var(--line);
  border-left: 3px solid var(--cyan); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  animation: toastIn 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.toast b { display: block; font-weight: 600; margin-bottom: 1px; }
.toast span { color: #c2cddb; font-size: 12px; line-height: 1.4; }
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }
.toast.event { border-left-color: var(--amber); }
.toast.out { opacity: 0; transform: translateX(20px); transition: all 0.4s; }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }

.banner {
  position: absolute; left: 50%; top: 26%; transform: translate(-50%, -50%); text-align: center; pointer-events: none;
  opacity: 0; transition: opacity 0.6s;
}
.banner.show { opacity: 1; }
.banner .t { font-size: 34px; font-weight: 700; letter-spacing: 0.06em; text-shadow: 0 4px 24px rgba(0, 0, 0, 0.6); }
.banner .d { font-size: 15px; color: #dbe6f2; margin-top: 4px; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7); max-width: 520px; }

.tooltip {
  position: fixed; z-index: 30; pointer-events: none; max-width: 300px;
  padding: 10px 12px; border-radius: 10px; background: rgba(10, 16, 28, 0.96); border: 1px solid var(--line-hi);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); font-size: 12px; line-height: 1.45; color: #d4deea;
  opacity: 0; transition: opacity 0.12s;
}
.tooltip.show { opacity: 1; }
.tooltip h5 { margin: 0 0 4px; font-size: 13px; color: var(--text); font-weight: 600; }
.tooltip .tr { display: flex; justify-content: space-between; gap: 16px; }
.tooltip .tr b { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); }
.tooltip .mut { color: var(--muted); }
.tooltip .warn { color: var(--warn); }
.tooltip hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

.hint {
  position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%);
  padding: 6px 12px; border-radius: 9px; background: rgba(10, 16, 28, 0.85); border: 1px solid var(--line);
  font-size: 12px; color: #d4deea; pointer-events: none; opacity: 0; transition: opacity 0.15s; white-space: nowrap;
}
.hint.show { opacity: 1; }
.hint.bad { color: #ffb3ab; }

/* ------------------------------------------------------------ modals */

.modal-wrap {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(10, 18, 34, 0.55), rgba(5, 10, 20, 0.85));
  animation: fadeIn 0.3s;
}
.modal-wrap[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: min(860px, calc(100vw - 40px)); max-height: calc(100vh - 60px); overflow-y: auto;
  padding: 26px 28px; border-radius: 18px; background: rgba(16, 25, 40, 0.97); border: 1px solid var(--line-hi);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5); animation: popIn 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
@keyframes popIn { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal h2 { margin: 0 0 4px; font-size: 24px; font-weight: 700; letter-spacing: 0.01em; }
.modal .lede { color: #c2cddb; line-height: 1.55; font-size: 14px; margin: 6px 0 16px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; align-items: center; }
.modal .foot .grow { flex: 1; color: var(--muted); font-size: 12px; }
.modal .btn { padding: 9px 16px; font-size: 13px; }
.modal .kicker { font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--amber); margin-bottom: 4px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.card {
  padding: 12px 14px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px;
}
.card h4 { margin: 0; font-size: 14px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card p { margin: 0; color: #b8c4d3; font-size: 12px; line-height: 1.45; flex: 1; }
.card .foot2 { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.card .price { font-weight: 600; color: var(--cyan); font-variant-numeric: tabular-nums; }
.card.done { border-color: rgba(111, 220, 140, 0.35); background: rgba(111, 220, 140, 0.07); }
.card.locked { opacity: 0.5; }
.card .pips { display: flex; gap: 3px; }
.card .pips i { width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, 0.12); }
.card .pips i.on { background: var(--cyan); box-shadow: 0 0 6px var(--cyan); }
.card .tagline { font-size: 11px; color: var(--muted); }

.echo-count { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; color: var(--cyan); font-size: 18px; }
.ledger { margin: 10px 0; border-top: 1px solid var(--line); }
.ledger .row { display: flex; justify-content: space-between; padding: 7px 2px; border-bottom: 1px solid var(--line); font-size: 13px; }
.ledger .row b { color: var(--cyan); font-variant-numeric: tabular-nums; }
.ledger .row.neg b { color: var(--bad); }
.ledger .row.total { font-weight: 700; font-size: 15px; border-bottom: 0; }

.almanac .ev { display: grid; grid-template-columns: 90px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.almanac .ev .when { color: var(--amber); font-weight: 600; font-variant-numeric: tabular-nums; }
.almanac .ev.past .when { color: var(--dim); }
.almanac .ev.unknown .when, .almanac .ev.unknown .what { color: var(--dim); font-style: italic; }
.almanac .ev .what b { display: block; margin-bottom: 2px; }
.almanac .ev .what span { color: #b8c4d3; font-size: 12.5px; }
.almanac .ev.now { background: rgba(242, 193, 78, 0.06); }

.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.help-cols h4 { margin: 10px 0 4px; color: var(--amber); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; }
.help-cols p, .help-cols li { color: #c2cddb; line-height: 1.5; font-size: 13px; }
.help-cols ul { padding-left: 18px; margin: 4px 0; }
kbd { font-family: inherit; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line-hi); }

.chart { width: 100%; height: 120px; display: block; margin-top: 6px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1250px) {
  .stat { min-width: 0; }
  .stat .meter { width: 46px; }
  .goals { display: none; }
}
@media (max-width: 1000px) {
  .date-box { min-width: 130px; }
  .stat .s { display: none; }
  .side .btn span { display: none; }
  .side .btn { min-width: 0; }
  .side .label { display: none; }
}

/* ------------------------------------------------------------ knowledge tree */

.tree-stats { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 6px; }
.tree-stats > div { flex: 1; min-width: 150px; padding: 8px 12px; border-radius: 10px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.tree-stats .k { font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
.tree-stats b { font-size: 18px; color: var(--cyan); font-variant-numeric: tabular-nums; }
svg.tree { width: 100%; height: auto; display: block; margin: 4px 0; }
svg.tree .branch { font: 600 10px var(--font); letter-spacing: 0.14em; opacity: 0.75; }
svg.tree .edge { fill: none; stroke: rgba(255, 255, 255, 0.12); stroke-width: 2; }
svg.tree .edge.lit { stroke-width: 2.5; opacity: 0.85; }
svg.tree .root { fill: #e9eff6; filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.6)); }
svg.tree .node { cursor: pointer; }
svg.tree .node .disc { fill: #1a2638; stroke: rgba(255, 255, 255, 0.18); stroke-width: 2; transition: stroke-width 0.15s; }
svg.tree .node.open .disc { stroke: var(--c); stroke-dasharray: 4 3; }
svg.tree .node.can .disc { stroke-dasharray: none; fill: #22324a; animation: nodePulse 1.6s ease-in-out infinite; }
svg.tree .node.owned .disc { fill: var(--c); stroke: rgba(255, 255, 255, 0.6); }
svg.tree .node:hover .disc { stroke-width: 3.5; }
svg.tree .node .ring { fill: none; stroke: var(--c); stroke-width: 1.5; opacity: 0.8; }
svg.tree .nlvl { font: 700 13px var(--font); fill: #93a3b8; pointer-events: none; }
svg.tree .node.open .nlvl { fill: var(--c); }
svg.tree .node.owned .nlvl { fill: #13202f; }
svg.tree .nlabel { font: 500 11px var(--font); fill: #b8c4d3; pointer-events: none; }
svg.tree .node.locked .nlabel { fill: #66768c; }
svg.tree .ncost { font: 700 10.5px var(--font); fill: var(--cyan); pointer-events: none; }
@keyframes nodePulse { 0%, 100% { stroke-width: 2; } 50% { stroke-width: 4.5; } }
.tree-detail { display: flex; gap: 16px; align-items: center; justify-content: space-between; padding: 12px 14px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); }
.tree-detail h4 { margin: 0 0 3px; font-size: 15px; }
.tree-detail p { margin: 0; color: #c2cddb; font-size: 13px; line-height: 1.45; }
.tree-detail .td-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; }

/* ------------------------------------------------------------ tutorial */

.coach {
  position: absolute; left: 12px; bottom: 150px; width: 310px; padding: 12px 14px 12px;
  background: linear-gradient(180deg, rgba(36, 52, 80, 0.95), rgba(18, 28, 44, 0.95));
  border: 1px solid rgba(242, 193, 78, 0.45); border-radius: var(--radius);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.4), 0 0 0 4px rgba(242, 193, 78, 0.06);
  animation: popIn 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
.coach[hidden] { display: none; }
.coach-head { display: flex; justify-content: space-between; align-items: center; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--amber); }
.coach-head button { background: none; border: 0; color: var(--dim); font: inherit; letter-spacing: 0; text-transform: none; font-size: 11px; cursor: pointer; }
.coach-head button:hover { color: var(--text); }
.coach h4 { margin: 6px 0 4px; font-size: 15px; font-weight: 600; }
.coach p { margin: 0; color: #cdd7e4; line-height: 1.5; font-size: 12.5px; }
.coach-foot { display: flex; justify-content: flex-end; margin-top: 10px; }
.coach-wait { margin-top: 8px; font-size: 11px; color: var(--dim); font-style: italic; }
.coach-target { position: relative; z-index: 2; animation: coachPulse 1.4s ease-in-out infinite; border-color: rgba(242, 193, 78, 0.9) !important; }
@keyframes coachPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(242, 193, 78, 0.55); } 50% { box-shadow: 0 0 0 6px rgba(242, 193, 78, 0); } }

.island-card { margin-top: 10px; }
.code-chip { font-family: ui-monospace, Consolas, monospace; font-size: 14px; letter-spacing: 0.12em; color: var(--cyan); background: rgba(92, 207, 224, 0.1); border: 1px solid rgba(92, 207, 224, 0.35); padding: 3px 10px; border-radius: 8px; user-select: text; }
.code-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.code-row input { flex: 1; min-width: 160px; font: inherit; font-size: 13px; color: var(--text); background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line-hi); border-radius: 9px; padding: 7px 10px; outline: none; user-select: text; }
.code-row input:focus { border-color: rgba(92, 207, 224, 0.6); }

/* ------------------------------------------------------------ endings */

#hud > .build, #hud > .side, #hud > .stock, #hud > .goals, #hud > .info, #hud > .coach, #hud > .toasts { transition: opacity 0.8s; }
body.cinematic #hud > .build, body.cinematic #hud > .side, body.cinematic #hud > .stock, body.cinematic #hud > .goals,
body.cinematic #hud > .info, body.cinematic #hud > .coach, body.cinematic #hud > .toasts { opacity: 0; pointer-events: none; }

/* ------------------------------------------------------------ crises */

.stat.alarm { border-color: rgba(255, 107, 94, 0.7); animation: alarmPulse 1.2s ease-in-out infinite; }
@keyframes alarmPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 94, 0.5); } 50% { box-shadow: 0 0 0 5px rgba(255, 107, 94, 0); } }
.crisis {
  position: absolute; left: 50%; transform: translateX(-50%); top: 120px;
  padding: 8px 10px 8px 14px; border-radius: 11px; font-size: 13px; color: #ffe1dc; white-space: nowrap;
  background: linear-gradient(180deg, rgba(120, 30, 30, 0.92), rgba(80, 18, 22, 0.92));
  border: 1px solid rgba(255, 107, 94, 0.7); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  animation: alarmPulse 1.4s ease-in-out infinite;
}
.crisis[hidden] { display: none; }
.crisis b { color: #fff; }
.crisis button { margin-left: 10px; font: inherit; font-size: 12px; color: #fff; background: rgba(255, 255, 255, 0.12); border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 8px; padding: 3px 10px; cursor: pointer; }
.crisis button:hover { background: rgba(255, 255, 255, 0.22); }

/* ------------------------------------------------------------ beacon tracker, export */

.beacon-track { margin-top: 4px; font-size: 10.5px; color: var(--muted); display: flex; gap: 4px; align-items: center; cursor: pointer; }
.beacon-track[hidden] { display: none; }
.beacon-track span { padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line-hi); color: var(--dim); }
.beacon-track span.on { color: #0f2a33; background: var(--cyan); border-color: var(--cyan); }
.beacon-track.charging span:last-child { color: var(--cyan); border-color: var(--cyan); animation: alarmPulse 1.6s ease-in-out infinite; }
.export-box { width: 100%; height: 160px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 11px; color: #cfe3ea; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line-hi); border-radius: 10px; padding: 10px; word-break: break-all; user-select: text; }

/* ------------------------------------------------------------ autobuild */

.auto {
  position: absolute; left: 12px; bottom: 150px; width: 300px; padding: 10px 12px;
  background: var(--panel); border: 1px solid rgba(92, 207, 224, 0.4); border-radius: var(--radius);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.auto[hidden] { display: none; }
.auto-head { display: flex; justify-content: space-between; font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--cyan); }
.auto .bar { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); margin: 7px 0 6px; overflow: hidden; }
.auto .bar i { display: block; height: 100%; background: linear-gradient(90deg, #5ccfe0, #b8f2ff); transition: width 0.3s; }
.auto-status { font-size: 12px; color: #cdd7e4; line-height: 1.4; }
.auto-actions { display: flex; gap: 6px; margin-top: 8px; }
.auto-actions .btn { padding: 4px 10px; font-size: 11.5px; }
.auto-opts { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12.5px; color: #c2cddb; margin: 4px 0; }
.auto-opts select, .wake-plan { font: inherit; font-size: 12.5px; color: var(--text); background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line-hi); border-radius: 8px; padding: 6px 8px; }
.wake-plan option, .auto-opts select option { background: #121c2c; }
.card .star { background: none; border: 0; font-size: 16px; color: var(--dim); cursor: pointer; }
.card .star.on { color: var(--amber); }
.chunk-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.chunk-tools .tagline { margin-left: auto; }
.chunks { max-height: 46vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; padding: 4px; background: rgba(0, 0, 0, 0.15); }
.chunk { display: grid; grid-template-columns: 18px 26px 40px 1fr 80px 84px; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 8px; cursor: grab; font-size: 13px; }
.chunk:hover { background: rgba(255, 255, 255, 0.05); }
.chunk.dragging { opacity: 0.4; }
.chunk.over { box-shadow: inset 0 2px 0 var(--cyan); }
.chunk .grip { color: var(--dim); letter-spacing: -2px; }
.chunk .num { color: var(--dim); font-variant-numeric: tabular-nums; font-size: 11px; }
.chunk .pic { height: 30px; display: flex; align-items: center; justify-content: center; }
.chunk .pic img { max-height: 30px; max-width: 38px; }
.chunk .glyph { color: #9aa3ab; font-size: 18px; }
.chunk .cost { color: var(--amber); font-variant-numeric: tabular-nums; text-align: right; font-size: 12px; }
.chunk .moves { display: flex; gap: 2px; justify-content: flex-end; }
.chunk .moves button { background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); color: var(--muted); border-radius: 6px; width: 24px; height: 22px; cursor: pointer; font-size: 10px; }
.chunk .moves button:hover { color: var(--text); border-color: var(--line-hi); }

/* ------------------------------------------------------------ research tree */

.modal.wide { width: min(1180px, calc(100vw - 32px)); }
svg.tree.research .branch { font-size: 9.5px; }
svg.tree.research .edge { stroke: rgba(255, 255, 255, 0.08); }
svg.tree.research .edge.lit { stroke-width: 2; opacity: 0.7; }

.res.holdable { cursor: pointer; }
.res.held { background: rgba(242, 193, 78, 0.16); box-shadow: inset 0 0 0 1px rgba(242, 193, 78, 0.6); }
.res.held .n::after { content: ' ⏸'; color: var(--amber); font-size: 10px; }

/* ------------------------------------------------------------ developer panel */

.dev { position: fixed; inset: 0; z-index: 15; display: flex; flex-direction: column; background: #0a1220; }
.dev[hidden] { display: none; }
body.dev-open #hud { display: none; }
.dev-head { display: flex; align-items: center; gap: 14px; padding: 10px 14px; background: rgba(16, 25, 40, 0.98); border-bottom: 1px solid var(--line-hi); }
.dev-title { font-weight: 700; letter-spacing: 0.04em; display: flex; align-items: center; gap: 8px; }
.dev-badge { font-size: 10px; letter-spacing: 0.14em; padding: 2px 7px; border-radius: 6px; background: #ff6b5e; color: #1a0705; }
.dev-run { flex: 1; color: var(--muted); font-size: 13px; }
.dev-run b { color: var(--text); }
.dev-spd { color: var(--cyan); }
.dev-speed { display: flex; gap: 4px; }
.dev-speed .btn { padding: 5px 10px; min-width: 40px; }
.dev-body { flex: 1; display: flex; min-height: 0; }
.dev-view { position: relative; flex: 1; min-width: 0; }
.dev-view canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
.dev-thought { position: absolute; left: 14px; bottom: 14px; padding: 8px 12px; border-radius: 10px; background: rgba(10, 16, 28, 0.85); border: 1px solid var(--line-hi); font-size: 13px; max-width: 60%; pointer-events: none; }
.dev-thought::before { content: 'Bot: '; color: var(--cyan); font-weight: 600; }
.dev-won { position: absolute; left: 50%; top: 18%; transform: translateX(-50%); text-align: center; pointer-events: none; }
.dev-won .t { font-size: 32px; font-weight: 700; text-shadow: 0 4px 20px rgba(0, 0, 0, 0.7); color: #d6f8ff; }
.dev-won .d { color: #cfe3ea; margin-top: 4px; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8); }
.dev-side { width: 360px; flex: none; overflow-y: auto; padding: 12px; background: rgba(14, 22, 36, 0.98); border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.dev-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ds { padding: 7px 9px; border-radius: 9px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); display: flex; flex-direction: column; }
.ds span { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
.ds b { font-size: 15px; font-variant-numeric: tabular-nums; }
.ds i { font-style: normal; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dev-res { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; font-variant-numeric: tabular-nums; padding: 2px 2px; }
.dev-res span { display: inline-flex; align-items: center; gap: 3px; }
.dev-sec h5 { margin: 4px 0 6px; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--amber); }
.dev-log #devLog { display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; font-size: 12px; }
.dev-log #devLog div { color: #c2cddb; line-height: 1.35; }
.dev-log #devLog div.hl { color: #ffe3a0; }
.dev-log #devLog span { display: inline-block; min-width: 58px; color: var(--dim); font-variant-numeric: tabular-nums; }
.dev-sec table { width: 100%; border-collapse: collapse; font-size: 12px; }
.dev-sec th { text-align: left; font-weight: 500; color: var(--dim); font-size: 10.5px; padding: 2px 4px; }
.dev-sec td { padding: 3px 4px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.dev-sec tr.won td { color: var(--cyan); }
.dev-opts label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: #c2cddb; padding: 2px 0; }
.dev-new { display: flex; gap: 6px; margin-top: 8px; }
.dev-new input { flex: 1; min-width: 0; font: inherit; font-size: 12px; color: var(--text); background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line-hi); border-radius: 8px; padding: 6px 8px; user-select: text; }
.dev-note { font-size: 11.5px; color: var(--dim); margin-top: 4px; line-height: 1.4; }
#devMind b { font-weight: 600; }
@media (max-width: 900px) { .dev-side { width: 260px; } .dev-speed .btn { min-width: 0; padding: 5px 7px; } }

/* ------------------------------------------------------------ sea chart */

svg.chart-map { width: 100%; height: auto; display: block; margin: 6px 0 10px; border-radius: 14px; }
svg.chart-map .grid { stroke: rgba(255, 255, 255, 0.05); stroke-width: 1; }
svg.chart-map .rose circle { fill: none; stroke: rgba(255, 255, 255, 0.18); }
svg.chart-map .rose path { fill: rgba(255, 255, 255, 0.28); }
svg.chart-map .rose text { fill: rgba(255, 255, 255, 0.4); font: 600 11px var(--font); }
svg.chart-map .route { fill: none; stroke: rgba(255, 255, 255, 0.16); stroke-width: 2; stroke-dasharray: 3 7; stroke-linecap: round; }
svg.chart-map .route.lit { stroke: rgba(242, 193, 78, 0.75); stroke-dasharray: 6 6; }
svg.chart-map .isle { cursor: pointer; }
svg.chart-map .isle .shallow { fill: rgba(120, 200, 230, 0.25); }
svg.chart-map .isle .ring { fill: none; stroke: rgba(255, 255, 255, 0.5); stroke-width: 1.5; stroke-dasharray: 4 5; }
svg.chart-map .isle .nm { fill: var(--text); font: 600 14px var(--font); }
svg.chart-map .isle .st { fill: var(--muted); font: 500 11px var(--font); }
svg.chart-map .isle.here .st { fill: var(--cyan); }
svg.chart-map .isle.won .st { fill: var(--amber); }
svg.chart-map .isle.new .st { fill: var(--good); }
svg.chart-map .isle.locked .nm, svg.chart-map .isle.locked .st { opacity: 0.55; }
svg.chart-map .isle .peaks { fill: none; stroke: #9fb3c0; stroke-width: 2; stroke-linejoin: round; }
svg.chart-map .isle .beam { stroke: rgba(255, 236, 170, 0.75); stroke-width: 3; stroke-linecap: round; filter: drop-shadow(0 0 6px rgba(255, 230, 150, 0.9)); }
svg.chart-map .isle .ship { fill: #f4ead2; stroke: #6b5338; stroke-width: 1; }
svg.chart-map .isle .fogcloud { fill: rgba(220, 230, 240, 0.22); }
svg.chart-map .isle .q { fill: rgba(255, 255, 255, 0.5); font: 700 22px var(--font); }
.chart-detail { align-items: flex-start; }
.chart-detail .kind { font-weight: 500; font-size: 12px; color: var(--muted); margin-left: 6px; }
.chart-detail .mut, .modal .mut { color: var(--muted); }
ul.rules { margin: 8px 0 6px; padding-left: 18px; color: #c2cddb; line-height: 1.5; }
.card ul.rules { margin-bottom: 0; }
.dev-new { flex-wrap: wrap; }
.dev-new select { font: inherit; font-size: 12px; color: var(--text); background: #1a2638; border: 1px solid var(--line-hi); border-radius: 8px; padding: 5px 6px; }

svg.chart-map .lane { fill: none; stroke: rgba(92, 207, 224, 0.75); stroke-width: 2.5; stroke-dasharray: 3 9; stroke-linecap: round; animation: lane 1.4s linear infinite; }
@keyframes lane { to { stroke-dashoffset: -24; } }
.cargo { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 2px; }
.cargo .k { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); margin-right: 4px; }
.cargo .btn { display: inline-flex; align-items: center; gap: 5px; }
.cargo .btn.on { box-shadow: inset 0 0 0 1px var(--cyan); color: var(--cyan); }
.shared { margin-top: 12px; }
.shared-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.shared-head .k { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.shared-head .mut { font-size: 12px; color: var(--muted); }
.shared-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; }
.shared-grid .sh { padding: 7px 9px; border-radius: 9px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); display: flex; flex-direction: column; gap: 2px; min-height: 52px; }
.shared-grid .sh b { font-size: 12.5px; color: var(--muted); }
.shared-grid .sh span { font-size: 11.5px; color: var(--dim); line-height: 1.35; }
.shared-grid .sh.secret b { color: var(--violet); }
.shared-grid .sh.found { border-color: rgba(184, 146, 240, 0.5); background: rgba(184, 146, 240, 0.08); }
.shared-grid .sh.found b { color: #e2d2ff; }
.shared-grid .sh.found span { color: #c2cddb; }
.shared-grid .sh.found.light { border-color: rgba(242, 193, 78, 0.5); background: rgba(242, 193, 78, 0.07); }
.shared-grid .sh.found.light b { color: var(--amber); }
.tree-detail.beyond { margin-top: 10px; border-color: rgba(184, 146, 240, 0.4); background: rgba(184, 146, 240, 0.06); }
.dev-rec { display: flex; gap: 6px; margin-top: 10px; }
.dev-rec .btn { flex: 1; }
.market { display: flex; flex-direction: column; gap: 2px; margin: 4px 0; }
.mrow { display: grid; grid-template-columns: 1.6fr 0.8fr 0.8fr 0.8fr 1.2fr 1.3fr; align-items: center; gap: 4px; font-size: 11.5px; }
.mrow.head { color: var(--dim); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; }
.mrow span { display: flex; align-items: center; gap: 3px; white-space: nowrap; }
.btn.mini { padding: 2px 6px; font-size: 11px; min-width: 0; }
.refine { margin-top: 12px; }
.refine .k { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); margin-bottom: 6px; }
.refine-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; }
.refine-row .btn { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; }
.refine-row .btn span { font-size: 11px; color: var(--muted); font-weight: 400; }
.ach-head { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); margin: 14px 0 6px; }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 6px; }
.ach { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); display: flex; flex-direction: column; gap: 2px; min-height: 58px; }
.ach b { font-size: 13px; color: var(--muted); }
.ach span { font-size: 11.5px; color: var(--dim); line-height: 1.35; }
.ach i { font-style: normal; font-size: 10.5px; color: var(--dim); margin-top: auto; }
.ach.secret b { color: #b9a3e0; }
.ach.got { border-color: rgba(242, 193, 78, 0.5); background: rgba(242, 193, 78, 0.08); }
.ach.got b { color: var(--amber); }
.ach.got span { color: #c2cddb; }
.ach.got.secret { border-color: rgba(184, 146, 240, 0.55); background: rgba(184, 146, 240, 0.09); }
.ach.got.secret b { color: #e2d2ff; }
