* { box-sizing: border-box; }
:root { color-scheme: dark; font-family: Arial, sans-serif; background: #151a17; color: #edf2e9; }
body { margin: 0; }
[hidden] { display: none !important; }
.viewer { height: 100vh; height: 100svh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; overflow: hidden; }
.stage { position: relative; min-height: 0; overflow: hidden; background: #1c231e; }
#canvas-host, #fallback { position: absolute; inset: 0; }
canvas { display: block; width: 100%; height: 100%; }
#fallback { display: grid; place-items: center; background: #151a17; }
#fallback img { width: 100%; height: 100%; object-fit: contain; }
.controls { display: flex; justify-content: center; align-items: center; gap: 20px; padding: 16px 24px max(16px, env(safe-area-inset-bottom)); background: #101612; }
.controls button, .controls a {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 48px; padding: 12px 20px; border: 1px solid #4b5b4b; border-radius: 6px;
  color: #e7eee2; background: #202b21; font: 500 14px Arial, sans-serif;
  text-decoration: none; white-space: nowrap; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.controls button:hover, .controls a:hover { background: #2d3b2c; border-color: #849b79; }
.controls button:focus-visible, .controls a:focus-visible { outline: 2px solid #b9ee73; outline-offset: 4px; }
.controls button:disabled { opacity: .4; cursor: default; }
.controls svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; }
#play { min-width: 112px; background: #b9ee73; color: #17220f; border-color: #b9ee73; }
#play:hover { background: #cbff8f; }
#play svg { fill: currentColor; stroke: none; }
#exit {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: max(20px, env(safe-area-inset-right));
  z-index: 20;
  background: #172019;
  border-color: #667766;
  box-shadow: 0 8px 18px rgba(0, 0, 0, .28);
}
#exit:hover { background: #263528; border-color: #9caf94; }
#seek { flex: 1; max-width: 720px; min-width: 0; height: 48px; margin: 0; accent-color: #b9ee73; cursor: pointer; }
#seek:focus-visible { outline: 2px solid #b9ee73; outline-offset: 4px; }
.scene-note { position: absolute; right: 4%; bottom: 12%; display: flex; align-items: center; gap: 16px; max-width: min(480px, calc(100% - 40px)); font-size: 17px; line-height: 1.5; pointer-events: none; text-shadow: 0 2px 6px #000; }
.scene-note > span:last-child { min-width: 0; }
#scene-note-title, #scene-note-detail { display: block; text-wrap: balance; word-break: normal; overflow-wrap: normal; hyphens: none; }
.scene-note[data-single-line="true"] { max-width: none; }
.scene-note[data-single-line="true"] #scene-note-title { white-space: nowrap; }
#scene-note-detail { color: #b1beb4; font-size: 14px; margin-top: 4px; }
.note-line { width: 48px; height: 1px; flex: 0 0 48px; background: #9daa9b; }
.note-line:before { content: ''; display: block; width: 5px; height: 5px; border-radius: 50%; background: #b9ee73; transform: translateY(-2px); }
.layer-callouts { position: absolute; inset: 0; pointer-events: none; }
.layer-callouts svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.layer-callouts polyline { fill: none; stroke: #c4d4c0; stroke-width: 1.25; stroke-linecap: round; stroke-linejoin: round; }
.layer-callouts polyline:nth-child(3) { stroke: #b9ee73; }
.layer-callouts circle { fill: #dbe8d4; }
.layer-callouts circle:nth-of-type(3) { fill: #b9ee73; }
.layer-callout { position: absolute; display: flex; align-items: center; gap: 9px; min-height: 34px; padding: 7px 9px; border: 1px solid #71866b70; border-radius: 4px; background: #172019f2; color: #e0e9dc; font-size: 12px; line-height: 1.3; transform: translateY(-50%); }
.layer-callout b { color: #a8ba9f; font-size: 10px; font-weight: 500; }
.layer-callout > span { min-width: 0; text-wrap: balance; word-break: normal; hyphens: none; }
.layer-callout:nth-of-type(3) { color: #c8f99b; border-color: #a9d57d80; }
.stage:has(.layer-callouts:not([hidden])) .scene-note { visibility: hidden; }
@media (max-width: 600px) {
  .controls { gap: 12px; padding: 8px 12px max(8px, env(safe-area-inset-bottom)); }
  .controls button, .controls a { min-width: 0; padding: 12px 6px; font-size: 12px; }
  #play { min-width: 78px; }
  #order { padding-inline: 9px; }
  #exit {
    top: max(10px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    padding: 10px 12px;
    font-size: 12px;
  }
  .scene-note { left: 20px; right: 20px; bottom: 7%; max-width: none; font-size: 14px; }
  #scene-note-detail { font-size: 12px; }
  .note-line { width: 24px; flex-basis: 24px; }
  .layer-callout { font-size: 11px; gap: 5px; padding: 6px; min-height: 36px; }
  .layer-callout b { font-size: 9px; }
}
@media (max-width: 360px) {
  .scene-note[data-single-line="true"] { left: 12px; right: 12px; gap: 10px; font-size: 13px; }
  .scene-note[data-single-line="true"] .note-line { width: 16px; flex-basis: 16px; }
}
