:root {
  --bg: #07070b;
  --bg-panel: #0e0e14;
  --bg-frame: #050508;
  --text: #ece8e0;
  --text-muted: #8d8880;
  --accent: #c4a35a;
  --accent-soft: rgba(196, 163, 90, 0.14);
  --moss: #6f9464;
  --border: rgba(196, 163, 90, 0.16);
  --frame-glow: rgba(111, 148, 100, 0.12);
  --font-display: "Instrument Serif", Georgia, serif;
  --font-body: "DM Sans", system-ui, sans-serif;
  --topbar-h: 3.5rem;
  --statusbar-h: 2.25rem;
  --guide-w: 17.5rem;
  --radius: 14px;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.28;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr var(--statusbar-h);
  height: 100dvh;
  max-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 clamp(0.85rem, 3vw, 1.5rem);
  border-bottom: 1px solid var(--border);
  background: rgba(7, 7, 11, 0.92);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand-mark {
  color: var(--accent);
  font-size: 1.1rem;
  line-height: 1;
}

.brand-name {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  line-height: 1.1;
}

.brand-tag {
  margin: 0.1rem 0 0;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--moss);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.icon-btn,
.text-btn {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
}

.icon-btn:hover,
.text-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.text-btn {
  padding: 0.45rem 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  border: 1px solid var(--border);
  font-size: 0.8125rem;
  font-weight: 500;
}

.main {
  display: grid;
  grid-template-columns: var(--guide-w) 1fr;
  min-height: 0;
  overflow: hidden;
}

.guide {
  border-right: 1px solid var(--border);
  background: var(--bg-panel);
  overflow: auto;
  min-height: 0;
}

.guide-inner {
  padding: 1.1rem 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.guide h2 {
  margin: 0 0 0.45rem;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--accent);
}

.guide p {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.control-list {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.control-list div {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.control-list dt {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.control-list dd {
  margin: 0;
  font-size: 0.84rem;
}

.stack-list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.stack-list li + li {
  margin-top: 0.25rem;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  padding: clamp(0.65rem, 2vw, 1.25rem);
  background:
    radial-gradient(ellipse 70% 55% at 50% 45%, var(--frame-glow), transparent 70%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 30%);
}

.game-frame {
  position: relative;
  flex: 1 1 auto;
  width: min(100%, 72rem);
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
  aspect-ratio: 16 / 10;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-frame);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.03) inset,
    0 24px 80px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.game-mount,
.game-mount canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.game-mount {
  position: absolute;
  inset: 0;
}

.webgpu-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(5, 5, 8, 0.88);
  z-index: 3;
}

.webgpu-overlay[hidden] {
  display: none !important;
}

.webgpu-card {
  max-width: 22rem;
  text-align: center;
}

.webgpu-card h2 {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-weight: 400;
}

.webgpu-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.stage-hint {
  position: absolute;
  left: 50%;
  bottom: 0.85rem;
  transform: translateX(-50%);
  padding: 0.4rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(7, 7, 11, 0.78);
  border: 1px solid var(--border);
  border-radius: 999px;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.25s;
  z-index: 2;
  white-space: nowrap;
}

.stage-hint.is-hidden {
  opacity: 0;
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: rgba(7, 7, 11, 0.92);
}

.status-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--moss);
  box-shadow: 0 0 10px var(--moss);
  flex-shrink: 0;
}

.statusbar.is-loading .status-dot {
  animation: pulse 1.2s ease-in-out infinite;
}

.statusbar.is-error .status-dot {
  background: #c45a5a;
  box-shadow: 0 0 10px #c45a5a;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 20;
}

.backdrop[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
  }

  .guide {
    position: fixed;
    top: var(--topbar-h);
    bottom: var(--statusbar-h);
    left: 0;
    width: min(18rem, 88vw);
    z-index: 30;
    border-right: 1px solid var(--border);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.35);
  }

  .app[data-panel="open"] .guide {
    transform: translateX(0);
  }

  .app[data-panel="open"] .backdrop {
    display: block !important;
  }

  .panel-toggle {
    display: inline-flex;
  }

  .game-frame {
    flex: 1 1 auto;
    aspect-ratio: auto;
    width: 100%;
    height: auto;
    min-height: 12rem;
    border-radius: 10px;
  }
}

@media (min-width: 901px) {
  .panel-toggle {
    display: none;
  }

  .backdrop {
    display: none !important;
  }
}

@media (max-width: 520px) {
  .brand-tag {
    display: none;
  }

  .stage-hint {
    max-width: calc(100% - 1.5rem);
    white-space: normal;
    text-align: center;
  }
}

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