:root {
  --bg: #0b0c0e;
  --panel: rgba(22, 24, 28, 0.92);
  --line: #2c3036;
  --text: #e6e8eb;
  --muted: #9aa1aa;
  --accent: #4f9cf9;
  --bad: #f2555a;
  --good: #3ecf8e;
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
#view { position: fixed; left: 0; top: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; cursor: grab; outline: none; }
#view.dragging { cursor: grabbing; }

#hud {
  position: fixed; left: 12px; top: 12px; padding: 8px 10px; border-radius: 8px;
  background: rgba(0, 0, 0, 0.55); font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre; pointer-events: none;
}
#hud .bad { color: var(--bad); }
#hud .good { color: var(--good); }
#hud .warn, #guide .warn { color: #ffb02e; }

#status {
  position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); padding: 10px 16px;
  border-radius: 8px; background: rgba(0, 0, 0, 0.7); font-size: 15px;
}
#prefix-badge {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); padding: 4px 12px; border-radius: 6px;
  background: rgba(255, 176, 46, 0.9); color: #000; font-weight: 600; letter-spacing: 0.05em; pointer-events: none;
}
#prefix:disabled + * , #prefix:disabled { opacity: 0.4; }
.hidden { display: none; }

#panel {
  z-index: 5; position: fixed; right: 12px; top: 12px; width: 330px; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px 10px;
}
#panel.collapsed #controls, #panel.collapsed #note { display: none; }
#panel header {
  position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0 8px; background: var(--panel); font-weight: 600;
}
#panel header button { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
#panel header button:hover { color: var(--text); }
.row label kbd { color: var(--muted); font-size: 10px; border: 1px solid var(--line); border-radius: 3px; padding: 0 3px; }

fieldset { border: none; border-top: 1px solid var(--line); margin: 6px 0 0; padding: 8px 0 2px; }
legend { color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: 0.06em; padding-right: 6px; }
.row { display: grid; grid-template-columns: 120px 1fr 64px; align-items: center; gap: 6px; margin: 4px 0; }
.row label { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row input[type=range] { width: 100%; accent-color: var(--accent); }
.row input[type=number] {
  width: 64px; background: #15171b; color: var(--text); border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 3px; font: inherit;
}
.row select { grid-column: 2 / 4; background: #15171b; color: var(--text); border: 1px solid var(--line); border-radius: 4px; padding: 2px; }
.row input[type=checkbox] { justify-self: start; accent-color: var(--accent); }
.row .text { grid-column: 2 / 4; color: var(--text); }
.buttons { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.buttons button {
  background: #1d2026; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px;
  cursor: pointer; font: inherit;
}
.buttons button:hover { border-color: var(--accent); }
.buttons kbd { color: var(--muted); margin-left: 4px; font-size: 11px; }
#keys { color: var(--muted); font-size: 12px; padding: 4px 0; }
#keys kbd { color: var(--text); background: #1d2026; border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; }
summary { cursor: pointer; color: var(--muted); margin-top: 8px; }

#toasts { position: fixed; z-index: 20; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; }
.toast { background: rgba(0, 0, 0, 0.8); border-left: 3px solid var(--accent); padding: 6px 12px; border-radius: 6px; max-width: 70vw; }
.toast.error { border-color: var(--bad); }

#view { touch-action: none; }
#status { min-width: 260px; text-align: center; }
#progress { margin-top: 8px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.1s linear; }
#keys kbd { margin-right: 2px; }
#note { color: var(--muted); font-size: 11px; margin: 10px 0 0; }

@media (max-width: 600px) {
  #panel { left: 12px; right: 12px; width: auto; top: auto; bottom: 12px; max-height: 45vh; }
  #hud { font-size: 11px; }
}

#guide { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.55); padding: 16px; z-index: 10; }
#guide.hidden { display: none; }
#guide .card {
  max-width: 640px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 18px 22px; line-height: 1.5;
}
#guide h2 { margin: 0 0 6px; font-size: 18px; }
#guide h3 { margin: 12px 0 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
#guide p { margin: 0 0 4px; color: var(--text); }
#guide ul { margin: 0; padding-left: 18px; }
#guide li { margin: 2px 0; }
#guide .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
#guide kbd { color: var(--text); background: #1d2026; border: 1px solid var(--line); border-radius: 3px; padding: 0 5px; font-size: 12px; }
#guide .bad { color: var(--bad); }
#guide .buttons { justify-content: flex-end; margin-top: 12px; }
@media (max-width: 600px) { #guide .cols { grid-template-columns: 1fr; } }

#gyro-btn {
  position: fixed; left: 12px; top: 112px; padding: 8px 14px; border-radius: 18px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.6); color: var(--text); font: inherit; font-weight: 600;
}
#gyro-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#gyro-btn.hidden, .row.hidden { display: none; }

#move-btn {
  position: fixed; left: 86px; top: 112px; padding: 8px 14px; border-radius: 18px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.6); color: var(--text); font: inherit; font-weight: 600;
}
#move-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#move-btn.hidden, #movepad.hidden { display: none; }
#movepad .pad-cluster { position: fixed; z-index: 4; bottom: 80px; display: grid; gap: 6px; }
#pad-left { left: 12px; grid-template-areas: ". f ." "l . r" ". b ."; grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px); }
#pad-right { right: 12px; grid-template-columns: 46px; grid-template-rows: repeat(2, 46px); }
#movepad button {
  width: 46px; height: 46px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.45);
  color: var(--text); font-size: 18px; touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
#movepad button.active { background: var(--accent); border-color: var(--accent); }
#movepad button.txt { font-size: 12px; font-weight: 600; }
