/* Fixed app chrome: only the narration feed scrolls. */
html, body { height: 100%; overflow: hidden; }
.app-shell { height: 100dvh; max-height: 100dvh; display: block; overflow: hidden; }
.topbar {
  position: absolute; z-index: 12; top: 0; left: 0; right: 0;
  background: linear-gradient(180deg, var(--bg) 58%, transparent);
}
.place-card {
  position: absolute; z-index: 11; top: 66px; left: 16px; right: 16px;
  margin: 0; min-height: 72px;
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background .25s ease, border-color .25s ease, box-shadow .25s ease;
}
.place-card:active { transform: scale(.992); }
.place-card:focus-visible { outline: 3px solid color-mix(in srgb, var(--gold) 45%, transparent); outline-offset: 2px; }
.place-card.status-waiting { border-color: rgba(242,200,107,.30); background: rgba(83,67,30,.88); }
.place-card.status-active { border-color: rgba(83,205,137,.34); background: rgba(22,71,50,.92); }
.place-card.status-error { border-color: rgba(239,120,111,.38); background: rgba(82,35,35,.92); }
.feed {
  position: absolute; inset: 146px 0 0; padding-top: 16px;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.player { position: absolute; z-index: 14; bottom: 0; left: 0; right: 0; }
.return-live { z-index: 13; }
.guide-notice {
  position: absolute; z-index: 18; left: 24px; right: 24px; bottom: calc(164px + var(--safe-bottom));
  width: fit-content; max-width: calc(100% - 48px); margin: auto;
  padding: 10px 16px; border: 1px solid rgba(239,120,111,.3); border-radius: 14px;
  background: #542e2d; color: #fff0ed; box-shadow: 0 12px 30px rgba(0,0,0,.22);
  font-size: .85rem; font-weight: 650; line-height: 1.35; text-align: center;
}
.failed-bubble {
  display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 10px;
  margin: 18px 0; animation: arrive .45s ease both;
}
.failed-icon {
  display: grid; place-items: center; width: 40px; height: 40px;
  border: 1px solid rgba(239,120,111,.38); border-radius: 14px;
  background: rgba(239,120,111,.15); color: #f3a29a; font-weight: 850;
}
.failed-body {
  min-width: 0; padding: 14px 15px; border: 1px solid rgba(239,120,111,.32);
  border-left: 3px solid #df8176; border-radius: 5px 21px 21px 21px;
  background: rgba(69,38,36,.88);
}
.failed-top { display: flex; justify-content: space-between; gap: 8px; color: #f3a29a; font-size: .72rem; font-weight: 700; }
.failed-distance { color: var(--muted); white-space: nowrap; font-weight: 400; }
.failed-place { margin: 7px 0 6px; font-size: 1rem; line-height: 1.45; overflow-wrap: anywhere; }
.failed-detail { margin: 0 0 13px; color: var(--muted); font-size: .8rem; line-height: 1.5; }
.retry-narration {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; padding: 8px 16px; border: 1px solid #df8176;
  border-radius: 12px; background: #d7796e; color: #fff; font-size: .8rem;
  font-weight: 750; cursor: pointer;
}
.retry-narration:disabled { opacity: .62; cursor: progress; }
.retry-narration:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.sheet { max-height: calc(100dvh - 16px); overflow-y: auto; }
.theme-picker button {
  position: relative;
  min-width: 0;
  padding: 12px 30px 12px 8px;
  font-size: clamp(.78rem, 3.5vw, .88rem);
  white-space: nowrap;
  word-break: keep-all;
  overflow: hidden;
  transition: .18s ease;
}
.theme-picker button:not(.selected) { opacity: .68; }
.theme-picker button.selected {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--gold) 32%, transparent);
}
.theme-picker button.selected::after {
  content: "✓"; position: absolute; top: 7px; right: 8px;
  display: grid; place-items: center; width: 18px; height: 18px;
  border-radius: 50%; background: var(--gold); color: #102219;
  font-size: .68rem; font-weight: 900;
}
.theme-picker button.selection-required { animation: keep-one .32s ease; }
@keyframes keep-one { 50% { transform: translateX(4px); } }

