:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #f4f7f6;
  --muted: #a9b5b1;
  --panel: rgba(15, 20, 22, 0.86);
  --panel-solid: #141a1c;
  --line: rgba(255, 255, 255, 0.14);
  --accent: #d7ff5f;
  --accent-dark: #1f2b07;
  --danger: #ff8c7d;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #d9dddc; }
button, input, select { font: inherit; }
button { color: inherit; }

.viewer-shell { position: relative; width: 100%; height: 100%; min-height: 36rem; overflow: hidden; isolation: isolate; }
#renderCanvas { width: 100%; height: 100%; display: block; outline: none; touch-action: none; cursor: grab; }
#renderCanvas:active { cursor: grabbing; }

.topbar { position: absolute; inset: 0 0 auto; z-index: 5; display: flex; align-items: flex-start; justify-content: space-between; padding: max(1.25rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) 0 max(1.25rem, env(safe-area-inset-left)); pointer-events: none; }
.project-mark, .top-actions { pointer-events: auto; }
.project-mark { display: flex; align-items: center; gap: .75rem; padding: .65rem .85rem; border: 1px solid var(--line); border-radius: 1rem; background: var(--panel); backdrop-filter: blur(16px); box-shadow: 0 12px 36px rgba(0,0,0,.12); }
.project-mark .mark { width: .7rem; height: 2.35rem; border-radius: .3rem; background: var(--accent); box-shadow: 0 0 18px rgba(215,255,95,.35); }
.project-mark div { display: grid; gap: .08rem; }
.project-mark strong { font-size: .95rem; letter-spacing: .12em; }
.project-mark span { color: var(--muted); font-size: .78rem; }
.top-actions { display: flex; gap: .55rem; }
.back-button { height: 3rem; display: flex; align-items: center; gap: .55rem; padding: 0 1rem 0 .85rem; border: 1px solid rgba(215,255,95,.4); border-radius: .9rem; background: var(--panel); backdrop-filter: blur(16px); color: var(--ink); cursor: pointer; font-weight: 700; }
.back-button[hidden] { display: none; }
.back-button span { font-size: 1.1rem; color: var(--accent); }
.back-button:hover, .back-button:focus-visible { border-color: var(--accent); outline: none; }
.icon-button { width: 3rem; height: 3rem; display: grid; place-items: center; border: 1px solid var(--line); border-radius: .9rem; background: var(--panel); backdrop-filter: blur(16px); font-size: 1.3rem; cursor: pointer; transition: transform .18s ease, border-color .18s ease, background .18s ease; }
.icon-button:hover, .icon-button:focus-visible { transform: translateY(-2px); border-color: rgba(215,255,95,.65); background: rgba(22,30,31,.95); outline: none; }
.icon-button.dark { background: rgba(255,255,255,.06); }
.icon-button.compact { width: 2.35rem; height: 2.35rem; border-radius: .7rem; }

