:root {
  color-scheme: dark;
  --bg: #0d0f0a;
  --surface: #15180f;
  --surface-2: #1d2117;
  --line: #343a29;
  --text: #f0eadb;
  --muted: #aaa994;
  --accent: #d9a441;
  --accent-2: #f0c66c;
  --danger: #c55742;
  --good: #7eaa5b;
  --shadow: 0 18px 50px #0007;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(#0002 1px, transparent 1px),
    linear-gradient(90deg, #0002 1px, transparent 1px),
    radial-gradient(circle at 80% 0%, #34351c55, transparent 38%),
    var(--bg);
  background-size: 32px 32px, 32px 32px, auto, auto;
  color: var(--text);
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, canvas:focus-visible {
  outline: 3px solid var(--accent-2);
  outline-offset: 3px;
}
.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: 70px;
  padding: 10px clamp(18px, 4vw, 58px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: #0d0f0aeb;
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand img { border-radius: 8px; }
.brand span { display: grid; text-transform: uppercase; letter-spacing: .08em; }
.brand b { font-size: .93rem; }
.brand small { margin-top: 2px; color: var(--muted); font-size: .65rem; }
.service-state { display: flex; align-items: center; gap: 20px; color: var(--muted); font-size: .84rem; }
.status-dot::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: var(--accent); }
.status-dot.online::before { background: var(--good); box-shadow: 0 0 0 4px #7eaa5b22; }
.status-dot.offline::before { background: var(--danger); }
main { width: min(1440px, 100%); margin: auto; }
.screen { padding: clamp(26px, 5vw, 70px) clamp(18px, 4vw, 58px) 80px; }
.center-card {
  width: min(620px, calc(100% - 36px));
  min-height: calc(100vh - 70px);
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.loader { width: 44px; height: 44px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
h1, h2, p { margin-top: 0; }
h1, h2 { font-family: Impact, "Arial Narrow", sans-serif; font-weight: 500; text-transform: uppercase; letter-spacing: .025em; }
.center-card h1 { margin: 24px 0 8px; font-size: clamp(2.2rem, 7vw, 4.5rem); }
.center-card p { color: var(--muted); }
.eyebrow { margin-bottom: 8px; color: var(--accent); font: 700 .72rem/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .16em; text-transform: uppercase; }
.hero {
  min-height: 420px;
  padding: clamp(28px, 5vw, 72px);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 40px;
  border: 1px solid var(--line);
  background:
    linear-gradient(90deg, #0f120dbb 0 48%, transparent 78%),
    repeating-linear-gradient(135deg, transparent 0 18px, #ffffff05 18px 20px),
    radial-gradient(circle at 82% 50%, #d9a44130, transparent 22%),
    #1a1e14;
  box-shadow: var(--shadow);
}
.hero h1 { max-width: 820px; margin: 0 0 18px; font-size: clamp(3.2rem, 7.3vw, 7.4rem); line-height: .83; }
.hero h1 em { color: var(--accent); font-style: normal; }
.hero p:not(.eyebrow) { max-width: 650px; margin-bottom: 0; color: var(--muted); font-size: 1.05rem; line-height: 1.6; }
.hero-actions { min-width: 220px; display: grid; gap: 10px; }
.button {
  min-height: 48px;
  padding: 13px 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
  letter-spacing: .035em;
  cursor: pointer;
}
.button:hover { border-color: var(--muted); filter: brightness(1.1); }
.button.primary { border-color: var(--accent); background: var(--accent); color: #17150e; }
.button.ghost { background: transparent; }
.button.danger { border-color: var(--danger); background: transparent; color: #ef927f; }
.button.compact { min-height: 42px; padding: 9px 13px; font-size: .82rem; }
.menu-grid { margin-top: 28px; display: grid; grid-template-columns: minmax(0, 2fr) minmax(290px, .8fr); gap: 28px; align-items: start; }
.panel { border: 1px solid var(--line); background: #14170fdd; box-shadow: 0 12px 35px #0003; }
.campaign-panel, .leaderboard-panel { padding: clamp(22px, 3vw, 38px); }
.section-heading { margin-bottom: 24px; display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.section-heading h2, .profile-panel h2, .controls-panel h2 { margin: 0; font-size: 2rem; }
.section-heading > span { color: var(--muted); font-size: .84rem; }
.levels-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.level-card {
  position: relative;
  min-height: 150px;
  padding: 20px;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.level-card:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.level-card:disabled { cursor: not-allowed; opacity: .44; }
.level-card.done { background: linear-gradient(135deg, #1b2416, var(--surface)); }
.level-number { color: var(--accent); font: 700 1.5rem/1 Impact, sans-serif; }
.level-card h3 { margin: 0 0 8px; font-size: 1.05rem; text-transform: uppercase; }
.level-card p { margin: 0; color: var(--muted); font-size: .84rem; line-height: 1.45; }
.level-meta { grid-column: 2; align-self: end; color: var(--accent-2); font-size: .75rem; }
.menu-sidebar { display: grid; gap: 28px; }
.profile-panel, .controls-panel { padding: 26px; }
.profile-panel label { display: block; margin: 20px 0 7px; color: var(--muted); font-size: .76rem; }
.input-row { display: flex; gap: 8px; }
input { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 2px; padding: 10px 12px; background: #090b08; color: var(--text); }
.form-message { min-height: 18px; margin: 9px 0 0; color: var(--good); font-size: .78rem; }
.controls-panel dl { margin: 20px 0 0; }
.controls-panel dl div { padding: 11px 0; display: flex; justify-content: space-between; gap: 10px; border-top: 1px solid var(--line); }
.controls-panel dt { font-weight: 700; }
.controls-panel dd { margin: 0; color: var(--muted); }
.leaderboard-panel { margin-top: 28px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 12px; border-top: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; }
th:last-child, td:last-child { text-align: right; }
td:first-child { color: var(--accent); font-weight: 800; }
.empty-row td { padding: 32px; color: var(--muted); text-align: center; }
.game-screen { padding-top: 24px; }
.battle-header { display: grid; grid-template-columns: 1fr auto 1fr; gap: 20px; align-items: center; }
.battle-header h1 { margin: 0; font-size: clamp(1.8rem, 4vw, 3.6rem); }
.battle-stats { display: flex; border: 1px solid var(--line); background: var(--surface); }
.battle-stats span { min-width: 105px; padding: 10px 16px; display: grid; gap: 3px; color: var(--muted); font-size: .68rem; text-transform: uppercase; }
.battle-stats span + span { border-left: 1px solid var(--line); }
.battle-stats b { color: var(--text); font-size: 1.12rem; }
.battle-actions { justify-self: end; display: flex; align-items: center; gap: 14px; }
.save-state { color: var(--muted); font-size: .78rem; }
.save-state.saved { color: var(--good); }
.save-state.error { color: #ef927f; }
.icon-button { width: 48px; height: 48px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 900; cursor: pointer; }
.objective-text { margin: 16px 0; color: var(--accent-2); }
.canvas-shell { position: relative; border: 1px solid #4b5039; background: #080a07; box-shadow: var(--shadow); line-height: 0; }
canvas { width: 100%; height: auto; display: block; cursor: crosshair; }
.battle-message { position: absolute; inset: 0; display: grid; place-items: center; background: #070906aa; color: var(--text); font: 500 clamp(2rem, 6vw, 5rem)/1 Impact, sans-serif; letter-spacing: .04em; text-transform: uppercase; }
.bonus-legend { padding: 14px; display: flex; justify-content: center; gap: 24px; color: var(--muted); font-size: .78rem; }
.bonus-legend i { width: 10px; height: 10px; display: inline-block; margin-right: 4px; border-radius: 50%; }
.repair { background: var(--good); }.shield { background: #5fa7d6; }.rapid { background: var(--accent); }
dialog { width: min(470px, calc(100% - 32px)); padding: 36px; border: 1px solid var(--accent); border-radius: 2px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); text-align: center; }
dialog::backdrop { background: #050604d9; backdrop-filter: blur(5px); }
dialog h2 { margin: 0 0 10px; font-size: 3rem; }
dialog > p:not(.eyebrow) { color: var(--muted); }
.dialog-actions, .result-actions { display: flex; gap: 10px; justify-content: center; margin-top: 28px; }
.result-card { padding: 50px 0; }
.result-card h1 { margin: 0; color: var(--accent); font-size: clamp(3rem, 9vw, 7rem); }
.result-stats { width: 100%; margin-top: 30px; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); }
.result-stats div { padding: 18px; display: grid; gap: 5px; }
.result-stats div + div { border-left: 1px solid var(--line); }
.result-stats span { color: var(--muted); font-size: .72rem; text-transform: uppercase; }
.result-stats b { font-size: 1.5rem; }
.toast { position: fixed; z-index: 50; right: 22px; bottom: 22px; max-width: min(390px, calc(100% - 44px)); padding: 13px 17px; border: 1px solid var(--line); background: #202519; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; }
.toast.visible { opacity: 1; transform: none; }
.not-found { display: grid; place-items: center; padding: 24px; }
.error-card { max-width: 620px; padding: clamp(30px, 7vw, 70px); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); text-align: center; }
.error-card img { margin-bottom: 22px; }
.error-card h1 { margin: 0; color: var(--accent); font-size: clamp(6rem, 24vw, 13rem); line-height: .8; }
.error-card h2 { margin: 20px 0 10px; font-size: 2.2rem; }
.error-card > p:not(.eyebrow) { margin-bottom: 28px; color: var(--muted); line-height: 1.6; }
@media (max-width: 900px) {
  .hero { min-height: 520px; align-items: flex-start; flex-direction: column; justify-content: flex-end; }
  .hero-actions { width: 100%; }
  .menu-grid { grid-template-columns: 1fr; }
  .menu-sidebar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .battle-header { grid-template-columns: 1fr auto; }
  .battle-stats { grid-row: 2; grid-column: 1 / -1; justify-self: stretch; }
  .battle-stats span { flex: 1; min-width: 0; }
}
@media (max-width: 620px) {
  .service-state .status-dot { display: none; }
  .hero { min-height: 560px; }
  .hero h1 { font-size: 3.1rem; }
  .levels-grid, .menu-sidebar { grid-template-columns: 1fr; }
  .section-heading { align-items: start; flex-direction: column; }
  .input-row, .dialog-actions, .result-actions { flex-direction: column; }
  .battle-actions .save-state { display: none; }
  .bonus-legend { flex-wrap: wrap; gap: 8px 16px; }
  .result-stats { grid-template-columns: 1fr; }
  .result-stats div + div { border-left: 0; border-top: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
