:root {
    --navy: #344563; --navy-dark: #1E2D45; --navy-light: #4A6080;
    --red: #E8473A; --red-dark: #C93A2E; --red-light: #EE6C61;
    --yellow: #F2C200; --green: #27AE60; --blue: #2F88C8;
    --gray-200: #D0D5DD; --gray-400: #98A2B3; --black: #0A0E18;
    --panel: rgba(30, 45, 69, 0.72);
    --panel-border: rgba(255, 255, 255, 0.08);
    --text: rgba(255, 255, 255, 0.92);
    --text-dim: rgba(255, 255, 255, 0.55);
    --font-display: 'Barlow Condensed', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; height: 100%; background: #000; color: var(--text); font-family: var(--font-body); overflow: hidden; }
  #stage { position: fixed; inset: 0; }
  canvas { display: block; }

  .panel { position: fixed; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }

  /* Phases */
  #phases { top: 16px; left: 16px; width: 320px; padding: 16px 16px 14px; }
  .eyebrow { color: var(--red); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .14em; }
  h1 { font-family: var(--font-display); font-weight: 900; text-transform: uppercase; font-size: 30px; line-height: 1; margin: 4px 0 12px; letter-spacing: .01em; }
  ol { list-style: none; margin: 0; padding: 0; }
  ol li { display: flex; gap: 10px; align-items: baseline; padding: 7px 10px; border-left: 2px solid transparent; border-radius: 0 6px 6px 0; cursor: pointer; color: var(--text-dim); font-size: 13.5px; transition: background .15s, color .15s; }
  ol li:hover { color: var(--text); }
  ol li .n { font-family: var(--font-display); font-weight: 800; font-size: 16px; width: 12px; }
  ol li.active { border-left-color: var(--red); background: rgba(232, 71, 58, 0.12); color: #fff; }
  #stepNote { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: rgba(232,71,58,0.14); border: 1px solid rgba(232,71,58,0.45); display: flex; gap: 10px; align-items: center; justify-content: space-between; font-size: 12.5px; }
  #stepNote[hidden] { display: none; }
  #stepNote button { background: var(--red); border-color: var(--red); flex: none; }
  .row { display: flex; gap: 6px; }
  #playerStatus { color: var(--red-light); text-transform: none; letter-spacing: 0; font-weight: 600; margin-left: 4px; }
  .row select { flex: 1; min-width: 0; }
  #legend { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--text-dim); }
  #legend[hidden], #mistakeBox[hidden] { display: none; }
  #mistakes button.on { background: #FF9F43; border-color: #FF9F43; color: #1b1206; }
  #mistakeCue { margin-top: 10px; padding: 8px 10px; border-left: 2px solid #FF9F43; background: rgba(255,159,67,.1); font-size: 12.5px; line-height: 1.45; border-radius: 0 6px 6px 0; }
  #mistakeCue[hidden] { display: none; }
  #legend i { width: 18px; height: 3px; border-radius: 2px; background: #FF9F43; }
  #favBtn { background: none; border: none; font-size: 22px; padding: 0 4px; color: var(--yellow); vertical-align: 3px; }
  #favBtn:hover { background: none; transform: scale(1.15); }
  .card .star { position: absolute; top: 8px; right: 10px; color: var(--yellow); font-size: 18px; text-shadow: 0 1px 4px #000; }
  .card .seen { position: absolute; top: 8px; left: 10px; font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; background: rgba(39,174,96,.85); padding: 2px 7px; border-radius: 100px; }
  .card { position: relative; }
  .lesson .done { float: right; color: var(--green-light, #3DC872); font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
  #strokeMeta { margin: -6px 0 10px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-dim); }
  #strokeMeta b { color: var(--yellow); font-weight: 700; }
  /* Compact, non-blocking loading toast (STK-1): the court, the placeholder player and the whole
     interface render straight away — this just reports progress while the real character streams in. */
  #loader { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; align-items: center; gap: 12px; padding: 9px 16px; border-radius: 100px; background: var(--panel); border: 1px solid var(--panel-border); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); pointer-events: none; transition: opacity .5s ease, transform .5s ease; }
  #loader.done { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  #loader svg { width: 24px; height: 19px; overflow: visible; flex: none; }
  #loader svg polygon { fill: var(--red); animation: chev 1.2s ease-in-out infinite; }
  #loader svg polygon:nth-child(2) { animation-delay: .2s; }
  @keyframes chev { 0%, 100% { opacity: .25; transform: translateX(0); } 50% { opacity: 1; transform: translateX(6px); } }
  #loader .brand { display: none; }
  #loader .sub { font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: none; color: var(--text); }
  #loader .bar { width: 110px; height: 3px; border-radius: 4px; background: rgba(255,255,255,.15); overflow: hidden; }
  #loader .bar i { display: block; height: 100%; width: 8%; background: linear-gradient(90deg, var(--red), var(--yellow)); transition: width .2s; }
  #contactCard { top: 16px; left: 50%; transform: translateX(-50%); padding: 10px 14px; }
  #contactCard[hidden] { display: none; }
  #contactCard .stats { display: flex; gap: 18px; margin-top: 6px; }
  #contactCard .stats div { display: flex; flex-direction: column; align-items: center; }
  #contactCard b { font-family: var(--font-display); font-size: 24px; font-weight: 800; line-height: 1; }
  #contactCard span { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--text-dim); margin-top: 3px; }
  #viewToggle { display: none; }
  #welcome { top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(440px, calc(100vw - 32px)); padding: 22px 24px; z-index: 45; background: rgba(20, 31, 51, 0.94); }
  #welcome[hidden] { display: none; }
  #welcome h2 { font-family: var(--font-display); font-weight: 900; text-transform: uppercase; font-size: 30px; margin: 4px 0 10px; }
  #welcome ul { margin: 0 0 12px; padding-left: 18px; font-size: 13.5px; line-height: 1.6; }
  #welcome .keys { font-size: 12px; color: var(--text-dim); line-height: 2; margin-bottom: 14px; }
  kbd { font-family: var(--font-mono); font-size: 11px; background: rgba(255,255,255,.1); border: 1px solid var(--panel-border); border-radius: 4px; padding: 1px 5px; margin: 0 1px; color: #fff; }
  #welcomeGo { background: var(--red); border-color: var(--red); width: 100%; padding: 10px; font-size: 14px; }
  #recBadge { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 46; background: var(--red); color: #fff; font: 700 12px var(--font-body); letter-spacing: .1em; padding: 6px 12px; border-radius: 100px; }
  #recBadge[hidden] { display: none; }
  #recBtn.on { background: var(--red); border-color: var(--red); }
  #quiz { top: 16px; left: 50%; transform: translateX(-50%); width: min(420px, calc(100vw - 32px)); padding: 16px 18px; z-index: 30; background: rgba(20,31,51,.95); }
  #quiz[hidden], #quizNext[hidden], #quizAnswers[hidden] { display: none; }
  #qClose { position: absolute; top: 10px; right: 10px; padding: 4px 9px; }
  #quiz h2 { font-family: var(--font-display); font-weight: 900; text-transform: uppercase; font-size: 24px; margin: 4px 0 6px; }
  #quiz p { font-size: 13px; line-height: 1.5; margin: 0 0 12px; }
  #quiz .seg button { flex: 1; padding: 10px; font-size: 14px; }
  #qRight:hover { background: rgba(39,174,96,.35); } #qWrong:hover { background: rgba(232,71,58,.35); }
  #quiz.good { border-color: var(--green); } #quiz.bad { border-color: var(--red); }
  body.quizzing #view, body.quizzing #mistakeCue, body.quizzing #contactCard { visibility: hidden; }
  #gallery { position: fixed; inset: 0; z-index: 44; background: rgba(7,11,20,.92); backdrop-filter: blur(8px); overflow-y: auto; padding: 28px clamp(16px, 4vw, 56px); }
  #gallery[hidden] { display: none; }
  #gallery .ghead { display: flex; justify-content: space-between; align-items: flex-start; max-width: 1200px; margin: 0 auto 18px; }
  #gallery h2 { font-family: var(--font-display); font-weight: 900; text-transform: uppercase; font-size: 40px; margin: 4px 0 0; }
  #galleryGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; max-width: 1200px; margin: 0 auto; }
  .gcat { grid-column: 1 / -1; font-family: var(--font-display); font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--red); font-size: 16px; margin-top: 8px; }
  .card { display: flex; flex-direction: column; justify-content: flex-start; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 14px; overflow: hidden; cursor: pointer; text-align: left; padding: 0; transition: transform .15s, border-color .15s; }
  .card:hover { transform: translateY(-2px); border-color: var(--red); }
  .card.current { border-color: var(--yellow); }
  .card .thumb { aspect-ratio: 4 / 3; background: #0b1220 center / cover no-repeat; display: flex; align-items: center; justify-content: center; color: var(--text-dim); font-size: 12px; }
  .card .body { padding: 10px 12px 12px; }
  .card b { font-family: var(--font-display); font-size: 22px; font-weight: 800; text-transform: uppercase; display: block; }
  .card span { font-size: 12px; color: var(--text-dim); line-height: 1.4; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .card .thumb { width: 100%; }
  .card .body { width: 100%; }
  .card i { font-style: normal; font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--yellow); }
  #lessonGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; max-width: 1200px; margin: 0 auto 22px; }
  .lesson { background: linear-gradient(135deg, rgba(232,71,58,.22), rgba(47,136,200,.14)); border: 1px solid rgba(232,71,58,.45); border-radius: 14px; padding: 14px 16px; text-align: left; cursor: pointer; }
  .lesson:hover { border-color: var(--red); }
  .lesson b { font-family: var(--font-display); font-size: 22px; font-weight: 800; text-transform: uppercase; display: block; }
  .lesson span { font-size: 12px; color: var(--text-dim); display: block; margin-top: 4px; line-height: 1.4; }
  .lesson i { font-style: normal; font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--red-light); }
  #lessonBar { top: 16px; left: 50%; transform: translateX(-50%); display: flex; gap: 16px; align-items: center; padding: 10px 14px; z-index: 29; border-color: rgba(232,71,58,.5); }
  #lessonBar[hidden] { display: none; }
  #lessonBar b { font-family: var(--font-display); font-size: 20px; font-weight: 800; text-transform: uppercase; }
  body.lesson-on #contactCard { top: 84px; }
  #ink { position: fixed; inset: 0; z-index: 15; pointer-events: none; touch-action: none; }
  body.drawing #ink { pointer-events: auto; cursor: crosshair; }
  #penBar { top: 16px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; padding: 8px 10px; z-index: 31; }
  #penBar[hidden] { display: none; }
  #penColors button { width: 26px; height: 26px; border-radius: 50%; padding: 0; border: 2px solid rgba(255,255,255,.3); }
  #penColors button.on { border-color: #fff; transform: scale(1.12); }
  #penBtn.on { background: var(--yellow); border-color: var(--yellow); color: #1a1406; }
  #miniFrame { position: fixed; left: 16px; bottom: 196px; width: 200px; height: 200px; border: 1px solid var(--panel-border); border-radius: 12px; pointer-events: none; z-index: 5; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
  #miniFrame[hidden] { display: none; }
  #miniFrame span { position: absolute; top: 6px; left: 8px; font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--text-dim); }
  #angleLabels { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
  .ang { position: absolute; transform: translate(-50%, -130%); font: 800 13px var(--font-display); letter-spacing: .02em; background: rgba(10,14,24,.78); border: 1px solid rgba(242,194,0,.6); color: var(--yellow); padding: 2px 6px; border-radius: 100px; white-space: nowrap; }
  .ang small { font: 600 9px var(--font-body); color: var(--text-dim); margin-left: 3px; text-transform: uppercase; letter-spacing: .08em; }
  .segs div.looped { background: rgba(242,194,0,.7) !important; }
  #loopBtn.on { background: rgba(242,194,0,.25); border-color: var(--yellow); }
  #caption { position: fixed; left: 50%; bottom: 36px; transform: translateX(-50%); width: min(1100px, calc(100vw - 64px)); z-index: 30; text-align: center; background: rgba(7,11,20,.72); border-radius: 18px; padding: 18px 26px; backdrop-filter: blur(6px); }
  #caption[hidden] { display: none; }
  #caption .cn { font-family: var(--font-display); font-weight: 900; text-transform: uppercase; font-size: clamp(26px, 3.4vw, 48px); color: #fff; }
  #caption .cn b { color: var(--red); }
  #caption .cc { font-size: clamp(15px, 1.5vw, 22px); line-height: 1.45; color: rgba(255,255,255,.9); margin-top: 6px; }
  #presentExit { position: fixed; top: 16px; right: 16px; z-index: 31; }
  #presentExit[hidden] { display: none; }
  body.present #phases, body.present #view, body.present #weight, body.present #transport, body.present #contactCard, body.present #miniFrame { display: none !important; }
  #actions { right: 16px; bottom: 104px; display: flex; gap: 6px; padding: 8px; z-index: 6; }
  body.present #actions { display: none; }
  @media (max-width: 1280px) { #clock { display: none; } }
  @media (min-width: 821px) and (max-width: 1240px) { #contactCard { top: auto; bottom: 104px; left: 352px; transform: none; padding: 8px 10px; } #contactCard .stats { gap: 10px; } #contactCard b { font-size: 18px; } #contactCard .stats div:nth-child(4) { display: none; } }
  #toast { position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); background: var(--navy-dark); border: 1px solid var(--panel-border); color: #fff; padding: 9px 14px; border-radius: 100px; font-size: 13px; z-index: 40; }
  #toast[hidden] { display: none; }
  #shareBtn { flex: none; }
  #cue { margin-top: 12px; font-size: 13px; line-height: 1.5; color: var(--text); min-height: 5.5em; }

  /* Camera & toggles */
  #view { top: 16px; right: 16px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
  .label { font-size: 10px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--text-dim); }
  .seg { display: flex; gap: 4px; flex-wrap: wrap; }
  select { font: 600 13px var(--font-body); color: var(--text); background: rgba(255,255,255,0.06); border: 1px solid var(--panel-border); border-radius: 6px; padding: 7px 8px; width: 100%; }
  select option, select optgroup { background: #1E2D45; color: #fff; }
  button { font: 600 12.5px var(--font-body); color: var(--text); background: rgba(255,255,255,0.06); border: 1px solid var(--panel-border); border-radius: 6px; padding: 7px 10px; cursor: pointer; transition: background .15s, border-color .15s; }
  button:hover { background: rgba(255,255,255,0.12); }
  button:focus-visible, select:focus-visible, ol li:focus-visible, .track:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }
  @media (prefers-reduced-motion: reduce) { #loader svg polygon { animation: none; } * { transition: none !important; } }
  button.on { background: var(--red); border-color: var(--red); color: #fff; }
  .toggle.on { background: rgba(47,136,200,0.25); border-color: var(--blue); color: #fff; }

  /* Weight */
  #weight { left: 16px; bottom: 104px; width: 320px; padding: 12px 14px; }
  .wrow { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin-top: 6px; }
  .wrow b { font-family: var(--font-mono); font-weight: 500; color: var(--text); }
  .wbar { position: relative; height: 10px; border-radius: 100px; background: rgba(255,255,255,0.08); overflow: hidden; margin-top: 8px; }
  .wbar .fill { position: absolute; top: 0; bottom: 0; left: 0; background: linear-gradient(90deg, var(--blue), var(--red)); border-radius: 100px; }
  .wbar .mid { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: rgba(255,255,255,0.35); }

  /* Transport */
  #transport { left: 16px; right: 16px; bottom: 16px; padding: 12px 14px; display: flex; gap: 14px; align-items: center; }
  #play { width: 44px; height: 44px; border-radius: 100px; font-size: 16px; padding: 0; flex: none; }
  #timeline { flex: 1; min-width: 0; }
  .track { position: relative; height: 34px; cursor: pointer; touch-action: none; }
  .segs { position: absolute; left: 0; right: 0; top: 8px; height: 8px; display: flex; gap: 2px; }
  .segs div { height: 100%; background: rgba(255,255,255,0.12); border-radius: 3px; }
  .segs div.active { background: rgba(232, 71, 58, 0.55); }
  .seglabels { position: absolute; left: 0; right: 0; top: 20px; display: flex; gap: 2px; font-size: 10px; color: var(--text-dim); }
  .seglabels span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding-left: 2px; }
  .tick { position: absolute; top: 4px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 8px rgba(242,194,0,.8); cursor: pointer; z-index: 1; }
  .tick[hidden] { display: none; }
  .head { position: absolute; top: 2px; width: 2px; height: 20px; background: #fff; margin-left: -1px; border-radius: 2px; box-shadow: 0 0 8px rgba(255,255,255,0.6); }
  #clock { font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); width: 92px; text-align: right; flex: none; }
  .group { display: flex; flex-direction: column; gap: 5px; flex: none; }

  @media (max-width: 820px) {
    #phases { width: auto; right: 16px; padding: 12px; }
    h1 { font-size: 22px; margin-bottom: 6px; }
    ol { display: flex; gap: 4px; }
    ol li { flex: 1; justify-content: center; padding: 6px 4px; border-left: none; border-bottom: 2px solid transparent; border-radius: 6px 6px 0 0; }
    ol li.active { border-bottom-color: var(--red); }
    ol li .t { display: none; }
    #cue { font-size: 12px; min-height: 0; }
    #view { top: auto; bottom: 212px; right: 16px; left: 16px; padding: 12px; max-height: calc(100vh - 360px); overflow-y: auto; display: none; z-index: 20; }
    #view.open { display: flex; }
    #view .toggles { display: flex !important; }
    #viewToggle { display: block; }
    #viewToggle.open { background: var(--red); border-color: var(--red); }
    #weight { display: none; }
    #contactCard { top: auto; bottom: 212px; left: 16px; right: 16px; transform: none; padding: 8px 10px; }
    #contactCard .stats { justify-content: space-between; }
    #contactCard b { font-size: 18px; }
    #contactCard .stats { gap: 10px; }
    #actions { display: none; }
    #miniFrame { display: none !important; }
    #weight { bottom: 150px; width: auto; right: 16px; padding: 8px 12px; }
    #transport { flex-wrap: wrap; gap: 10px; }
    #timeline { order: -1; flex-basis: 100%; }
    #clock { display: none; }
  }

  .toggles { display: flex; flex-direction: column; gap: 10px; }
  .seg.wide { max-width: 260px; }
  .dim { color: var(--text-dim); }
  .capSub { color: var(--text-dim); font-size: .55em; }

/* Platform header (48px bar on top): everything fixed moves down, the 3D view keeps full height below it */
lagana-header { position: fixed; top: 0; left: 0; right: 0; z-index: 60; }
body.has-platform-header #stage { top: 48px; }
body.has-platform-header #phases,
body.has-platform-header #view,
body.has-platform-header #contactCard,
body.has-platform-header #lessonBar,
body.has-platform-header #quiz,
body.has-platform-header #penBar,
body.has-platform-header #presentExit,
body.has-platform-header #loader,
body.has-platform-header #updateNotice { top: 64px; }

/* Install button (PWA, STK-1): same look as the other tool buttons in #actions; hidden until the
   browser offers an install prompt (js/pwa.js). */
#installBtn[hidden] { display: none; }

/* "New version available" banner (PWA, STK-1): same top-centre slot as #quiz/#lessonBar, shown only
   while a new service worker is waiting to take over. */
#updateNotice { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 55; display: flex; align-items: center; gap: 10px; padding: 10px 14px; font-size: 13px; }
#updateNotice[hidden] { display: none; }
#updateNotice button { background: var(--red); border-color: var(--red); flex: none; }
