:root {
  --bg: #05070d;
  --panel: rgba(12, 18, 32, 0.82);
  --border: rgba(140, 170, 255, 0.22);
  --text: #e8eefc;
  --muted: #9aa8c7;
  --accent: #7eb6ff;
  --accent-strong: #4f8cff;
  --chip: rgba(255, 255, 255, 0.06);
  --danger: #ff8a8a;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

#canvas-wrap {
  position: relative;
  min-height: 0;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(70, 110, 200, 0.18), transparent 60%),
    radial-gradient(800px 500px at 80% 100%, rgba(40, 80, 160, 0.12), transparent 55%),
    var(--bg);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.topbar,
.footer {
  position: relative;
  z-index: 2;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  background: var(--panel);
  border-color: var(--border);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: min(100%, 220px);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1rem, 2.8vw, 1.25rem);
  font-weight: 650;
  letter-spacing: 0.01em;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.seg {
  display: inline-flex;
  padding: 0.2rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--chip);
  gap: 0.15rem;
}

.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.seg button[aria-pressed="true"] {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #061018;
  font-weight: 650;
}

.seg button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.meta {
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--chip);
}

.hud {
  position: absolute;
  left: 0.75rem;
  bottom: 0.75rem;
  z-index: 2;
  max-width: min(92vw, 320px);
  padding: 0.65rem 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: var(--shadow);
}

.hud strong {
  color: var(--text);
  font-weight: 600;
}

.footer {
  padding: 0.55rem 1rem calc(0.55rem + var(--safe-bottom));
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.status-error {
  color: var(--danger);
}

@media (max-width: 640px) {
  .topbar {
    align-items: stretch;
  }

  .controls {
    width: 100%;
    justify-content: space-between;
  }

  .seg {
    flex: 1 1 auto;
    justify-content: space-between;
  }

  .seg button {
    flex: 1 1 auto;
    padding-inline: 0.45rem;
    font-size: 0.75rem;
  }

  .hud {
    font-size: 0.72rem;
  }
}