.voice-section { margin-top: 24px; }
.voice-section-title { font-size: .9rem; font-weight: 750; margin-bottom: 10px; }
.voice-picker { display: grid; gap: 9px; }
.voice-option {
  display: flex; align-items: center; gap: 12px; min-height: 72px; padding: 7px 12px 7px 8px;
  border: 1px solid var(--line); border-radius: 17px; background: rgba(255,255,255,.04);
  transition: border-color .2s, background .2s;
}
.voice-option.selected { border-color: rgba(242,200,107,.55); background: rgba(242,200,107,.10); }
.voice-preview {
  position: relative; flex: none; width: 56px; height: 56px; padding: 0; border: 0;
  border-radius: 50%; background: transparent; cursor: pointer;
}
.voice-preview img { display: block; width: 56px; height: 56px; border-radius: 50%; }
.voice-preview-symbol {
  position: absolute; right: -2px; bottom: -2px; display: grid; place-items: center;
  width: 23px; height: 23px; border: 2px solid var(--panel); border-radius: 50%;
  background: var(--gold); color: #102219; font-size: .65rem; font-weight: 900;
}
.voice-preview.loading .voice-preview-symbol { font-size: .9rem; }
.voice-select {
  flex: 1; min-width: 0; padding: 6px 0; border: 0; background: none;
  color: var(--text); text-align: left; cursor: pointer;
}
.voice-select strong, .voice-select small { display: block; }
.voice-select strong { font-size: .9rem; }
.voice-select small { margin-top: 3px; color: var(--muted); font-size: .72rem; }
.voice-check {
  display: none; place-items: center; flex: none; width: 21px; height: 21px;
  border-radius: 50%; background: var(--gold); color: #102219; font-size: .72rem; font-weight: 900;
}
.voice-option.selected .voice-check { display: grid; }
.voice-preview:focus-visible, .voice-select:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 10px; }
.voice-note { margin: 9px 2px 0; color: var(--muted); font-size: .72rem; line-height: 1.5; }
.voice-note.error { color: #ef8d84; }

.install-app-btn {
  display: flex; align-items: center; gap: 12px; width: 100%;
  margin-top: 22px; padding: 12px 14px; border: 1px solid rgba(242,200,107,.38);
  border-radius: 16px; background: rgba(242,200,107,.11); color: var(--text);
  text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.install-app-btn:active { transform: scale(.985); }
.install-app-btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.install-app-icon, .install-help-icon {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px;
  border-radius: 12px; background: var(--gold); color: #102219;
  font-size: 1.45rem; font-weight: 800;
}
.install-app-btn strong, .install-app-btn small { display: block; }
.install-app-btn strong { font-size: .9rem; }
.install-app-btn small { margin-top: 2px; color: var(--muted); font-size: .72rem; }
.install-app-arrow { margin-left: auto; color: var(--gold); font-size: 1.4rem; }
dialog#installHelp {
  width: min(calc(100% - 32px), 420px); max-width: none; margin: auto;
  border: 1px solid var(--line); border-radius: 24px;
  background: var(--panel); color: var(--text);
  box-shadow: 0 25px 80px rgba(0,0,0,.32);
}
.install-help-card { padding: 26px 24px 24px; }
.install-help-icon { width: 50px; height: 50px; margin-bottom: 18px; }
.install-help-card h2 { margin: 0 0 10px; font-size: 1.25rem; }
.install-help-card p { margin: 0; color: var(--muted); line-height: 1.75; font-size: .9rem; }
.install-help-card .save-btn { margin-top: 22px; }

/* Light mode follows the device preference; the original dark palette remains the default. */
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f4f2ea;
    --panel: #fffdf8;
    --panel2: #edf3ec;
    --text: #17251f;
    --muted: #718078;
    --gold: #b47b24;
    --line: rgba(31, 67, 52, .13);
  }

  body { background: radial-gradient(circle at 50% -10%, #dcecdf 0, #f4f2ea 42%); }
  .app-shell { background: linear-gradient(180deg, rgba(250, 249, 244, .58), #f4f2ea 48%); }
  .icon-btn, .close-btn { background: rgba(31, 67, 52, .08); }
  .place-card {
    background: rgba(255, 253, 248, .84);
    box-shadow: 0 14px 40px rgba(42, 57, 49, .09);
  }
  .place-card.status-waiting { border-color: rgba(180,123,36,.24); background: rgba(255,247,222,.96); }
  .place-card.status-active { border-color: rgba(39,139,91,.24); background: rgba(230,247,236,.97); }
  .place-card.status-error { border-color: rgba(190,69,66,.24); background: rgba(255,235,233,.97); }
  .place-pin, .mini-icon { background: rgba(180, 123, 36, .10); }
  .live-dot { background: #a2aaa6; }
  .live-dot.active { background: #278b5b; box-shadow: 0 0 0 5px rgba(39, 139, 91, .12); }
  .date-divider span, .theme-picker button { background: rgba(31, 67, 52, .06); }
  .welcome-card {
    border-color: rgba(180, 123, 36, .20);
    background: linear-gradient(145deg, rgba(225, 239, 226, .96), rgba(250, 247, 237, .98));
    box-shadow: 0 20px 50px rgba(42, 57, 49, .10);
  }
  .welcome-card p, .theme-row span { color: #53665d; }
  .bubble-body {
    background: rgba(255, 255, 252, .94);
    box-shadow: 0 10px 30px rgba(42, 57, 49, .055);
  }
  .bubble.playing .bubble-body {
    box-shadow: 0 0 0 1px var(--theme), 0 15px 40px rgba(42, 57, 49, .12);
  }
  .voice-pill { background: #f0f3ed; }
  .transcript { color: #3f5149; }
  .player {
    background: rgba(255, 253, 248, .95);
    box-shadow: 0 -20px 50px rgba(42, 57, 49, .12);
  }
  .progress { background: rgba(31, 67, 52, .10); }
  .play-main, .save-btn { color: #fffdf7; }
  .return-live { background: #f8f5e9; }
  .guide-notice { background: #fff1ee; color: #8f3834; box-shadow: 0 12px 30px rgba(42,57,49,.14); }
  .failed-icon { background: #fff1ee; border-color: #f0ccc7; color: #a8433d; }
  .failed-body { background: #fff8f6; border-color: #edcac6; border-left-color: #c45c55; box-shadow: 0 10px 30px rgba(42,57,49,.055); }
  .failed-top { color: #a8433d; }
  .retry-narration { background: #ae4742; border-color: #ae4742; }
  dialog::backdrop, dialog#preferences { background: rgba(22, 31, 27, .38); }
  .sheet { background: #fffdf8; }
  .range-label select { background: #f4f6f0; }
  .theme-picker button.selected {
    border-color: rgba(180, 123, 36, .45);
    background: rgba(180, 123, 36, .10);
  }
  .voice-option { background: rgba(31,67,52,.04); }
  .voice-option.selected { border-color: rgba(180,123,36,.48); background: rgba(180,123,36,.09); }
  .voice-note.error { color: #a8433d; }
  .install-app-btn { border-color: rgba(180,123,36,.28); background: rgba(180,123,36,.09); }
}

@media (prefers-color-scheme: light) and (min-width: 700px) {
  .app-shell { box-shadow: 0 30px 100px rgba(42, 57, 49, .16); }
}

@media (min-width: 700px) {
  .app-shell { height: calc(100dvh - 40px); max-height: calc(100dvh - 40px); }
}
