:root {
  --bg: #f2f5f7;
  --card: #ffffff;
  --ink: #12222c;
  --muted: #5b6b75;
  --line: #d9e1e6;
  --accent: #0a6fae;
  --accent-ink: #ffffff;
  --accent-soft: #e3f0f8;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --mark: rgba(255, 205, 0, 0.38);
  --mark-line: #d49b00;
  --region: rgba(10, 111, 174, 0.12);
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: flex; flex-direction: column; background: var(--bg); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; flex: none; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand strong { display: block; font-size: 17px; }
.brand small { display: block; font-size: 11px; letter-spacing: .06em; color: var(--muted); white-space: nowrap; }
.mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.mark.big { width: 52px; height: 52px; font-size: 24px; border-radius: 14px; }
.device-chip { max-width: 50%; padding: 8px 12px; border: 1px solid var(--accent); border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.feed { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 760px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.welcome h1 { font-size: 21px; margin: 0 0 6px; }
.welcome p { margin: 0 0 12px; color: var(--muted); line-height: 1.45; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.hint { font-size: 13px; color: var(--muted); }
.primary, .secondary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 16px; border-radius: 12px; font-weight: 600; border: 1px solid var(--accent); }
.primary { background: var(--accent); color: var(--accent-ink); }
.secondary { background: var(--card); color: var(--accent); }
.wide { width: 100%; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 6px 0; text-decoration: underline; }
.icon-button { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); flex: none; }

.message { display: flex; flex-direction: column; gap: 6px; }
.message.user { align-items: flex-end; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 16px; line-height: 1.45; overflow-wrap: anywhere; }
.message.user .bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.message.user img { max-width: 160px; border-radius: 10px; border: 1px solid var(--line); }
.answer { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; line-height: 1.5; overflow-wrap: anywhere; }
.answer.warn { background: var(--warn-soft); border-color: #f0d9a6; }
.answer h3 { font-size: 15px; margin: 12px 0 4px; }
.answer p { margin: 0 0 8px; }
.answer ol, .answer ul { margin: 0 0 8px; padding-left: 22px; }
.answer li { margin: 3px 0; }
.cite { display: inline-block; min-width: 24px; padding: 0 6px; margin: 0 1px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; line-height: 20px; vertical-align: 1px; }
.sources { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.source { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: #f8fafb; }
.source b { color: var(--accent); }
.source span { flex: 1; font-size: 14px; }
.source small { color: var(--muted); }
.note { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.choices { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.thinking { color: var(--muted); font-style: italic; }
.thinking::after { content: ""; display: inline-block; width: 1em; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.composer-wrap { background: var(--card); border-top: 1px solid var(--line); padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); }
.composer { display: flex; align-items: flex-end; gap: 8px; max-width: 760px; margin: 0 auto; }
.composer textarea { flex: 1; min-height: 44px; max-height: 140px; resize: none; overflow-y: hidden; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); line-height: 1.35; font-size: 16px; }
.send { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-ink); flex: none; }
.send:disabled { opacity: .5; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; max-width: 760px; margin: 0 auto 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 4px 4px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); font-size: 13px; }
.chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 6px; }
.chip button { width: 28px; height: 28px; border: 0; background: none; display: grid; place-items: center; }
.chip svg { width: 16px; height: 16px; }

.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(10, 20, 26, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet-panel { width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto; background: var(--card); border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 19px; }
.sheet input[type=search] { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; font-size: 16px; }
.device-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.device-list button { width: 100%; text-align: left; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
.device-list button[aria-current=true] { border-color: var(--accent); background: var(--accent-soft); }
.device-list strong { display: block; }
.device-list small { display: block; color: var(--muted); margin-top: 2px; }
.sheet-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.overlay { position: fixed; inset: 0; z-index: 30; background: #1b252b; color: #fff; display: flex; flex-direction: column; }
.overlay-bar { display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: #111a1f; }
.overlay-bar .icon-button, .overlay-tools .tool { background: #26333a; border-color: #34444c; color: #fff; }
.viewer-title { flex: 1; min-width: 0; }
.viewer-title strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-title small { color: #b7c4cb; }
.stage { flex: 1; overflow: auto; position: relative; -webkit-overflow-scrolling: touch; }
.page { position: relative; width: 100%; max-width: 900px; margin: 0 auto; background: #fff; }
.page img { display: block; width: 100%; height: auto; }
.mark-box { position: absolute; border: 2px solid var(--mark-line); background: var(--mark); border-radius: 3px; pointer-events: none; }
.mark-box.region { border: 2px dashed var(--accent); background: var(--region); }
.loading { position: absolute; inset: 40% 0 auto; text-align: center; color: #b7c4cb; }
.overlay-tools { display: flex; gap: 8px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: #111a1f; overflow-x: auto; }
.tool { min-width: 44px; height: 44px; border-radius: 12px; border: 1px solid; font-size: 20px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 12px; white-space: nowrap; }
.tool.text { font-size: 14px; font-weight: 600; }
.tool.accent { background: var(--accent) !important; border-color: var(--accent) !important; }
.tool:disabled { opacity: .4; }

.ar { background: #000; overflow: hidden; touch-action: none; }
.ar video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ar-drawing { position: absolute; left: 50%; top: 40%; transform-origin: center; max-width: none; background: #fff; border-radius: 6px; box-shadow: 0 0 0 2px rgba(255,255,255,.6); user-select: none; -webkit-user-select: none; touch-action: none; }
.ar-message { position: absolute; top: 30%; left: 16px; right: 16px; padding: 14px; border-radius: 12px; background: rgba(0,0,0,.7); text-align: center; }
.ar-controls { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0,0,0,.75) 30%); display: flex; flex-direction: column; gap: 8px; }
.ar-tip { margin: 0; font-size: 12px; color: #d5dee3; }
.ar-controls label { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.ar-controls input { flex: 1; }
.ar-buttons { display: flex; gap: 8px; }
.ar-buttons button { flex: 1; }

.login-backdrop { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 10px; text-align: center; align-items: center; }
.login-card h2 { margin: 4px 0 0; }
.login-card p { margin: 0; color: var(--muted); }
.login-card input { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; font-size: 16px; }
.error { color: #b3261e; min-height: 1.2em; }

