/* =====================================================================
   PBLRC NETWORKING ARCADE — styles
   Layout concept: a dark arcade floor (neon grid) with lit cabinets;
   pixel type for marquees, Montserrat for everything students read.
   Single deliberate dark look (arcade screen), colors set explicitly.
   ===================================================================== */

@font-face { font-family: 'Press Start 2P'; src: url('../assets/fonts/press-start-2p.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Montserrat'; font-weight: 400; src: url('../assets/fonts/montserrat-400.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Montserrat'; font-weight: 600; src: url('../assets/fonts/montserrat-600.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Montserrat'; font-weight: 700; src: url('../assets/fonts/montserrat-700.woff2') format('woff2'); font-display: swap; }

:root {
  /* Brand */
  --red: #E53935;
  --gold: #FFC107;
  --green: #2E7D32;
  --charcoal: #212529;
  --gray: #E9ECEF;
  /* Arcade accents */
  --neon: #29D3FF;
  --purple: #B05CFF;
  --green-lit: #5FD068;     /* readable green for text on dark */
  --red-lit: #FF6B66;       /* readable red for text on dark */
  /* Surfaces */
  --bg: #0A0C16;
  --bg-2: #10142A;
  --panel: #161B2E;
  --panel-2: #1D2340;
  --line: #2A3257;
  --text: #E9ECEF;
  --muted: #A9B1CC;
  --grid: rgba(41, 211, 255, 0.07);
  /* Type */
  --pixel: 'Press Start 2P', 'Courier New', monospace;
  --body: 'Montserrat', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', 'Consolas', 'Liberation Mono', 'Courier New', monospace;
  /* Scale */
  --r: 10px;
  --glow-neon: 0 0 0 1px rgba(41, 211, 255, .35), 0 0 18px rgba(41, 211, 255, .25);
  --glow-purple: 0 0 0 1px rgba(176, 92, 255, .4), 0 0 18px rgba(176, 92, 255, .25);
  --glow-gold: 0 0 0 1px rgba(255, 193, 7, .45), 0 0 18px rgba(255, 193, 7, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html.large-text { font-size: 118%; }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    radial-gradient(1200px 600px at 50% -10%, rgba(176, 92, 255, .16), transparent 70%);
  background-size: 32px 32px, 32px 32px, 100% 100%;
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--body);
  font-size: 1rem;
  line-height: 1.6;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--bg-2); }

img { max-width: 100%; }
a { color: var(--neon); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

h1, h2, h3, .pixel { font-family: var(--pixel); font-weight: 400; letter-spacing: .02em; line-height: 1.45; text-wrap: balance; }
h1 { font-size: clamp(1.1rem, 4vw, 2rem); margin: 0; }
h2 { font-size: clamp(.85rem, 2.4vw, 1.1rem); margin: 0 0 .9rem; }
h3 { font-size: .78rem; margin: 0 0 .6rem; }
p { margin: 0 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }
code, kbd, .mono { font-family: var(--mono); }
code { background: rgba(255, 255, 255, .07); padding: .05em .35em; border-radius: 4px; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 .35em; font-size: .85em; }

.wrap {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: rgba(16, 20, 42, .92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.topbar .wrap { display: flex; align-items: center; gap: .75rem; padding-block: .55rem; }
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--text); min-width: 0; background: none; border: 0; padding: 0; cursor: pointer; }
.brand .pixel { font-size: .62rem; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .pixel span { color: var(--gold); }
.topbar .spacer { flex: 1; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-width: 44px; min-height: 44px; padding: 0 .7rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; font-size: .85rem; font-weight: 600;
}
.icon-btn:hover { border-color: var(--neon); box-shadow: var(--glow-neon); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn[aria-pressed="true"] { border-color: var(--red); color: var(--red-lit); }
@media (max-width: 640px) { .icon-btn .lbl { display: none; } .brand .pixel { font-size: .5rem; } }
@media (max-width: 480px) { .brand .pixel { display: none; } }

/* ---------- Logo ---------- */
.logo-plate {
  display: inline-flex; align-items: center; justify-content: center;
  background: #FFFFFF; border-radius: 12px; padding: 8px;
  box-shadow: 0 0 0 2px rgba(255, 193, 7, .55), 0 0 24px rgba(255, 193, 7, .25);
}
.logo-plate.dark-variant { background: transparent; box-shadow: none; padding: 0; }
.logo-plate img { display: block; height: 100%; width: auto; object-fit: contain; }
.logo-sm { height: 46px; padding: 3px 6px; border-radius: 8px; }
.logo-md { height: 112px; }
.logo-lg { height: clamp(120px, 20vw, 170px); }
.logo-placeholder {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  border: 2px dashed var(--gold); border-radius: 12px; color: var(--gold);
  background: rgba(255, 193, 7, .06); padding: 6px 10px; line-height: 1.3;
}
.logo-placeholder b { font-family: var(--pixel); font-size: .6rem; }
.logo-placeholder small { font-size: .62rem; color: var(--gray); }
.logo-sm.logo-placeholder { padding: 2px 6px; }
.logo-sm.logo-placeholder small { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 46px; padding: .55rem 1.1rem;
  border-radius: 8px; border: 2px solid transparent;
  font-family: var(--pixel); font-size: .68rem; letter-spacing: .04em; line-height: 1.3;
  cursor: pointer; text-decoration: none; user-select: none;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease;
}
.btn:active { transform: translateY(2px); }
.btn-primary { background: var(--gold); color: #1A1300; box-shadow: 0 4px 0 #A87A00, 0 0 20px rgba(255, 193, 7, .25); }
.btn-primary:hover { background: #FFD24A; }
.btn-primary:active { box-shadow: 0 2px 0 #A87A00; }
.btn-go { background: var(--green); color: #FFFFFF; box-shadow: 0 4px 0 #17461A, 0 0 18px rgba(95, 208, 104, .25); }
.btn-go:hover { background: #379B3D; }
.btn-ghost { background: var(--panel); color: var(--text); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--neon); box-shadow: var(--glow-neon); }
.btn-danger { background: transparent; color: var(--red-lit); border-color: var(--red); }
.btn-danger:hover { background: rgba(229, 57, 53, .15); }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-sm { min-height: 38px; padding: .35rem .75rem; font-size: .58rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }

/* ---------- Panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 1.1rem; min-width: 0; }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; margin-bottom: .8rem; }
.panel-title h2 { margin: 0; }
section + section { margin-top: 1.4rem; }
main { padding-block: 1.2rem 3rem; }

/* ---------- Hero ---------- */
.hero { display: grid; grid-template-columns: auto 1fr; gap: 1.4rem; align-items: center; padding-block: 1.2rem .4rem; }
.hero-text { min-width: 0; }
.hero .eyebrow { font-family: var(--body); font-weight: 700; font-size: .75rem; letter-spacing: .14em; text-transform: uppercase; color: var(--neon); margin-bottom: .4rem; }
.hero h1 { color: var(--gray); text-shadow: 0 0 1px #fff, 0 0 14px rgba(41, 211, 255, .55), 3px 3px 0 var(--purple); }
.hero h1 .gold { color: var(--gold); text-shadow: 0 0 14px rgba(255, 193, 7, .5), 3px 3px 0 var(--red); }
.tagline { margin: .7rem 0 1rem; color: var(--muted); font-style: italic; }
.press-start {
  font-family: var(--pixel); font-size: .8rem; letter-spacing: .08em;
  background: transparent; color: var(--gold); border: 2px solid var(--gold); border-radius: 8px;
  padding: .85rem 1.1rem; min-height: 48px; cursor: pointer; box-shadow: var(--glow-gold);
}
.press-start .blink { animation: blink 1.1s steps(2, start) infinite; }
.press-start { white-space: nowrap; }
@media (max-width: 400px) { .press-start { white-space: normal; } }
.press-start:hover { background: rgba(255, 193, 7, .1); }
@keyframes blink { to { visibility: hidden; } }
@media (max-width: 640px) { .hero { grid-template-columns: 1fr; text-align: center; justify-items: center; } }

/* ---------- Player stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: .8rem .9rem; min-width: 0; }
.stat .k { font-size: .7rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.stat .v { font-family: var(--pixel); font-size: 1rem; margin-top: .4rem; color: var(--gold); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .v.sm { font-size: .7rem; line-height: 1.6; color: var(--text); }
.rankbar { margin-top: .5rem; }

.bar { height: 12px; background: #0D1022; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--neon), var(--purple)); border-radius: inherit; transition: width .6s ease; }
.bar.gold > i { background: linear-gradient(90deg, var(--gold), var(--red)); }
.bar.green > i { background: linear-gradient(90deg, var(--green), var(--green-lit)); }

/* ---------- Cabinets ---------- */
.cabinets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 1000px) { .cabinets { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 540px) { .cabinets { grid-template-columns: 1fr; } }
.cabinet {
  --c: var(--neon);
  position: relative; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 2px solid var(--c); border-radius: 14px 14px 8px 8px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .5), 0 0 22px color-mix(in srgb, var(--c) 30%, transparent);
  overflow: hidden; min-width: 0;
}
.cabinet .marquee {
  background: repeating-linear-gradient(90deg, color-mix(in srgb, var(--c) 22%, #0A0C16) 0 6px, color-mix(in srgb, var(--c) 30%, #0A0C16) 6px 12px);
  border-bottom: 2px solid var(--c); padding: .75rem .6rem; text-align: center;
}
.cabinet .marquee h2 { margin: 0; font-size: .74rem; color: #FFFFFF; text-shadow: 0 0 10px var(--c); }
.cabinet .screen { margin: .8rem; padding: .9rem; border-radius: 10px; background: #070912; border: 1px solid var(--line); display: grid; grid-template-columns: 64px 1fr; gap: .8rem; align-items: center; }
.cabinet .screen svg { width: 64px; height: 64px; image-rendering: pixelated; }
.cabinet .screen p { margin: 0; font-size: .85rem; color: var(--muted); }
.cabinet dl { margin: 0 .9rem; display: grid; grid-template-columns: 1fr auto; gap: .25rem .6rem; font-size: .85rem; }
.cabinet dt { color: var(--muted); }
.cabinet dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.cabinet .bar { margin: .7rem .9rem 0; }
.cabinet .controls { margin-top: auto; padding: .9rem; display: flex; justify-content: center; }
.cabinet .controls .btn { width: 100%; }
.cabinet.c-binary { --c: var(--neon); }
.cabinet.c-hex { --c: var(--purple); }
.cabinet.c-subnet { --c: var(--gold); }
.cabinet.c-cisco { --c: var(--green-lit); }
.cabinet.c-ailab { --c: var(--purple); }
.cabinet:hover { transform: translateY(-2px); transition: transform .15s ease; }

/* ---------- Achievements ---------- */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; }
.badge { display: grid; grid-template-columns: 40px 1fr; gap: .6rem; align-items: center; padding: .6rem; border-radius: 10px; border: 1px solid var(--line); background: #0E1224; min-width: 0; }
.badge svg { width: 40px; height: 40px; image-rendering: pixelated; }
.badge b { display: block; font-size: .8rem; line-height: 1.3; }
.badge span { display: block; font-size: .72rem; color: var(--muted); line-height: 1.35; }
.badge.locked { opacity: .5; filter: grayscale(1); }
.badge.earned { border-color: var(--gold); box-shadow: var(--glow-gold); }

/* ---------- Game lobby ---------- */
.lobby-head { display: grid; grid-template-columns: 72px 1fr; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.lobby-head svg { width: 72px; height: 72px; image-rendering: pixelated; }
.lobby-head p { margin: .4rem 0 0; color: var(--muted); }
.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.seg { display: flex; flex-wrap: wrap; gap: .35rem; }
.seg button {
  flex: 1 1 auto; min-height: 44px; padding: .4rem .7rem; border-radius: 8px;
  background: #0D1022; border: 1px solid var(--line); cursor: pointer; font-weight: 600; font-size: .85rem;
}
.seg button[aria-pressed="true"] { background: var(--purple); border-color: var(--purple); color: #FFFFFF; box-shadow: var(--glow-purple); }
.opt-label { font-size: .72rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: .4rem; display: block; }
.switch { display: flex; align-items: center; gap: .6rem; cursor: pointer; min-height: 44px; }
.switch input { width: 22px; height: 22px; accent-color: var(--gold); }

.levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .8rem; }
.level-card {
  display: flex; flex-direction: column; gap: .4rem; text-align: left;
  background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: .9rem;
  cursor: pointer; min-width: 0;
}
.level-card:hover:not([disabled]) { border-color: var(--neon); box-shadow: var(--glow-neon); }
.level-card .lv { font-family: var(--pixel); font-size: .6rem; color: var(--neon); }
.level-card .name { font-weight: 700; }
.level-card .desc { font-size: .82rem; color: var(--muted); }
.level-card .meta { margin-top: auto; display: flex; justify-content: space-between; gap: .5rem; font-size: .78rem; font-variant-numeric: tabular-nums; }
.level-card.done { border-color: var(--green-lit); }
.level-card.done .lv::after { content: ' ★ CLEARED'; color: var(--green-lit); }
.level-card[disabled] { opacity: .5; cursor: not-allowed; }
.level-card[disabled] .lv::after { content: ' LOCKED'; color: var(--muted); }

/* ---------- Play screen ---------- */
.hud {
  display: flex; flex-wrap: wrap; gap: .5rem 1.1rem; align-items: center;
  background: #070912; border: 1px solid var(--line); border-radius: var(--r);
  padding: .6rem .9rem; margin-bottom: 1rem;
}
.hud .item { display: flex; flex-direction: column; min-width: 0; }
.hud .k { font-size: .62rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.hud .v { font-family: var(--pixel); font-size: .78rem; color: var(--gold); font-variant-numeric: tabular-nums; }
.hud .v.neon { color: var(--neon); }
.hud .v.green { color: var(--green-lit); }
.hud .grow { flex: 1 1 160px; }
.timerbar { height: 10px; }
.timerbar > i { background: linear-gradient(90deg, var(--green-lit), var(--gold)); transition: width 1s linear; }
.timerbar.low > i { background: var(--red); }

.play-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
@media (max-width: 920px) { .play-grid { grid-template-columns: 1fr; } }

.qcard { background: var(--panel); border: 2px solid var(--line); border-radius: 14px; padding: 1.2rem; min-width: 0; }
.qcard .qnum { font-family: var(--pixel); font-size: .58rem; color: var(--purple); margin-bottom: .6rem; }
.qcard .prompt { font-size: 1.15rem; font-weight: 700; margin-bottom: 1rem; }
.qcard .visual { margin-bottom: 1rem; overflow-x: auto; }
.answer-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.answer-input {
  flex: 1 1 200px; min-width: 0; min-height: 50px; padding: .5rem .8rem;
  background: #070912; border: 2px solid var(--line); border-radius: 8px;
  font-family: var(--mono); font-size: 1.2rem; color: var(--text);
}
.answer-input:focus { border-color: var(--neon); outline: none; box-shadow: var(--glow-neon); }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .7rem; margin-bottom: .8rem; }
.field label { display: block; font-size: .78rem; font-weight: 700; color: var(--muted); margin-bottom: .25rem; }
.field input { width: 100%; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .6rem; }
.choice {
  min-height: 56px; padding: .5rem .8rem; border-radius: 10px; cursor: pointer;
  background: #0D1022; border: 2px solid var(--line); font-family: var(--mono); font-size: 1.1rem; font-weight: 700;
}
.choice:hover:not([disabled]) { border-color: var(--neon); box-shadow: var(--glow-neon); }
.choice .key { font-family: var(--body); font-size: .7rem; color: var(--muted); margin-right: .4rem; }
.choice.right { border-color: var(--green-lit); background: rgba(46, 125, 50, .25); }
.choice.wrong { border-color: var(--red); background: rgba(229, 57, 53, .18); }

.feedback { margin-top: 1rem; border-radius: 10px; padding: .9rem 1rem; border: 2px solid; }
.feedback.good { border-color: var(--green-lit); background: rgba(46, 125, 50, .18); }
.feedback.bad { border-color: var(--red); background: rgba(229, 57, 53, .12); }
.feedback.info { border-color: var(--neon); background: rgba(41, 211, 255, .08); }
.feedback .title { font-family: var(--pixel); font-size: .7rem; margin-bottom: .5rem; }
.feedback.good .title { color: var(--green-lit); }
.feedback.bad .title { color: var(--red-lit); }
.feedback.info .title { color: var(--neon); }
.feedback p:last-child, .feedback ul:last-child, .feedback ol:last-child { margin-bottom: 0; }
.feedback ol, .feedback ul { padding-left: 1.2rem; margin: .3rem 0 .6rem; }
.q-actions { margin-top: 1rem; }

.points-pop { position: fixed; z-index: 60; pointer-events: none; font-family: var(--pixel); color: var(--gold); font-size: 1rem; text-shadow: 0 0 10px rgba(255, 193, 7, .7); animation: popup 1s ease-out forwards; }
@keyframes popup { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-60px); opacity: 0; } }

.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- Bits ---------- */
.bit-chart { display: grid; grid-template-columns: repeat(var(--n, 8), minmax(28px, 1fr)); gap: .3rem; min-width: calc(var(--n, 8) * 31px); }
.bit-chart .pv { text-align: center; font-family: var(--mono); font-size: .85rem; font-weight: 700; color: var(--muted); }
.bit-chart .pv.on { color: var(--gold); }
.bit {
  min-height: 54px; border-radius: 8px; cursor: pointer;
  background: #070912; border: 2px solid var(--line);
  font-family: var(--pixel); font-size: 1.05rem; color: #5B6488;
  transition: background .12s ease, color .12s ease, box-shadow .12s ease;
}
.bit[aria-pressed="true"] { background: rgba(41, 211, 255, .14); border-color: var(--neon); color: var(--neon); box-shadow: var(--glow-neon); }
.bit:disabled { cursor: default; }
.bit-sum { margin-top: .6rem; font-family: var(--mono); font-size: 1rem; overflow-wrap: anywhere; }
.bit-sum b { color: var(--gold); font-size: 1.25rem; }
.digits { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: flex-start; }
.digit {
  display: inline-grid; place-items: center; width: 44px; height: 56px;
  font-family: var(--pixel); font-size: 1.15rem; border-radius: 8px;
  background: #070912; border: 2px solid var(--line); color: #5B6488;
  animation: flipin .45s ease both;
}
.digit.one { color: var(--neon); border-color: var(--neon); box-shadow: var(--glow-neon); }
.digit.hl { outline: 3px solid var(--gold); outline-offset: 2px; }
@keyframes flipin { from { transform: rotateX(90deg); opacity: 0; } to { transform: none; opacity: 1; } }
.digits .gap { width: .9rem; }

/* ---------- Hex tiles ---------- */
.tiles { display: flex; flex-wrap: wrap; gap: .5rem; }
.tile {
  display: inline-grid; place-items: center; min-width: 64px; height: 72px; padding: 0 .7rem;
  font-family: var(--pixel); font-size: 1.4rem; color: #FFFFFF;
  background: radial-gradient(circle at 50% 30%, rgba(176, 92, 255, .45), rgba(176, 92, 255, .12));
  border: 2px solid var(--purple); border-radius: 10px; box-shadow: var(--glow-purple);
  animation: flipin .45s ease both;
}
.hex-chart { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .35rem; }
.hex-chart button {
  display: grid; gap: .1rem; padding: .35rem .2rem; border-radius: 8px; cursor: pointer; text-align: center;
  background: #0D1022; border: 1px solid var(--line); min-height: 44px;
}
.hex-chart button b { font-family: var(--pixel); font-size: .8rem; color: var(--purple); }
.hex-chart button span { font-family: var(--mono); font-size: .7rem; color: var(--muted); }
.hex-chart button[aria-pressed="true"] { border-color: var(--purple); box-shadow: var(--glow-purple); }
.hex-detail { margin-top: .6rem; font-size: .9rem; min-height: 3em; }

.nibbles { display: flex; flex-wrap: wrap; gap: .8rem; }
.nibble { display: grid; gap: .4rem; justify-items: center; padding: .5rem; border-radius: 10px; border: 2px dashed transparent; transition: border-color .4s ease, padding .4s ease; }
.nibble .digits { gap: .25rem; }
.nibble .digit { width: 36px; height: 46px; font-size: .95rem; }
.nibble .hx { font-family: var(--pixel); font-size: 1.1rem; color: var(--purple); opacity: 0; transform: translateY(-6px); transition: opacity .4s ease, transform .4s ease; }
.nibble .calc { font-family: var(--mono); font-size: .75rem; color: var(--muted); opacity: 0; transition: opacity .4s ease; }
.nibbles.grouped { gap: 1.6rem; }
.nibbles.grouped .nibble { border-color: var(--purple); }
.nibbles.grouped .nibble .hx, .nibbles.grouped .nibble .calc { opacity: 1; transform: none; }

/* ---------- IP diagram ---------- */
.ipdiag { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .45rem; min-width: 520px; }
.octet { border-radius: 10px; padding: .5rem; background: #070912; border: 2px solid var(--line); text-align: center; min-width: 0; }
.octet .dec { font-family: var(--pixel); font-size: 1rem; }
.octet .lab { font-size: .68rem; color: var(--muted); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.octet .bits { display: flex; justify-content: center; gap: 2px; margin-top: .35rem; font-family: var(--mono); font-size: .9rem; font-weight: 700; }
.octet .bits span { width: 1.05em; border-radius: 3px; }
.octet .bits .nb { background: rgba(255, 193, 7, .22); color: var(--gold); }
.octet .bits .hb { background: rgba(41, 211, 255, .16); color: var(--neon); }
.octet:nth-child(1) .dec { color: var(--red-lit); }
.octet:nth-child(2) .dec { color: var(--gold); }
.octet:nth-child(3) .dec { color: var(--green-lit); }
.octet:nth-child(4) .dec { color: var(--neon); }
.octet.hl { border-color: var(--gold); box-shadow: var(--glow-gold); }
.legend { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: .5rem; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: .35rem; }
.legend .ln { background: var(--gold); }
.legend .lh { background: var(--neon); }
.dots { font-family: var(--pixel); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; font-variant-numeric: tabular-nums; }
th, td { padding: .35rem .5rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; }
td.mono { font-family: var(--mono); }

/* ---------- Side tools ---------- */
.tools { display: grid; gap: 1rem; min-width: 0; }
.tools .panel h3 { color: var(--neon); }
.steps { margin: 0; padding-left: 1.2rem; }
.steps li { margin-bottom: .35rem; }
.tip { border-left: 3px solid var(--gold); padding-left: .7rem; color: var(--gray); }

/* ---------- Terminal ---------- */
.terminal {
  background: #03060A; border: 2px solid var(--green-lit); border-radius: 10px;
  box-shadow: 0 0 22px rgba(95, 208, 104, .18), inset 0 0 40px rgba(0, 0, 0, .6);
  font-family: var(--mono); font-size: .9rem; line-height: 1.45; color: #C8F7CF;
  display: flex; flex-direction: column; min-width: 0;
}
.term-out { height: min(52vh, 440px); overflow: auto; padding: .7rem .8rem 0; white-space: pre; tab-size: 4; }
.term-out .err { color: #FF8A80; }
.term-out .sys { color: #FFE082; }
.term-out .cmd { color: #FFFFFF; }
.term-out .note { color: #80D8FF; white-space: pre-wrap; font-family: var(--body); font-size: .85rem; }
.term-line { display: flex; align-items: center; gap: .35rem; padding: .35rem .8rem .7rem; border-top: 1px dashed rgba(95, 208, 104, .25); }
.term-line .ps { white-space: pre; color: #FFFFFF; font-weight: 700; }
.term-line input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; color: #FFFFFF; font-family: var(--mono); font-size: 1rem; padding: .3rem 0; caret-color: var(--green-lit); }
.term-keys { display: flex; flex-wrap: wrap; gap: .35rem; padding: 0 .8rem .7rem; }
.term-keys button { min-height: 38px; padding: 0 .65rem; border-radius: 6px; background: #0B1A10; border: 1px solid rgba(95, 208, 104, .4); color: #C8F7CF; font-family: var(--mono); cursor: pointer; }
.modebadge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; background: rgba(95, 208, 104, .15); color: var(--green-lit); border: 1px solid rgba(95, 208, 104, .4); }

.tasks { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.task { display: grid; grid-template-columns: 28px 1fr; gap: .5rem; align-items: start; padding: .55rem; border-radius: 8px; background: #0D1022; border: 1px solid var(--line); }
.task .chk { width: 24px; height: 24px; border-radius: 6px; border: 2px solid var(--line); display: grid; place-items: center; font-weight: 700; }
.task.done { border-color: rgba(95, 208, 104, .6); }
.task.done .chk { background: var(--green); border-color: var(--green-lit); color: #FFFFFF; }
.task .t { font-size: .9rem; }
.task .h { margin-top: .3rem; font-size: .82rem; color: var(--muted); }
.task .h code { color: var(--gold); }
.task .hint-btn { margin-top: .35rem; background: none; border: 0; color: var(--neon); cursor: pointer; padding: .2rem 0; font-size: .8rem; font-weight: 600; text-decoration: underline; min-height: 32px; }
.task input { margin-top: .4rem; width: 100%; min-height: 40px; background: #070912; border: 1px solid var(--line); border-radius: 6px; padding: .3rem .5rem; font-family: var(--mono); }
.task .ans-row { display: flex; gap: .4rem; flex-wrap: wrap; }
.task .ans-row input { flex: 1 1 140px; }
.task .ans-msg { font-size: .8rem; margin-top: .25rem; }

/* ---------- Tutorial / dialog ---------- */
dialog {
  width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 40px);
  background: var(--bg-2); color: var(--text);
  border: 2px solid var(--neon); border-radius: 14px; padding: 0;
  box-shadow: 0 0 40px rgba(41, 211, 255, .25);
}
dialog::backdrop { background: rgba(3, 4, 10, .78); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .9rem 1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg-2); z-index: 1; }
.dlg-head h2 { margin: 0; font-size: .8rem; }
.dlg-body { padding: 1rem; overflow: auto; }
.dlg-foot { padding: .8rem 1rem 1rem; border-top: 1px solid var(--line); }
.glossary dt { font-weight: 700; color: var(--gold); margin-top: .7rem; }
.glossary dd { margin: .15rem 0 0; color: var(--gray); }
.glossary-search { width: 100%; min-height: 44px; background: #070912; border: 1px solid var(--line); border-radius: 8px; padding: .4rem .7rem; margin-bottom: .4rem; }
.tut-progress { display: flex; gap: .35rem; }
.tut-progress i { width: 22px; height: 6px; border-radius: 3px; background: var(--line); }
.tut-progress i.on { background: var(--neon); }
.tut-slide { min-height: 160px; }
.tut-example { background: #070912; border: 1px solid var(--line); border-radius: 10px; padding: .8rem; margin: .6rem 0; overflow-x: auto; }

.settings-list { display: grid; gap: 1rem; }
.settings-list .row { display: grid; gap: .4rem; }
.settings-list select { min-height: 44px; background: #070912; border: 1px solid var(--line); border-radius: 8px; padding: .3rem .6rem; }
.notice { font-size: .85rem; padding: .7rem .8rem; border-radius: 8px; background: rgba(41, 211, 255, .08); border: 1px solid rgba(41, 211, 255, .35); }
.notice.warn { background: rgba(255, 193, 7, .08); border-color: rgba(255, 193, 7, .45); }

/* ---------- Results ---------- */
.results { text-align: center; display: grid; justify-items: center; gap: .8rem; padding-block: 1rem; }
.results .headline { font-family: var(--pixel); font-size: clamp(1rem, 4vw, 1.6rem); color: var(--gold); text-shadow: 0 0 16px rgba(255, 193, 7, .5), 3px 3px 0 var(--red); }
.results .headline.retry { color: var(--neon); text-shadow: 0 0 16px rgba(41, 211, 255, .5), 3px 3px 0 var(--purple); }
.result-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .7rem; width: 100%; max-width: 720px; }
.new-badges { display: flex; flex-wrap: wrap; justify-content: center; gap: .6rem; }
.levelup {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; pointer-events: none;
}
.levelup div {
  font-family: var(--pixel); font-size: clamp(1.2rem, 6vw, 2.6rem); color: var(--gold);
  text-shadow: 0 0 20px rgba(255, 193, 7, .8), 4px 4px 0 var(--red);
  animation: levelup 2.2s ease forwards; text-align: center; padding: 1rem; background: rgba(10, 12, 22, .75); border-radius: 14px;
}
.levelup small { display: block; font-size: .45em; color: var(--neon); margin-top: .6rem; text-shadow: none; }
@keyframes levelup { 0% { transform: scale(.3); opacity: 0; } 15% { transform: scale(1.1); opacity: 1; } 25% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 65; }
.toasts { position: fixed; z-index: 80; right: max(12px, env(safe-area-inset-right, 0px)); bottom: calc(12px + env(safe-area-inset-bottom, 0px)); display: grid; gap: .5rem; max-width: min(360px, calc(100vw - 24px)); }
.toast { display: grid; grid-template-columns: 36px 1fr; gap: .6rem; align-items: center; padding: .7rem .8rem; border-radius: 10px; background: var(--panel-2); border: 2px solid var(--gold); box-shadow: var(--glow-gold); animation: toastin .3s ease; font-size: .88rem; }
.toast svg { width: 36px; height: 36px; image-rendering: pixelated; }
.toast b { display: block; font-family: var(--pixel); font-size: .55rem; color: var(--gold); margin-bottom: .2rem; }
@keyframes toastin { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.footer { border-top: 1px solid var(--line); padding-block: 1.2rem 2rem; color: var(--muted); font-size: .82rem; }
.footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .6rem; }

.crumbs { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }

/* ---------- Reduced motion ---------- */
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after {
  animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important;
}
html.reduce-motion .press-start .blink { animation: none !important; }
html.reduce-motion .cabinet:hover { transform: none; }

/* Compact tables inside side tools */
.tools th, .tools td { padding: .3rem .35rem; }
