/* Tree Inspector game UI (viewer/src/ui/ui.js). Field-guide look: paper panel, ink text, moss accent.
   Hidden entirely under ?shots (measurement runs). Pure CSS: no animation that would keep the page drawing. */
:root {
  --paper: #f3efe4; --paper-2: #e9e3d3; --ink: #20281f; --ink-2: #4c5747; --rule: #d3cbb6;
  --moss: #3f6a37; --moss-2: #2f5229; --ochre: #b5852b; --shadow: 0 6px 24px rgba(10, 14, 8, .28);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --panel-w: 380px;
}
.shots #topbar, .shots #panel, .shots #tools, .shots #marker, .shots #ruler, .shots .sound-toggle { display: none !important; }
.sound-toggle { display: none !important; } /* the setting's own mute button: driven from the tools dock */

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible { outline: 2px solid var(--ochre); outline-offset: 2px; }

/* ---------- loading */
#loading { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: #11160f; color: #e9e5d6; font: 15px/1.5 var(--sans); }
#loading div { display: grid; gap: 6px; text-align: center; }
#loading b { font: 600 22px var(--serif); letter-spacing: .02em; }
#loading span { color: #a9b2a0; }

/* ---------- top bar */
#topbar { position: fixed; top: 10px; left: 10px; right: 10px; z-index: 20; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font: 14px/1.2 var(--sans); color: var(--ink); pointer-events: none; }
#topbar > * { pointer-events: auto; }
#topbar .brand { font: 600 16px var(--serif); background: var(--paper); padding: 9px 14px; border-radius: 10px; box-shadow: var(--shadow); letter-spacing: .02em; }
#topbar .spacer { flex: 1; pointer-events: none; }
.segs { display: inline-flex; background: var(--paper); border-radius: 10px; padding: 3px; box-shadow: var(--shadow); gap: 2px; align-items: center; }
.seg { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; color: var(--ink-2); min-height: 32px; }
.seg:hover { background: var(--paper-2); color: var(--ink); }
.seg.on { background: var(--moss); color: #fff; }
.mystery-tag { padding: 7px 12px; font: italic 600 14px var(--serif); color: var(--moss-2); }
#topbar .link { background: var(--paper); border: 0; padding: 9px 14px; border-radius: 10px; box-shadow: var(--shadow); color: var(--ink-2); }
#topbar .link:hover { color: var(--ink); }

/* ---------- side panel */
#panel { position: fixed; z-index: 15; top: 62px; left: 10px; bottom: 74px; width: var(--panel-w); display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink); border-radius: 14px; box-shadow: var(--shadow); font: 14px/1.45 var(--sans); }
#panel.collapsed { width: 0; padding: 0; box-shadow: none; background: transparent; }
#panel.collapsed > :not(.collapse) { display: none; }
#panel .collapse { position: absolute; top: 14px; right: -16px; width: 32px; height: 44px; border: 0; border-radius: 0 10px 10px 0; background: var(--paper);
  box-shadow: 4px 2px 10px rgba(10, 14, 8, .2); font-size: 20px; color: var(--ink-2); z-index: 1; }
