:root {
  --bg: #0f1428;
  --bg-2: #161d38;
  --surface: #1d2545;
  --surface-2: #252f57;
  --line: #34407a;
  --text: #eef1ff;
  --muted: #a3acd6;
  --accent: #7c8cff;
  --accent-ink: #0f1428;
  --good: #3ddc97;
  --good-bg: rgba(61, 220, 151, 0.14);
  --bad: #ff6b81;
  --bad-bg: rgba(255, 107, 129, 0.14);
  --info: #6cc7ff;
  --info-bg: rgba(108, 199, 255, 0.14);
  --warn: #ffc857;
  --easy: #3ddc97;
  --medium: #ffc857;
  --hard: #ff6b81;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 12px 32px rgba(3, 6, 20, 0.45);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(124, 140, 255, 0.18), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(61, 220, 151, 0.10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

h1, h2 { line-height: 1.25; margin: 0 0 16px; }
h1 { font-size: clamp(1.5rem, 3vw, 2rem); }
h2 { font-size: 1.25rem; }
p { margin: 0 0 12px; }
code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: rgba(124, 140, 255, 0.16);
  border: 1px solid rgba(124, 140, 255, 0.28);
  border-radius: 6px;
  padding: 1px 6px;
  overflow-wrap: anywhere;
}
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: rgba(15, 20, 40, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: 0.02em; }
.brand.big { font-size: 1.6rem; justify-content: center; }
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--good));
  box-shadow: 0 0 16px rgba(124, 140, 255, 0.6);
}
.brand.big .brand-mark { width: 40px; height: 40px; border-radius: 12px; }
.hud { flex: 1; display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; }
.xp strong { color: var(--warn); font-size: 1.1rem; }
.clock {
  font-family: var(--mono);
  font-size: 1.15rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  min-width: 92px;
  text-align: center;
}
.clock.warn { color: var(--warn); border-color: var(--warn); }
.clock.danger { color: var(--bad); border-color: var(--bad); animation: pulse 1s ease-in-out infinite; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.langs { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lang {
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  border: 0;
  padding: 6px 12px;
  cursor: pointer;
}
.lang.active { background: var(--accent); color: var(--accent-ink); }

.app-main { max-width: 1040px; margin: 0 auto; padding: 32px 24px 64px; }
.view { animation: rise 0.35s ease-out; }

.btn {
  font: inherit;
  font-weight: 700;
  border-radius: 999px;
  padding: 10px 20px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s ease;
  color: var(--text);
  background: var(--surface-2);
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, .lang:focus-visible, .dot:focus-visible, .island:focus-visible, .level-card:focus-visible, .choice:focus-within {
  outline: 3px solid var(--info);
  outline-offset: 2px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.success { background: var(--good); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn.ghost { background: transparent; border-color: var(--line); }
a.btn { text-decoration: none; }
.btn.small { padding: 6px 14px; font-size: 0.875rem; }
.btn.block { width: 100%; }
.btn.logout { display: inline-flex; align-items: center; gap: 6px; }
.btn.logout .icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.pill.level-easy { color: var(--easy); border-color: var(--easy); }
.pill.level-medium { color: var(--medium); border-color: var(--medium); }
.pill.level-hard { color: var(--hard); border-color: var(--hard); }

.card {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 24px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.banner.info { border-color: var(--info); background: var(--info-bg); }

.level-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; }
.level-card {
  --tone: var(--accent);
  font: inherit;
  color: var(--text);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 24px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.level-card:hover { transform: translateY(-4px); border-color: var(--tone); box-shadow: 0 16px 40px rgba(3, 6, 20, 0.55), 0 0 0 1px var(--tone); }
.level-card.level-easy { --tone: var(--easy); }
.level-card.level-medium { --tone: var(--medium); }
.level-card.level-hard { --tone: var(--hard); }
.level-art { width: 72px; height: 72px; fill: none; stroke: var(--tone); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.level-card:hover .level-art { animation: bob 0.9s ease-in-out infinite; }
.level-name { font-size: 1.4rem; font-weight: 800; color: var(--tone); }
.level-desc { color: var(--muted); flex: 1; }
.level-meta { display: flex; gap: 8px; flex-wrap: wrap; }

.island-path { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px; margin-bottom: 32px; }
.island {
  font: inherit;
  color: var(--text);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
}
.island:hover:not(:disabled) { transform: translateY(-3px); border-color: var(--accent); }
.island.open { border-color: var(--accent); box-shadow: var(--shadow), 0 0 24px rgba(124, 140, 255, 0.35); }
.island.finished { border-color: var(--good); }
.island.locked { opacity: 0.55; cursor: not-allowed; }
.island-index {
  position: absolute;
  top: 14px;
  right: 16px;
  font-weight: 800;
  color: var(--muted);
}
.island-icon { width: 36px; height: 36px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.island.finished .island-icon { stroke: var(--good); }
.island.locked .island-icon { stroke: var(--muted); }
.island-title { font-weight: 800; font-size: 1.05rem; }
.island-status { color: var(--muted); font-size: 0.875rem; }
.meter { width: 100%; height: 6px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.meter::after { content: ""; display: block; height: 100%; width: var(--pct); background: linear-gradient(90deg, var(--accent), var(--good)); border-radius: inherit; transition: width 0.4s ease; }
.map-actions { display: flex; justify-content: flex-end; }

.section-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.section-head h1 { margin: 0; flex: 1; min-width: 200px; }
.dots { display: flex; gap: 8px; flex-wrap: wrap; }
.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: transparent;
  padding: 0;
  cursor: pointer;
}
.dot.answered { background: var(--accent); border-color: var(--accent); }
.dot.current { transform: scale(1.3); border-color: var(--text); }

.stage { display: flex; flex-direction: column; gap: 16px; }
.question { display: flex; flex-direction: column; gap: 16px; }
.eyebrow { font-size: 0.8rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.prompt { margin: 0; font-size: 1.2rem; font-weight: 600; }
.code {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.9rem;
  background: #0a0e1d;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
}

.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-2);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.choice:hover { border-color: var(--accent); }
.choice.selected { border-color: var(--accent); background: rgba(124, 140, 255, 0.14); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-key {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-weight: 800;
  background: var(--surface-2);
  color: var(--muted);
}
.choice.selected .choice-key { background: var(--accent); color: var(--accent-ink); }
.choice-label { flex: 1; overflow-wrap: anywhere; }

.answer-input, .answer-area, .login-card input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: #0a0e1d;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.answer-input.mono { font-family: var(--mono); }
.answer-area { resize: vertical; min-height: 140px; }
.answer-input:focus, .answer-area:focus, .login-card input:focus { outline: 3px solid var(--info); outline-offset: 1px; border-color: var(--info); }
.long { display: flex; flex-direction: column; gap: 6px; }

.help-box { border-radius: var(--radius-sm); padding: 12px 14px; border: 1px dashed var(--line); }
.help-box p { margin: 0; }
.help-box.hint { border-color: var(--warn); background: rgba(255, 200, 87, 0.08); }
.help-box.explanation { border-color: var(--info); background: var(--info-bg); }

.feedback { display: flex; align-items: center; gap: 12px; border-radius: var(--radius-sm); padding: 0; min-height: 0; }
.feedback.good, .feedback.bad, .feedback.info { padding: 12px 14px; }
.feedback.good { background: var(--good-bg); color: var(--good); }
.feedback.bad { background: var(--bad-bg); color: var(--bad); }
.feedback.info { background: var(--info-bg); color: var(--info); }
.question-actions, .section-nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.section-nav { justify-content: space-between; }

.card.burst { animation: burst 0.5s ease-out; }
.card.shake { animation: shake 0.45s ease-in-out; }

.done { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 40px; }
.done .lead { max-width: 520px; color: var(--muted); font-size: 1.1rem; }
.trophy {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6c9, var(--warn) 45%, #c98a12);
  box-shadow: 0 0 48px rgba(255, 200, 87, 0.55);
  animation: bob 2.4s ease-in-out infinite;
}
.trophy.timeout { background: radial-gradient(circle at 35% 30%, #dfe6ff, var(--info) 50%, #2f6fa0); box-shadow: 0 0 48px rgba(108, 199, 255, 0.45); }

.dialog {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  width: min(460px, calc(100vw - 32px));
}
.dialog::backdrop { background: rgba(5, 8, 20, 0.7); backdrop-filter: blur(3px); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 50;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: rise 0.25s ease-out;
  transition: opacity 0.4s ease;
  max-width: calc(100vw - 32px);
}
.toast.bad { border-color: var(--bad); color: var(--bad); }
.toast.leaving { opacity: 0; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center; position: relative; }
.login-card h1 { font-size: 1.3rem; margin: 8px 0 0; }
.login-card form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.login-langs { position: absolute; top: 16px; right: 16px; }

.data-table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
.data-table caption { text-align: left; font-weight: 700; color: var(--muted); padding-bottom: 6px; }
.data-table th, .data-table td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; }
.data-table th { background: var(--surface-2); }
.data-table td { font-family: var(--mono); font-size: 0.9rem; background: var(--bg-2); }

.icon-btn {
  font: inherit;
  font-size: 0.75rem;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.icon-btn:focus-visible, .chip:focus-visible, .bucket:focus-visible, .bit:focus-visible { outline: 3px solid var(--info); outline-offset: 2px; }

.order { display: flex; flex-direction: column; gap: 8px; }
.order-end { font-size: 0.8rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.order-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.order-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-2);
  position: relative;
  transition: border-color 0.15s ease;
}
.order-row.dragging { z-index: 2; border-color: var(--accent); box-shadow: var(--shadow); background: var(--surface-2); }
.order-row.drop-before { border-color: var(--good); }
.order-pos { flex: none; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); color: var(--muted); font-weight: 800; font-size: 0.85rem; }
.drag-handle { flex: none; cursor: grab; touch-action: none; user-select: none; color: var(--muted); font-size: 1.2rem; padding: 4px; }
.order-row.dragging .drag-handle { cursor: grabbing; }
.order-label { flex: 1; overflow-wrap: anywhere; }
.order-code { flex: 1; margin: 0; font-family: var(--mono); font-size: 0.85rem; white-space: pre; overflow-x: auto; }
.order-btns { display: flex; gap: 4px; flex: none; }

.categorize { display: flex; flex-direction: column; gap: 12px; }
.bucket-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.bucket {
  border: 2px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  min-height: 92px;
  background: rgba(10, 14, 29, 0.5);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.bucket.pool { min-height: 64px; border-style: solid; }
.bucket.armed.target { border-color: var(--accent); }
.bucket.over { border-color: var(--good); background: var(--good-bg); }
.bucket-title { font-weight: 800; font-size: 0.9rem; margin-bottom: 8px; color: var(--muted); }
.bucket-items { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  cursor: grab;
}
.chip.mono { font-family: var(--mono); }
.chip.selected { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.fields { display: grid; gap: 12px; }
.field-row { display: grid; grid-template-columns: minmax(150px, 220px) 1fr; align-items: center; gap: 12px; }
.field-label { font-weight: 600; }

.bits { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.bit-group { display: flex; flex-direction: column; gap: 6px; }
.bit-group-label { font-size: 0.8rem; font-weight: 800; color: var(--muted); }
.bit-row { display: flex; gap: 4px; }
.bit {
  font: inherit;
  width: 42px;
  padding: 6px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: background 0.12s ease, transform 0.12s ease;
}
.bit:active { transform: scale(0.94); }
.bit.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.bit-value { font-family: var(--mono); font-weight: 800; font-size: 1.1rem; }
.bit-label { font-size: 0.7rem; }
.bits-readout { flex-basis: 100%; font-family: var(--mono); font-size: 1.3rem; font-weight: 800; color: var(--warn); white-space: pre; }

.grid-wrap { overflow-x: auto; }
.grid { border-collapse: collapse; min-width: 100%; }
.grid th, .grid td { border: 1px solid var(--line); padding: 8px 10px; text-align: center; }
.grid thead th { background: var(--surface-2); font-size: 0.9rem; }
.grid tbody th { text-align: left; background: var(--bg-2); font-weight: 600; }
.grid tbody th.mono { font-family: var(--mono); font-size: 0.85rem; }
.grid-corner { color: var(--muted); }
.grid-cell { display: grid; place-items: center; cursor: pointer; padding: 4px; }
.grid-cell input { width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; }

.topology-wrap { display: flex; flex-direction: column; gap: 6px; }
.topology { width: 100%; height: auto; background: radial-gradient(circle at 50% 40%, rgba(124, 140, 255, 0.08), transparent 70%), #0a0e1d; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.topology .wire { stroke: var(--line); stroke-width: 4; stroke-linecap: round; }
.topology .wire-hit { stroke: transparent; stroke-width: 22; stroke-linecap: round; pointer-events: stroke; }
.topology .topo-link.target { cursor: pointer; }
.topology .topo-link.target:hover .wire, .topology .topo-link.target:focus .wire { stroke: var(--info); }
.topology .topo-link.selected .wire { stroke: var(--warn); stroke-width: 6; stroke-dasharray: 10 6; animation: dash 0.8s linear infinite; }
.topology .node-halo { fill: transparent; stroke: transparent; stroke-width: 3; }
.topology .node-shape { fill: var(--surface-2); stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.topology .kind-switch .node-shape, .topology .kind-hub .node-shape { stroke: var(--good); }
.topology .kind-router .node-shape, .topology .kind-firewall .node-shape { stroke: var(--warn); }
.topology .kind-cloud .node-shape, .topology .kind-server .node-shape { stroke: var(--info); }
.topology .topo-node.target { cursor: pointer; }
.topology .topo-node.target:hover .node-halo, .topology .topo-node.target:focus .node-halo { stroke: var(--info); fill: rgba(108, 199, 255, 0.08); }
.topology .topo-node.selected .node-halo { stroke: var(--warn); fill: rgba(255, 200, 87, 0.14); }
.topology .topo-node.selected .node-shape { fill: #4d4528; stroke: var(--warn); }
.topology .topo-label { fill: var(--text); font-size: 14px; font-weight: 700; }
.topology .topo-sub, .topology .topo-link-label { fill: var(--muted); font-size: 12px; }
.topology .target:focus { outline: none; }

.es-console { display: flex; flex-direction: column; gap: 12px; }
.es-dataset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 14px; background: var(--bg-2); }
.es-dataset summary { cursor: pointer; font-weight: 700; }
.es-dataset p { margin: 10px 0; }
.es-panes { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.es-pane { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.es-pane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 800; font-size: 0.85rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); min-height: 40px; }
.es-editor {
  width: 100%;
  min-height: 280px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 0.88rem;
  line-height: 1.5;
  tab-size: 2;
  color: var(--text);
  background: #0a0e1d;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.es-editor:focus { outline: 3px solid var(--info); outline-offset: 1px; }
.es-output { min-height: 280px; max-height: 520px; overflow: auto; background: #0a0e1d; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.es-result summary { cursor: pointer; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.es-json { margin: 6px 0 0; font-family: var(--mono); font-size: 0.82rem; white-space: pre; overflow-x: auto; color: #cfd6ff; }
.es-error { color: var(--bad); }
.es-error pre { white-space: pre-wrap; font-family: var(--mono); }
.status { font-family: var(--mono); font-weight: 800; font-size: 0.8rem; padding: 2px 8px; border-radius: 6px; }
.status.s2 { background: var(--good-bg); color: var(--good); }
.status.s4, .status.s5 { background: var(--bad-bg); color: var(--bad); }

.btn .icon, .btn.ghost .icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; margin-right: 6px; }

.sound-btns { display: inline-flex; gap: 6px; }
.sound-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.sound-btn.on { color: var(--good); border-color: var(--good); }
.sound-btn .icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sound-btn:focus-visible { outline: 3px solid var(--info); outline-offset: 2px; }
.music-menu {
  position: fixed;
  z-index: 40;
  width: min(280px, calc(100vw - 16px));
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: rise 0.18s ease-out;
}
.music-menu-title { font-size: 0.75rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 6px 10px; }
.music-item {
  font: inherit;
  color: var(--text);
  width: 100%;
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.music-item:hover, .music-item:focus-visible { background: var(--surface-2); outline: none; }
.music-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); }
.music-item.active .music-dot { background: var(--good); border-color: var(--good); box-shadow: 0 0 10px rgba(61, 220, 151, 0.6); }

.fx-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 60; }
.fx-float {
  position: fixed;
  z-index: 61;
  transform: translate(-50%, 0);
  font-weight: 900;
  font-size: 1.2rem;
  color: var(--warn);
  text-shadow: 0 2px 12px rgba(255, 200, 87, 0.6);
  pointer-events: none;
  animation: float-up 1.3s ease-out forwards;
}

:root { --gold: #ffd166; --silver: #c9d6ff; --bronze: #e8a87c; --low: #ff8fa0; }
.grade-A { --medal: var(--gold); }
.grade-B { --medal: var(--silver); }
.grade-C { --medal: var(--bronze); }
.grade-D, .grade-F { --medal: var(--low); }

.levels-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.levels-head h1 { margin: 0; }
.level-card { position: relative; overflow: hidden; }
.level-card.completed {
  border-color: var(--medal);
  background: linear-gradient(160deg, color-mix(in srgb, var(--medal) 22%, var(--surface)), var(--bg-2) 70%);
  box-shadow: var(--shadow), 0 0 28px color-mix(in srgb, var(--medal) 30%, transparent);
}
.level-card.completed .level-art { stroke: var(--medal); }
.level-ribbon {
  position: absolute;
  top: 16px;
  right: -36px;
  transform: rotate(35deg);
  background: var(--medal);
  color: var(--accent-ink);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 40px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.level-ribbon .icon { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.5; }
.level-best { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 700; }
.grade-chip {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border-radius: 8px;
  font-weight: 900;
  color: var(--accent-ink);
  background: var(--medal, var(--muted));
}
.rules { margin-top: 28px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 16px; background: var(--bg-2); }
.rules summary { cursor: pointer; font-weight: 700; }
.rules ul { margin: 10px 0 0; padding-left: 20px; color: var(--muted); }
.rules li { margin: 4px 0; }

.island.celebrate { animation: island-pop 0.9s ease-out; border-color: var(--good); box-shadow: var(--shadow), 0 0 36px rgba(61, 220, 151, 0.55); }
.island.unlocked { animation: unlock 1.2s ease-out 0.5s both; }

.result-hero { display: flex; align-items: center; justify-content: center; gap: 28px; flex-wrap: wrap; margin: 8px 0 12px; }
.grade-badge {
  width: 132px;
  height: 132px;
  display: grid;
  place-items: center;
  border-radius: 28px;
  font-size: 4.5rem;
  font-weight: 900;
  color: var(--accent-ink);
  background: radial-gradient(circle at 35% 30%, #fff, var(--medal) 55%);
  box-shadow: 0 0 48px color-mix(in srgb, var(--medal) 55%, transparent);
  transform: scale(0) rotate(-20deg);
  opacity: 0;
}
.grade-badge.stamped { animation: stamp 0.55s cubic-bezier(0.2, 1.6, 0.4, 1) forwards; }
.result-score { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.result-percent { font-size: 3.2rem; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1; }
.result-rows { list-style: none; margin: 8px 0 0; padding: 0; width: min(560px, 100%); display: flex; flex-direction: column; gap: 8px; }
.result-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line); text-align: left; }
.result-title { flex: 1; font-weight: 700; }
.result-pct { font-family: var(--mono); color: var(--muted); min-width: 56px; text-align: right; }
.stars { display: inline-flex; gap: 2px; }
.stars .star { width: 22px; height: 22px; fill: transparent; stroke: var(--line); stroke-width: 1.6; stroke-linejoin: round; transition: transform 0.3s ease, fill 0.3s ease; }
.stars .star.lit { fill: var(--gold); stroke: var(--gold); }
.stars.pending .star.lit { fill: transparent; stroke: var(--line); transform: scale(0.6); }
.done-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }

.title-icon { width: 30px; height: 30px; fill: none; stroke: var(--gold); stroke-width: 2; vertical-align: -4px; margin-right: 10px; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 16px; }
.tab {
  font: inherit;
  font-weight: 800;
  color: var(--muted);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tab.active.level-easy { color: var(--accent-ink); background: var(--easy); border-color: var(--easy); }
.tab.active.level-medium { color: var(--accent-ink); background: var(--medium); border-color: var(--medium); }
.tab.active.level-hard { color: var(--accent-ink); background: var(--hard); border-color: var(--hard); }
.tab-count { font-size: 0.75rem; background: rgba(0, 0, 0, 0.2); border-radius: 999px; padding: 1px 8px; }
.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.board-row {
  display: grid;
  grid-template-columns: 64px 1fr auto 72px minmax(110px, auto);
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  animation: rise 0.35s ease-out both;
}
.board-row:nth-child(2) { animation-delay: 0.05s; }
.board-row:nth-child(3) { animation-delay: 0.1s; }
.board-row:nth-child(n+4) { animation-delay: 0.15s; }
.board-row.rank-1 { border-color: var(--gold); background: linear-gradient(90deg, rgba(255, 209, 102, 0.18), var(--surface) 60%); }
.board-row.rank-2 { border-color: var(--silver); }
.board-row.rank-3 { border-color: var(--bronze); }
.board-row.me { outline: 2px solid var(--accent); outline-offset: 2px; }
.board-rank { display: flex; align-items: center; gap: 4px; font-weight: 900; font-size: 1.1rem; }
.board-rank .icon { width: 20px; height: 20px; fill: none; stroke-width: 2; }
.rank-1 .board-rank .icon { stroke: var(--gold); }
.rank-2 .board-rank .icon { stroke: var(--silver); }
.rank-3 .board-rank .icon { stroke: var(--bronze); }
.board-name { font-weight: 800; display: flex; align-items: center; gap: 8px; overflow-wrap: anywhere; }
.pill.you { color: var(--accent); border-color: var(--accent); }
.board-pct { font-family: var(--mono); font-weight: 800; text-align: right; }
.board-empty { padding: 24px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius-sm); }

@keyframes float-up { 0% { opacity: 0; transform: translate(-50%, 0) scale(0.8); } 15% { opacity: 1; transform: translate(-50%, -12px) scale(1.1); } 100% { opacity: 0; transform: translate(-50%, -70px) scale(1); } }
@keyframes stamp { 0% { opacity: 0; transform: scale(2.4) rotate(-20deg); } 100% { opacity: 1; transform: scale(1) rotate(-6deg); } }
@keyframes island-pop { 0% { transform: scale(1); } 30% { transform: scale(1.08); } 60% { transform: scale(0.97); } 100% { transform: scale(1); } }
@keyframes unlock { 0% { box-shadow: var(--shadow), 0 0 0 0 rgba(124, 140, 255, 0.8); } 100% { box-shadow: var(--shadow), 0 0 0 26px rgba(124, 140, 255, 0); } }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
@keyframes dash { to { stroke-dashoffset: -16; } }
@keyframes burst {
  0% { box-shadow: var(--shadow), 0 0 0 0 rgba(61, 220, 151, 0.6); }
  100% { box-shadow: var(--shadow), 0 0 0 24px rgba(61, 220, 151, 0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

@media (max-width: 720px) {
  .app-header { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .brand { flex: 1; white-space: nowrap; font-size: 0.95rem; }
  .hud { order: 3; flex-basis: 100%; justify-content: flex-start; }
  .logout-text { display: none; }
  .field-row { grid-template-columns: 1fr; gap: 6px; }
  .bit { width: 34px; }
  .board-row { grid-template-columns: 48px 1fr auto 60px; }
  .board-meta { grid-column: 2 / -1; }
  .sound-btn { width: 32px; height: 32px; }
  .bits { gap: 12px; }
  .app-main { padding: 20px 16px 48px; }
  .card { padding: 18px; }
}

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

:root { --boss: #ff4d6d; --boss-deep: #2a0b18; --boss-glow: rgba(255, 77, 109, 0.45); --final: var(--boss); }
.pill.level-final { color: var(--boss); border-color: var(--boss); }

.boss-art { display: block; overflow: visible; }
.boss-art .boss-shadow { fill: rgba(0, 0, 0, 0.45); stroke: none; }
.boss-art .boss-shirt { fill: #e9ecf2; stroke: #9aa3b5; stroke-width: 1.5; }
.boss-art .boss-collar { fill: #ffffff; stroke: #9aa3b5; stroke-width: 1.2; stroke-linejoin: round; }
.boss-art .boss-skin { fill: #d9a882; stroke: #8a5a3c; stroke-width: 1.5; }
.boss-art .boss-beard { fill: #2a2421; stroke: none; opacity: 0.92; }
.boss-art .boss-lip { fill: none; stroke: #b07a5a; stroke-width: 2; stroke-linecap: round; }
.boss-art .boss-hair { fill: #1f1a18; stroke: none; }
.boss-art .boss-frame { fill: none; stroke: #111; stroke-width: 2.5; stroke-linecap: round; }
.boss-art .boss-lens { fill: #0d0d12; stroke: #000; stroke-width: 1.5; }
.boss-art .boss-glint { fill: none; stroke: #ff6b81; stroke-width: 2; stroke-linecap: round; animation: boss-glint 4s infinite; }

.level-card.level-boss {
  --tone: var(--boss);
  grid-column: 1 / -1;
  align-items: center;
  text-align: center;
  padding: 32px 24px;
  border-color: var(--boss);
  background: radial-gradient(circle at 50% 0%, var(--boss-glow), transparent 65%), linear-gradient(180deg, var(--surface), var(--bg-2));
  box-shadow: var(--shadow), 0 0 40px rgba(255, 77, 109, 0.2);
}
.level-card.level-boss .level-art { width: 150px; height: 150px; animation: bob 2.4s ease-in-out infinite; filter: drop-shadow(0 8px 24px var(--boss-glow)); }
.level-card.level-boss .level-name { font-size: 2rem; letter-spacing: 0.02em; text-transform: uppercase; }
.level-card.level-boss .level-desc { max-width: 52ch; }
.level-card.level-boss .boss-hp { width: min(420px, 100%); }
.level-card.level-boss .level-meta { justify-content: center; }

.boss-hp { position: relative; display: block; height: 16px; border-radius: 999px; background: var(--boss-deep); border: 2px solid rgba(255, 255, 255, 0.15); overflow: hidden; }
.boss-hp-fill, .boss-hp-trail { position: absolute; inset: 0 auto 0 0; border-radius: inherit; }
.boss-hp-fill { background: linear-gradient(90deg, #ff2e57, var(--boss) 60%, #ff8a5c); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25); transition: width 0.35s ease-out; }
.boss-hp-trail { background: #fff3b0; transition: width 0.9s ease-in 0.35s; }

.boss-panel {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px 20px;
  margin-bottom: 24px;
  border-radius: var(--radius);
  border: 1px solid var(--boss);
  background: radial-gradient(circle at 10% 50%, var(--boss-glow), transparent 55%), var(--surface);
  box-shadow: var(--shadow);
}
.boss-stage { flex: none; }
.boss-panel .boss-art { width: 110px; height: 110px; animation: bob 2.4s ease-in-out infinite; }
.boss-panel.compact { padding: 10px 16px; gap: 14px; margin: 0 0 16px; position: sticky; top: 8px; z-index: 5; }
.boss-panel.compact .boss-art { width: 56px; height: 56px; }
.boss-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.boss-name-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.boss-name { font-weight: 900; text-transform: uppercase; letter-spacing: 0.04em; color: var(--boss); }
.boss-status { font-weight: 800; color: var(--warn); }
.boss-hp-label { margin-left: auto; font-family: var(--mono); font-size: 0.875rem; color: var(--muted); }
.boss-panel.low .boss-hp-fill { animation: pulse 0.8s ease-in-out infinite; }
.boss-panel.dead .boss-art { filter: grayscale(1) brightness(0.6); transform: rotate(-8deg) translateY(6px); animation: none; }
.boss-panel.dead .boss-status { color: var(--good); }
.boss-panel.hit .boss-art { animation: boss-hit 0.5s ease-out; }
.boss-panel.hit { animation: boss-flash 0.5s ease-out; }
.boss-panel.heal .boss-art { animation: boss-heal 0.6s ease-out; }
.boss-panel.attack .boss-art { animation: boss-lunge 0.45s ease-in-out; }
body.boss-quake .app-main { animation: shake 0.4s ease-in-out; }

.fx-float.damage { color: #ffffff; font-size: 1.6rem; text-shadow: 0 0 12px var(--boss), 0 2px 0 var(--boss-deep); }
.fx-float.heal { color: var(--good); text-shadow: 0 2px 12px rgba(61, 220, 151, 0.6); }

.view.boss-map h1, .view.boss-done h1 { color: var(--boss); }
.boss-finale { display: flex; justify-content: center; margin: 8px 0 16px; max-height: 200px; }
.boss-finale.victory.play { animation: finale-collapse 0.5s ease-in 1.4s forwards; }
.boss-finale .boss-art { width: 170px; height: 170px; filter: drop-shadow(0 10px 30px var(--boss-glow)); }
.boss-finale.victory.play .boss-art { animation: boss-defeat 1.4s ease-in forwards; }
.boss-finale.survived.play .boss-art { animation: boss-taunt 0.6s ease-in-out 3; }
.boss-line { font-weight: 700; }
body.boss-hidden .boss-stage, body.boss-hidden .level-card.level-boss .level-art, body.boss-hidden .boss-finale { display: none; }

@keyframes finale-collapse { to { max-height: 0; margin: 0; } }
@keyframes boss-glint { 0%, 85%, 100% { opacity: 0.35; } 92% { opacity: 1; filter: drop-shadow(0 0 4px #ff6b81); } }
@keyframes boss-hit {
  0% { transform: translateX(0); filter: none; }
  15% { transform: translateX(10px) rotate(6deg); filter: brightness(3) saturate(0); }
  40% { transform: translateX(-8px) rotate(-4deg); filter: none; }
  70% { transform: translateX(4px); }
  100% { transform: translateX(0); }
}
@keyframes boss-flash { 0% { box-shadow: var(--shadow), 0 0 0 0 rgba(255, 255, 255, 0.7); } 100% { box-shadow: var(--shadow), 0 0 0 18px rgba(255, 255, 255, 0); } }
@keyframes boss-heal { 0%, 100% { filter: none; } 40% { filter: drop-shadow(0 0 14px var(--good)) brightness(1.3); } }
@keyframes boss-lunge { 0%, 100% { transform: scale(1); } 40% { transform: scale(1.25) translateY(6px); } }
@keyframes boss-taunt { 0%, 100% { transform: translateY(0) rotate(0); } 25% { transform: translateY(-8px) rotate(-6deg); } 75% { transform: translateY(-8px) rotate(6deg); } }
@keyframes boss-defeat {
  0% { transform: none; filter: none; opacity: 1; }
  10%, 30%, 50% { transform: translateX(-8px) rotate(-5deg); filter: brightness(2.5); }
  20%, 40%, 60% { transform: translateX(8px) rotate(5deg); filter: none; }
  75% { transform: scale(1.2); filter: brightness(4) saturate(0); opacity: 1; }
  100% { transform: scale(0.2) rotate(30deg); filter: brightness(4) saturate(0); opacity: 0; }
}

@media (max-width: 720px) {
  .boss-panel { gap: 12px; padding: 12px; }
  .boss-panel .boss-art { width: 72px; height: 72px; }
  .boss-panel.compact .boss-art { width: 44px; height: 44px; }
  .level-card.level-boss .level-art { width: 120px; height: 120px; }
}
