:root {
  --bg: #f3f2ee;
  --panel: rgba(255, 255, 255, 0.92);
  --ink: #1d1d1b;
  --muted: #6f6d67;
  --line: #dcdad3;
  --accent: #2f4f86;
  --accent-ink: #fff;
  --danger: #b4232f;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button, select, input, textarea { font: inherit; color: inherit; }
button, select {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 6px 11px; cursor: pointer; font-size: 14px; line-height: 1.2;
}
button:hover:not(:disabled) { border-color: #b9b6ad; }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.primary.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

.bar {
  position: fixed; top: 12px; left: 12px; right: 12px;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  pointer-events: none;
}
.bar > * { pointer-events: auto; }
.brand {
  font-weight: 800; letter-spacing: 0.02em; background: var(--panel); padding: 7px 12px;
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.brand span { color: var(--accent); }
.group {
  display: flex; gap: 6px; align-items: center; background: var(--panel); padding: 5px;
  border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(6px);
}
.variant select { max-width: 220px; font-weight: 600; }
.status { font-size: 12px; color: var(--muted); padding: 0 6px; white-space: nowrap; }
.status.dirty { color: #a8590c; font-weight: 600; }
.seg button { border-color: transparent; background: transparent; }
.seg button.active { background: var(--ink); color: #fff; }
.opts { margin-left: auto; }
.opts label { font-size: 14px; display: flex; gap: 5px; align-items: center; padding: 0 4px; white-space: nowrap; }
body:not([data-mode="iso"]) .iso-only { display: none; }

.menu { position: relative; }
.menu summary { list-style: none; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 14px; }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 5; display: flex; flex-direction: column; gap: 4px;
  background: #fff; padding: 6px; border-radius: var(--radius); box-shadow: var(--shadow); min-width: 220px;
}
.menu-pop button { text-align: left; border-color: transparent; }

.walk-hint {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: rgba(20, 20, 20, 0.78); color: #fff; padding: 12px 18px; border-radius: var(--radius);
  font-size: 14px; display: flex; flex-direction: column; gap: 4px; align-items: center; text-align: center;
  pointer-events: none;
}
.walk-hint .touch { display: none; }
@media (pointer: coarse) { .walk-hint .desk { display: none; } .walk-hint .touch { display: inline; } }

.info {
  position: fixed; left: 12px; bottom: 12px; background: var(--panel); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 36px 12px 14px; max-width: min(360px, calc(100vw - 24px));
}
.info #info-title { font-weight: 700; }
.info #info-id { font-size: 12px; color: var(--muted); margin: 3px 0 6px; font-family: ui-monospace, Menlo, monospace; }
.info small { color: var(--muted); }
.info button { position: absolute; top: 6px; right: 6px; border: 0; background: none; font-size: 18px; padding: 2px 8px; }

.chat {
  position: fixed; top: 70px; right: 12px; bottom: 12px; width: min(380px, calc(100vw - 24px));
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(8px);
  display: flex; flex-direction: column; transform: translateX(calc(100% + 24px)); transition: transform 0.2s ease;
}
body.chat-open .chat { transform: none; }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.chat-head button { border: 0; background: none; font-size: 20px; padding: 0 6px; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { padding: 8px 11px; border-radius: 10px; font-size: 14px; line-height: 1.4; white-space: pre-wrap; max-width: 92%; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.assistant { align-self: flex-start; background: #fff; border: 1px solid var(--line); }
.msg.pending { color: var(--muted); font-style: italic; }
.msg.error { align-self: flex-start; background: #fdecee; color: var(--danger); }
.msg small { display: block; margin-top: 4px; font-size: 12px; color: #2f7a3a; font-weight: 600; }
.chat form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.chat textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 14px; }
.chat form.busy button { opacity: 0.5; pointer-events: none; }

dialog { border: 0; border-radius: 12px; box-shadow: var(--shadow); padding: 18px 20px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.25); }
dialog h3 { margin: 0 0 6px; }
dialog p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
dialog input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 14px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 0; padding: 0; }

.toast {
  position: fixed; left: 50%; top: 76px; transform: translate(-50%, -12px); opacity: 0; transition: 0.2s;
  background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 8px; font-size: 14px; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

.loading { position: fixed; inset: 0; display: grid; place-items: center; color: var(--muted); background: var(--bg); transition: opacity 0.3s; }
body.ready .loading { opacity: 0; pointer-events: none; }

@media (max-width: 760px) {
  .bar { top: 8px; left: 8px; right: 8px; gap: 6px; }
  .brand { display: none; }
  .opts { margin-left: 0; }
  .opts label { display: none; }
  .status { display: none; }
  .chat { top: auto; height: 55vh; right: 8px; left: 8px; width: auto; bottom: 8px; transform: translateY(calc(100% + 16px)); }
}
