:root {
  --bg: #eef1f4; --panel: #fbfaf6; --card: rgba(255, 255, 255, 0.94); --line: #d6dbe0; --ink: #1f2a33; --soft: #586571;
  --teal: #0b7d72; --pink: #c2255c; --green: #1b8a4e; --red: #b9301f; --amber: #a86a0a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { display: grid; grid-template-columns: clamp(340px, 34vw, 500px) 1fr; overflow: hidden; }
.hidden { display: none !important; }
button, select { font: inherit; color: var(--ink); border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 12px; }
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: #9aa9b6; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--teal); border-color: var(--teal); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
small { color: var(--soft); font-size: 11px; letter-spacing: 0.06em; }
code, pre { font: 12.5px/1.5 ui-monospace, Consolas, "Cascadia Mono", monospace; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 4px 18px rgba(40, 60, 80, 0.12); }

/* left panel */
#panel { display: flex; flex-direction: column; min-height: 0; height: 100vh; background: var(--panel); border-right: 1px solid var(--line); padding: 12px; gap: 8px; }
#panel header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
h1 { margin: 0; font-size: 21px; letter-spacing: -0.01em; }
h1::before { content: ""; display: inline-block; width: 15px; height: 15px; margin-right: 8px; border-radius: 50%; background: var(--teal); box-shadow: inset 0 0 0 4px #fff, 0 0 0 1px var(--teal); vertical-align: -1px; }
.pick { color: var(--soft); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.tabs { display: flex; gap: 6px; align-items: center; }
.tabs button { padding: 5px 14px; }
.tabs button.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.tabs select { margin-left: auto; max-width: 190px; padding: 5px 8px; }
.tab { flex: 1 1 auto; min-height: 0; border: 1px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden; }
#tabCode textarea { width: 100%; height: 100%; border: 0; padding: 10px; resize: none; font: 13px/1.5 ui-monospace, Consolas, monospace; outline: none; }
.CodeMirror { height: 100%; font: 13px/1.5 ui-monospace, Consolas, "Cascadia Mono", monospace; }
.CodeMirror-gutters { background: #f4f3ee; border-right: 1px solid #e4e2da; }
.cm-run { background: #d7f1ec; }
.cm-err { background: #fbdcd6; }
#tabGuide { overflow-y: auto; padding: 4px 14px 14px; }
#tabGuide h3 { margin: 16px 0 6px; font-size: 14px; }
#tabGuide h3 small { font-weight: 400; margin-left: 6px; letter-spacing: 0; }
#tabGuide table { width: 100%; border-collapse: collapse; }
#tabGuide td { padding: 5px 6px 5px 0; border-top: 1px solid #eceae3; vertical-align: top; }
#tabGuide td:first-child { width: 44%; }
#tabGuide code { background: #eef4f3; color: #0a5f57; padding: 1px 5px; border-radius: 4px; white-space: nowrap; display: inline-block; margin-bottom: 2px; }
#tabGuide pre { margin: 0; padding: 10px 12px; background: #f6f5f0; border: 1px solid #e6e4dc; border-radius: 8px; overflow-x: auto; }
.lead { color: var(--soft); }
#console { flex: 0 0 118px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; background: #f6f5f0; padding: 7px 10px;
  font: 12.5px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
#console .err { color: var(--red); font-weight: 600; }
#console .sys { color: var(--soft); }
#console .ok { color: var(--green); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions .primary { padding: 7px 20px; }

/* stage */
#stage { position: relative; min-width: 0; min-height: 0; height: 100vh; overflow: hidden;
  background: linear-gradient(#f3f5f7, #e3e8ec); }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#view:active { cursor: grabbing; }
#stage > .card { position: absolute; padding: 9px 12px; }
#hud { top: 12px; left: 12px; display: flex; gap: 20px; }
.stat { min-width: 86px; }
.stat b { display: block; font-size: 21px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 3px; background: #e3e7eb; overflow: hidden; margin-top: 3px; }
.bar i { display: block; height: 100%; width: 0; background: var(--teal); border-radius: 3px; }
.bar i.batt { background: var(--green); width: 100%; }
.bar i.low { background: var(--red); }
#speed { bottom: 12px; left: 12px; display: flex; gap: 5px; align-items: center; }
#speed small { margin-right: 4px; }
#speed button, #views button { padding: 4px 11px; }
#speed button.on, #views button.on { background: var(--teal); border-color: var(--teal); color: #fff; }
#views { bottom: 12px; right: 12px; display: flex; gap: 5px; align-items: center; }
.tip { color: var(--soft); font-size: 12px; margin-left: 6px; }

/* report */
#report { top: 12px; right: 12px; width: 330px; max-height: calc(100% - 76px); overflow-y: auto; padding: 14px 16px; }
.rhead { display: flex; gap: 14px; align-items: center; }
.rhead b { display: block; font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; }
#rBest { color: var(--soft); font-size: 12px; }
.grade { width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; font-size: 38px; font-weight: 800; color: #fff; background: var(--teal); }
.grade.gS { background: #b7791f; } .grade.gA { background: var(--green); } .grade.gB { background: var(--teal); }
.grade.gC { background: #3d6fa5; } .grade.gD { background: #6b7785; } .grade.gE { background: var(--red); }
#rWhy { margin: 10px 0 8px; }
#report h3 { margin: 12px 0 4px; font-size: 12px; color: var(--soft); letter-spacing: 0.06em; text-transform: uppercase; font-weight: 600; }
#report table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
#report td { padding: 3px 0; border-top: 1px solid #eceff1; }
#report td:last-child { text-align: right; font-weight: 600; }
.room { display: grid; grid-template-columns: 112px 1fr 44px; gap: 8px; align-items: center; padding: 2px 0; }
.room span:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.room .bar { margin: 0; height: 8px; }
#report .actions { margin-top: 14px; }

@media (max-width: 820px) {
  body { grid-template-columns: 1fr; grid-template-rows: 54vh 46vh; overflow: hidden; }
  #panel { height: auto; order: 2; border-right: 0; border-top: 1px solid var(--line); }
  #stage { height: auto; order: 1; }
  #console { flex-basis: 64px; }
  .tip { display: none; }
  #hud { gap: 12px; } .stat { min-width: 64px; } .stat b { font-size: 17px; }
  #report { width: auto; left: 12px; }
}
