:root {
  color-scheme: dark;
  --bg: #071015;
  --panel: rgba(8, 16, 22, .92);
  --panel-2: rgba(18, 30, 38, .94);
  --line: rgba(255,255,255,.16);
  --text: #f4f7f8;
  --muted: #9dafb7;
  --accent: #5db9e6;
  --danger: #ef6a6a;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--bg); font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; color: var(--text); }
button { font: inherit; }
#renderCanvas { width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.topbar {
  position: fixed; z-index: 20; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { font-weight: 900; letter-spacing: .16em; font-size: 18px; color: #f1cf82; text-shadow: 0 2px 10px #000; }
.subtitle { margin-top: 2px; font-size: 11px; color: var(--muted); text-shadow: 0 2px 8px #000; }
button {
  min-height: 42px; border: 1px solid var(--line); border-radius: 11px; background: #1c2b34; color: var(--text);
  padding: 8px 12px; font-weight: 750; cursor: pointer;
}
button:active { transform: translateY(1px); }
button.active { background: #126b9c; border-color: #65c7f5; box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); }
button.danger.active { background: #9f3535; border-color: #ff8585; }
button:disabled { opacity: .42; }
button.secondary { background: rgba(10,20,27,.88); backdrop-filter: blur(8px); }
.builder-panel {
  position: fixed; z-index: 20; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom));
  max-width: 980px; margin: 0 auto; border: 1px solid var(--line); border-radius: 16px; background: var(--panel);
  box-shadow: 0 12px 42px rgba(0,0,0,.45); backdrop-filter: blur(12px); padding: 8px;
}
.tools { display: flex; gap: 6px; overflow-x: auto; overscroll-behavior-x: contain; padding-bottom: 4px; scrollbar-width: none; }
.tools::-webkit-scrollbar { display: none; }
.tools button { flex: 0 0 auto; font-size: 12px; }
.status-row { display: flex; justify-content: space-between; gap: 12px; margin: 4px 4px 0; font-size: 11px; color: var(--muted); }
#counterText { white-space: nowrap; }
.toast {
  position: fixed; z-index: 40; left: 50%; top: 74px; transform: translate(-50%, -12px); opacity: 0;
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 12px; padding: 10px 14px; font-size: 12px;
  transition: .2s ease; pointer-events: none; max-width: calc(100vw - 24px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.reference-dialog {
  width: min(96vw, 1100px); height: min(88vh, 850px); padding: 0; border: 1px solid var(--line); border-radius: 16px;
  background: #081117; color: var(--text); overflow: hidden;
}
.reference-dialog::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(4px); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px; border-bottom: 1px solid var(--line); }
.dialog-header strong { display: block; font-size: 14px; }
.dialog-header div div { margin-top: 2px; font-size: 11px; color: var(--muted); }
.reference-dialog img { width: 100%; height: calc(100% - 67px); object-fit: contain; background: #05090c; }
@media (max-width: 600px) {
  .brand { font-size: 16px; }
  .subtitle { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .status-row { font-size: 10px; }
  button { min-height: 40px; padding: 8px 10px; }
}
