:root {
  color-scheme: dark;
  font-family: ui-sans-serif, system-ui, sans-serif;
  background: #131511;
  color: #eeefe8;
  --muted: #a3a797;
  --panel: #1b1e17;
  --line: #33382b;
  --accent: #d3ef86;
  --mono: ui-monospace, 'SF Mono', Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  min-width: 280px;
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 18% 4%, #21271a, transparent 60%);
}

.workspace {
  width: min(1040px, calc(100% - 64px));
  margin: 0 auto;
  padding: clamp(27px, 6vw, 76px) 0 44px;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: clamp(22px, 4vw, 40px);
}

.mark {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: grid;
  grid-template: repeat(2, 6px) / repeat(2, 6px);
  place-content: center;
  gap: 3px;
  border-radius: 10px;
  background: var(--accent);
}

.mark span { background: #252e1b; }
.mark span:nth-child(2) { opacity: .43; }

h1 {
  margin: 0;
  font-size: clamp(27px, 5vw, 46px);
  font-weight: 740;
  letter-spacing: -.055em;
  line-height: 1.1;
}

.title-detail { color: #b6bdab; font-weight: 440; }

.page-description {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 302px;
  gap: 22px;
  align-items: start;
}

.display,
.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 16px;
}

.display {
  padding: clamp(13px, 3vw, 25px);
  background: linear-gradient(145deg, #262c20, #1c211a 60%);
  box-shadow: 0 18px 52px #0003, inset 0 1px #ffffff0b;
}

.display-top,
.display-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font: 11px var(--mono);
  letter-spacing: .05em;
}

.display-top { padding: 0 3px 13px; }
.display-bottom { padding: 16px 3px 1px; }
.display-label { text-transform: uppercase; color: #d6daca; }

.screen {
  overflow: hidden;
  display: grid;
  place-items: center;
  border: 1px solid #383f32;
  border-radius: 12px;
  padding: clamp(5px, 1vw, 10px);
  background: #111811;
  box-shadow: inset 0 2px 9px #070a07;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 160 / 144;
  image-rendering: pixelated;
  border-radius: 4px;
  background: #192e2a;
}

.state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #d1d5c7;
}

.state::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #747b65;
}

.state[data-state='running']::before { background: var(--accent); box-shadow: 0 0 10px #d3ef8666; }
.state[data-state='paused']::before { background: #ebc784; }
.state[data-state='error']::before { background: #ef9a86; }

.sound-toggle {
  min-height: 27px;
  padding: 0 8px;
  letter-spacing: inherit;
  white-space: nowrap;
}

.sound-toggle[aria-pressed='true'] { color: var(--accent); }

.sidebar { display: grid; gap: 16px; }
.panel { padding: 17px; }

h2 {
  margin: 0 0 13px;
  font-size: 15px;
  font-weight: 630;
  letter-spacing: -.015em;
}

.cartridge {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px;
  border: 1px solid var(--line);
  background: #161913;
  border-radius: 9px;
}

.cartridge-icon {
  position: relative;
  width: 22px;
  height: 24px;
  flex: 0 0 auto;
  border: 1px solid #758461;
  border-radius: 3px 6px 3px 3px;
  background: #343d2b;
}

.cartridge-icon::before {
  content: '';
  position: absolute;
  inset: 5px 4px 7px;
  border: 1px solid #828d6b;
  border-radius: 1px;
  background: #545f42;
}

.cartridge-icon::after {
  content: '';
  position: absolute;
  inset: auto 4px 3px;
  height: 1px;
  background: #828d6b;
}

.cartridge-info { min-width: 0; flex: 1; }

.cartridge-info strong,
.cartridge-info span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cartridge-info strong { font-size: 13px; font-weight: 620; }
.cartridge-info span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.mapper { color: var(--muted); font: 10px var(--mono); }

button {
  font: inherit;
  color: inherit;
  border: 1px solid #3e4435;
  border-radius: 8px;
  background: #292e23;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:hover { background: #343b2c; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button:disabled { opacity: .45; cursor: default; }
button:disabled:hover { background: #292e23; }

.primary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  min-height: 43px;
  margin-top: 12px;
  padding: 0 12px;
  color: #1c2414;
  background: var(--accent);
  border-color: transparent;
  font-size: 13px;
  font-weight: 760;
}

.primary:hover { background: #e3fbab; }
.primary span { font: 17px var(--mono); }

.secondary-actions {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.secondary-actions button { min-height: 37px; font-size: 12px; }

.text-button {
  margin-top: 9px;
  min-height: 32px;
  padding: 0 3px;
  background: transparent;
  border-color: transparent;
  color: #c4cbb7;
  font-size: 12px;
  text-align: left;
}

.text-button:hover { background: transparent; color: var(--accent); text-decoration: underline; }
.notice { margin: 9px 0 0; color: #ffc0ae; font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 5px 0 13px;
}

.dpad {
  display: grid;
  grid-template: repeat(3, 36px) / repeat(3, 36px);
  gap: 2px;
}

.dpad button {
  border-radius: 6px;
  padding: 0;
  font-size: 12px;
  color: #d1d9c4;
}

.up { grid-area: 1 / 2; }
.left { grid-area: 2 / 1; }
.right { grid-area: 2 / 3; }
.down { grid-area: 3 / 2; }

.dpad-center {
  grid-area: 2 / 2;
  display: grid;
  place-items: center;
  border: 1px solid #3e4435;
  background: #262b21;
  border-radius: 6px;
}

.dpad-center::before {
  content: '';
  width: 11px;
  height: 11px;
  border: 1px solid #484f3d;
  border-radius: 50%;
  background: #1d221a;
}

.action-buttons { display: flex; align-items: center; gap: 8px; padding-right: 2px; }
.action-buttons button {
  width: 45px;
  height: 45px;
  padding: 0;
  display: grid;
  place-content: center;
  gap: 1px;
  border-radius: 50%;
  border-color: #647448;
  background: #3b4b2b;
  color: #e9f4d3;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.action-buttons button:hover { background: #4b5e36; }
.action-buttons button:first-child { margin-top: 17px; }
.action-buttons span { color: #c3cfae; font: 9px var(--mono); }

.system-buttons { display: flex; justify-content: center; gap: 8px; }
.system-buttons button { min-height: 33px; padding: 0 8px; font-size: 11px; }
kbd { margin-left: 3px; color: var(--muted); font: 9px var(--mono); }

[data-button] { touch-action: none; user-select: none; }
[data-button].pressed { color: #1c2414; background: var(--accent); border-color: var(--accent); }
[data-button].pressed span, [data-button].pressed kbd { color: #3b492d; }

@media (max-width: 790px) {
  .workspace { width: min(620px, calc(100% - 32px)); }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .sidebar { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}

@media (max-width: 590px) {
  .sidebar { grid-template-columns: minmax(0, 1fr); }
  .cartridge-panel { order: 1; }
  .controls { justify-content: space-evenly; }
  .dpad { grid-template: repeat(3, 42px) / repeat(3, 42px); }
  .action-buttons button { width: 48px; height: 48px; }
  .mark { width: 34px; height: 34px; }
}
