:root {
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --teal: #7ff3ff; --cyan: #34d6ff; --steel: #1b2731; --steel2: #263640; --edge: #3f5966;
  --blue: #2f9bff; --orange: #ff8a2a; --txt: #e7f1f5; --mut: #9db3bd;
  --panelW: 176px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0a2430; color: var(--txt);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; overscroll-behavior: none; touch-action: none; }
#stage, #stage canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

/* ------- shared controls ------- */
.big { display: flex; align-items: center; gap: 14px; min-height: 52px; width: 100%; padding: 8px 20px;
  border-radius: 10px; border: 1px solid #4a6b79; background: linear-gradient(180deg, #2a4553, #162630);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12), 0 4px 14px rgba(0,0,0,.4); font-size: 19px; font-weight: 600; text-align: left; }
.big:active, .act:active, .item:active { transform: scale(.97); filter: brightness(1.2); }
.big .ico { width: 30px; text-align: center; color: var(--teal); font-size: 22px; }
.act { min-height: 44px; min-width: 44px; padding: 0 14px; border-radius: 9px; border: 1px solid #4a6b79;
  background: linear-gradient(180deg, #2a4553, #172932); font-weight: 600; }
.act.ok { background: linear-gradient(180deg, #1e8a9e, #0f5363); border-color: #59d9ee; }
.act.danger { background: linear-gradient(180deg, #7a3328, #46201b); border-color: #c0614f; }
.act[aria-pressed="true"] { background: linear-gradient(180deg, #1e8a9e, #0f5363); border-color: var(--teal); }
.big2 { padding: 0 26px; font-size: 17px; }
.iconbtn { position: absolute; width: 48px; height: 48px; border-radius: 50%; border: 1px solid #4a6b79;
  background: rgba(16,30,38,.88); font-size: 17px; font-weight: 700; display: grid; place-items: center; }

/* ------- screens ------- */
.screen { position: fixed; inset: 0; z-index: 20; padding: calc(12px + var(--sat)) calc(16px + var(--sar)) calc(12px + var(--sab)) calc(16px + var(--sal)); }
.panelScreen { display: grid; place-items: center; background: rgba(4,12,18,.62); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.card { width: min(440px, 100%); max-height: 100%; overflow: auto; background: linear-gradient(180deg, rgba(30,48,58,.97), rgba(14,24,30,.97));
  border: 1px solid #436170; border-radius: 14px; padding: 14px 18px; box-shadow: 0 12px 40px rgba(0,0,0,.55); touch-action: pan-y; }
.card.wide { width: min(700px, 100%); }
.card h2 { margin: 0 0 10px; font-size: 22px; letter-spacing: .06em; text-transform: uppercase; color: var(--teal); }
.card p, .card li { color: #cfe0e6; } .card ul { padding-left: 18px; margin: 6px 0; } .card li { margin: 4px 0; }
.blue { color: var(--blue); } .orange { color: var(--orange); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.col { display: grid; gap: 10px; }
.lbl { color: var(--mut); font-weight: 600; }
.note { font-size: 13px; color: var(--mut) !important; }
.seg { display: flex; border: 1px solid #4a6b79; border-radius: 9px; overflow: hidden; }
.seg button { min-height: 44px; min-width: 96px; border: 0; background: #172932; font-weight: 600; }
.seg button.on { background: linear-gradient(180deg, #1e8a9e, #0f5363); }
#mapCards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mapCard { display: flex; gap: 10px; padding: 8px; border-radius: 10px; border: 2px solid #34505d; background: #13222a; text-align: left; min-height: 44px; }
.mapCard.on { border-color: var(--teal); box-shadow: 0 0 0 1px var(--teal) inset; }
.mapCard canvas { width: 84px; height: 84px; border-radius: 6px; flex: none; image-rendering: pixelated; }
.mapCard b { display: block; font-size: 16px; } .mapCard small { color: var(--mut); font-size: 12px; line-height: 1.3; display: block; }

/* home */
#home { background: transparent; }
.homeShade { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(4,14,20,.78) 0%, rgba(4,14,20,.35) 55%, rgba(4,14,20,.55) 100%); pointer-events: none; }
.homeLeft { position: absolute; left: calc(28px + var(--sal)); top: calc(26px + var(--sat)); }
.logo { margin: 0; font-size: clamp(40px, 8.5vw, 84px); line-height: 1; font-weight: 900; letter-spacing: .04em; font-style: italic;
  background: linear-gradient(180deg, #f4f7f9 0%, #b7c2ca 45%, #6d7a84 55%, #c9d2d8 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 #1d2a32) drop-shadow(0 8px 18px rgba(0,0,0,.6)); }
.logoLine { display: block; height: 3px; margin-top: 10px; background: linear-gradient(90deg, transparent, var(--cyan), transparent); position: relative; }
.logoLine i { position: absolute; left: 50%; top: -7px; width: 14px; height: 14px; transform: translateX(-50%) rotate(45deg); border: 2px solid var(--teal); background: #0b2a36; box-shadow: 0 0 12px var(--cyan); }
.tag { margin: 12px 0 0; color: #bfe9f2; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; font-size: 12px; text-shadow: 0 2px 6px #000; }
.menu { position: absolute; right: calc(28px + var(--sar)); top: 50%; transform: translateY(-50%); width: min(290px, 40vw); display: grid; gap: 12px; }
.ver { position: absolute; left: calc(28px + var(--sal)); bottom: calc(14px + var(--sab)); font-size: 12px; color: var(--mut); letter-spacing: .08em; }

/* ------- HUD ------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud > * { pointer-events: auto; }
#topbar { position: absolute; top: calc(6px + var(--sat)); left: calc(8px + var(--sal)); display: flex; gap: 6px; pointer-events: none; }
.pill { display: flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px; border-radius: 9px; background: rgba(12,24,31,.85); border: 1px solid #36515d; font-weight: 700; }
.pill.small { font-size: 13px; color: var(--mut); padding: 0 9px; }
.gem { width: 16px; height: 18px; background: linear-gradient(160deg, #e6ffff, #43d9ff 50%, #0b6aa0); clip-path: polygon(50% 0, 100% 30%, 80% 100%, 20% 100%, 0 30%); filter: drop-shadow(0 0 4px #3fe0ff); }
#creditsVal { font-size: 18px; min-width: 52px; font-variant-numeric: tabular-nums; }
.pbar { width: 54px; height: 7px; border-radius: 4px; background: #1d2b33; overflow: hidden; } .pbar i { display: block; height: 100%; width: 50%; background: #4fe08a; }
#power.low .pbar i { background: #ff5a3a; } #power.low { border-color: #ff5a3a; }
#powerTxt { font-size: 12px; color: var(--mut); font-variant-numeric: tabular-nums; }
#pauseBtn { top: calc(6px + var(--sat)); right: calc(var(--panelW) + 12px + var(--sar)); }
#hud.collapsed #pauseBtn { right: calc(62px + var(--sar)); }
#panel { position: absolute; top: calc(6px + var(--sat)); right: calc(6px + var(--sar)); bottom: calc(6px + var(--sab)); width: var(--panelW);
  display: flex; flex-direction: column; gap: 6px; padding: 6px; border-radius: 12px; background: rgba(12,22,29,.9); border: 1px solid #36515d; }
#hud.collapsed #panel { display: none; }
#panelToggle { width: 44px; height: 44px; top: auto; bottom: calc(10px + var(--sab)); right: calc(var(--panelW) + 12px + var(--sar)); }
#hud.collapsed #panelToggle { right: calc(10px + var(--sar)); }
#tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.tab { min-height: 44px; border-radius: 8px; border: 1px solid #36515d; background: #15242c; font-size: 13px; font-weight: 700; color: var(--mut); }
.tab.active { color: #fff; background: linear-gradient(180deg, #1e7f92, #10505f); border-color: var(--teal); }
#items { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; align-content: start; }
.item { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 1px; padding: 4px 2px 5px; min-height: 96px;
  border-radius: 11px; border: 1px solid #3f6372; background: linear-gradient(180deg, #24414d 0%, #15262e 60%, #101c22 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.1), 0 2px 6px rgba(0,0,0,.35); overflow: hidden; }
.item::after { content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; background: linear-gradient(180deg, rgba(127,243,255,.08), transparent 40%); }
.icoWrap { position: relative; width: 58px; height: 54px; display: grid; place-items: center; border-radius: 9px;
  background: radial-gradient(circle at 50% 40%, rgba(110,200,230,.22), rgba(0,0,0,0) 70%); }
.item img { width: 52px; height: 52px; object-fit: contain; filter: drop-shadow(0 3px 3px rgba(0,0,0,.55)); }
.item .nm { font-size: 11px; font-weight: 700; line-height: 1.1; text-align: center; color: #eef6f9; }
.item .cost { display: flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--teal); font-weight: 800; font-variant-numeric: tabular-nums; }
.item .cost.stat { color: #c9e6ee; font-size: 10.5px; font-weight: 700; }
.gemS { display: inline-block; width: 9px; height: 11px; background: linear-gradient(160deg, #e6ffff, #43d9ff 50%, #0b6aa0); clip-path: polygon(50% 0, 100% 30%, 80% 100%, 20% 100%, 0 30%); }
.cost.stat .gemS { display: none; }
.item.locked img { filter: grayscale(.85) brightness(.55) drop-shadow(0 3px 3px rgba(0,0,0,.55)); }
.item.locked .cost { color: #ffb38f; }
.item.locked .nm { color: #9fb1b8; }
.item.poor:not(.locked) .cost:not(.stat) { color: #ff8a7a; }
.item.busy:not(.locked) { opacity: .6; }
.item .ring { position: absolute; inset: -2px; border-radius: 50%; pointer-events: none; display: block;
  background: conic-gradient(#7ff3ff calc(var(--p) * 1%), rgba(255,255,255,.08) 0); -webkit-mask: radial-gradient(circle, transparent 25px, #000 26px, #000 28px, transparent 29px); mask: radial-gradient(circle, transparent 25px, #000 26px, #000 28px, transparent 29px); }
.item .lock { position: absolute; left: -2px; top: -2px; width: 20px; height: 20px; border-radius: 50%; background: #2a3a42; border: 1px solid #6c8792; display: grid; place-items: center; }
.item .lock::before { content: ''; width: 8px; height: 6px; margin-top: 3px; border-radius: 1.5px; background: #cfe0e6; box-shadow: 0 -4px 0 -1px transparent; }
.item .lock::after { content: ''; position: absolute; top: 3px; width: 6px; height: 6px; border: 1.6px solid #cfe0e6; border-bottom: 0; border-radius: 4px 4px 0 0; }
.item .badge { position: absolute; top: -3px; right: -4px; min-width: 20px; height: 20px; border-radius: 10px; background: var(--cyan); color: #00222c; font-size: 12px; font-weight: 800; display: grid; place-items: center; padding: 0 5px; box-shadow: 0 0 8px rgba(52,214,255,.7); }
.item.ready { border-color: var(--teal); box-shadow: 0 0 12px rgba(127,243,255,.6) inset; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { box-shadow: 0 0 20px rgba(127,243,255,.9) inset; } }
#selInfo { margin-top: auto; font-size: 12px; color: var(--mut); padding: 4px; line-height: 1.3; min-height: 38px; }
#selInfo b { color: #fff; }
#minimapWrap { position: absolute; left: calc(8px + var(--sal)); bottom: calc(8px + var(--sab)); width: 116px; height: 116px; border-radius: 10px; overflow: hidden;
  border: 2px solid #3f5f6d; background: #08161d; box-shadow: 0 4px 14px rgba(0,0,0,.5); }
#minimap { width: 100%; height: 100%; display: block; }
#actionBar, #placeBar { position: absolute; bottom: calc(8px + var(--sab)); left: calc(132px + var(--sal)); display: flex; align-items: center; gap: 6px; }
#selCount { font-weight: 700; font-size: 13px; text-shadow: 0 1px 3px #000; padding: 0 4px; }
#placeBar { left: 50%; transform: translateX(calc(-50% - var(--panelW) / 2)); background: rgba(12,22,29,.9); padding: 5px; border-radius: 12px; border: 1px solid #36515d; }
#placeHint { font-size: 13px; color: var(--mut); padding: 0 6px; }
#boxSel { position: absolute; border: 1.5px solid var(--teal); background: rgba(127,243,255,.12); pointer-events: none; }
#toasts { position: absolute; top: calc(50px + var(--sat)); left: 50%; transform: translateX(calc(-50% - var(--panelW) / 2)); display: grid; gap: 4px; pointer-events: none; justify-items: center; }
.toast { padding: 6px 14px; border-radius: 8px; background: rgba(8,18,24,.9); border: 1px solid #3f5f6d; font-weight: 700; font-size: 13px; animation: fade 2.6s forwards; }
.toast.warn { border-color: #ff7a5a; color: #ffd2c6; }
@keyframes fade { 0% { opacity: 0; transform: translateY(-6px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

#endStats { width: 100%; border-collapse: collapse; margin: 4px 0; font-size: 14px; } #endStats td { padding: 4px 4px; border-bottom: 1px solid #2c4350; }
#end .card { width: min(560px, 100%); padding: 10px 16px; } #end h2 { margin-bottom: 2px; } #endSub { margin: 0 0 4px; font-size: 14px; } #end .row { margin: 6px 0 0; }
#endStats td.gap { padding-left: 18px; } #endStats td:nth-child(2), #endStats td:last-child { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
#endTitle.win { color: #7ff3ff; } #endTitle.lose { color: #ff9a7a; }

#rotate, #loading { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; text-align: center; background: #07171f; color: var(--teal); }
#rotate div { font-size: 54px; } #rotate p { color: #cfe0e6; font-weight: 600; }
.spin { width: 40px; height: 40px; margin: 0 auto; border: 4px solid #1d3a45; border-top-color: var(--teal); border-radius: 50%; animation: sp 0.9s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (orientation: portrait) and (max-width: 700px) { #rotate.active { display: grid !important; } }
@media (max-height: 360px) { .item { min-height: 86px; } .icoWrap { height: 46px; } .item img { width: 44px; height: 44px; } }
