:root {
  --bg: #07080a;
  --panel: #111318;
  --line: #262a33;
  --text: #d9dde4;
  --dim: #8a919e;
  --accent: #3cf06e;      /* Berzerk robot green */
  --warn: #ffd23c;        /* Evil Otto yellow */
  --screen: #000;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
button {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .6; cursor: default; }
button:focus-visible, canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.logo {
  margin: 0; font: 700 26px/1 ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: .18em; color: var(--accent); text-shadow: 0 0 12px rgba(60, 240, 110, .45);
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.stage {
  flex: 1; display: flex; gap: 16px; justify-content: center; align-items: flex-start;
  padding: 16px; flex-wrap: wrap;
}
.screen {
  position: relative; background: var(--screen); border: 1px solid var(--line); border-radius: 8px;
  width: min(100%, 896px, calc((100vh - 190px) * 256 / 224)); aspect-ratio: 256 / 224; overflow: hidden;
}
.screen canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
/* MAME's picture is drawn into #view. SDL's own canvas only takes keyboard focus: kept a few pixels big and
   invisible, because SDL redraws it every frame at its full size (a full-size one cost 80% of the speed) */
.screen #canvas { position: absolute; left: 0; top: 0; width: 4px; height: 4px; opacity: 0; }
.screen:fullscreen { border: 0; border-radius: 0; width: 100vw; height: 100vh; aspect-ratio: auto; }
.screen:fullscreen #view { object-fit: contain; }

.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; background: radial-gradient(circle, rgba(0,0,0,.55), rgba(0,0,0,.85));
}
.overlay[hidden] { display: none; }
.start {
  font: 700 20px/1 ui-monospace, Consolas, monospace; letter-spacing: .12em;
  padding: 14px 26px; border-color: var(--accent); color: var(--accent);
}
.set-line { margin: 0; color: var(--dim); font-size: 13px; }

.panel {
  width: min(100%, 340px); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 14px 16px;
}
.panel h2 { margin: 0 0 4px; font-size: 16px; }
.hint { margin: 0 0 10px; color: var(--dim); font-size: 13px; }
.sets { display: flex; flex-direction: column; gap: 6px; }
.set {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: baseline;
  text-align: left; padding: 8px 10px;
}
.set[aria-checked="true"] { border-color: var(--accent); background: #13201a; }
.set .nm { font-weight: 600; }
.set .tag { grid-column: 2; color: var(--dim); font-size: 13px; }
.set .badge { font-size: 11px; color: var(--bg); background: var(--accent); border-radius: 3px; padding: 0 5px; margin-left: 6px; }
.set .badge.miss { background: var(--warn); }
.why { margin-top: 12px; font-size: 13px; color: var(--text); }
.why h3 { margin: 0 0 6px; font-size: 14px; }
.why ul { margin: 0; padding-left: 18px; }
.why li { margin-bottom: 5px; }

.help {
  display: flex; flex-wrap: wrap; gap: 8px 22px; justify-content: center;
  padding: 0 16px 12px; color: var(--dim); font-size: 13px;
}
kbd {
  font: 12px ui-monospace, Consolas, monospace; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; margin-right: 2px;
}
.foot { padding: 12px 16px; border-top: 1px solid var(--line); color: var(--dim); font-size: 12px; text-align: center; }
.foot a { color: var(--dim); }

/* ---- touch controls (js/touch.js) ---- */
.tc-panel { display: none; }
.touch, .touch body {
  touch-action: none; overscroll-behavior: none; -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
.touch .help, .touch #btn-full { display: none; }
.touch .tc-panel {
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr; align-items: center;
  position: relative; flex: 1; min-height: 220px; touch-action: none;
  padding: 0 max(12px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(12px, env(safe-area-inset-left));
}
.tc-zone { position: relative; align-self: stretch; touch-action: none; grid-column: 1; grid-row: 2; }
.tc-pad {
  --pad: clamp(54px, 15vw, 76px);
  position: absolute; width: calc(var(--pad) * 2); height: calc(var(--pad) * 2);
  margin: calc(var(--pad) * -1) 0 0 calc(var(--pad) * -1); border-radius: 50%;
  border: 2px solid rgba(60, 240, 110, .45); background: radial-gradient(rgba(60, 240, 110, .10), rgba(0, 0, 0, .25));
  pointer-events: none; opacity: .5; transition: opacity .2s;
}
.tc-pad.on { opacity: 1; transition: none; }
.tc-pad i {
  position: absolute; left: 50%; top: 50%; width: 46%; height: 46%; margin: -23% 0 0 -23%; border-radius: 50%;
  background: rgba(60, 240, 110, .8); box-shadow: 0 0 12px rgba(60, 240, 110, .5);
}
.tc-pad span {
  position: absolute; left: -30px; right: -30px; bottom: -20px; text-align: center; color: rgba(60, 240, 110, .85);
  font: 700 11px/1 ui-monospace, Consolas, monospace; letter-spacing: .08em;
}
.tc-pad.on span { display: none; }
.tc-mid { display: flex; gap: 12px; justify-content: center; grid-column: 1 / -1; grid-row: 1; padding-top: 10px; }
.tc-right { display: grid; place-items: center; align-self: stretch; grid-column: 2; grid-row: 2; }
.tc-btn, .tc-fire {
  display: grid; place-items: center; color: #000; touch-action: none;
  font: 700 12px/1 ui-monospace, Consolas, monospace; letter-spacing: .08em;
}
.tc-btn { width: 72px; height: 40px; border-radius: 10px; background: rgba(255, 210, 60, .85); }
.tc-fire {
  width: clamp(88px, 26vw, 120px); height: clamp(88px, 26vw, 120px); border-radius: 50%;
  background: rgba(255, 70, 55, .92); font-size: 16px; box-shadow: 0 0 18px rgba(255, 70, 55, .35);
}
.tc-btn.on, .tc-fire.on { filter: brightness(1.35); transform: scale(.96); }

/* Portrait phone: game across the top, controls fill the rest */
@media (orientation: portrait) {
  .touch body { height: 100dvh; overflow: hidden; }
  .touch .top { padding: 8px 12px; }
  .touch .logo { font-size: 18px; }
  .touch .actions button { padding: 4px 8px; font-size: 13px; }
  .touch .stage { flex: 0 0 auto; padding: 8px 0 0; gap: 8px; }
  .touch .screen { width: 100vw; border-left: 0; border-right: 0; border-radius: 0; }
  .touch .panel { position: fixed; inset: 52px 8px auto 8px; width: auto; max-height: calc(100dvh - 64px); overflow: auto; z-index: 10; }
  .touch .foot { display: none; }
}
/* Landscape phone: game in the middle, stick left, fire right */
@media (orientation: landscape) {
  .touch body { height: 100dvh; overflow: hidden; }
  .touch .top, .touch .foot { display: none; }
  .touch .stage { position: fixed; inset: 0; padding: 0; align-items: center; z-index: 1; pointer-events: none; }
  .touch .screen { pointer-events: auto; width: min(100vw - 2 * clamp(150px, 26vw, 220px), 100dvh * 256 / 224); }
  .touch .tc-panel {
    position: fixed; inset: 0; z-index: 2; pointer-events: none;
    grid-template-columns: clamp(150px, 26vw, 220px) 1fr clamp(150px, 26vw, 220px); grid-template-rows: auto 1fr;
  }
  .touch .tc-zone, .touch .tc-right, .touch .tc-mid { pointer-events: auto; }
  .touch .tc-zone { grid-column: 1; grid-row: 1 / -1; }
  .touch .tc-mid { grid-column: 3; grid-row: 1; }
  .touch .tc-right { grid-column: 3; grid-row: 2; }
}

/* ---- Options tabs and the editor (js/editor.js) ---- */
.panel { width: min(100%, 440px); max-height: calc(100vh - 120px); overflow: auto; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tab { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 6px 10px; color: var(--dim); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.opt.off { opacity: .5; cursor: default; }
.opt input[type="checkbox"] { margin-top: 3px; accent-color: var(--accent); }
.opt span { display: flex; flex-direction: column; gap: 2px; }
.opt small, .item small { color: var(--dim); font-size: 12px; }
.opt select, .toks select, .newword input[type="text"], .item input[type="text"] {
  font: inherit; font-size: 13px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px;
}
.soon { color: var(--warn); font-size: 13px; }
.meter { font-size: 12px; color: var(--dim); margin-bottom: 8px; }
.phr { padding: 8px 0; border-bottom: 1px solid var(--line); }
.phr h4 { margin: 0 0 6px; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.phr summary { cursor: pointer; font-size: 13px; font-weight: 600; }
.toks { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 8px; border-radius: 12px; cursor: pointer;
  background: #13201a; border: 1px solid #245a37; font: 12px ui-monospace, Consolas, monospace; text-transform: uppercase;
}
.chip.pitch { background: #1d1a10; border-color: #5a4d24; color: var(--warn); text-transform: none; }
.chip.new { border-color: var(--accent); }
.x, .play, .small { padding: 0 6px; font-size: 12px; border-radius: 10px; line-height: 18px; }
.chip .x { border: 0; background: none; color: var(--dim); }
.item { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 4px 0; }
.newword { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.newword input[type="file"] { font-size: 12px; color: var(--dim); max-width: 100%; }
.status { min-height: 1.4em; font-size: 12px; color: var(--accent); }
