/* =============================================================================
   Uncrypt Playground — theme
   AMOLED black · one muted-red accent · minimalist · restrained type.
   No neon, no oversized bold. Texture comes from mono labels, hairline borders
   and generous negative space rather than glow.
   ============================================================================= */

:root {
  --bg:            #000000;
  --surface-1:     #0a0a0c;
  --surface-2:     #101014;
  --surface-3:     #16161b;
  --border:        #1f1f26;
  --border-strong: #2b2b34;

  --text:      #e7e7ea;
  --text-dim:  #9a9aa3;
  --text-mute: #63636c;

  --accent:      #d43a4b;   /* muted crimson — the only red, used sparingly */
  --accent-hi:   #e4586a;
  --accent-dim:  rgba(212, 58, 75, 0.12);
  --accent-line: rgba(212, 58, 75, 0.32);

  --ok:   #57a97a;
  --ok-dim: rgba(87, 169, 122, 0.12);
  --warn: #c6a24e;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  --wrap: 1120px;
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  font-weight: 400;
  letter-spacing: 0.1px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* barely-there vignette + top wash of accent; keep opacity tiny (not neon) */
  background-image:
    radial-gradient(1200px 480px at 50% -10%, rgba(212,58,75,0.06), transparent 60%),
    radial-gradient(800px 800px at 100% 0%, rgba(255,255,255,0.015), transparent 60%);
  background-attachment: fixed;
  min-height: 100vh;
}

h1, h2, h3, h4 { font-weight: 550; line-height: 1.25; letter-spacing: -0.2px; margin: 0 0 0.5em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
a { color: var(--text); text-decoration: none; transition: color 0.15s var(--ease); }
a:hover { color: var(--accent-hi); }

.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 24px; }
.muted { color: var(--text-mute); }
.dim { color: var(--text-dim); }

.skip {
  position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff;
  padding: 8px 14px; border-radius: var(--r-sm); z-index: 100;
}
.skip:focus { left: 12px; top: 12px; }

/* mono micro-label used for category tags, kickers, code-ish accents */
.mono-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-mute);
}

/* --------------------------------------------------------------------------
   Header / nav
   -------------------------------------------------------------------------- */
.site-head {
  position: sticky; top: 0; z-index: 40;
  background: rgba(0,0,0,0.72);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.head-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 12px; height: 12px; border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.brand-text { font-family: var(--font-mono); font-size: 0.95rem; letter-spacing: 0.02em; color: var(--text); }
.brand-sep { color: var(--text-mute); margin: 0 2px; }
.brand-sub { color: var(--text-dim); }
.brand:hover .brand-text { color: var(--text); }

.site-nav { display: flex; gap: 4px; }
.site-nav a {
  padding: 8px 14px; border-radius: var(--r-sm); font-size: 0.9rem; color: var(--text-dim);
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); }
.site-nav a.active { color: var(--text); background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--accent); }

/* --------------------------------------------------------------------------
   Hero
   -------------------------------------------------------------------------- */
.hero { padding: 72px 0 40px; border-bottom: 1px solid var(--border); }
.hero-kicker { margin-bottom: 18px; }
.hero h1 {
  font-size: clamp(2rem, 4.5vw, 3rem); font-weight: 500; letter-spacing: -0.6px;
  max-width: 16ch; margin-bottom: 18px;
}
.hero h1 .accent { color: var(--accent); }
.hero-lede { max-width: 60ch; color: var(--text-dim); font-size: 1.05rem; }
.hero-actions { display: flex; gap: 12px; margin-top: 28px; flex-wrap: wrap; }

.hero-stats { display: flex; gap: 32px; margin-top: 44px; flex-wrap: wrap; }
.hero-stat .n { font-size: 1.6rem; font-family: var(--font-mono); color: var(--text); }
.hero-stat .l { display: block; }

