:root {
  --bg: #14161b;
  --panel: #1b1e25;
  --panel2: #232733;
  --line: #2f3442;
  --text: #e8ebf2;
  --muted: #9aa3b5;
  --accent: #4fd1a5;
  --gold: #ffd166;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; }

#app { display: flex; height: 100vh; height: 100dvh; }

#stage { position: relative; flex: 1; min-width: 0; overflow: hidden; background: #3b2a1f; user-select: none; }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#game { touch-action: none; }
#bg.fallback { background:
  repeating-linear-gradient(0deg, rgba(0,0,0,.18) 0 2px, transparent 2px 28px),
  linear-gradient(#5c3f2b, #3b2a1f); }

#hud { position: absolute; top: 12px; left: 16px; right: 16px; pointer-events: none;
  text-shadow: 0 2px 0 rgba(0,0,0,.45); display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.hud-right { background: rgba(0,0,0,.42); border-radius: 10px; padding: 7px 10px; font-size: 12px; min-width: 168px;
  font-variant-numeric: tabular-nums; text-shadow: none; }
.hud-right .bar.small { height: 6px; margin: 3px 0 5px; }
.hud-right .bar.small:last-child { margin-bottom: 0; }
#calBar { height: 100%; width: 0; background: linear-gradient(90deg, #ffd166, #ff6b6b); }
#bookBar { height: 100%; width: 0; background: linear-gradient(90deg, #a259ff, #7fe3ff); }
.hud-right.urgent .cal { color: #ff9b9b; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
#buffs { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.buff { background: rgba(0,0,0,.5); border-radius: 99px; padding: 3px 10px; font-size: 12px; text-shadow: none; font-variant-numeric: tabular-nums; }
.buff.fire { background: rgba(255,107,53,.85); }
.buff.order { background: rgba(79,140,255,.85); }
.money { font-size: clamp(26px, 4vw, 38px); font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.money small { font-size: .45em; color: #f4e3b0; font-weight: 600; }
.rate { color: #f1e7d6; font-size: 14px; font-variant-numeric: tabular-nums; }

#hint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); max-width: calc(100% - 32px);
  background: rgba(0,0,0,.55); padding: 8px 14px; border-radius: 999px; font-size: 13px; text-align: center;
  pointer-events: none; transition: opacity .6s; }
#hint.gone { opacity: 0; }

#zoomCtl { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; }
#zoomCtl button { width: 34px; height: 34px; border-radius: 9px; border: 1px solid #3a4150; background: rgba(16,18,26,.78);
  color: var(--text); font-size: 18px; cursor: pointer; }
#zoomCtl button:hover { border-color: var(--accent); }
#toast { position: absolute; left: 50%; top: 84px; transform: translateX(-50%); max-width: calc(100% - 32px);
  background: #1f6f55; border: 1px solid #4fd1a5; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); }

#panel { width: 370px; flex: none; background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; }
.brand { padding: 14px 16px 12px; border-bottom: 1px solid var(--line); }
.brand h1 { margin: 0 0 10px; font-size: 20px; letter-spacing: .3px; }
.doc { font-size: 13px; font-variant-numeric: tabular-nums; }
.doc-row { display: flex; justify-content: space-between; gap: 8px; }
.muted { color: var(--muted); }
.bar { height: 10px; background: #0f1116; border-radius: 99px; margin: 6px 0; overflow: hidden; border: 1px solid var(--line); }
#docBar { height: 100%; width: 0; background: linear-gradient(90deg, #4fd1a5, #7fe3ff); transition: width .08s linear; }

.tabs { display: flex; padding: 8px 10px 0; gap: 6px; }
.tab { flex: 1; background: transparent; border: 1px solid var(--line); border-bottom: 0; padding: 8px;
  border-radius: 10px 10px 0 0; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--panel2); color: var(--text); font-weight: 600; }

.list { flex: 1; overflow-y: auto; padding: 10px; background: var(--panel2); margin: 0 10px; border-radius: 0 0 10px 10px; min-height: 0; }
.item { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; cursor: pointer;
  transition: border-color .15s, transform .1s; }
.item:last-child { margin-bottom: 0; }
.item.can:hover { border-color: var(--accent); transform: translateY(-1px); }
.item:active.can { transform: translateY(1px); }
.item:disabled { cursor: not-allowed; }
.item:disabled .info, .item:disabled .ico { opacity: .55; }
.item.locked .name { color: var(--muted); }
.ico { font-size: 26px; width: 40px; text-align: center; flex: none; }
.ico img { width: 40px; height: 40px; image-rendering: pixelated; display: block; margin: 0 auto; }
.item.locked .ico img { filter: brightness(0) opacity(.45); }
.info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.name { font-weight: 600; font-size: 14px; }
.desc { font-size: 12px; color: var(--muted); }
.meta { display: flex; flex-direction: column; align-items: flex-end; flex: none; font-variant-numeric: tabular-nums; }
.cost { color: var(--gold); font-weight: 700; font-size: 14px; }
.item:disabled .cost { color: #b08d3a; }
.own { font-size: 18px; font-weight: 800; color: #c9cfdb; }

.foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 16px; font-size: 12px; }
.foot-btns { display: flex; gap: 6px; flex: none; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; cursor: pointer; }
.ghost:hover { border-color: var(--muted); }
.ghost.danger:hover { border-color: var(--danger); color: var(--danger); }

.tab { font-size: 13px; padding: 8px 4px; position: relative; }
.sell-hud { pointer-events: auto; width: 100%; margin-top: 7px; background: #2fbf71; color: #062716; border: 0; border-radius: 8px;
  padding: 6px 8px; font-weight: 700; font-size: 12px; cursor: pointer; }
.sell-hud small { display: block; font-size: 10px; font-weight: 500; opacity: .85; margin-top: 1px; }
.sell-hud:hover:not(:disabled) { filter: brightness(1.1); }
.sell-hud:disabled { background: rgba(255,255,255,.12); color: #c8ccd6; cursor: not-allowed; font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 99px; background: var(--gold); color: #1b1e25;
  font-size: 11px; font-weight: 800; line-height: 18px; }
.small { font-size: 12px; }
.btn-primary { background: var(--accent); color: #0d2a20; border: 0; border-radius: 10px; padding: 9px 14px; font-weight: 700; cursor: pointer; }
.btn-primary:disabled { background: #3a4150; color: var(--muted); cursor: not-allowed; }
.btn-primary:not(:disabled):hover { filter: brightness(1.08); }

.ach-head { margin-bottom: 8px; }
.ach { display: flex; gap: 10px; align-items: center; padding: 7px 8px; border-radius: 8px; background: var(--panel); margin-bottom: 6px; border: 1px solid var(--line); }
.ach .a-ico { font-size: 22px; width: 30px; text-align: center; }
.ach .a-name { font-size: 13px; font-weight: 600; }
.ach .a-desc { font-size: 11px; color: var(--muted); }
.ach.off { opacity: .4; }
.ach.off .a-ico { filter: grayscale(1); }

#modal { position: fixed; inset: 0; background: rgba(8,10,14,.72); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 16px; }
#modal[hidden] { display: none; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(420px, 100%);
  box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-card h2 { margin: 0 0 12px; font-size: 22px; }
.modal-card p { margin: 6px 0; }
.modal-card .big { font-size: 28px; font-weight: 800; color: var(--gold); text-align: center; margin: 12px 0; }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-btns .btn-primary { flex: 1; }
.ok { color: var(--accent); }
.bad { color: #ff9b9b; }

#starView { position: fixed; inset: 0; z-index: 20; overflow-y: auto; overflow-x: hidden; color: #e8ebf2;
  background: radial-gradient(ellipse at 50% 45%, #232c63 0%, #0d1130 55%, #05060d 100%);
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18px 16px 24px; }
#starView[hidden] { display: none; }
.twinkle { position: absolute; width: 2px; height: 2px; background: #fff; border-radius: 50%; pointer-events: none;
  animation: tw 2.6s ease-in-out infinite alternate; }
@keyframes tw { from { opacity: .15; } to { opacity: .9; } }
.sv-top { text-align: center; position: relative; }
.sv-title { font-size: 13px; letter-spacing: 2px; text-transform: uppercase; color: #9aa6e8; }
.sv-stars { font-size: 22px; margin-top: 2px; }
.sv-stars b { color: var(--gold); font-size: 30px; }
.sv-sub { font-size: 12px; color: #aab3e0; max-width: 560px; }
.sv-sky { position: relative; flex: none; aspect-ratio: 1;
  width: max(310px, min(640px, calc(100vw - 32px), calc(100vh - 220px))); }
#svLines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#svLines line { stroke: rgba(150,170,255,.28); stroke-width: 2; vector-effect: non-scaling-stroke; transition: stroke .4s; }
#svLines line.outline { stroke-dasharray: 4 6; stroke: rgba(150,170,255,.16); }
#svLines line.lit { stroke: #ffd166; stroke-dasharray: none; filter: drop-shadow(0 0 3px rgba(255,209,102,.8)); }
.sv-node { position: absolute; transform: translate(-50%, -50%); width: 54px; height: 54px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2d3770, #151a3a); border: 2px solid #4a5590; font-size: 24px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; transition: box-shadow .3s, transform .15s; }
.sv-node:hover { transform: translate(-50%, -50%) scale(1.08); }
.sv-node.root { width: 74px; height: 74px; font-size: 34px; }
.sv-node.root .lbl { display: none; }
.sv-node .lbl { position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: 3px; font-size: 11px;
  white-space: nowrap; color: #c9d1ff; text-shadow: 0 1px 2px #000; pointer-events: none; }
.sv-node .cost { position: absolute; top: -6px; right: -10px; background: #0b0f22; border: 1px solid #ffd166; color: #ffd166;
  font-size: 10px; font-weight: 700; border-radius: 99px; padding: 0 5px; line-height: 16px; }
.sv-node.owned { background: radial-gradient(circle at 35% 30%, #fff1c2, #e0a526); border-color: #fff6d6;
  box-shadow: 0 0 22px 5px rgba(255,209,102,.55); }
.sv-node.owned .cost { display: none; }
.sv-node.avail { border-color: #ffd166; animation: glow 1.5s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 16px 3px rgba(255,209,102,.5); } }
.sv-node.locked { opacity: .4; filter: grayscale(.7); }
.sv-node.sel { outline: 2px solid #7fe3ff; outline-offset: 4px; }
.sv-detail { position: relative; width: min(560px, 100%); background: rgba(16,21,50,.88); border: 1px solid #3a4470;
  border-radius: 12px; padding: 10px 14px; font-size: 14px; min-height: 64px; }
.sv-detail b { color: #fff; }
.sv-detail .btn-primary { margin-top: 8px; width: 100%; }
.sv-start { position: relative; font-size: 16px; padding: 12px 26px; }

@media (max-width: 760px) {
  .sv-node { width: 44px; height: 44px; font-size: 19px; }
  .sv-node.root { width: 60px; height: 60px; font-size: 28px; }
  .sv-node .lbl { font-size: 10px; display: none; }
  .sv-node.sel .lbl { display: block; z-index: 2; background: rgba(5,6,13,.85); padding: 1px 6px; border-radius: 6px; }
  .hud-right { min-width: 0; font-size: 11px; }
  #app { flex-direction: column; }
  #stage { flex: none; height: 50vh; height: 50dvh; }
  #panel { width: auto; flex: 1; border-left: 0; border-top: 1px solid var(--line); }
  .brand { padding: 10px 16px; }
  .brand h1 { display: none; }
}
