/* Netwall - styles. Dark "network operations" theme. Mobile-first: portrait phones, landscape phones, desktop. */
:root {
  --bg: #070b16;
  --panel: #0c1322;
  --panel2: #111b30;
  --line: #1d2c4c;
  --text: #d3e6ff;
  --dim: #7f97bd;
  --cyan: #4de3ff;
  --amber: #ffd24d;
  --red: #ff5c7a;
  --green: #35e0a1;
  --side-w: 320px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --btn: 40px;
  --aspect: 26 / 16;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
@media (pointer: coarse) { :root { --btn: 46px; } }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.35 var(--font);
  overflow: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
input { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
svg.ic { width: 1.25em; height: 1.25em; flex: none; }

/* ---------------------------------------------------------------- layout */
#app {
  position: fixed; inset: 0; height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side-w);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top" "stage side";
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  background:
    radial-gradient(1200px 600px at 20% -10%, #0f1f3d 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 110%, #1b1035 0%, transparent 55%), var(--bg);
}
#topbar { grid-area: top; display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; padding: 6px 10px; background: rgba(8, 13, 26, .85); border-bottom: 1px solid var(--line); }
#stage { grid-area: stage; position: relative; min-width: 0; min-height: 0; overflow: hidden; touch-action: none; }
#side > * { flex: none; }
#side { grid-area: side; display: flex; flex-direction: column; gap: 10px; padding: 10px; overflow-y: auto; border-left: 1px solid var(--line); background: rgba(8, 13, 26, .7); -webkit-overflow-scrolling: touch; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

/* portrait phones / narrow windows: board on top, panels underneath */
@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) {
  #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "top" "stage" "side"; }
  #stage { aspect-ratio: var(--aspect-p, 16 / 26); max-height: 58dvh; width: 100%; }
  #side { border-left: 0; border-top: 1px solid var(--line); padding: 8px 10px calc(8px + var(--safe-b)); gap: 8px; }
}
/* landscape phones: short viewport, narrow side panel */
@media (orientation: landscape) and (max-height: 520px) {
  :root { --side-w: 236px; --btn: 40px; }
  #topbar { padding: 3px 8px; gap: 4px 6px; flex-wrap: nowrap; }
  #side { gap: 6px; padding: 6px; }
}
@media (orientation: landscape) and (min-width: 761px) and (max-width: 1000px) and (min-height: 521px) { :root { --side-w: 270px; } }

