:root {
  --bg: #101316;
  --panel: #171b1f;
  --panel-2: #20262b;
  --line: rgba(255,255,255,.1);
  --muted: #949da5;
  --text: #f4f6f7;
  --accent: #ffd447;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; touch-action: none; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
button, input { font: inherit; }
button { color: inherit; -webkit-tap-highlight-color: transparent; }

.app { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  height: calc(68px + var(--safe-top));
  padding: var(--safe-top) 18px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: rgba(16,19,22,.96);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto;
  color: #111; background: var(--accent); border-radius: 9px;
  font: 900 16px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.brand-copy { display: flex; flex-direction: column; min-width: 0; }
.brand-copy strong { font-size: 15px; }
.brand-copy small { margin-top: 2px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.button, .icon-button {
  min-height: 42px; border: 1px solid transparent; border-radius: 10px;
  background: var(--panel-2); cursor: pointer;
}
.button { padding: 0 16px; font-size: 14px; font-weight: 700; }
.button.primary { color: #151719; background: var(--accent); }
.button.ghost { color: #d6dade; border-color: var(--line); background: transparent; }
.button.danger { color: #ff746f; border-color: rgba(255,116,111,.28); background: rgba(255,116,111,.08); }
.icon-button { width: 42px; padding: 0; font-size: 24px; }
button:disabled { opacity: .32; cursor: default; }

.main { min-height: 0; flex: 1; display: grid; grid-template-columns: 54px minmax(0,1fr) 190px; }
.toolbar {
  position: relative; width: 54px; padding: 8px 5px calc(10px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 5px;
  border-right: 1px solid var(--line); background: var(--panel);
  overflow-y: auto; z-index: 18; transition: width 180ms ease, box-shadow 180ms ease;
}
.toolbar:not(.collapsed) { width: 80px; box-shadow: 16px 0 34px rgba(0,0,0,.32); }
.toolbar.collapsed .tool:not(.active):not(.quick-tool) { display: none; }
.drawer-toggle {
  min-height: 38px; border: 1px solid var(--line); border-radius: 9px; color: var(--accent);
  background: #22282d; font-size: 25px; line-height: 1; cursor: pointer;
}
.tool {
  min-height: 58px; padding: 6px 3px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 0; border-radius: 11px; background: transparent; cursor: pointer;
}
.tool b { font: 700 24px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.tool span { color: var(--muted); font-size: 11px; }
.tool.active { color: #141719; background: var(--accent); }
.tool.active span { color: rgba(20,23,25,.72); font-weight: 800; }

.workspace {
  position: relative; min-width: 0; min-height: 0; overflow: hidden;
  background-color: #0d0f11;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 32px 32px;
  touch-action: none;
}
.workspace, .stage, .scene, #overlay, #overlay * {
  touch-action: none !important;
  -webkit-touch-callout: none;
}
.welcome {
  position: absolute; inset: 0; padding: 30px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.welcome-symbol {
  width: 74px; height: 74px; margin-bottom: 22px; display: grid; place-items: center;
  border: 1px solid rgba(255,212,71,.35); border-radius: 22px; color: var(--accent);
  background: rgba(255,212,71,.07); font-size: 40px;
}
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.welcome h1 { margin: 0; font-size: clamp(36px,5vw,62px); line-height: 1.08; letter-spacing: -.04em; }
.welcome-text { max-width: 460px; margin: 18px 0 26px; color: var(--muted); font-size: 15px; line-height: 1.7; }
.photo-button {
  min-height: 58px; padding: 0 24px; border: 0; border-radius: 14px;
  color: #121416; background: var(--accent); font-weight: 900; box-shadow: 0 18px 50px rgba(0,0,0,.28);
}
.photo-button span { margin-right: 8px; font-size: 22px; vertical-align: -1px; }
.welcome-hint { margin: 14px 0 0; color: #646d74; font-size: 11px; }
.stage { position: absolute; inset: 0; overflow: hidden; }
.scene { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.scene img, .scene svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.scene img { pointer-events: none; object-fit: fill; }
.scene svg { overflow: visible; touch-action: none; }
.annotation-line, .draft-line {
  fill: none; stroke: var(--ann-color, #ffd447); stroke-width: var(--ann-width, 3);
  vector-effect: non-scaling-stroke; stroke-linecap: round; stroke-linejoin: round;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.85));
}
.annotation-text {
  fill: var(--ann-color, #ffd447); stroke: rgba(0,0,0,.92); stroke-width: 4px;
  paint-order: stroke fill; stroke-linejoin: round;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "PingFang SC", monospace;
  font-weight: 800; text-anchor: middle; dominant-baseline: central;
}
.arrow-head { fill: context-stroke; }
.annotation-hit { fill: none; stroke: transparent; stroke-width: 24; vector-effect: non-scaling-stroke; pointer-events: stroke; }
.annotation.selected .annotation-line { filter: drop-shadow(0 0 5px var(--ann-color)); }
.draft-line { stroke-dasharray: 8 7; opacity: .88; }
.draft-point { fill: var(--accent); stroke: #101316; stroke-width: 2; vector-effect: non-scaling-stroke; }
.draft-eraser {
  fill: rgba(255,255,255,.18); stroke: #fff; stroke-width: 2;
  vector-effect: non-scaling-stroke; pointer-events: none;
}

.status-pill {
  position: absolute; left: 50%; bottom: calc(90px + var(--safe-bottom)); z-index: 8;
  max-width: calc(100% - 110px); padding: 10px 15px; transform: translateX(-50%);
  border: 1px solid rgba(255,255,255,.12); border-radius: 999px;
  color: #eef1f3; background: rgba(20,24,27,.9); backdrop-filter: blur(16px);
  font-size: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.25);
}
.fit-button {
  position: absolute; right: 14px; bottom: calc(94px + var(--safe-bottom)); z-index: 8;
  min-width: 48px; height: 40px; border: 1px solid var(--line); border-radius: 10px;
  color: #dce0e3; background: rgba(23,27,31,.88);
}
.exit-fullscreen {
  position: absolute; right: 14px; top: 14px; z-index: 30;
  height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px;
  color: #e2e5e7; background: rgba(16,19,22,.9); backdrop-filter: blur(12px);
}
.page-strip {
  position: absolute; left: 50%; bottom: calc(10px + var(--safe-bottom)); z-index: 15;
  width: min(720px, calc(100% - 24px)); height: 70px; padding: 7px;
  display: flex; align-items: center; gap: 7px; transform: translateX(-50%);
  border: 1px solid rgba(255,255,255,.12); border-radius: 14px;
  background: rgba(18,22,25,.9); backdrop-filter: blur(18px); box-shadow: 0 14px 40px rgba(0,0,0,.36);
}
.page-thumbs { min-width: 0; flex: 1; display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none; }
.page-thumbs::-webkit-scrollbar { display: none; }
.page-thumb {
  position: relative; width: 64px; height: 54px; flex: 0 0 64px; padding: 0;
  overflow: hidden; border: 2px solid transparent; border-radius: 9px; background: #090b0c;
}
.page-thumb img { width: 100%; height: 100%; display: block; object-fit: cover; pointer-events: none; }
.page-thumb span {
  position: absolute; left: 3px; top: 3px; min-width: 18px; height: 18px; padding: 0 4px;
  display: grid; place-items: center; border-radius: 5px; color: #fff;
  background: rgba(0,0,0,.68); font-size: 10px; font-weight: 800;
}
.page-thumb.active { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(0,0,0,.7); }
.page-arrow, .add-page {
  height: 54px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 9px; background: #242a2f;
}
.page-arrow { width: 38px; font-size: 30px; line-height: 1; }
.page-arrow:disabled { opacity: .24; }
.add-page { width: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--accent); }
.add-page b { font-size: 20px; line-height: 1; }
.add-page span { font-size: 9px; }
.page-count { min-width: 42px; color: #a8b0b6; font: 700 11px/1 ui-monospace, monospace; text-align: center; }

.inspector {
  padding: 18px 14px calc(18px + var(--safe-bottom)); border-left: 1px solid var(--line);
  background: var(--panel); overflow-y: auto;
}
.inspector section + section { margin-top: 28px; }
.panel-label { margin: 0 0 11px; color: #737c84; font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.color-row { display: flex; flex-wrap: wrap; gap: 9px; }
.color-swatch {
  width: 28px; height: 28px; padding: 0; border: 2px solid transparent; border-radius: 50%;
  background: var(--swatch); box-shadow: inset 0 0 0 1px rgba(0,0,0,.2);
}
.color-swatch.active { border-color: #fff; box-shadow: 0 0 0 2px #373d42; }
.tips p:last-child { margin: 0; color: #bbc1c6; font-size: 13px; line-height: 1.6; }
.gesture-note {
  padding: 12px; display: flex; gap: 10px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.025);
}
.gesture-note span { color: var(--accent); }
.gesture-note p { margin: 0; color: #89929a; font-size: 11px; line-height: 1.6; }
.gesture-note strong { color: #dbe0e3; }
.panel-button {
  width: 100%; min-height: 42px; margin-top: 7px; border: 1px solid var(--line); border-radius: 10px;
  color: #dce1e4; background: #23292e; font-size: 12px; font-weight: 700;
}
.panel-button.danger-text { color: #ff8d87; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; background: rgba(0,0,0,.56); backdrop-filter: blur(4px); }
.sheet {
  width: min(680px, 100%); padding: 10px 22px calc(20px + var(--safe-bottom));
  border: 1px solid rgba(255,255,255,.12); border-bottom: 0; border-radius: 22px 22px 0 0;
  background: #1b2024; box-shadow: 0 -30px 80px rgba(0,0,0,.35);
}
.sheet-handle { width: 42px; height: 4px; margin: 0 auto 14px; border-radius: 3px; background: #4f575e; }
.sheet-title { display: flex; align-items: flex-start; justify-content: space-between; }
.sheet h2 { margin: 0 0 14px; font-size: 22px; }
.close-button { width: 38px; height: 38px; border: 0; border-radius: 50%; color: #abb2b8; background: #292f34; font-size: 24px; }
.dimension-input {
  width: 100%; height: 62px; padding: 0 16px; border: 2px solid #4c555c; border-radius: 12px; outline: none;
  color: #fff; background: #111518; font: 800 28px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.dimension-input:focus { border-color: var(--accent); }
.quick-symbols { margin-top: 12px; display: grid; grid-template-columns: repeat(4,1fr); gap: 7px; }
.quick-symbols button { min-height: 42px; border: 1px solid var(--line); border-radius: 9px; color: #d7dce0; background: #242a2f; font-size: 13px; }
.sheet-actions { margin-top: 18px; display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.toast {
  position: fixed; left: 50%; top: calc(84px + var(--safe-top)); z-index: 200;
  padding: 11px 16px; transform: translateX(-50%); border-radius: 10px;
  color: #111; background: var(--accent); font-size: 13px; font-weight: 800; box-shadow: 0 10px 36px rgba(0,0,0,.35);
}
.hidden { display: none !important; }

.hub-backdrop {
  position: fixed; inset: 0; z-index: 90; padding: max(22px, var(--safe-top)) 22px max(22px, var(--safe-bottom));
  display: grid; place-items: center; background: #0d1012;
}
.hub-panel { width: min(980px, 100%); height: min(760px, 100%); display: flex; flex-direction: column; }
.hub-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 8px 4px 22px; border-bottom: 1px solid var(--line); }
.hub-header h1 { margin: 0; font-size: clamp(30px, 4vw, 48px); letter-spacing: -.04em; }
.hub-header p:last-child { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.hub-header-actions, .hub-toolbar { display: flex; gap: 9px; align-items: center; }
.hub-toolbar { padding: 18px 4px 12px; }
.project-list { min-height: 0; padding: 4px; display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 13px; overflow-y: auto; }
.project-card { min-height: 174px; padding: 18px; display: flex; flex-direction: column; text-align: left; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
.project-card:hover { border-color: rgba(255,212,71,.45); }
.project-card-cover { height: 68px; margin: -8px -8px 14px; overflow: hidden; border-radius: 10px; background: #0b0d0e; }
.project-card-cover img { width: 100%; height: 100%; display: block; object-fit: cover; }
.project-card h3 { margin: 0; overflow: hidden; color: var(--text); font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }
.project-card-meta { margin: 7px 0 16px; color: var(--muted); font-size: 11px; }
.project-card-actions { margin-top: auto; display: flex; gap: 7px; }
.project-card-actions button { min-height: 36px; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px; background: #252b30; font-size: 11px; }
.project-card-actions .open-project { flex: 1; color: #121416; border-color: var(--accent); background: var(--accent); font-weight: 800; }
.project-card-actions .delete-project { color: #ff8d87; }
.empty-projects { margin: auto; color: var(--muted); text-align: center; }
.compact-sheet { width: min(560px, 100%); }
.field-label { margin-top: 14px; display: grid; gap: 7px; color: #aab1b7; font-size: 12px; }
.text-input { width: 100%; height: 48px; padding: 0 13px; border: 1px solid #4b545b; border-radius: 10px; outline: none; color: #fff; background: #111518; }
.text-input:focus { border-color: var(--accent); }
.form-error { margin: 12px 0 0; color: #ff8d87; font-size: 12px; }
.inline-user-form { margin: 14px 0; display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; }
.user-list { max-height: 48vh; overflow-y: auto; }
.user-row { padding: 11px 2px; display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line); }
.user-row strong { flex: 1; }
.user-row small { color: var(--muted); }
.user-row button { min-height: 34px; border: 1px solid var(--line); border-radius: 8px; color: #ffb0aa; background: #252b30; }
.sync-dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: #4ed38a; }

.app.focus-mode .topbar, .app.focus-mode .inspector { display: none; }
.app.focus-mode .main { grid-template-columns: 54px minmax(0,1fr); }
.app.focus-mode .exit-fullscreen { display: block !important; }
.app.focus-mode .page-strip { width: min(820px, calc(100% - 24px)); }
html:fullscreen .app, html:-webkit-full-screen .app { width: 100%; height: 100%; background: var(--bg); }
.workspace.hand-mode, .workspace.hand-mode #overlay { cursor: grab; }

@media (max-width: 900px) {
  .main { grid-template-columns: 54px minmax(0,1fr); }
  .inspector { display: none; }
}
@media (max-width: 640px) {
  .topbar { padding-left: 10px; padding-right: 10px; }
  .brand-copy small, #newPhotoBtn { display: none; }
  #fullscreenBtn { display: none; }
  .button { padding: 0 12px; }
  .main { grid-template-columns: 1fr; grid-template-rows: minmax(0,1fr) calc(66px + var(--safe-bottom)); }
  .workspace { grid-row: 1; }
  .toolbar {
    grid-row: 2; width: 100%; padding: 5px 6px var(--safe-bottom); flex-direction: row; border: 0; border-top: 1px solid var(--line); overflow-x: auto;
  }
  .toolbar:not(.collapsed) { width: 100%; box-shadow: 0 -14px 32px rgba(0,0,0,.32); }
  .toolbar.collapsed .tool:not(.active):not(.quick-tool) { display: none; }
  .drawer-toggle { min-width: 42px; min-height: 54px; flex: 0 0 42px; }
  .tool { min-width: 60px; min-height: 54px; flex: 1 0 60px; }
  .tool b { font-size: 20px; }
  .quick-symbols { grid-template-columns: repeat(3,1fr); }
  .page-strip { bottom: calc(8px + var(--safe-bottom)); width: calc(100% - 16px); height: 62px; padding: 5px; }
  .page-thumb { width: 56px; height: 50px; flex-basis: 56px; }
  .page-arrow { width: 32px; height: 50px; }
  .add-page { width: 48px; height: 50px; }
  .page-count { display: none; }
  .fit-button { bottom: calc(82px + var(--safe-bottom)); }
  .status-pill { bottom: calc(78px + var(--safe-bottom)); }
  .app.focus-mode .main { grid-template-columns: 1fr; grid-template-rows: minmax(0,1fr) calc(66px + var(--safe-bottom)); }
  #accountBtn { display: none; }
  .project-list { grid-template-columns: 1fr; }
  .hub-backdrop { padding: max(12px, var(--safe-top)) 12px max(12px, var(--safe-bottom)); }
  .hub-header h1 { font-size: 30px; }
  .hub-header-actions .button { display: none; }
  .inline-user-form { grid-template-columns: 1fr; }
}
@media (orientation: portrait) and (min-width: 641px) {
  .main { grid-template-columns: 54px minmax(0,1fr); }
}
