:root {
  --paper: #eee8dd;
  --paper-deep: #dcd3c4;
  --ink: #201e19;
  --muted: #746d60;
  --line: rgba(32, 30, 25, 0.14);
  --moss: #315c4c;
  --glass: rgba(251, 248, 241, 0.66);
  --glass-strong: rgba(251, 248, 241, 0.84);
  --shadow: 0 18px 50px rgba(43, 37, 26, 0.14);
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(80% 70% at 50% 18%, #f8f4ec 0%, #e9e2d5 48%, #cfc4b2 100%);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
}

.viewer-shell {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: min(420px, 100vh);
  min-height: min(420px, 100dvh);
  overflow: hidden;
  isolation: isolate;
}

.viewer-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    radial-gradient(70% 60% at 50% 55%, transparent 55%, rgba(55, 45, 30, 0.09) 100%);
  pointer-events: none;
}

#scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}

.chrome {
  position: absolute;
  z-index: 5;
  pointer-events: none;
}

.topbar {
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: clamp(18px, 2.4vw, 30px) clamp(18px, 3vw, 38px);
}

.title-block { max-width: 620px; }

.kicker {
  margin: 0 0 6px;
  color: var(--moss);
  font-size: 0.66rem;
  font-weight: 750;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(1.35rem, 2.6vw, 2.1rem);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: -0.035em;
}

h1 em {
  color: var(--moss);
  font-weight: 400;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 37px;
  height: 37px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--glass);
  box-shadow: var(--shadow);
  cursor: pointer;
  backdrop-filter: blur(14px);
  transition: background 160ms ease;
}

.text-button {
  height: 37px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--glass);
  box-shadow: var(--shadow);
  color: #5b554a;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  backdrop-filter: blur(14px);
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
}

.text-button:hover { background: var(--glass-strong); }

.text-button[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: #f8f3e7;
}

.text-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.icon-button:hover { background: var(--glass-strong); }
.icon-button svg { width: 16px; height: 16px; }

.loading {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass-strong);
  box-shadow: var(--shadow);
  color: #514b41;
  font-size: 0.76rem;
  pointer-events: none;
  backdrop-filter: blur(14px);
  transform: translate(-50%, -50%);
  transition: opacity 240ms ease, visibility 240ms ease;
}

.loading p { margin: 0; }

.loading.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(49, 92, 76, 0.2);
  border-top-color: var(--moss);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 21;
  width: min(440px, calc(100vw - 36px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--glass-strong);
  box-shadow: var(--shadow);
  color: #4f4940;
  font-size: 0.85rem;
  transform: translate(-50%, -50%);
  backdrop-filter: blur(14px);
}

.error[hidden] { display: none; }
.error p { margin: 0 0 8px; }
.error code {
  display: inline-block;
  padding: 4px 7px;
  border-radius: 5px;
  background: rgba(32, 30, 25, 0.07);
  font-size: 0.78rem;
}

.empty-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 4;
  margin: 0;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  color: #5a5449;
  font-size: 0.76rem;
  pointer-events: none;
  backdrop-filter: blur(12px);
  transform: translate(-50%, -50%);
}

.empty-hint[hidden] { display: none; }

.bottom-ui {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 0 clamp(14px, 3vw, 38px) calc(16px + env(safe-area-inset-bottom));
  pointer-events: none;
}

.bird-bar {
  display: flex;
  align-items: center;
  gap: 3px;
  max-width: 100%;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--glass);
  box-shadow: var(--shadow);
  pointer-events: auto;
  backdrop-filter: blur(16px);
}

.bird-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 160ms ease, opacity 160ms ease;
}

.bird-toggle:hover { background: rgba(255, 255, 255, 0.48); }

.bird-toggle[aria-pressed="true"] {
  background: var(--glass-strong);
  box-shadow: 0 1px 5px rgba(50, 43, 30, 0.12);
}

.bird-toggle[aria-pressed="false"] { opacity: 0.48; }

.check {
  position: relative;
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border: 1.5px solid #8b8375;
  border-radius: 50%;
  background: transparent;
  transition: background 160ms ease, border-color 160ms ease;
}

.check::after {
  content: "";
  position: absolute;
  top: 1.5px;
  left: 4.4px;
  width: 4px;
  height: 7.5px;
  border: solid #fffdf7;
  border-width: 0 1.5px 1.5px 0;
  opacity: 0;
  transform: rotate(45deg);
  transition: opacity 120ms ease;
}

.bird-toggle[aria-pressed="true"] .check {
  border-color: var(--moss);
  background: var(--moss);
}

.bird-toggle[aria-pressed="true"] .check::after { opacity: 1; }

.bird-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
}

.bird-text small {
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.bar-divider {
  width: 1px;
  height: 28px;
  margin: 0 4px;
  background: var(--line);
}

.show-all {
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: #5b554a;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 160ms ease;
}

.show-all:hover { background: rgba(255, 255, 255, 0.5); }

.hint-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(920px, 100%);
  padding: 0 8px;
  color: var(--muted);
  font-size: 0.66rem;
  pointer-events: none;
}

.hint-row p { margin: 0; }

.mobile-hint { display: none; }

.scale-note {
  display: flex;
  align-items: center;
  gap: 7px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.mini-ruler {
  display: inline-flex;
  height: 10px;
  border: 1px solid currentColor;
}

.mini-ruler i {
  display: block;
  width: 3px;
  border-left: 1px solid currentColor;
}

.mini-ruler i:first-child { border-left: 0; }
.mini-ruler i:nth-child(5n + 1) { background: currentColor; }

button:focus-visible {
  outline: 2px solid var(--moss);
  outline-offset: 3px;
}

.noscript {
  max-width: 720px;
  margin: 20px auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--glass);
  color: #4f4940;
  font-size: 0.9rem;
}

@media (max-width: 780px) {
  .topbar {
    align-items: flex-start;
    gap: 12px;
    padding-top: 16px;
  }

  h1 { font-size: clamp(1.12rem, 5.2vw, 1.4rem); }
  h1 em { display: block; }
  .kicker { font-size: 0.58rem; }

  .top-actions {
    position: fixed;
    top: auto;
    right: 14px;
    bottom: calc(104px + env(safe-area-inset-bottom));
    z-index: 6;
  }

  .icon-button { width: 38px; height: 38px; }
  .text-button { height: 38px; padding: 0 10px; font-size: 0.64rem; }

  .bottom-ui {
    gap: 8px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .bird-bar {
    flex-wrap: nowrap;
    justify-content: center;
    width: 100%;
    border-radius: 14px;
  }

  .bird-toggle {
    flex: 1 1 0;
    justify-content: center;
    gap: 4px;
    min-height: 40px;
    padding: 7px 4px;
  }

  .bird-text { font-size: 0.64rem; }
  .bird-text small { font-size: 0.54rem; }
  .check { width: 13px; height: 13px; }
  .check::after { top: 1px; left: 3.4px; width: 3.2px; height: 6px; }
  .bar-divider { display: none; }
  .show-all { flex: 0 0 auto; padding: 7px 7px; font-size: 0.62rem; }

  .hint-row {
    justify-content: center;
    gap: 12px;
    padding: 0;
    font-size: 0.6rem;
  }

  .hint-row > p:first-child { display: block; }
  .desktop-hint { display: none; }
  .mobile-hint { display: inline; }
}

@media (max-height: 500px) and (pointer: coarse) {
  .top-actions {
    position: fixed;
    top: auto;
    right: 14px;
    bottom: calc(104px + env(safe-area-inset-bottom));
    z-index: 6;
  }
}

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