:root {
  --ink: #e7eef2;
  --muted: #9aafb8;
  --line: rgba(214, 228, 232, 0.18);
  --card: rgba(8, 16, 24, 0.82);
  --warm: #f3d7a1;
  --chrome-core: 56px;
  --chrome-bar: var(--chrome-core);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #03060a;
  color: var(--ink);
  font-family: "Outfit", "Segoe UI", sans-serif;
}

body {
  display: flex;
  flex-direction: column;
}

body.quiet {
  --chrome-bar: calc(var(--chrome-core) + env(safe-area-inset-bottom, 0px));
}

.outside {
  flex: none;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  padding-right: calc(14px + env(safe-area-inset-right, 0px));
  padding-bottom: 6px;
  padding-left: calc(14px + env(safe-area-inset-left, 0px));
  background: #071018;
  border-bottom: 1px solid var(--line);
}

footer.outside {
  padding-top: 4px;
  padding-right: calc(14px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(14px + env(safe-area-inset-left, 0px));
  border-bottom: 0;
  border-top: 1px solid var(--line);
}

.title-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  touch-action: none;
}

.hud { position: absolute; z-index: 2; pointer-events: none; }

.dock,
.tools {
  display: none;
  z-index: 4;
  left: 0;
  right: 0;
  bottom: var(--chrome-bar);
  max-height: min(70vh, calc(100% - var(--chrome-bar)));
  overflow: auto;
  pointer-events: auto;
  background: rgba(8, 16, 24, 0.94);
  border: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding-top: 12px;
  padding-right: calc(12px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
}

.dock.open,
.tools.open {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.dock.open label,
.dock.open button,
.tools.open label,
.tools.open button {
  min-height: 48px;
}

.kicker {
  margin: 0;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--warm);
}

h1 {
  margin: 0;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 22px;
  font-weight: 560;
  letter-spacing: -0.03em;
}

.lede, .define, #status, #attrib {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

#search, #position {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

#position {
  margin-top: 6px;
  flex-wrap: wrap;
}

#search input, #position input, .chrome-bar button, .presets button, #search button, #position button {
  font: inherit;
  color: var(--ink);
  background: rgba(8, 16, 24, 0.78);
  border: 1px solid var(--line);
  border-radius: 999px;
}

#search input, #position input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border-radius: 12px;
}

#position input { flex: 1 1 100%; }

.eye {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  margin-top: 6px;
  padding: 4px 8px 4px 12px;
  pointer-events: auto;
  color: var(--ink);
  font-size: 13px;
  background: rgba(8, 16, 24, 0.92);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.eye input {
  width: 4.5rem;
  flex: 0 0 4.5rem;
  font: inherit;
  color: var(--ink);
  background: rgba(8, 16, 24, 0.78);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
}

#search button, #position button, .chrome-bar button, .presets button {
  padding: 8px 12px;
  cursor: pointer;
}

.chrome-bar {
  z-index: 6;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
  background: rgba(7, 16, 24, 0.92);
  padding-top: 6px;
  padding-right: calc(8px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(8px + env(safe-area-inset-left, 0px));
}

body:not(.quiet) .chrome-bar {
  padding-bottom: 6px;
}

.chrome-bar button {
  min-height: 44px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chrome-bar button.icon {
  display: grid;
  place-items: center;
  flex: 0 0 48px;
  width: 48px;
  min-width: 48px;
  padding: 0;
}

.chrome-bar button.icon[hidden] {
  display: none;
}

.chrome-bar button.icon.is-on {
  background: #d7e4f2;
  color: #102033;
  border-color: #8eb0d0;
}

.glyph {
  width: 22px;
  height: 22px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#zoom-in, #zoom-out {
  flex: 0 0 48px;
  width: 48px;
  min-width: 48px;
  min-height: 44px;
  padding-inline: 0;
}

button:focus,
#search input:focus,
#position input:focus {
  outline: none;
}

button:focus-visible,
#search input:focus-visible,
#position input:focus-visible,
.eye input:focus-visible,
canvas:focus-visible {
  outline: 2px solid #f3d7a1;
  outline-offset: 2px;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  pointer-events: auto;
}

.define { margin-top: 8px; max-width: 38em; font-size: 12px; }
.sources a { color: inherit; margin-inline-end: 0.75em; }

.presets button { font-size: 12px; padding: 4px 10px; }

.tools {
  font-size: 13px;
}

.tools label {
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: auto;
  background: rgba(8, 16, 24, 0.72);
  border-radius: 999px;
  padding: 4px 12px;
}

.tools label.pose-child {
  margin-inline-start: 18px;
}

.tools label.is-waiting {
  flex-wrap: wrap;
  opacity: 0.72;
}

.tools label .need {
  flex: 1 0 100%;
  margin-inline-start: 22px;
  color: var(--muted);
  font-size: 12px;
}

#card {
  top: 18px;
  inset-inline-end: 18px;
  z-index: 3;
  width: min(360px, calc(100vw - 36px));
  max-height: calc(100% - var(--chrome-bar) - 28px);
  overflow: auto;
  padding: 14px 14px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

#card-close {
  float: inline-end;
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  cursor: pointer;
}

