/* Onboarding: story cards, the guide bubble with its spotlight, tips, and the start-screen branding.
   Loaded after styles.css. Class names are prefixed (ob-*, ct-*) so they never clash with the HUD. */

/* ---------------------------------------------------------------- safe-area probe (read by JS) */
.ob-probe {
  position: fixed; left: 0; top: 0; width: 0; height: 0; visibility: hidden; pointer-events: none;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

/* ---------------------------------------------------------------- guide layer */
.ob-layer { position: fixed; inset: 0; z-index: 75; pointer-events: none; }

.ob-spot {
  position: absolute; left: 0; top: 0; width: 0; height: 0; border-radius: 12px;
  border: 2px solid var(--gold-2, #ffd58a); opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), width 0.3s, height 0.3s, box-shadow 0.35s;
}
.ob-spot::after { content: ""; position: absolute; inset: -2px; border-radius: inherit; animation: ob-pulse 1.6s ease-out infinite; }
.ob-layer.show .ob-spot.show { opacity: 1; }
.ob-spot.dim { box-shadow: 0 0 0 200vmax rgba(8, 7, 12, 0.4); }
@keyframes ob-pulse { from { box-shadow: 0 0 0 0 rgba(255, 213, 138, 0.6); } to { box-shadow: 0 0 0 14px rgba(255, 213, 138, 0); } }

.ob-tap { position: absolute; left: 0; top: 0; width: 0; height: 0; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.ob-layer.show .ob-tap.show { opacity: 1; }
.ob-tap i { position: absolute; left: -7px; top: -7px; width: 14px; height: 14px; border-radius: 50%; background: rgba(255, 213, 138, 0.85); box-shadow: 0 0 0 3px rgba(42, 26, 8, 0.35); animation: ob-tap 1.5s ease-in-out infinite; }
.ob-tap i::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid rgba(255, 213, 138, 0.9); animation: ob-ripple 1.5s ease-out infinite; }
@keyframes ob-tap { 0%, 100% { transform: scale(0.75); } 35% { transform: scale(1); } }
@keyframes ob-ripple { from { transform: scale(1); opacity: 0.9; } to { transform: scale(3); opacity: 0; } }

.ob-bubble {
  position: absolute; left: 0; top: 0; width: 320px; max-width: calc(100vw - 16px);
  padding: 12px 15px 11px; border-radius: 16px; color: var(--ink, #f7eedb); pointer-events: auto;
  background: linear-gradient(165deg, #3b2b20 0%, #261d18 100%);
  border: 1px solid rgba(232, 180, 88, 0.6);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  opacity: 0; transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.2s;
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
.ob-layer.show .ob-bubble { opacity: 1; }
.ob-layer:not(.show) .ob-bubble { pointer-events: none; }
.ob-bubble.pop .ob-body { animation: ob-pop 0.32s ease both; }
@keyframes ob-pop { from { opacity: 0; transform: translateY(4px); } }

.ob-arrow { position: absolute; display: none; width: 14px; height: 14px; background: #34271e; border: 1px solid rgba(232, 180, 88, 0.6); transform: rotate(45deg); }
.ob-bubble[data-side="below"] .ob-arrow { display: block; top: -8px; left: calc(var(--ax, 50%) - 7px); border-right: 0; border-bottom: 0; background: #3a2a20; }
.ob-bubble[data-side="above"] .ob-arrow { display: block; bottom: -8px; left: calc(var(--ax, 50%) - 7px); border-left: 0; border-top: 0; background: #271e19; }
.ob-bubble[data-side="right"] .ob-arrow { display: block; left: -8px; top: calc(var(--ax, 50%) - 7px); border-top: 0; border-right: 0; }
.ob-bubble[data-side="left"] .ob-arrow { display: block; right: -8px; top: calc(var(--ax, 50%) - 7px); border-bottom: 0; border-left: 0; }

.ob-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ob-count { color: var(--gold, #e8b458); font-size: 10px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; }
.ob-quit { border: 0; background: none; padding: 6px 0 6px 10px; margin: -6px 0; color: var(--muted, #b9ad9d); font-size: 11px; text-decoration: underline; text-underline-offset: 3px; }
.ob-quit:hover { color: var(--ink, #f7eedb); }
.ob-progress { height: 3px; margin: 7px 0 9px; border-radius: 2px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.ob-progress i { display: block; height: 100%; border-radius: 2px; background: linear-gradient(90deg, #d8913f, var(--gold-2, #ffd58a)); transition: width 0.4s; }
.ob-title { display: block; font-family: var(--serif, "Marcellus", Georgia, serif); font-weight: 400; font-size: 19px; line-height: 1.2; color: var(--gold-2, #ffd58a); }
.ob-bubble p { margin: 5px 0 0; font-size: 13px; line-height: 1.5; color: var(--ink, #f7eedb); }
.ob-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.ob-actions button.link { padding: 8px 0; }
.ob-actions button.primary.small { padding: 9px 16px; }
.ob-actions button.ghost.small { padding: 8px 14px; }
.ob-actions > :only-child { margin-left: auto; }

.ob-bubble.tip { padding: 11px 13px 9px; }
.ob-bubble.tip .ob-title { font-family: inherit; font-weight: 700; font-size: 14px; }
.ob-bubble.tip p { font-size: 12.5px; }

.ob-wait { display: flex; align-items: center; gap: 10px; }
.ob-wait p { flex: 1; margin: 0 !important; }
.ob-spinner { flex: none; width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255, 213, 138, 0.25); border-top-color: var(--gold-2, #ffd58a); animation: ob-spin 0.9s linear infinite; }
@keyframes ob-spin { to { transform: rotate(360deg); } }

/* Phones and small windows: tighter bubble, bigger touch targets stay. */
.ob-layer.compact .ob-bubble { padding: 9px 12px 8px; border-radius: 14px; }
.ob-layer.compact .ob-progress { margin: 5px 0 6px; }
.ob-layer.compact .ob-title { font-size: 16px; }
.ob-layer.compact .ob-bubble p { font-size: 12px; line-height: 1.4; margin-top: 3px; }
.ob-layer.compact .ob-actions { margin-top: 5px; }
.ob-layer.compact .ob-actions button.primary.small { padding: 8px 14px; min-height: 36px; }

/* ---------------------------------------------------------------- story cards */
.ob-cards {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: radial-gradient(circle at 50% 35%, rgba(60, 36, 28, 0.35), rgba(8, 7, 12, 0.75));
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.ob-cards.open { opacity: 1; pointer-events: auto; }
.ob-card {
  display: flex; flex-direction: column; width: min(560px, 100%); max-height: 100%; overflow: hidden;
  border-radius: 22px; background: linear-gradient(172deg, #2c221d 0%, #1b1619 100%);
  border: 1px solid rgba(232, 180, 88, 0.35); box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6);
  animation: ob-card-in 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes ob-card-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } }
.ob-art { position: relative; flex: none; height: 200px; overflow: hidden; }
.ob-art svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.ob-art::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 40px; background: linear-gradient(to bottom, rgba(40, 32, 28, 0), #2a211c); }
.ob-card-body { display: flex; flex-direction: column; min-height: 0; padding: 2px 26px 22px; overflow: auto; }
.ob-card .eyebrow { color: var(--gold, #e8b458); }
.ob-card h2 { margin: 6px 0 8px; font-family: var(--serif, "Marcellus", Georgia, serif); font-weight: 400; font-size: 31px; line-height: 1.1; color: var(--ink, #f7eedb); }
.ob-lead { margin: 0; color: #decfb8; font-size: 14.5px; line-height: 1.55; }
.ob-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.ob-chips span { padding: 6px 11px; border-radius: 20px; background: rgba(232, 180, 88, 0.1); border: 1px solid rgba(232, 180, 88, 0.28); font-size: 12.5px; }
.ob-goal-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.ob-goal-row span { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.1); font-size: 12.5px; text-align: center; }
.ob-goal-row b { font-size: 22px; line-height: 1; }
.ob-timeline { position: relative; display: grid; gap: 6px; margin: 4px 0 0; padding: 0; list-style: none; }
.ob-timeline li { display: grid; grid-template-columns: 54px 26px 1fr; align-items: center; gap: 6px; padding: 7px 11px; border-radius: 11px; background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.07); }
.ob-timeline time { font-family: var(--serif, "Marcellus", Georgia, serif); font-size: 17px; color: var(--gold-2, #ffd58a); }
.ob-timeline span { font-size: 16px; text-align: center; }
.ob-timeline b { font-size: 13px; font-weight: 500; }
.ob-goals { display: grid; gap: 6px; margin: 12px 0 0; padding: 0; list-style: none; }
.ob-goals li { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 11px; background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.1); }
.ob-goals span { font-size: 17px; }
.ob-goals b { font-size: 13px; font-weight: 600; }
.ob-goals em { font-style: normal; font-size: 12px; color: var(--green, #8fcf8a); white-space: nowrap; }
.ob-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; }
.ob-pips { display: flex; gap: 6px; }
.ob-pips i { width: 7px; height: 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.2); transition: width 0.25s, background 0.25s; }
.ob-pips i.on { width: 22px; background: var(--gold, #e8b458); }
.ob-card-actions { display: flex; align-items: center; gap: 16px; margin-left: auto; }
.ob-card-actions button { white-space: nowrap; }
.ob-card-actions button.link { padding: 10px 0; }

/* Narrow portrait windows: smaller picture. */
@media (max-width: 559px) {
  .ob-art { height: 132px; }
  .ob-card-body { padding: 2px 18px 16px; }
  .ob-card h2 { font-size: 25px; }
  .ob-lead { font-size: 13.5px; }
}
/* Phones in landscape and other short screens: picture on the left, text on the right. */
@media (max-height: 540px) and (min-width: 560px) {
  .ob-card { flex-direction: row; width: min(780px, 100%); max-height: calc(100vh - 20px); max-height: calc(100dvh - 20px); }
  .ob-art { width: 36%; height: auto; align-self: stretch; }
  .ob-art::after { top: 0; left: auto; width: 56px; height: auto; background: linear-gradient(to right, rgba(40, 32, 28, 0), #2a211c); }
  .ob-card-body { flex: 1; padding: 16px 20px 14px 14px; }
  .ob-card h2 { font-size: 24px; margin: 4px 0 6px; }
  .ob-lead { font-size: 13px; line-height: 1.45; }
  .ob-chips { margin-top: 10px; }
  .ob-chips span { padding: 4px 9px; font-size: 12px; }
  .ob-goal-row { margin-top: 10px; }
  .ob-goal-row span { padding: 7px 4px; font-size: 12px; }
  .ob-goal-row b { font-size: 18px; }
  .ob-timeline { gap: 4px; }
  .ob-timeline li { padding: 4px 9px; }
  .ob-timeline time { font-size: 15px; }
  .ob-goals { margin-top: 8px; gap: 4px; }
  .ob-goals li { padding: 6px 10px; }
  .ob-card-foot { margin-top: auto; padding-top: 12px; }
}
@media (max-height: 540px) and (min-width: 560px) and (max-width: 720px) {
  .ob-pips { display: none; }
  .ob-card-actions { gap: 12px; }
}
@media (max-height: 400px) and (min-width: 560px) {
  .ob-card h2 { font-size: 21px; }
  .ob-lead { font-size: 12.5px; }
  .ob-card-body { padding-top: 12px; padding-bottom: 10px; }
  .ob-card-foot { padding-top: 8px; }
}

/* ---------------------------------------------------------------- start screen branding */
/* The banner bleeds to the window's edges, so the welcome window's padding is pinned here and the
   banner's negative margins always match it (same breakpoints as styles.css: 860 px wide, 500 px tall). */
.modal.welcome { padding: 28px 30px; }
.modal.welcome .ct-hero {
  position: relative; display: flex; align-items: flex-end; gap: 16px;
  margin: -28px -30px 16px; padding: 30px 30px 16px; min-height: 196px; overflow: hidden;
}
.ct-hero .ct-sky { position: absolute; inset: 0; }
.ct-hero .ct-sky svg { display: block; width: 100%; height: 100%; }
.ct-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(24, 20, 26, 0) 25%, rgba(28, 23, 28, 0.72) 68%, rgba(31, 26, 32, 0.97)); }
.ct-hero > :not(.ct-sky) { position: relative; z-index: 1; }
.ct-mark { flex: none; display: grid; place-items: center; width: 66px; height: 66px; border-radius: 18px; background: linear-gradient(145deg, #944426, #b35c3b); box-shadow: 0 10px 26px rgba(148, 68, 38, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25); }
.ct-mark svg { width: 38px; height: 46px; }
.ct-hero-text { min-width: 0; }
.modal.welcome h1.ct-title { margin: 4px 0 2px; font-family: var(--serif, "Marcellus", Georgia, serif); font-weight: 400; font-size: clamp(34px, 5.2vw, 54px); line-height: 1; letter-spacing: 0.01em; text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45); }
.modal.welcome h1.ct-title em { color: var(--gold-2, #ffd58a); font-size: 1em; font-style: normal; }
.modal.welcome h1.ct-title .ct-place { display: inline-block; margin-left: 0.32em; font-size: 0.5em; letter-spacing: 0.08em; color: #f3e4c8; vertical-align: 0.18em; }
.modal.welcome h1.ct-title .ct-place::before { content: ": "; margin-left: -0.32em; color: var(--gold-2, #ffd58a); }
.ct-tag { margin: 7px 0 0; color: #eadcc5; font-size: 14px; line-height: 1.4; }
.ct-tag span { color: var(--gold, #e8b458); white-space: nowrap; }
.modal.welcome .ct-hero .eyebrow { text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5); }

@media (max-width: 860px) {
  .modal.welcome { padding: 22px 18px; }
  .modal.welcome .ct-hero { margin: -22px -18px 12px; padding: 24px 18px 12px; min-height: 150px; }
  .ct-mark { width: 50px; height: 50px; border-radius: 14px; }
  .ct-mark svg { width: 29px; height: 35px; }
}
/* Phones in landscape: slimmer banner, compact feature list (the saved games matter more). */
@media (max-height: 500px) {
  .modal.welcome { padding: 12px 16px 16px; }
  .modal.welcome .ct-hero { min-height: 112px; margin: -12px -16px 10px; padding: 16px 16px 10px; }
  .modal.welcome h1.ct-title { font-size: 30px; }
  .ct-tag { font-size: 12.5px; margin-top: 4px; }
  .ct-mark { width: 46px; height: 46px; border-radius: 13px; }
  .ct-mark svg { width: 27px; height: 33px; }
  .modal.welcome .lead { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; font-size: 12.5px; line-height: 1.45; margin-bottom: 8px; }
  .modal.welcome .welcome-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 8px 0; }
  .modal.welcome .welcome-grid div { padding: 8px 10px; }
  .modal.welcome .welcome-grid b { font-size: 12px; }
  .modal.welcome .welcome-grid span { display: none; }
}

/* picture-quality choice on the first launch (src/ui/quality.js) */
.q-opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 2px; }
.q-opt { display: flex; flex-direction: column; align-items: stretch; gap: 5px; min-height: 44px; padding: 10px 10px 11px; border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12); background: rgba(255, 255, 255, 0.04); color: var(--ink, #f7eedb); text-align: left; cursor: pointer;
  transition: background 0.15s, border-color 0.15s; }
.q-opt:hover { border-color: rgba(232, 180, 88, 0.45); }
.q-opt.on { border-color: var(--gold, #e8b458); background: rgba(232, 180, 88, 0.14); box-shadow: inset 0 0 0 1px var(--gold, #e8b458); }
.q-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.q-ico { font-size: 19px; line-height: 1; }
.q-head b { font-size: 15px; }
.q-head em { font-style: normal; font-size: 10.5px; font-weight: 600; color: #15403f; background: var(--gold, #e8b458); padding: 2px 6px; border-radius: 6px; }
.q-opt small { font-size: 11.5px; line-height: 1.32; color: var(--muted, #b9ab94); }
@media (max-width: 559px) { .q-opts { grid-template-columns: 1fr; } }
@media (max-height: 400px) and (min-width: 560px) {
  .q-opts { gap: 6px; margin-top: 6px; }
  .q-opt { padding: 8px 8px 9px; gap: 3px; }
  .q-opt small { font-size: 10.5px; }
}

/* A readable, touch-first lesson card, with persistent navigation. */
.ob-lesson-icon { display: block; font-size: 48px; margin-bottom: 12px; }
.ob-card-actions { flex-wrap: wrap; gap: 10px; }
.ob-card-foot { position: sticky; bottom: 0; padding-top: 14px; background: inherit; }
.ob-pips i.on { width: 24px; border-radius: 8px; }
@media (pointer: coarse), (max-height: 500px), (max-width: 700px) {
  .ob-card-actions button { min-width: 96px; min-height: 48px; padding: 12px 18px; font-size: 15px; }
  .ob-card .ob-lead { font-size: 15px; line-height: 1.5; }
  .ob-bubble button { min-height: 48px; }
  .ob-bubble { max-height: calc(100dvh - 24px); overflow-y: auto; }
}
@media (max-height: 500px) {
  .ob-card-body { padding: 16px 22px; }
  .ob-card h2 { font-size: clamp(22px, 4vh, 30px); }
  .ob-lesson-icon { font-size: 32px; margin-bottom: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .ob-cards *, .ob-layer * { animation: none !important; transition: none !important; }
}