/* ---------------------------------------------------------------- top bar */
.stat { display: flex; align-items: center; gap: 6px; padding: 0 10px; height: var(--btn); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; font-family: var(--mono); font-size: 16px; white-space: nowrap; }
.stat b { font-weight: 700; letter-spacing: .02em; }
.stat small { color: var(--dim); }
.stat .lbl { color: var(--dim); font-size: 11px; letter-spacing: .12em; }
#statLives { color: var(--red); }
#statGold { color: var(--amber); }
#statLives.low { animation: pulse 0.8s infinite; }
@keyframes pulse { 50% { background: #3a1020; } }
.spacer { flex: 1 1 8px; }
.chip { display: flex; align-items: center; gap: 6px; padding: 0 10px; height: var(--btn); border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-family: var(--mono); font-size: 13px; color: var(--cyan); }
.chip #netPing { color: var(--dim); }
.chip.bad #netPing { color: var(--red); }

button { min-height: var(--btn); border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; touch-action: manipulation; transition: background .12s, border-color .12s, transform .05s; }
button:hover { border-color: #35538a; background: #15233f; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
button.icon { min-width: var(--btn); padding: 0 8px; font-family: var(--mono); font-size: 13px; }
button.icon.toggle[aria-pressed="true"] { background: #0f3550; border-color: var(--cyan); color: var(--cyan); }
button.primary { background: linear-gradient(#1b7a96, #135872); border-color: #2fb4d6; color: #eaffff; font-weight: 600; }
button.primary:hover { background: linear-gradient(#2290b0, #176b8a); }
button.danger { color: var(--red); }
button.big { min-height: calc(var(--btn) + 6px); font-size: 16px; padding: 0 20px; }
button.link { background: none; border: 0; color: var(--dim); text-decoration: underline; min-height: 36px; padding: 0 8px; }
button.link:hover { color: var(--text); background: none; }
button.floating { position: absolute; right: 8px; bottom: 8px; background: rgba(12, 19, 34, .85); }
#btnWave.attn { animation: glow 1.4s infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 4px rgba(77, 227, 255, .25); } }

@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) {
  #topbar { padding: 6px 8px; }
  .stat { padding: 0 8px; font-size: 15px; }
  #btnWave { flex: 1 1 auto; }
  .spacer { flex: 0 0 0; }
}

/* ---------------------------------------------------------------- stage overlays */
.hint { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 20px); padding: 6px 12px; border-radius: 999px; background: rgba(8, 13, 26, .92); border: 1px solid var(--line); font-family: var(--mono); font-size: 13px; pointer-events: none; white-space: nowrap; }
.hint.ok { color: var(--green); border-color: #1c6a55; }
.hint.bad { color: var(--red); border-color: #6a2336; }
.hint.info { color: var(--cyan); }
.paused-tag { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 10px 26px; border-radius: 999px; background: rgba(8, 13, 26, .88); border: 1px solid var(--amber); color: var(--amber); font-weight: 800; letter-spacing: .3em; font-size: 18px; pointer-events: none; z-index: 2; }
.banner { position: absolute; left: 0; right: 0; top: 34%; text-align: center; pointer-events: none; font-weight: 800; font-size: clamp(22px, 5vw, 44px); letter-spacing: .14em; color: var(--cyan); text-shadow: 0 0 24px rgba(77, 227, 255, .6); opacity: 0; transform: scale(.96); transition: opacity .3s, transform .3s; }
.banner.show { opacity: 1; transform: none; }
.banner.boss { color: var(--red); text-shadow: 0 0 24px rgba(255, 92, 122, .7); }
#toasts { position: absolute; left: 0; right: 0; bottom: 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { padding: 7px 14px; background: rgba(8, 13, 26, .94); border: 1px solid var(--line); border-radius: 10px; font-size: 14px; animation: toast 2.6s forwards; max-width: calc(100% - 24px); text-align: center; }
.toast.bad { border-color: #6a2336; color: #ffb3c1; }
.toast.good { border-color: #1c6a55; color: #aef5d6; }
@keyframes toast { 0% { opacity: 0; transform: translateY(8px); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
.confirm { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; gap: 8px; padding: 6px; border-radius: 14px; background: rgba(8, 13, 26, .94); border: 1px solid var(--line); z-index: 3; white-space: nowrap; }
.confirm.top { bottom: auto; top: 52px; }
.confirm .primary.big { min-width: 120px; }
.reconnect { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 12px; background: rgba(5, 8, 16, .72); z-index: 4; font-size: 16px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--cyan); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- side panel */
#side h4 { margin: 0 0 6px; font-size: 11px; letter-spacing: .14em; color: var(--dim); text-transform: uppercase; font-weight: 600; }
#palette { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.tbtn { position: relative; flex-direction: column; gap: 2px; padding: 6px 4px 5px; min-height: 66px; text-align: center; line-height: 1.15; }
.tbtn canvas { width: 34px; height: 34px; pointer-events: none; }
.tbtn .nm { font-size: 11.5px; color: var(--text); }
.tbtn .cost { font-family: var(--mono); font-size: 12px; color: var(--amber); }
.tbtn .key { position: absolute; top: 3px; left: 5px; font-family: var(--mono); font-size: 10px; color: var(--dim); }
.tbtn.sel { border-color: var(--cyan); background: #0f3550; box-shadow: inset 0 0 0 1px var(--cyan); }
.tbtn.poor .cost { color: var(--red); }
.tbtn.poor { opacity: .72; }
@media (pointer: coarse) { .tbtn .key { display: none; } }
@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) {
  #palette { position: sticky; top: -8px; z-index: 2; margin: -8px -10px 0; padding: 8px 10px 6px; background: rgba(8, 13, 26, .97); }
  #palette { display: flex; overflow-x: auto; gap: 6px; padding-bottom: 2px; scrollbar-width: none; scroll-snap-type: x proximity; scroll-padding: 0 10px; }
  #palette::-webkit-scrollbar { display: none; }
  .tbtn { flex: 0 0 76px; min-height: 72px; scroll-snap-align: start; }
}
@media (orientation: landscape) and (max-height: 520px) {
  #palette { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
  .tbtn { min-height: 58px; padding: 3px 2px; }
  .tbtn canvas { width: 26px; height: 26px; }
}

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
#info:empty { display: none; }
.info-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.info-head canvas { width: 38px; height: 38px; flex: none; }
.info-head .nm { font-weight: 700; }
.info-head .lv { color: var(--dim); font-size: 12px; font-family: var(--mono); }
.info .desc { color: var(--dim); font-size: 13px; margin: 2px 0 6px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-family: var(--mono); font-size: 12.5px; margin-bottom: 8px; }
.kvp { display: contents; }
.kvp span:first-child { color: var(--dim); }
.kv .up { color: var(--green); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions button { flex: 1 1 auto; font-size: 14px; }
.actions .cost { font-family: var(--mono); color: var(--amber); }
.byline { font-size: 11.5px; color: var(--dim); margin-top: 6px; display: flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

#nextwave .panel { padding: 8px 10px; }
.wv { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-family: var(--mono); font-size: 12.5px; }
.wv .e { display: inline-flex; align-items: center; gap: 4px; }
.wv .e i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.wv .tag { padding: 1px 6px; border-radius: 6px; font-size: 11px; border: 1px solid; }
.wv .tag.air { color: #e29bff; border-color: #5b3a73; }
.wv .tag.boss { color: var(--red); border-color: #6a2336; }
#players .pl { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13.5px; }
#players .pl .off { color: var(--dim); font-size: 12px; }
#players .pl .you { color: var(--dim); font-size: 12px; }
#players .actions { margin-top: 6px; }

/* ---------------------------------------------------------------- overlays (menus) */
.overlay { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 14px; background: rgba(4, 7, 14, .78); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); overflow-y: auto; }
.card { width: min(560px, 100%); max-height: 100%; overflow-y: auto; margin: auto; padding: 20px 20px 16px; border-radius: 18px; background: linear-gradient(#0f1830, #0a1124); border: 1px solid #25396a; box-shadow: 0 20px 60px rgba(0, 0, 0, .6), 0 0 0 1px rgba(77, 227, 255, .06); }
.card.wide { width: min(680px, 100%); }
.card h1 { margin: 0; font-size: clamp(30px, 8vw, 46px); letter-spacing: .26em; font-weight: 800; color: #eaffff; text-shadow: 0 0 22px rgba(77, 227, 255, .55); }
.card h2 { margin: 0 0 8px; font-size: 24px; }
.card h3 { margin: 0 0 6px; font-size: 14px; letter-spacing: .08em; text-transform: uppercase; color: var(--dim); }
.logo { display: flex; align-items: center; gap: 14px; justify-content: center; }
.logo-mark { width: 44px; height: 44px; flex: none; background: url("../icons/icon.svg") center/contain no-repeat; filter: drop-shadow(0 0 10px rgba(77, 227, 255, .5)); }
.tag { text-align: center; color: var(--dim); margin: 6px 0 14px; }
.muted { color: var(--dim); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.row.small { margin-top: 6px; }
.row > .big { flex: 1 1 200px; }
.msg { min-height: 1.4em; text-align: center; color: var(--amber); margin: 8px 0 0; }
.msg.bad { color: var(--red); }
.resume { width: 100%; margin-top: 10px; border-color: var(--cyan); color: var(--cyan); }

.maps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 4px; }
.mapcard { flex-direction: column; align-items: stretch; gap: 4px; padding: 8px; text-align: left; min-height: 0; border-radius: 12px; }
.mapcard canvas { width: 100%; aspect-ratio: 26 / 16; border-radius: 6px; background: #060a14; }
.mapcard .nm { font-weight: 700; font-size: 13.5px; min-height: 2.6em; }
.mapcard .df { font-size: 11px; color: var(--dim); letter-spacing: .06em; }
.mapcard .df b { color: var(--amber); letter-spacing: 1px; }
.mapcard[aria-checked="true"] { border-color: var(--cyan); background: #0f3550; box-shadow: inset 0 0 0 1px var(--cyan); }
.mapdesc { text-align: center; color: var(--dim); font-size: 13px; min-height: 2.6em; margin: 6px 0 4px; }
@media (max-width: 480px) { .mapcard .df { display: none; } .mapcard .nm { font-size: 12.5px; } .card { padding: 16px 14px 12px; } }

.field { display: block; margin: 12px 0; }
.field span { display: block; font-size: 12px; color: var(--dim); margin-bottom: 4px; letter-spacing: .06em; }
input { width: 100%; min-height: var(--btn); border-radius: 10px; border: 1px solid var(--line); background: #070d1b; color: var(--text); padding: 0 12px; font: inherit; font-size: 16px; /* >=16px stops iOS zooming on focus */ }
input.code { text-align: center; letter-spacing: .5em; font-family: var(--mono); font-size: 22px; text-transform: uppercase; padding-left: .5em; margin-bottom: 8px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.split .col { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: 12px; background: rgba(255, 255, 255, .02); border: 1px solid var(--line); }
.split .col button { margin-top: auto; }
@media (max-width: 480px) { .split { grid-template-columns: 1fr; } }

.howto { padding-left: 18px; margin: 10px 0 0; display: grid; gap: 8px; }
.howto li { color: #bcd3f5; }
.howto b { color: var(--text); }
.kbd-only { display: inline; } .touch-only { display: none; }
@media (pointer: coarse) { .kbd-only { display: none; } .touch-only { display: inline; } }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; margin: 10px 0 4px; font-family: var(--mono); font-size: 14px; }
.stats div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--line); }
.stats span { color: var(--dim); }

/* the board gets the whole stage while a menu is shown behind blurred overlays; hide HUD chrome pre-game */
#app[data-screen="menu"] #side,
#app[data-screen="menu"] #topbar > :not(#btnMenu) { visibility: hidden; }

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

/* compact info panel on stacked (portrait / narrow) layouts: must come after the base rules above */
@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) {
  .kv { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-bottom: 6px; }
  .kvp { display: inline-flex; gap: 6px; }
  .info .desc { font-size: 12.5px; margin: 0 0 4px; }
  .info-head { margin-bottom: 4px; }
  .info-head canvas { width: 32px; height: 32px; }
  .panel { padding: 8px 10px; }
  .actions button { min-height: 42px; }
}

/* stacked layouts: keep the top bar to two rows even with the co-op chip */
@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) {
  .chip { padding: 0 8px; font-size: 12.5px; }
  .chip #netPing { display: none; }
  #netChip { margin-left: auto; }
  .spacer { display: none; }
  #btnWave { flex: 1 1 130px; }
}

/* narrow portrait phones: the room chip moves into the players panel, stats shrink so the bar stays two rows */
@media (max-width: 420px) {
  #netChip { display: none; }
  .stat { padding: 0 7px; gap: 4px; font-size: 14px; }
  .stat .lbl { font-size: 10px; letter-spacing: .06em; }
  #topbar { gap: 5px 6px; padding: 5px 6px; }
}
/* small landscape phones: one slim top bar, narrower side panel */
@media (orientation: landscape) and (max-height: 520px) and (max-width: 700px) {
  :root { --side-w: 200px; --btn: 38px; }
  #netChip { display: none; }
  .stat .lbl { display: none; }
  .stat { padding: 0 6px; font-size: 14px; }
  button.icon { min-width: 36px; padding: 0 6px; }
  #topbar { gap: 4px; padding: 3px 6px; }
  .tbtn .nm { font-size: 10.5px; }
}

/* very small phones (320px) */
@media (max-width: 340px) {
  :root { --btn: 38px; }
  .stat .lbl { display: none; }
  .stat { padding: 0 6px; }
  #btnWave { flex: 1 1 80px; padding: 0 8px; }
  button.icon { min-width: 38px; padding: 0 4px; }
  #topbar { gap: 4px; padding: 4px; }
}
