:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --border-strong: #cdd2d9;
  --text: #111418;
  --text-2: #4b5563;
  --muted: #6b7280;
  --accent: #2459c9;
  --accent-hover: #1d4aab;
  --accent-soft: #e8effc;
  --on-accent: #ffffff;
  --success: #15803d;
  --success-soft: #e7f5ec;
  --danger: #c2362c;
  --danger-soft: #fdecea;
  --cat-web: #2a78d6;
  --cat-crypto: #eb6834;
  --cat-forensics: #1baf7a;
  --cat-reverse: #eda100;
  --cat-misc: #e87ba4;

  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 12px 32px rgb(15 23 42 / 0.14);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0e1013;
  --surface: #16191e;
  --surface-2: #1d2127;
  --border: #272c33;
  --border-strong: #363c45;
  --text: #eceff3;
  --text-2: #b3bac5;
  --muted: #8b939f;
  --accent: #6b9bf2;
  --accent-hover: #87aef5;
  --accent-soft: rgb(107 155 242 / 0.14);
  --on-accent: #0b1220;
  --success: #4cc17a;
  --success-soft: rgb(76 193 122 / 0.12);
  --danger: #f07a70;
  --danger-soft: rgb(240 122 112 / 0.12);
  --cat-web: #3987e5;
  --cat-crypto: #d95926;
  --cat-forensics: #199e70;
  --cat-reverse: #c98500;
  --cat-misc: #d55181;
  --shadow: 0 12px 32px rgb(0 0 0 / 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #0e1013;
    --surface: #16191e;
    --surface-2: #1d2127;
    --border: #272c33;
    --border-strong: #363c45;
    --text: #eceff3;
    --text-2: #b3bac5;
    --muted: #8b939f;
    --accent: #6b9bf2;
    --accent-hover: #87aef5;
    --accent-soft: rgb(107 155 242 / 0.14);
    --on-accent: #0b1220;
    --success: #4cc17a;
    --success-soft: rgb(76 193 122 / 0.12);
    --danger: #f07a70;
    --danger-soft: rgb(240 122 112 / 0.12);
    --cat-web: #3987e5;
    --cat-crypto: #d95926;
    --cat-forensics: #199e70;
    --cat-reverse: #c98500;
    --cat-misc: #d55181;
    --shadow: 0 12px 32px rgb(0 0 0 / 0.5);
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
code, pre, kbd { font-family: var(--mono); font-size: 0.9em; }
code { background: var(--surface-2); border: 1px solid var(--border); padding: 0.05em 0.35em; border-radius: 4px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; font-weight: 600; letter-spacing: -0.01em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skip-link {
  position: absolute;
  left: 16px;
  top: -60px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  z-index: 200;
}
.skip-link:focus { top: 12px; color: var(--on-accent); }

.topbar { position: sticky; top: 0; z-index: 50; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1160px; margin: 0 auto; padding: 0 20px; height: 60px; display: flex; align-items: center; gap: 28px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 16px; white-space: nowrap; }
.brand:hover { color: var(--text); }
.brand-mark { width: 24px; height: 24px; color: #2459c9; flex: none; }
.nav { display: flex; align-items: center; gap: 4px; }
.nav a { color: var(--text-2); text-decoration: none; font-weight: 500; padding: 6px 10px; border-radius: var(--radius-sm); }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current='page'] { color: var(--text); background: var(--surface-2); }
.theme-toggle {
  width: 36px;
  height: 36px;
  margin-left: auto;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: color 0.12s, background-color 0.12s, border-color 0.12s;
}
.theme-toggle:hover { color: var(--text); background: var(--surface-2); border-color: var(--border-strong); }
.theme-icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-icon-moon { fill: currentColor; stroke: none; }
.theme-icon-sun { display: none; }
:root[data-theme='dark'] .theme-icon-moon { display: none; }
:root[data-theme='dark'] .theme-icon-sun { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-icon-moon { display: none; }
  :root:not([data-theme]) .theme-icon-sun { display: block; }
}
@media (max-width: 480px) {
  .topbar-inner { padding: 0 16px; gap: 12px; }
  .brand span { display: none; }
}

main { flex: 1; width: 100%; max-width: 1160px; margin: 0 auto; padding: 36px 20px 64px; }
main:focus { outline: none; }
@media (max-width: 720px) { main { padding: 24px 16px 48px; } }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px 24px; margin-bottom: 24px; }
.page-head h1 { font-size: 26px; margin: 0 0 4px; }
.page-head p { margin: 0; color: var(--text-2); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.section { margin-top: 40px; }
.section > h2 { font-size: 18px; margin-bottom: 14px; }
.muted { color: var(--muted); }

.footer { color: var(--muted); font-size: 13px; text-align: center; padding: 20px 16px 28px; border-top: 1px solid var(--border); }
.footer p { margin: 0; }

.loading { min-height: 40vh; display: grid; place-items: center; color: var(--muted); }

.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-2);
}
.error-box { border-color: var(--danger); background: var(--danger-soft); color: var(--text); }
.empty { color: var(--muted); padding: 40px 16px; text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius); margin: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: 500 14px var(--font);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}
.btn:hover { color: var(--text); background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }

.input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: 14px var(--mono);
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-msg { min-height: 1.5em; margin: 8px 0 0; font-size: 14px; color: var(--text-2); }
.form-msg.bad { color: var(--danger); }

.intro { padding: 12px 0 8px; max-width: 720px; }
.intro h1 { font-size: clamp(28px, 5vw, 40px); margin-bottom: 12px; letter-spacing: -0.02em; }
.intro .lead { font-size: 17px; color: var(--text-2); margin: 0 0 24px; }

.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.cat-card { display: block; color: var(--text); text-decoration: none; transition: border-color 0.12s; }
.cat-card:hover { color: var(--text); border-color: var(--border-strong); }
.cat-card h3 { font-size: 15px; margin: 0; }
.cat-card p { margin: 8px 0 10px; color: var(--text-2); font-size: 14px; }
.cat-card .muted { font-size: 13px; }
.cat-card-head { display: flex; align-items: center; gap: 8px; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--cat); flex: none; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; counter-reset: step; }
.step { counter-increment: step; }
.step::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin-bottom: 12px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
}
.step h3 { font-size: 15px; margin-bottom: 4px; }
.step p { margin: 0; color: var(--text-2); font-size: 14px; }
@media (max-width: 860px) { .steps { grid-template-columns: 1fr; } }

.progress { font-size: 14px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.progress strong { color: var(--text); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 28px; }
.toolbar-right { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-left: auto; }
.segmented { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.seg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-2);
  font: 500 13px var(--font);
  cursor: pointer;
}
.seg:hover { color: var(--text); background: var(--surface-2); }
.seg[aria-pressed='true'] { color: var(--text); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border-strong); }
.seg .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.toolbar .search { width: 220px; height: 36px; font-family: var(--font); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
@media (max-width: 720px) {
  .toolbar-right { margin-left: 0; width: 100%; }
  .toolbar .search { flex: 1; width: auto; }
}

.cat-section { margin-bottom: 36px; }
.cat-section > h2 { display: flex; align-items: center; gap: 10px; font-size: 16px; margin-bottom: 12px; }
.cat-section > h2 small { font-weight: 400; font-size: 13px; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 128px;
  padding: 16px;
  text-align: left;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.12s, background-color 0.12s;
}
.card:hover { border-color: var(--border-strong); }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-title { font-size: 15px; margin: 0; flex: 1; }
.card-meta { font-size: 13px; color: var(--muted); }
.card-points { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.card.is-solved { background: var(--surface-2); }
.card.is-solved .card-title { color: var(--text-2); }
.cat-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge svg { width: 12px; height: 12px; }
.badge-success { color: var(--success); background: var(--success-soft); }
.badge-neutral { color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); }

.modal {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: auto;
}
.modal::backdrop { background: rgb(10 12 16 / 0.55); }
.modal-head { position: relative; padding: 22px 24px 18px; border-bottom: 1px solid var(--border); }
.modal-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 8px; }
.modal-head h2 { font-size: 22px; margin: 0 44px 6px 0; }
.modal-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--muted); }
.modal-meta strong { color: var(--text); font-weight: 600; }
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.modal-close:hover { color: var(--text); background: var(--surface-2); }
.modal-close svg { width: 16px; height: 16px; }
.modal-body { padding: 20px 24px 24px; }
.desc { color: var(--text-2); }
.desc p { margin: 0 0 12px; }
.desc strong, .desc em { color: var(--text); }
.desc audio { width: 100%; margin: 4px 0 12px; }
.cipher {
  margin: 12px 0;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 260px;
  overflow: auto;
  font-size: 13px;
  line-height: 1.6;
}
.cipher.emoji { word-break: normal; font-size: 17px; line-height: 1.8; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 4px; }
.hints { display: grid; gap: 8px; margin-top: 20px; }
.hints h3 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 0; }
.hint { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); font-size: 14px; }
.hint-btn { justify-content: flex-start; width: 100%; color: var(--text-2); font-weight: 400; }
.flag-form { display: flex; gap: 8px; margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border); }
.flag-form .input { flex: 1; }
.solved-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--success-soft);
  color: var(--success);
  font-weight: 500;
}
.solved-banner svg { width: 16px; height: 16px; }
@media (max-width: 520px) {
  .flag-form { flex-direction: column; }
  .modal-head h2 { font-size: 19px; }
}

.rules { max-width: 760px; }
.rules ol { margin: 0; padding-left: 20px; color: var(--text-2); }
.rules li { margin-bottom: 10px; }
.rules li strong { color: var(--text); }
.bonus { margin-top: 20px; padding: 14px 16px; border-radius: var(--radius-sm); border: 1px dashed var(--border-strong); background: var(--surface-2); }
.bonus p { margin: 0 0 6px; color: var(--text-2); font-size: 14px; }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 300; display: grid; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 14px;
}
.toast.good { border-left-color: var(--success); }
.toast.bad { border-left-color: var(--danger); }
.toast strong { display: block; margin-bottom: 2px; }
.toast code { word-break: break-all; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
