:root {
  color-scheme: dark;
  --bg: #101214;
  --panel: #181b1f;
  --line: #2d3338;
  --text: #f2efe7;
  --muted: #aab1ad;
  --accent: #e24d3d;
  --wood: #7a563b;
  --focus: #77d0ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 10%, rgba(119, 208, 255, 0.08), transparent 28rem),
    linear-gradient(135deg, #101214, #17120f 50%, #101214);
  color: var(--text);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

.shell {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  padding: 18px;
}

.stage-wrap {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.topbar,
.panel {
  border: 1px solid var(--line);
  background: rgba(24, 27, 31, 0.86);
  backdrop-filter: blur(14px);
}

.topbar {
  min-height: 82px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  line-height: 1.04;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 54px);
}

h2 {
  font-size: 28px;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.stats span {
  min-width: 84px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111417;
  color: var(--muted);
}

.stats b {
  color: var(--text);
}

.canvas-shell {
  position: relative;
  min-height: 280px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #15191d;
}

canvas {
  width: 100%;
  height: 100%;
  min-height: min(60svh, 720px);
  display: block;
  image-rendering: pixelated;
}

.message {
  position: absolute;
  left: 16px;
  bottom: 16px;
  max-width: min(420px, calc(100% - 32px));
  padding: 10px 12px;
  border-radius: 7px;
  background: rgba(16, 18, 20, 0.72);
  border: 1px solid rgba(242, 239, 231, 0.16);
  color: var(--text);
  transition: opacity 180ms ease, transform 180ms ease;
}

.message.hidden {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

.touchbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.pad,
.actions,
.buttons {
  display: flex;
  gap: 10px;
}

.control,
.buttons button {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #20262b;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.control {
  min-width: 74px;
  font-weight: 800;
  font-size: 18px;
}

.control.small {
  min-width: 72px;
  font-size: 14px;
}

.control.attack {
  border-color: rgba(226, 77, 61, 0.65);
  background: #3a211f;
}

.control:active,
.control.active,
.buttons button:active {
  transform: translateY(2px) scale(0.98);
  border-color: var(--focus);
}

.panel {
  align-self: stretch;
  border-radius: 8px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-head {
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

select {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111417;
  color: var(--text);
  padding: 0 10px;
}

.buttons {
  flex-wrap: wrap;
}

.buttons button {
  flex: 1 1 92px;
  min-height: 44px;
}

.keys {
  margin: auto 0 0;
  display: grid;
  gap: 10px;
}

.keys div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  text-align: right;
}

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

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats {
    width: 100%;
    justify-content: stretch;
  }

  .stats span {
    flex: 1;
    min-width: 0;
  }

  canvas {
    min-height: 58svh;
  }

  .touchbar {
    position: sticky;
    bottom: 8px;
    z-index: 2;
    grid-template-columns: 1fr;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .pad,
  .actions {
    justify-content: space-between;
  }

  .control {
    flex: 1;
  }
}

@media (max-width: 520px) {
  .stats span {
    font-size: 13px;
    padding: 8px;
  }

  .control {
    min-width: 0;
    min-height: 58px;
  }
}
