: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: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center;
  pointer-events: none;
}
.bar > *, .bar-left > *, .bar-right > * { pointer-events: auto; }
.bar-left, .bar-right { display: flex; gap: 10px; align-items: center; min-width: 0; pointer-events: none; }
.bar-right { justify-content: flex-end; }
.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);
}
#btn-save { white-space: nowrap; }
button.icon { padding: 6px 9px; display: inline-flex; align-items: center; gap: 5px; }
button.icon svg { display: block; }
.status { font-size: 12px; color: var(--muted); padding: 0 4px; white-space: nowrap; }
.status.dirty { color: #a8590c; font-weight: 600; }
.status.dirty::before { content: "● "; }
.seg button { border-color: transparent; background: transparent; }
.seg button.active { background: var(--ink); color: #fff; }
.short { display: none; }
body:not([data-mode="iso"]) .iso-only { display: none; }

.menu { position: relative; }
.menu summary {
  list-style: none; border: 1px solid transparent; border-radius: 8px; padding: 6px 10px; cursor: pointer;
  font-size: 14px; white-space: nowrap; user-select: none;
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: " ▾"; color: var(--muted); font-size: 11px; }
.menu summary:hover, .menu[open] summary { background: #fff; border-color: var(--line); }
#variant-name { font-weight: 650; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.menu-pop {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 5; display: flex; flex-direction: column; gap: 2px;
  background: #fff; padding: 6px; border-radius: var(--radius); box-shadow: var(--shadow); min-width: 240px;
}
.menu-right .menu-pop { left: auto; right: 0; min-width: 210px; }
.menu-pop button { text-align: left; border-color: transparent; white-space: nowrap; }
.menu-pop button:hover:not(:disabled) { background: var(--bg); border-color: transparent; }
.menu-pop hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; width: auto; }
.menu-pop label { font-size: 14px; display: flex; gap: 8px; align-items: center; padding: 6px 10px; white-space: nowrap; cursor: pointer; }
.menu-pop select { margin: 2px 6px 4px; }
.menu-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 6px 10px 2px; }
.menu-list { display: flex; flex-direction: column; gap: 2px; max-height: 50vh; overflow-y: auto; }
.menu-list button.current { font-weight: 650; }
.menu-list button.current::before { content: "✓ "; }
.menu-list button:not(.current) { padding-left: 25px; }

.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.close { position: absolute; top: 6px; right: 6px; border: 0; background: none; font-size: 18px; padding: 2px 8px; }
.info-tools { display: flex; gap: 6px; margin: 2px 0 8px; }
.info-tools button { padding: 4px 9px; font-size: 13px; }
body.dragging, body.dragging #scene { cursor: grabbing !important; }
#scene.rotmode { cursor: alias; }
body.mobile .info-tools, body.mobile .info small { display: none; }

.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; }
.pdf-formats { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }
.pdf-formats label { display: flex; gap: 10px; align-items: baseline; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-weight: 600; }
.pdf-formats label:has(:checked) { border-color: var(--accent); background: #eef2f9; }
.pdf-formats input { width: auto; margin: 0; }
.pdf-formats small { font-weight: 400; color: var(--muted); }
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: 900px) {
  .status:not(.dirty) { display: none; }
}
@media (max-width: 760px) {
  .bar { top: 8px; left: 8px; right: 8px; gap: 6px; grid-template-columns: 1fr auto; }
  .seg { grid-row: 2; grid-column: 1 / -1; justify-self: center; }
  .long { display: none; }
  .short { display: inline; }
  .status { display: none; }
  #variant-name { max-width: 38vw; }
  .chat { top: auto; height: 55vh; right: 8px; left: 8px; width: auto; bottom: 8px; transform: translateY(calc(100% + 16px)); }
}