#panel.collapsed .collapse { left: 0; right: auto; border-radius: 10px; }
.sp-head { padding: 16px 20px 10px; border-bottom: 1px solid var(--rule); }
.sp-head h1 { margin: 0; font: 600 24px/1.15 var(--serif); }
.sp-head .sci { margin: 4px 0 0; color: var(--ink-2); font: 15px var(--serif); }
.sp-head .sub { margin: 6px 0 0; color: var(--ink-2); font-size: 13px; }
#panel .tabs { display: flex; gap: 2px; padding: 8px 12px 0; border-bottom: 1px solid var(--rule); }
.tabs button { border: 0; background: transparent; padding: 8px 10px 9px; border-bottom: 3px solid transparent; color: var(--ink-2); font-weight: 500; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--moss); }
.tab-body { flex: 1; overflow-y: auto; padding: 6px 20px 20px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.tab-body h2 { font: 600 17px var(--serif); margin: 18px 0 6px; }
.how { color: var(--ink-2); margin: 4px 0 10px; font-size: 13.5px; }
.note { background: var(--paper-2); padding: 8px 10px; border-radius: 8px; font-size: 13px; }

/* guide */
.technique { border-bottom: 1px solid var(--rule); padding: 4px 0 8px; }
.technique summary { list-style: none; display: flex; align-items: baseline; gap: 8px; cursor: pointer; padding: 10px 0 4px; }
.technique summary::-webkit-details-marker { display: none; }
.technique summary::before { content: "▸"; color: var(--moss); font-size: 12px; width: 10px; }
.technique[open] summary::before { content: "▾"; }
.technique .tt { font: 600 17px var(--serif); }
.technique .count { color: var(--ink-2); font-size: 12px; }
.feature { padding: 8px 0 8px 18px; }
.feature + .feature { border-top: 1px dotted var(--rule); }
.f-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.f-label { font-weight: 600; }
.f-note { font-size: 12px; color: var(--ink-2); font-style: italic; text-align: right; }
.explain { margin: 2px 0 4px; color: var(--ink-2); font-size: 13px; }
.explain.small { font-size: 12px; }
.value { margin: 4px 0 0; padding: 6px 10px; background: #fbf9f3; border-left: 3px solid var(--moss); border-radius: 0 6px 6px 0; }
.show { border: 1px solid var(--moss); background: transparent; color: var(--moss-2); border-radius: 999px; padding: 4px 11px; font-size: 13px; white-space: nowrap; min-height: 30px; }
.show:hover { background: var(--moss); color: #fff; }

/* calendar */
.calendar .cal-row { display: grid; grid-template-columns: 116px 1fr; align-items: center; gap: 6px; margin: 3px 0; font-size: 12.5px; }
.cal-bar { display: grid; grid-template-columns: repeat(12, 1fr); gap: 2px; }
.cal-m { height: 12px; border-radius: 3px; background: var(--paper-2); text-align: center; font-size: 10.5px; line-height: 12px; color: var(--ink-2); }
.cal-row:not(.head) .cal-m.on { background: var(--moss); }
.cal-row.head .cal-m { background: transparent; }
.cal-m.now { outline: 2px solid var(--ochre); outline-offset: -1px; }

/* unique */
.keyfeat { padding-left: 20px; margin: 4px 0; }
.keyfeat li { margin: 8px 0; }
.keyfeat li > span { display: block; margin-bottom: 4px; }
.lookalike { background: #fbf9f3; border: 1px solid var(--rule); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.la-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 6px; }
.la-head i { color: var(--ink-2); font-family: var(--serif); }
.lookalike p { margin: 6px 0; font-size: 13.5px; }
.chip { margin-left: auto; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--moss); color: #fff; }
.chip.dim { background: var(--paper-2); color: var(--ink-2); }
.chip.warn { margin-left: 6px; background: transparent; color: #9a5b00; border: 1px solid #c98a2b; padding: 0 6px; font-size: 10.5px; white-space: nowrap; cursor: help; }
.compare td .chip.warn { display: table; margin: 3px 0 0; }
.compare { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 4px; }
.compare th { text-align: left; font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--rule); }
.compare td { padding: 4px 6px; vertical-align: top; border-bottom: 1px dotted var(--rule); }
.compare td:first-child { color: var(--ink-2); white-space: nowrap; }

/* key */
.trail { padding-left: 20px; font-size: 12.5px; color: var(--ink-2); margin: 6px 0; }
.trail li { margin: 3px 0; }
.trail b { color: var(--ink); font-weight: 500; }
.couplet .step { margin: 12px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
.couplet h2 { margin-top: 4px; }
.options { display: grid; gap: 8px; margin-top: 12px; }
.option { text-align: left; border: 1px solid var(--rule); background: #fbf9f3; border-radius: 10px; padding: 11px 14px; min-height: 44px; }
.option:hover { border-color: var(--moss); background: #fff; }
.hint { margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: #f6ead0; border: 1px solid #e3cf9f; }
.hint p { margin: 0 0 8px; }
.hint .show { margin-right: 6px; }
.result { margin-top: 14px; padding: 12px 14px; border-radius: 10px; }
.result.ok { background: #e3eedb; border: 1px solid #b9d2a8; }
.result h2 { margin-top: 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.row button, .m-body button { border: 1px solid var(--rule); background: #fbf9f3; border-radius: 8px; padding: 8px 12px; }
.row button.primary { background: var(--moss); border-color: var(--moss); color: #fff; }

/* ---------- tools dock */
#tools { position: fixed; z-index: 20; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center;
  background: var(--paper); padding: 6px; border-radius: 14px; box-shadow: var(--shadow); font: 13.5px var(--sans); color: var(--ink); max-width: calc(100vw - 20px); }
.tool { border: 0; background: transparent; padding: 8px 12px; border-radius: 9px; min-height: 38px; color: var(--ink); white-space: nowrap; }
.tool:hover:not(:disabled) { background: var(--paper-2); }
.tool.on { background: #dde8d5; color: var(--moss-2); }
#tools .segs { box-shadow: none; background: var(--paper-2); }

/* ---------- marker and ruler */
#marker { position: fixed; left: 0; top: 0; z-index: 12; pointer-events: none; will-change: transform; }
#marker .ring { position: absolute; left: -26px; top: -26px; width: 52px; height: 52px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 2px rgba(181, 133, 43, .9), 0 0 12px rgba(0, 0, 0, .5); }
#marker .callout { position: absolute; left: 40px; top: -34px; width: max-content; max-width: 280px; pointer-events: auto; background: var(--paper); color: var(--ink);
  border-radius: 10px; padding: 8px 30px 8px 12px; box-shadow: var(--shadow); font: 13px/1.4 var(--sans); }
#marker .callout b { display: block; font: 600 14px var(--serif); }
#marker.short .callout span { display: none; }
#marker.left .callout { left: auto; right: 40px; }
#marker .x, .m-head .x { position: absolute; top: 4px; right: 4px; border: 0; background: transparent; font-size: 18px; color: var(--ink-2); width: 28px; height: 28px; }
#ruler { position: fixed; z-index: 12; right: 16px; bottom: 76px; background: var(--paper); color: var(--ink); padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow); font: 13px var(--sans); }
#ruler .bar { height: 10px; border: 2px solid var(--ink); border-top: 0; margin-bottom: 6px; background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), var(--ink-2) calc(10% - 1px) 10%); background-size: 100% 4px; background-repeat: no-repeat; background-position: bottom; }
#ruler .tree { margin-top: 4px; color: var(--ink-2); font-size: 12px; }

/* ---------- credits modal */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(10, 14, 8, .45); display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }
.m-card { position: relative; width: min(920px, 100%); max-height: min(86vh, 900px); display: flex; flex-direction: column; background: var(--paper); color: var(--ink); border-radius: 14px; box-shadow: var(--shadow); font: 14px/1.45 var(--sans); }
.m-head { position: relative; padding: 16px 48px 8px 20px; }
.m-head h2 { margin: 0; font: 600 20px var(--serif); }
.m-card .tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--rule); }
.m-body { overflow: auto; padding: 8px 20px 20px; }
.m-body table { border-collapse: collapse; font-size: 12.5px; width: 100%; margin: 8px 0; }
.m-body th, .m-body td { border-bottom: 1px solid var(--rule); padding: 4px 6px; text-align: left; vertical-align: top; }
.m-body a { color: var(--moss-2); word-break: break-word; }
.m-body code { font-size: 12px; background: var(--paper-2); padding: 0 3px; border-radius: 3px; }
.sources li { margin: 6px 0; }
.ui-error { position: fixed; top: 60px; left: 10px; background: #f6ead0; color: #20281f; padding: 10px 14px; border-radius: 10px; z-index: 30; }

/* ---------- narrow screens and touch: panel becomes a bottom sheet above the tools */
@media (max-width: 759px) {
  #topbar { top: 6px; left: 6px; right: 6px; gap: 6px; font-size: 13px; }
  #topbar .brand { display: none; }
  .seg { padding: 6px 9px; }
  #panel { top: auto; left: 6px; right: 6px; bottom: 66px; width: auto; height: 46vh; }
  #panel.collapsed { height: 0; }
  #panel .collapse { top: -38px; right: 10px; border-radius: 10px; width: 44px; height: 34px; transform: rotate(-90deg); }
  #panel.collapsed .collapse { left: auto; right: 10px; top: -40px; }
  #tools { bottom: 6px; left: 6px; right: 6px; transform: none; gap: 2px; padding: 4px; flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; scrollbar-width: none; }
  #tools::-webkit-scrollbar { display: none; }
  .tool { padding: 7px 8px; flex: none; }
  #tools .segs { flex: none; }
  #marker .callout { left: -130px; top: 34px; max-width: 260px; }
  #marker.left .callout { left: -130px; }
  #ruler { bottom: auto; top: 54px; right: 6px; }
}

/* ---------- specimen view (viewer/src/specimen-view.js): cross-fade overlay, back control */
#xfade { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 5; pointer-events: none; }
#xfade[hidden] { display: none; }
#specbar { position: fixed; z-index: 18; top: 62px; right: 16px; display: flex; gap: 8px; align-items: center; font: 14px/1.2 var(--sans); color: var(--ink); }
#specbar[hidden] { display: none; }
#specbar .back { border: 0; background: var(--moss); color: #fff; padding: 9px 14px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 600; }
#specbar .back:hover { background: var(--moss-2); }
#specbar .what { background: var(--paper); padding: 9px 12px; border-radius: 10px; box-shadow: var(--shadow); color: var(--ink-2); font: italic 14px var(--serif); }
.shots #specbar { display: none !important; }
@media (max-width: 759px) { #specbar { top: 58px; right: 10px; } #specbar .what { display: none; } }

/* ---------- sound panel (src/ui/sound-panel.js): slides in from the right; a transition, no animation loop */
#soundpanel { position: fixed; z-index: 18; top: 62px; right: 10px; bottom: 74px; width: 360px; max-width: calc(100vw - 20px); display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink); border-radius: 14px; box-shadow: var(--shadow); font: 14px/1.4 var(--sans);
  transform: translateX(calc(100% + 24px)); visibility: hidden; transition: transform .22s ease-out, visibility 0s .22s; }
#soundpanel.open { transform: none; visibility: visible; transition: transform .22s ease-out; }
.shots #soundpanel { display: none !important; }
.snd-head { position: relative; padding: 14px 16px 10px; border-bottom: 1px solid var(--rule); }
.snd-head h2 { margin: 0 30px 4px 0; font: 600 19px var(--serif); }
.snd-head .x { position: absolute; top: 8px; right: 8px; border: 0; background: transparent; font-size: 20px; color: var(--ink-2); width: 34px; height: 34px; }
.snd-head .how { font-size: 12.5px; margin: 2px 0 8px; }
.snd-master { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; font-weight: 600; }
.snd-now { margin: 8px 0 0; font-size: 12.5px; color: var(--moss-2); min-height: 1.4em; }
.snd-list { flex: 1; overflow-y: auto; padding: 0 10px 14px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.snd-list h3 { font: 600 15px var(--serif); margin: 14px 6px 4px; }
.snd-list h3 .count { color: var(--ink-2); font: 12px var(--sans); }
.snd-row { border-radius: 10px; padding: 6px 8px; margin: 2px 0; cursor: pointer; border: 1px solid transparent; transition: background-color .15s, border-color .15s; }
.snd-row:hover { background: var(--paper-2); }
.snd-row:focus-visible { outline: 2px solid var(--ochre); outline-offset: 1px; }
.snd-main { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center; }
.snd-ico { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: var(--paper-2); }
.snd-ico.glyph { display: grid; place-items: center; font-size: 20px; color: var(--moss-2); }
.snd-names { min-width: 0; line-height: 1.25; }
.snd-names b { font-weight: 600; }
.snd-sci { font-size: 12px; color: var(--ink-2); font-family: var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snd-badge { display: none; font-size: 10.5px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--ochre); color: #fff; vertical-align: 1px; white-space: nowrap; }
.snd-badge::before { content: "● "; }
.snd-row.live.call { background: #f6ead0; border-color: #e3cf9f; }
.snd-row.live.call .snd-badge { display: inline-block; }
.snd-row.live.bed .snd-badge { display: inline-block; background: var(--paper-2); color: var(--ink-2); }
.snd-row.live.bed .snd-badge::before { content: ""; }
.snd-row.muted .snd-names, .snd-row.muted .snd-ico { opacity: .5; }
.snd-ctl { display: flex; align-items: center; gap: 6px; }
.snd-ctl input[type=range] { width: 76px; }
#soundpanel input[type=range] { accent-color: var(--moss); min-height: 28px; touch-action: pan-x; }
#soundpanel .mute { border: 1px solid var(--rule); background: #fbf9f3; border-radius: 8px; padding: 6px 10px; min-height: 32px; font-size: 12.5px; }
#soundpanel .mute.small { padding: 4px 8px; min-width: 58px; }
#soundpanel .mute.off { background: var(--paper-2); color: #9a5b00; border-color: #c98a2b; }
.snd-note { margin: 6px 0 2px 50px; font-size: 13px; }
.snd-note p { margin: 4px 0; }
.snd-note .credit { font-size: 11.5px; color: var(--ink-2); }
@media (max-width: 760px) {
  #soundpanel { top: auto; left: 8px; right: 8px; bottom: 70px; width: auto; max-width: none; height: 62vh; transform: translateY(calc(100% + 90px)); }
  .snd-ctl input[type=range] { width: 64px; }
  .snd-head .how { display: none; }
}

/* toast while the sound panel is closed: who is calling now, each name opens the panel at its row */
.snd-toast { position: fixed; left: 50%; bottom: 92px; transform: translate(-50%, 8px); z-index: 30; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; max-width: min(92vw, 640px);
  padding: 6px 8px 6px 12px; background: var(--paper, #f4f1e8); color: var(--ink, #1d2a1c); border: 1px solid #e3cf9f; border-radius: 999px; box-shadow: 0 6px 20px rgba(0,0,0,.18);
  font-size: 13px; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; }
.snd-toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.snd-toast-k { color: var(--ink-2, #55624f); margin-right: 2px; }
.snd-toast-b { display: inline-flex; align-items: center; gap: 6px; border: 1px solid #e3cf9f; background: #f6ead0; color: inherit; border-radius: 999px; padding: 3px 10px 3px 3px; font: inherit; cursor: pointer; }
.snd-toast-b:hover { background: #f1dfb6; }
.snd-toast-b img, .snd-toast-b .g { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; display: inline-grid; place-items: center; background: var(--paper-2, #ebe6d6); font-size: 12px; }
.sound-open .snd-toast { display: none; }
.snd-row.flash { outline: 2px solid var(--ochre, #b8862b); outline-offset: 1px; }
@media (max-width: 700px) { .snd-toast { bottom: 140px; font-size: 12px; } }