body.quiet footer.outside { display: none; }

body.quiet header.outside {
  display: block;
  padding-top: calc(4px + env(safe-area-inset-top, 0px));
  padding-bottom: 4px;
}

body.quiet header.outside .title-row,
body.quiet header.outside .lede { display: none; }

body.quiet .dock:not(.open),
body.quiet .tools:not(.open) { display: none; }

body.quiet .dock.open,
body.quiet .tools.open {
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
}

#card h2 {
  margin: 0 0 4px;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 26px;
  line-height: 1.15;
}

#card .meta { color: var(--muted); font-size: 12px; margin-bottom: 8px; }

#card .line {
  margin: 0 0 6px;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

#card .note { color: var(--muted); font-size: 12px; line-height: 1.4; }

#card a { color: var(--warm); }

#card svg { width: 100%; height: auto; display: block; margin: 8px 0; }

#status {
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
footer.outside { display: none; }

.credit {
  position: absolute;
  z-index: 5;
  right: calc(8px + env(safe-area-inset-right, 0px));
  bottom: calc(var(--chrome-bar) + 8px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  max-width: min(280px, 78%);
  pointer-events: auto;
}

html[dir="rtl"] .credit {
  right: auto;
  left: calc(8px + env(safe-area-inset-left, 0px));
  align-items: flex-start;
}

.credit-link,
.credit-full {
  color: var(--ink);
  background: rgba(7, 16, 24, 0.62);
  border-radius: 12px;
}

.credit-link {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px 10px;
  margin: 0;
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1.3;
}

.credit-link a {
  min-width: 0;
  color: inherit;
  text-decoration: none;
  overflow-wrap: anywhere;
}

html[dir="rtl"] .credit-link { justify-content: flex-start; }

.credit-full {
  margin: 0;
  padding: 8px 10px;
  max-height: 22vh;
  overflow: auto;
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
}

#credit-info {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(7, 16, 24, 0.45);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.credit.collapsed .credit-link,
.credit.collapsed .credit-full { display: none; }

.credit:not(.collapsed) #credit-info { display: none; }

body.edge {
  --chrome-bar: calc(var(--chrome-core) + env(safe-area-inset-bottom, 0px));
}

body.edge header.outside {
  position: absolute;
  z-index: 3;
  top: calc(8px + env(safe-area-inset-top, 0px));
  inset-inline-start: calc(8px + env(safe-area-inset-inline-start, 0px));
  width: max-content;
  max-width: min(48%, 240px);
  padding: 4px 8px;
  border: 0;
  border-radius: 12px;
  background: rgba(7, 16, 24, 0.62);
  pointer-events: none;
}

body.edge header.outside:has(#status:empty) { display: none; }

body.edge header.outside .title-row,
body.edge header.outside .lede,
body.edge #chrome { display: none; }

body.edge .credit:not(.collapsed) {
  max-height: 132px;
  overflow: auto;
}

body.edge .credit-full { max-height: none; }

body.edge .credit-link {
  flex-direction: column;
  align-items: flex-end;
  width: 100%;
}

body.edge:not(.side) .credit {
  top: calc(8px + env(safe-area-inset-top, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  bottom: auto;
  max-width: min(220px, 46%);
}

html[dir="rtl"] body.edge:not(.side) .credit {
  right: auto;
  left: calc(8px + env(safe-area-inset-left, 0px));
}

body.edge:not(.side) .dock,
body.edge:not(.side) .tools {
  max-height: min(58vh, calc(100% - var(--chrome-bar) - 96px));
}

body.edge:not(.side) .chrome-bar {
  justify-content: space-evenly;
}

body.edge:not(.side) .chrome-bar button.icon {
  flex: 1 1 0;
  width: auto;
  max-width: 56px;
  min-width: 40px;
}

body.edge.side {
  --chrome-bar: 0px;
  --chrome-side: calc(56px + env(safe-area-inset-right, 0px));
}

html[dir="rtl"] body.edge.side {
  --chrome-side: calc(56px + env(safe-area-inset-left, 0px));
}

body.edge.side .chrome-bar {
  top: 0;
  right: 0;
  bottom: 0;
  left: auto;
  width: var(--chrome-side);
  flex-direction: column;
  justify-content: flex-end;
  align-items: stretch;
  gap: 4px;
  overflow: auto;
  padding: calc(8px + env(safe-area-inset-top, 0px)) calc(6px + env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) 6px;
}

html[dir="rtl"] body.edge.side .chrome-bar {
  right: auto;
  left: 0;
  padding-right: 6px;
  padding-left: calc(6px + env(safe-area-inset-left, 0px));
}

body.edge.side .chrome-bar button.icon,
body.edge.side #zoom-in,
body.edge.side #zoom-out {
  flex: 0 0 40px;
  height: 40px;
  min-height: 40px;
  width: 100%;
  max-width: none;
  min-width: 0;
}

body.edge.side .credit {
  top: calc(8px + env(safe-area-inset-top, 0px));
  right: calc(var(--chrome-side) + 8px);
  bottom: auto;
  left: auto;
  max-width: min(220px, 34vw);
  align-items: flex-end;
}

html[dir="rtl"] body.edge.side .credit {
  right: auto;
  left: calc(var(--chrome-side) + 8px);
  align-items: flex-start;
}

body.edge.side .dock.open,
body.edge.side .tools.open,
body.edge.side #card {
  inset-inline-end: calc(var(--chrome-side) + 8px);
}

body.edge #credit-info {
  width: 44px;
  height: 44px;
}

@media (min-width: 700px) {
  .dock.open,
  .tools.open {
    top: 0;
    bottom: var(--chrome-bar);
    inset-inline-start: 0;
    inset-inline-end: auto;
    width: min(320px, 40vw);
    max-height: none;
    border-radius: 0;
    border-start-end-radius: 16px;
    border-end-end-radius: 16px;
    padding-right: 12px;
    padding-left: calc(12px + env(safe-area-inset-left, 0px));
  }

  html[dir="rtl"] .dock.open,
  html[dir="rtl"] .tools.open {
    padding-left: 12px;
    padding-right: calc(12px + env(safe-area-inset-right, 0px));
  }
}

@media (max-width: 800px) {
  h1 { font-size: 18px; }
  .lede { font-size: 12px; }
  #card {
    top: auto;
    bottom: calc(var(--chrome-bar) + 8px);
    left: calc(10px + env(safe-area-inset-left, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    width: auto;
    max-height: min(40vh, 260px, calc(100% - var(--chrome-bar) - 16px));
  }
  #card svg { max-height: 110px; }
}

@media (max-width: 520px) {
  .chrome-bar {
    gap: 4px;
    padding-right: calc(6px + env(safe-area-inset-right, 0px));
    padding-left: calc(6px + env(safe-area-inset-left, 0px));
  }

  .chrome-bar button {
    flex: 1 1 auto;
    min-width: max-content;
    padding: 6px 6px;
    font-size: 13px;
  }

  #zoom-in, #zoom-out {
    flex: 0 0 44px;
    font-size: 20px;
  }
}

@media (max-height: 500px) and (min-width: 560px) {
  .dock.open,
  .tools.open {
    top: 0;
    bottom: var(--chrome-bar);
    inset-inline-start: 0;
    inset-inline-end: auto;
    width: min(300px, 46vw);
    max-height: none;
    border-radius: 0;
    border-start-end-radius: 16px;
    border-end-end-radius: 16px;
  }
}

@media (max-width: 640px), (max-height: 500px) {
  header.outside .title-row,
  header.outside .lede { display: none; }
  header.outside {
    padding-top: calc(4px + env(safe-area-inset-top, 0px));
    padding-bottom: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  canvas { scroll-behavior: auto; }
}
