:root {
  --bg: #f4f1fa; --panel: #ffffff; --ink: #2a2440; --muted: #6d6585; --line: #e2dcef;
  --accent: #ec60a0; --accent-d: #c8417f; --accent-soft: #fde6f1; --ok: #2f9d6a; --danger: #d0464b;
  --device: #ec60a0; --device-d: #c8417f; --screen-bg: #0e0b18; --shadow: 0 6px 24px rgba(42, 36, 64, .12);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17141f; --panel: #221e2e; --ink: #ece8f6; --muted: #a59dbd; --line: #383149;
    --accent: #f06fab; --accent-d: #d2508d; --accent-soft: #3a2433; --shadow: 0 6px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  min-height: 100vh;
}
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.logo { width: 22px; height: 24px; border-radius: 50%; background: var(--accent); box-shadow: inset 0 -3px 0 var(--accent-d); display: inline-block; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab, .sub {
  border: 0; background: transparent; color: var(--muted); padding: 7px 12px; border-radius: 999px; font: inherit; cursor: pointer;
}
.tab:hover, .sub:hover { background: var(--accent-soft); color: var(--ink); }
.tab.active, .sub.active { background: var(--accent); color: #fff; }

main { display: flex; gap: 24px; padding: 20px 16px 40px; max-width: 1200px; margin: 0 auto; align-items: flex-start; flex-wrap: wrap; }
.device-wrap { flex: 0 0 auto; position: sticky; top: 72px; }
.device {
  background: linear-gradient(160deg, var(--device), var(--device-d)); border-radius: 36px; padding: 22px 22px 16px;
  box-shadow: var(--shadow), inset 0 2px 0 rgba(255, 255, 255, .25);
}
.screen-frame { position: relative; background: var(--screen-bg); border-radius: 12px; padding: 10px; }
#screen { display: block; image-rendering: pixelated; image-rendering: crisp-edges; width: 480px; height: 384px; background: #000; border-radius: 4px; }
.overlay { position: absolute; inset: 10px; display: flex; align-items: center; justify-content: center; background: rgba(14, 11, 24, .92); border-radius: 4px; }
.overlay.hidden { display: none; }
.overlay-card { color: #f3f0fa; text-align: center; padding: 18px; max-width: 420px; }
.overlay-card h1 { font-size: 20px; margin: 0 0 6px; }
.overlay-card .hint { color: #b9b2cf; }
.buttons { display: flex; justify-content: space-around; padding: 18px 10px 8px; }
.hw {
  width: 64px; height: 64px; border-radius: 50%; border: 0; cursor: pointer; font: 700 20px/1 system-ui, sans-serif; color: var(--accent-d);
  background: radial-gradient(circle at 35% 30%, #fff, #f4e6ee); box-shadow: 0 5px 0 rgba(0, 0, 0, .25);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.hw.down { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0, 0, 0, .25); background: #f2d7e4; }
.quick { width: 0; min-width: 100%; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; padding-top: 8px; }
.chip { border: 0; border-radius: 999px; padding: 5px 11px; background: rgba(255, 255, 255, .22); color: #fff; font: inherit; font-size: 13px; cursor: pointer; }
.chip.on { background: #fff; color: var(--accent-d); }
.status { color: #fff; opacity: .9; font-size: 12.5px; text-align: center; padding-top: 10px; min-height: 1.5em; width: 0; min-width: 100%; overflow-wrap: anywhere; }

.panels { flex: 1 1 380px; min-width: 0; }
.panel { display: none; background: var(--panel); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.panel.active { display: block; }
.panel h2 { font-size: 17px; margin: 18px 0 8px; }
.panel h2:first-child { margin-top: 0; }
.panel h3 { font-size: 15px; margin: 16px 0 6px; }
.panel h3 small { color: var(--muted); font-weight: 400; }
.subtabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.sub-panel { display: none; }
.sub-panel.active { display: block; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.row.indent { padding-left: 46px; color: var(--muted); }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 10px; padding: 7px 12px; font: inherit; font-size: 14px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.file-btn { position: relative; overflow: hidden; display: inline-block; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
input[type=text], input[type=number], input[type=search], select {
  font: inherit; font-size: 14px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink);
}
#cmdLine, #codeLine { flex: 1 1 240px; }
#sceneFilter { width: 100%; margin: 6px 0 8px; }
.hint { color: var(--muted); font-size: 13px; }
.err { color: #ff8a8f; font-size: 13px; min-height: 1em; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font-size: 12.5px; background: var(--bg); }
table.keys td { padding: 4px 8px 4px 0; vertical-align: top; }
table.keys td:first-child { color: var(--muted); white-space: nowrap; }
.log { background: var(--bg); border-radius: 8px; padding: 8px 10px; font: 12px/1.45 ui-monospace, Consolas, monospace; max-height: 240px; overflow: auto; white-space: pre-wrap; word-break: break-all; margin: 0; }
.log.small { max-height: 160px; }
.tablewrap { max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.data th { position: sticky; top: 0; background: var(--panel); color: var(--muted); font-weight: 600; }
table.data td.num { font-family: ui-monospace, Consolas, monospace; }
table.data .edit { cursor: pointer; text-decoration: underline dotted; }
.scene-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; max-height: 420px; overflow: auto; }
.scene-list button { text-align: left; font-size: 12.5px; font-family: ui-monospace, Consolas, monospace; }
.opts { display: flex; flex-direction: column; gap: 6px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch span { width: 36px; height: 20px; border-radius: 999px; background: var(--line); position: relative; flex: 0 0 auto; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { left: 18px; }
.switch.big { font-weight: 600; margin: 10px 0; }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.slot { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.slot b { display: block; }
.slot .when { color: var(--muted); font-size: 12px; min-height: 1.3em; }
.slot .row { margin: 4px 0 0; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: 14px; transition: all .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 820px) {
  main { padding: 12px 16px 40px; gap: 16px; }
  .device-wrap { position: static; width: 100%; }
  .device { padding: 16px 14px 12px; border-radius: 28px; }
  #screen { width: 100%; height: auto; aspect-ratio: 160 / 128; }
  .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row.indent { padding-left: 0; }
}