/* --------------------------------------------------------------------------
   Buttons / pills
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  font: inherit; font-size: 0.9rem; padding: 9px 16px; border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-strong);
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease), color 0.15s var(--ease);
}
.btn:hover { border-color: var(--accent-line); color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hi); border-color: var(--accent-hi); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }

.pill {
  display: inline-block; font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.1em;
  text-transform: uppercase; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border-strong);
  color: var(--text-dim);
}
.diff-easy   { color: #6fb58a; border-color: rgba(111,181,138,0.35); }
.diff-medium { color: var(--warn); border-color: rgba(198,162,78,0.35); }
.diff-hard   { color: var(--accent-hi); border-color: var(--accent-line); }

/* --------------------------------------------------------------------------
   Category sections + lab grid
   -------------------------------------------------------------------------- */
.cat-section { padding: 44px 0; border-bottom: 1px solid var(--border); scroll-margin-top: 76px; }
.cat-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.cat-head-left { max-width: 62ch; }
.cat-title { display: flex; align-items: baseline; gap: 12px; margin-bottom: 6px; }
.cat-title h2 { margin: 0; font-weight: 500; }
.cat-desc { color: var(--text-dim); margin: 0; }
.cat-progress { text-align: right; min-width: 130px; }
.cat-progress .frac { font-family: var(--font-mono); font-size: 0.95rem; color: var(--text-dim); }
.cat-progress .frac .done { color: var(--accent); }
.progress-track { height: 3px; background: var(--surface-3); border-radius: 999px; margin-top: 8px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.5s var(--ease); }
.cat-badge-earned { color: var(--ok); font-size: 0.8rem; margin-top: 6px; display: none; }

.lab-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.lab-card {
  position: relative; display: flex; flex-direction: column;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 16px 16px 14px;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease), transform 0.15s var(--ease);
}
.lab-card:hover { border-color: var(--accent-line); background: var(--surface-2); }
.lab-card:hover .lab-card-go { color: var(--accent-hi); }
.lab-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.lab-card-lvl { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.12em; color: var(--text-mute); }
.lab-card h3 { font-size: 1rem; font-weight: 500; margin: 0 0 6px; }
.lab-card p { font-size: 0.86rem; color: var(--text-dim); margin: 0 0 14px; flex: 1; }
.lab-card-foot { display: flex; align-items: center; justify-content: space-between; }
.lab-card-status { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--text-mute); }
.lab-card-go { font-size: 0.82rem; color: var(--text-dim); font-family: var(--font-mono); }
.lab-card.is-solved { border-color: rgba(87,169,122,0.28); }
.lab-card.is-solved .lab-card-status { color: var(--ok); }
.lab-card .check { width: 14px; height: 14px; display: none; }
.lab-card.is-solved .check { display: inline-block; }
.lab-card-link { position: absolute; inset: 0; border-radius: var(--r-md); }

/* --------------------------------------------------------------------------
   About / prose panels
   -------------------------------------------------------------------------- */
.panel { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 28px; }
.about { padding: 48px 0; }
.about-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-top: 22px; }
.about-card h3 { font-size: 1rem; font-weight: 500; margin-bottom: 6px; }
.about-card p { color: var(--text-dim); font-size: 0.9rem; margin: 0; }
.about-card .mono-label { display: block; margin-bottom: 10px; color: var(--accent); }

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.site-foot { border-top: 1px solid var(--border); margin-top: 40px; }
.foot-inner { display: flex; justify-content: space-between; gap: 20px; padding: 26px 0; flex-wrap: wrap; }
.foot-note { margin: 0; font-size: 0.86rem; color: var(--text-dim); max-width: 60ch; }
.foot-meta { margin: 0; font-size: 0.8rem; }

/* --------------------------------------------------------------------------
   Forms / inputs
   -------------------------------------------------------------------------- */
input[type="text"], input[type="search"], input[type="password"], input[type="email"],
input[type="url"], input[type="number"], textarea, select {
  width: 100%; font: inherit; font-size: 0.92rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); padding: 9px 12px; transition: border-color 0.15s var(--ease);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent-line); }
textarea { min-height: 92px; resize: vertical; font-family: var(--font-sans); }
.poc-input { font-family: var(--font-mono); font-size: 0.85rem; line-height: 1.5; min-height: 120px; white-space: pre; }
.field { margin-bottom: 14px; }
.field-label { display: block; font-size: 0.78rem; color: var(--text-mute); margin-bottom: 6px; letter-spacing: 0.02em; }
::placeholder { color: var(--text-mute); }