.help-dialog { width: min(52rem, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); margin: auto; padding: 0; overflow: auto; border: 1px solid rgba(255,255,255,.18); border-radius: 1.4rem; background: #0c1112; color: var(--ink); box-shadow: 0 35px 120px rgba(0,0,0,.55); }
.help-dialog::backdrop { background: rgba(4,8,9,.68); backdrop-filter: blur(9px); }
.help-dialog[open] { animation: helpIn .3s cubic-bezier(.2,.8,.2,1) both; }
.help-shell { padding: 1.4rem; }
.help-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.25rem; }
.help-head > div { min-width: 0; }
.help-head h1 { margin: .25rem 0 .45rem; font-size: clamp(1.55rem, 3vw, 2.15rem); line-height: 1.08; letter-spacing: -.035em; }
.help-head p { margin: 0; color: var(--muted); font-size: .93rem; line-height: 1.5; }
.help-head p strong { color: var(--accent); }
.help-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; margin-top: 1.25rem; }
.help-item { min-height: 7rem; display: grid; grid-template-columns: 3.25rem minmax(0, 1fr); align-items: start; gap: .85rem; padding: .9rem; border: 1px solid var(--line); border-radius: .9rem; background: rgba(255,255,255,.045); }
.help-item-icon { width: 3.25rem; height: 3.25rem; display: grid; place-items: center; border-radius: .75rem; background: rgba(215,255,95,.12); color: var(--accent); }
.help-item-icon svg { width: 1.7rem; height: 1.7rem; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.help-item-symbol { font-size: 1.25rem; font-weight: 850; }
.help-item h2 { margin: .08rem 0 .3rem; font-size: .96rem; }
.help-item p { margin: 0; color: #bec8c4; font-size: .82rem; line-height: 1.45; }
.help-quickbar { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .7rem; }
.help-quickbar span { display: inline-flex; align-items: center; gap: .45rem; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: .65rem; color: #dfe6e3; font-size: .78rem; }
.help-quickbar strong { min-width: 1.1rem; color: var(--accent); font-size: 1rem; text-align: center; }
.help-footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.help-footer p { margin: 0; color: var(--muted); font-size: .78rem; line-height: 1.4; }
.help-footer p strong { color: var(--ink); }
.help-footer button { flex: 0 0 auto; min-height: 3rem; padding: .7rem 1.1rem; border: 0; border-radius: .75rem; background: var(--accent); color: #111; font-weight: 800; cursor: pointer; }
.help-footer button:hover, .help-footer button:focus-visible { background: #e2ff89; outline: 2px solid white; outline-offset: 2px; }

.loading, .error-panel { position: absolute; z-index: 8; left: 50%; top: 50%; transform: translate(-50%,-50%); width: min(25rem, calc(100% - 2rem)); display: grid; justify-items: center; gap: .7rem; padding: 1.6rem; border: 1px solid var(--line); border-radius: 1.25rem; background: var(--panel); backdrop-filter: blur(18px); text-align: center; box-shadow: 0 24px 80px rgba(0,0,0,.28); }
.loading[hidden], .error-panel[hidden] { display: none; }
.loading span, .error-panel span { color: var(--muted); font-size: .9rem; }
.loading-ring { width: 2.5rem; height: 2.5rem; border: 3px solid rgba(255,255,255,.14); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.progress-track { width: 100%; height: .25rem; overflow: hidden; border-radius: 10rem; background: rgba(255,255,255,.1); }
.progress-track span { display: block; width: 5%; height: 100%; border-radius: inherit; background: var(--accent); transition: width .2s ease; }
.error-panel strong { color: var(--danger); }
.error-panel button { margin-top: .25rem; padding: .65rem .9rem; border: 0; border-radius: .7rem; background: var(--accent); color: #111; font-weight: 750; cursor: pointer; }

.nav-pad { position: absolute; z-index: 4; right: max(1.25rem, env(safe-area-inset-right)); top: 50%; transform: translateY(-40%); display: grid; grid-template-columns: repeat(2, 2.75rem); gap: .35rem; padding: .45rem; border: 1px solid var(--line); border-radius: 1rem; background: var(--panel); backdrop-filter: blur(16px); }
.nav-pad > button:first-child, .nav-pad > button:nth-child(3) { grid-column: 1 / -1; width: 2.75rem; justify-self: center; }
.nav-pad > div { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, 2.75rem); gap: .35rem; }
.nav-pad button { height: 2.75rem; border: 0; border-radius: .7rem; background: rgba(255,255,255,.07); font-size: 1.25rem; cursor: pointer; }
.nav-pad button:hover, .nav-pad button:focus-visible { background: var(--accent); color: #111; outline: none; }

.eyebrow { color: var(--muted); font-size: .72rem; line-height: 1.2; letter-spacing: .09em; text-transform: uppercase; }
.touch-hint { display: none; position: absolute; z-index: 3; left: 50%; top: 6rem; transform: translateX(-50%); width: max-content; max-width: calc(100% - 2rem); padding: .55rem .75rem; border-radius: .65rem; background: rgba(15,20,22,.72); color: #e8eeec; font-size: .78rem; text-align: center; pointer-events: none; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes helpIn { from { opacity: 0; transform: translateY(.8rem) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes fadeHint { 0%,65% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }

@media (max-width: 700px) {
  .viewer-shell { min-height: 28rem; }
  .project-mark span { display: none; }
  .topbar { padding: max(.75rem, env(safe-area-inset-top)) max(.75rem, env(safe-area-inset-right)) 0 max(.75rem, env(safe-area-inset-left)); }
  .top-actions { gap: .35rem; }
  .project-mark { padding: .55rem .65rem; }
  .back-button strong { display: none; }
  .back-button { width: 2.75rem; padding: 0; justify-content: center; }
  .icon-button { width: 2.75rem; height: 2.75rem; }
  .help-button { position: fixed; left: max(.75rem, env(safe-area-inset-left)); bottom: max(.75rem, env(safe-area-inset-bottom)); z-index: 6; border-color: rgba(215,255,95,.4); }
  .nav-pad { display: none; }
  .touch-hint { display: block; animation: fadeHint 5s 1.2s both; }
  .help-dialog { inset: auto 0 0; width: 100%; max-width: none; max-height: min(92dvh, 48rem); margin: 0; border-width: 1px 0 0; border-radius: 1.4rem 1.4rem 0 0; }
  .help-shell { padding: 1.15rem max(1rem, env(safe-area-inset-right)) max(1.15rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); }
  .help-grid { grid-template-columns: 1fr; gap: .5rem; margin-top: 1rem; }
  .help-item { min-height: 0; grid-template-columns: 2.75rem minmax(0, 1fr); padding: .75rem; }
  .help-item-icon { width: 2.75rem; height: 2.75rem; }
  .help-footer { align-items: stretch; flex-direction: column; }
  .help-footer button { width: 100%; }
}

@media (max-width: 420px) {
  .project-mark .mark, .project-mark div span { display: none; }
  .project-mark { min-width: 3rem; height: 2.75rem; justify-content: center; padding: .4rem; }
  .project-mark strong { font-size: .76rem; letter-spacing: .08em; }
  .top-actions { gap: .25rem; }
  .icon-button, .back-button { width: 2.55rem; height: 2.55rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