/* --------------------------------------------------------------------------
   Lab chrome
   -------------------------------------------------------------------------- */
.lab-body { background: var(--bg); }
.lab-topbar { border-bottom: 1px solid var(--border); background: rgba(0,0,0,0.6); }
.lab-topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 52px; }
.lab-back { font-size: 0.85rem; color: var(--text-dim); }
.lab-back:hover { color: var(--text); }
.lab-id-meta { display: flex; align-items: center; gap: 12px; }
.lab-level { font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-mute); }

.lab-head { padding: 34px 0 22px; }
.lab-title { font-size: 1.5rem; font-weight: 500; margin-bottom: 8px; }
.lab-objective { color: var(--text-dim); max-width: 72ch; margin-bottom: 20px; }

.lab-controls {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 20px;
  padding: 16px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-md);
  flex-wrap: wrap;
}
.flag-form { flex: 1; min-width: 260px; }
.flag-row { display: flex; gap: 8px; }
.flag-row input { font-family: var(--font-mono); }
.flag-status { margin: 8px 0 0; font-size: 0.85rem; min-height: 1.2em; }
.flag-status.ok { color: var(--ok); }
.flag-status.err { color: var(--accent-hi); }
.lab-links { display: flex; gap: 8px; }

.lab-main { padding: 20px 0 40px; }
.lab-stage {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 26px;
}
.lab-stage h2 { font-weight: 500; }
.lab-sandbox-note { font-size: 0.8rem; margin-top: 18px; }

/* generic in-lab UI atoms reused by many labs */
.app-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 18px; margin: 0 0 16px; }
.app-card:last-child { margin-bottom: 0; }
.result-box {
  font-family: var(--font-mono); font-size: 0.85rem; white-space: pre-wrap; word-break: break-word;
  background: #050506; border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 14px; color: var(--text-dim); margin-top: 12px;
}
.result-box .flagline { color: var(--accent-hi); }
.hint-none { display: none; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.tag-open { color: var(--ok); } .tag-closed { color: var(--text-mute); }

/* --------------------------------------------------------------------------
   Walkthrough pages
   -------------------------------------------------------------------------- */
.wt-hero { padding: 56px 0 28px; border-bottom: 1px solid var(--border); }
.wt-warn {
  display: flex; gap: 12px; align-items: flex-start; margin-top: 20px;
  background: var(--accent-dim); border: 1px solid var(--accent-line);
  border-radius: var(--r-md); padding: 14px 16px; font-size: 0.9rem; color: var(--text-dim);
}
.wt-cat-nav { display: flex; flex-wrap: wrap; gap: 8px; padding: 24px 0; border-bottom: 1px solid var(--border); }
.wt-cat-nav a { font-family: var(--font-mono); font-size: 0.78rem; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; color: var(--text-dim); }
.wt-cat-nav a:hover { border-color: var(--accent-line); color: var(--text); }

.wt-list { padding: 24px 0 48px; }
.wt-group { margin-bottom: 40px; scroll-margin-top: 76px; }
.wt-group > h2 { font-weight: 500; display: flex; align-items: baseline; gap: 10px; }
.wt-item {
  border: 1px solid var(--border); border-radius: var(--r-md); margin-bottom: 10px; overflow: hidden;
  background: var(--surface-1);
}
.wt-item > summary {
  cursor: pointer; padding: 14px 18px; display: flex; align-items: center; gap: 12px; list-style: none;
}
.wt-item > summary::-webkit-details-marker { display: none; }
.wt-item > summary:hover { background: var(--surface-2); }
.wt-item[open] > summary { border-bottom: 1px solid var(--border); }
.wt-item .wt-lvl { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-mute); min-width: 58px; }
.wt-item .wt-name { flex: 1; }
.wt-body { padding: 6px 18px 20px; }
.wt-body h4 { font-weight: 550; color: var(--text); margin: 18px 0 6px; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.08em; }
.wt-body p, .wt-body li { color: var(--text-dim); }
.wt-body ol, .wt-body ul { padding-left: 20px; }
.wt-body a { color: var(--accent-hi); text-decoration: underline; text-underline-offset: 2px; }

/* code blocks (terminal-ish, no neon) */
pre, code, .code { font-family: var(--font-mono); }
.wt-body pre, pre.code {
  background: #050506; border: 1px solid var(--border); border-left: 2px solid var(--accent-line);
  border-radius: var(--r-sm); padding: 14px 16px; overflow-x: auto; font-size: 0.84rem;
  color: #cfd0d4; margin: 10px 0 16px; line-height: 1.55;
}
:not(pre) > code {
  background: var(--surface-3); border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 6px; font-size: 0.85em; color: #d8b4bb;
}
.wt-open-lab { display: inline-flex; margin-top: 8px; }

/* --------------------------------------------------------------------------
   Modal / badge
   -------------------------------------------------------------------------- */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.72); backdrop-filter: blur(3px); }
.modal-card {
  position: relative; z-index: 1; width: 100%; max-width: 560px;
  background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  padding: 28px; box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
.modal-close { position: absolute; top: 12px; right: 14px; background: none; border: none; color: var(--text-mute); font-size: 1.4rem; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-kicker { color: var(--accent); }
.modal-title { font-weight: 550; margin: 4px 0 8px; }
.modal-desc { color: var(--text-dim); font-size: 0.92rem; }
.badge-preview-wrap { margin: 16px 0; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; background: #050506; }
#badge-canvas { display: block; width: 100%; height: auto; }
.modal-actions { display: flex; gap: 10px; }
.modal-hint { margin-top: 14px; font-size: 0.82rem; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--surface-3); border: 1px solid var(--border-strong); border-left: 2px solid var(--accent);
  color: var(--text); padding: 12px 18px; border-radius: var(--r-sm); font-size: 0.9rem;
  opacity: 0; pointer-events: none; transition: opacity 0.25s var(--ease), transform 0.25s var(--ease); z-index: 70;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --------------------------------------------------------------------------
   Self-test page
   -------------------------------------------------------------------------- */
.check-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.check-row .st { font-family: var(--font-mono); font-size: 0.8rem; }
.st-pass { color: var(--ok); } .st-fail { color: var(--accent-hi); } .st-warn { color: var(--warn); }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 720px) {
  body { font-size: 14.5px; }
  .head-inner { height: 56px; }
  .site-nav a { padding: 7px 10px; }
  .hero { padding: 48px 0 32px; }
  .cat-head { flex-direction: column; align-items: flex-start; }
  .cat-progress { text-align: left; width: 100%; }
  .lab-controls { flex-direction: column; align-items: stretch; }
  .lab-links { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* --------------------------------------------------------------------------
   Utilities — used by the trusted shell pages (home, walkthrough, selftest)
   so their markup carries NO inline style attributes. This keeps the strict
   Content-Security-Policy intact (style-src 'self', no 'unsafe-inline'):
   inline style="" attributes would be dropped by the browser under that CSP.
   Lab pages don't rely on these — they ship their own inline styles and run
   without the strict CSP so they stay exploitable.
   -------------------------------------------------------------------------- */
.u-accent    { color: var(--accent); }
.u-accent-hi { color: var(--accent-hi); }
.u-medium    { font-weight: 500; }
.u-measure   { max-width: 70ch; }
.u-flex1     { flex: 1; }
.u-mono-sm   { font-family: var(--font-mono); font-size: 0.8rem; }
.u-fs-sm     { font-size: 0.88rem; }
.u-fs-xs     { font-size: 0.82rem; }
.u-mb-14     { margin-bottom: 14px; }
.u-mt-20     { margin-top: 20px; }
.u-mt-22     { margin-top: 22px; }
.u-mt-26     { margin-top: 26px; }
.u-pb-20     { padding-bottom: 20px; }
.u-no-border { border-bottom: none; }

/* Claim-badge button starts hidden; app.js reveals it (via the CSSOM, which
   CSP allows) once a whole track is complete — so no inline style is needed. */
.cat-claim { display: none; margin-top: 10px; }
