/* ==========================================================================
   web.css — loads AFTER popup.css and rebuilds the extension popup as a
   full-screen web app. All app logic (popup.js) is untouched: this layer
   only re-frees the fixed 390x600 popup box and, on desktop, converts the
   app's bottom nav into a frosted-glass left sidebar with the app itself
   floating as a rounded card over an animated "open water" page canvas.
   Depth system: sea canvas (base) → glass rail (elevated) → app card (floating).
   ========================================================================== */

:root {
  --rail-w: 256px;
  --col-w: 660px;
  --page-pad: 28px;
  --card-r: 26px;
  --sea-ink: 12, 62, 92;           /* shadow/tint ink for the water depth */
  --page-bg: #f2fafd;
}

html, body { height: 100%; }

body {
  width: auto;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(85% 60% at 12% -6%, rgba(255, 255, 255, 0.85), transparent 58%),
    radial-gradient(70% 55% at 88% 8%, rgba(214, 243, 255, 0.7), transparent 60%),
    linear-gradient(180deg, #f2fbfe 0%, #ddeef7 52%, #c9e2f0 100%);
}
/* when a biome is equipped the whole page water takes on its cast */
body.has-biome-theme {
  background:
    radial-gradient(85% 60% at 12% -6%, rgba(255, 255, 255, 0.85), transparent 58%),
    radial-gradient(70% 55% at 88% 8%, color-mix(in srgb, var(--biome-tint) 10%, #ffffff88), transparent 60%),
    linear-gradient(180deg,
      color-mix(in srgb, var(--biome-tint) 5%, #f4fbfe) 0%,
      color-mix(in srgb, var(--biome-tint) 12%, #e2eff6) 52%,
      color-mix(in srgb, var(--biome-tint) 20%, #cfe3ef) 100%);
}

#app {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100dvh;
  background: transparent;
}

/* ==========================================================================
   The open-water canvas that fills the space around the app (desktop only).
   Everything animates transform/opacity only.
   ========================================================================== */
.page-sea { display: none; }

@media (min-width: 900px) {
  .page-sea {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
  }

  /* slanted light shafts, swaying almost imperceptibly */
  .sea-ray {
    position: absolute;
    top: -12vh;
    width: 170px;
    height: 130vh;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.08) 55%, transparent 80%);
    transform: rotate(13deg);
    opacity: 0.3;
    animation: seaRay 16s ease-in-out infinite alternate;
  }
  .sea-ray.sr1 { left: 6%; }
  .sea-ray.sr2 { left: 22%; width: 90px; opacity: 0.26; animation-delay: -5s; animation-duration: 21s; }
  .sea-ray.sr3 { right: 10%; width: 130px; opacity: 0.3; animation-delay: -11s; animation-duration: 18s; }
  @keyframes seaRay {
    from { transform: rotate(13deg) translateX(-26px); opacity: 0.24; }
    to   { transform: rotate(13deg) translateX(26px);  opacity: 0.44; }
  }

  /* kelp silhouettes rooted in the bottom corners, swaying like the real plant */
  .sea-kelp { position: absolute; bottom: -14px; fill: rgba(var(--sea-ink), 0.09); }
  .sea-kelp.k1 { left: calc(var(--rail-w) - 60px); }
  .sea-kelp.k2 { right: -26px; fill: rgba(var(--sea-ink), 0.075); }
  .sea-kelp .blade { transform-box: fill-box; transform-origin: 50% 100%; animation: kelpSway 7s ease-in-out infinite alternate; }
  .sea-kelp .blade.b2 { animation-delay: -2.4s; animation-duration: 8.5s; }
  .sea-kelp .blade.b3 { animation-delay: -4.8s; animation-duration: 6.4s; }
  .sea-kelp .blade.b4 { animation-delay: -1.2s; animation-duration: 9.2s; }
  @keyframes kelpSway {
    from { transform: rotate(-3.5deg); }
    to   { transform: rotate(4deg); }
  }

  /* far-off fish silhouettes crossing the open water */
  .sea-fish {
    position: absolute;
    color: rgba(var(--sea-ink), 0.1);
    animation: seaSwim 60s linear infinite;
  }
  .sea-fish.sf1 { top: 68%; animation-delay: -12s; }
  .sea-fish.sf2 { top: 24%; color: rgba(var(--sea-ink), 0.07); animation-duration: 85s; animation-delay: -47s; animation-direction: reverse; transform: scaleX(-1); }
  .sea-fish.sf3 { top: 84%; color: rgba(var(--sea-ink), 0.08); animation-duration: 72s; animation-delay: -30s; }
  @keyframes seaSwim {
    0%   { translate: -12vw 0; }
    25%  { translate: 16vw -14px; }
    50%  { translate: 45vw 6px; }
    75%  { translate: 76vw -10px; }
    100% { translate: 112vw 0; }
  }

  /* bubbles rising the full height of the page */
  .sea-bub {
    position: absolute;
    bottom: -30px;
    width: var(--bs, 8px);
    height: var(--bs, 8px);
    border-radius: 50%;
    background: radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.22) 55%, rgba(255, 255, 255, 0.04) 74%);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45);
    opacity: 0;
    animation: seaBub var(--bt, 18s) linear var(--bd, 0s) infinite;
  }
  @keyframes seaBub {
    0%   { opacity: 0; transform: translateY(0) translateX(0); }
    8%   { opacity: 0.65; }
    45%  { transform: translateY(-48vh) translateX(10px); }
    75%  { opacity: 0.5; transform: translateY(-78vh) translateX(-6px); }
    100% { opacity: 0; transform: translateY(-108vh) translateX(4px); }
  }

  /* fine grain so the gradients never band */
  .sea-grain {
    position: absolute;
    inset: 0;
    opacity: 0.4;
    mix-blend-mode: soft-light;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  }
}

/* ---------- back-to-site link ---------- */
.home-chip {
  position: fixed;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13.5px;
  text-decoration: none;
  padding: 10px 14px;
  border-radius: 12px;
  transition: color 0.15s ease, background-color 0.15s ease;
}
.home-chip:hover { color: var(--ocean-dark); background: rgba(224, 243, 252, 0.9); }
.home-chip:focus-visible { outline: 3px solid var(--ocean); outline-offset: 2px; }
.home-chip svg { flex-shrink: 0; }

/* ==========================================================================
   Mobile / narrow (< 900px): the app fills the screen edge to edge,
   bottom nav stays at the bottom — exactly the extension layout, full-bleed.
   ========================================================================== */
@media (max-width: 899px) {
  body { background: #fff; }
  .home-chip { display: none; }
}

/* ==========================================================================
   Desktop (>= 900px): frosted glass sidebar + the app as a floating card.
   ========================================================================== */
@media (min-width: 900px) {

  #app {
    display: flex;
    flex-direction: column;
  }
  /* the rail only exists on screens popup.js gives a bottom nav (Learn, Units,
     Shop, Account). Immersive screens — mode choice, quizzes — center full-width,
     exactly like Duolingo web hides its sidebar during a lesson. */
  #app:has(> .bottomnav) { padding: var(--page-pad) 40px var(--page-pad) calc(var(--rail-w) + 40px); }
  #app:not(:has(> .bottomnav)) { padding: var(--page-pad) 40px; }
  #app:not(:has(> .bottomnav)) ~ .home-chip,
  body:has(#app:not(:has(> .bottomnav))) .home-chip { left: 16px; bottom: 14px; width: auto; }

  /* one soft, water-tinted shadow under the whole column (the card itself is
     assembled from the stacked screen blocks popup.js renders) */
  #app::before {
    content: "";
    position: absolute;
    top: var(--page-pad);
    bottom: var(--page-pad);
    left: 40px;
    right: 40px;
    max-width: var(--col-w);
    margin-inline: auto;
    border-radius: var(--card-r);
    background: #fff;
    box-shadow:
      0 1px 2px rgba(var(--sea-ink), 0.08),
      0 12px 28px -10px rgba(var(--sea-ink), 0.18),
      0 40px 80px -28px rgba(var(--sea-ink), 0.32);
    z-index: -1;
  }
  #app:has(> .bottomnav)::before { left: calc(var(--rail-w) + 40px); }

  /* every screen block popup.js renders becomes part of the centered card.
     (.bottomnav is the sidebar; .ring-trans is a full-surface transition.) */
  #app > *:not(.bottomnav):not(.ring-trans) {
    width: 100%;
    max-width: var(--col-w);
    margin-inline: auto;
    border-inline: 2px solid var(--gray-line);
    background-clip: padding-box;
  }
  .has-biome-theme #app > *:not(.bottomnav):not(.ring-trans) { border-inline-color: var(--biome-tint-dark); }

  /* round + close the card: first block gets the top edge, the block sitting
     against the bottom nav (or the only block, on nav-less screens) the bottom */
  #app > *:not(.bottomnav):not(.ring-trans):first-child {
    border-top: 2px solid var(--gray-line);
    border-radius: var(--card-r) var(--card-r) 0 0;
  }
  #app > *:nth-last-child(2):not(.bottomnav):not(.ring-trans):not(:only-of-type),
  #app > *:not(.bottomnav):not(.ring-trans):last-child {
    border-bottom: 2px solid var(--gray-line);
    border-radius: 0 0 var(--card-r) var(--card-r);
  }
  /* clip children to the rounded corners ONLY on blocks that are not themselves
     scroll containers (.fin-scroll/.path/.settings-page already clip via overflow-y) */
  .shop-page, .cp-home, .landing, .complete-screen, .test-intro { overflow: hidden; }
  #app > *:not(.bottomnav):not(.ring-trans):first-child:last-child {
    border-radius: var(--card-r);
  }
  .has-biome-theme #app > *:not(.bottomnav):not(.ring-trans):first-child { border-top-color: var(--biome-tint-dark); }
  .has-biome-theme #app > *:nth-last-child(2):not(.bottomnav):not(.ring-trans),
  .has-biome-theme #app > *:not(.bottomnav):not(.ring-trans):last-child { border-bottom-color: var(--biome-tint-dark); }

  /* screens with their own solid backgrounds keep them; the shared white
     surfaces read as one continuous column against the page background */
  .topbar { justify-content: flex-end; background: #fff; }
  .landing, .quiz-screen, .complete-screen { background: #fff; }

  /* The clickable wordmark is #railBrand, created by web-boot.js OUTSIDE #app —
     screen transitions animate the topbar with a transform, which breaks
     position:fixed for anything inside it (the old pinned .brand flew into the
     card on every navigation). The topbar's own brand stays hidden here. */
  .topbar .brand { display: none; }
  #railBrand {
    display: none;
    position: fixed;
    top: 18px;
    left: 18px;
    z-index: 35;
    align-items: center;
    gap: 10px;
    padding: 8px 14px 8px 10px;
    border: none;
    border-radius: 14px;
    background: transparent;
    cursor: pointer;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 27px;
    letter-spacing: -0.5px;
    color: var(--duo-green);
    transition: background-color 0.15s ease, transform 0.1s ease;
  }
  body:has(#app > .bottomnav) #railBrand { display: inline-flex; }
  #railBrand:hover { background: rgba(236, 248, 253, 0.9); }
  #railBrand:focus-visible { outline: 3px solid var(--ocean); outline-offset: 2px; }
  #railBrand:active { transform: scale(0.96); }
  #railBrand svg { flex-shrink: 0; }

  /* ---------- the sidebar (the app's own bottom nav, re-laid as glass) ---------- */
  .bottomnav {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 30;
    width: var(--rail-w);
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 6px;
    padding: 96px 18px 76px;
    border-top: 0;
    border-right: 1px solid rgba(var(--sea-ink), 0.12);
    background: rgba(255, 255, 255, 0.72);
    -webkit-backdrop-filter: blur(18px) saturate(1.25);
    backdrop-filter: blur(18px) saturate(1.25);
    box-shadow: 1px 0 24px rgba(var(--sea-ink), 0.06);
  }

  /* (rail wordmark removed — the real #logoHome brand is pinned here instead, see above) */

  .navbtn {
    flex-direction: row;
    justify-content: flex-start;
    gap: 16px;
    padding: 12px 16px;
    border-radius: 14px;
    border: 2px solid transparent;
    font-size: 14.5px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-dim);
    text-align: left;
    line-height: 1.3;
  }
  .navbtn:hover { background: rgba(236, 248, 253, 0.9); color: var(--text); }
  .navbtn:focus-visible { outline: 3px solid var(--ocean); outline-offset: 2px; }
  .navbtn:active { transform: scale(0.98); }
  .navbtn.active {
    background: var(--skin-soft, #e8fad4);
    border-color: color-mix(in srgb, var(--skin-dark, var(--duo-green)) 45%, #fff);
    color: var(--skin-dark, var(--duo-green));
  }
  .navbtn .icon svg { width: 27px; height: 27px; }
  /* the rail has room for the full tab name ("Prep" stays in the extension's bottom bar) */
  .navbtn .nav-short { display: none; }
  .navbtn .nav-long { display: inline; }
  /* the assignments count sits at the right end of the rail item, not over the icon */
  .navbtn .nav-badge { top: 50%; left: auto; right: 12px; transform: translateY(-50%); }

  /* ---------- shop: compact preview so the catalogue gets the space ---------- */
  .shop-preview { grid-template-columns: 220px 1fr; gap: 12px; padding: 12px 16px; }
  .shop-preview .shop-fish-box { min-height: 0; height: 150px; }
  .shop-preview .shop-glass { max-height: 150px; overflow-y: auto; padding: 12px 14px; }
  .shop-hint.eq-summary { gap: 5px; }
  .shop-body .shop-grid { grid-template-columns: repeat(4, 1fr); }

  /* back-to-site pinned to the bottom of the rail */
  .home-chip {
    left: 18px;
    bottom: 16px;
    width: calc(var(--rail-w) - 36px);
  }

  /* ---------- quick-action widgets at the foot of the rail ---------- */
  .rail-widgets {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: auto;
    padding-top: 16px;
  }
  .rail-widget {
    display: flex; align-items: center; gap: 10px; text-align: left;
    padding: 10px 12px; border-radius: 14px; cursor: pointer;
    border: 2px solid rgba(var(--sea-ink), 0.1);
    background: rgba(255, 255, 255, 0.8);
    font-family: var(--font-display);
    transition: transform 0.12s ease, background-color 0.12s ease;
  }
  .rail-widget:hover { background: #fff; transform: translateY(-1px); }
  .rail-widget:active { transform: scale(0.97); }
  .rail-widget:focus-visible { outline: 3px solid var(--ocean); outline-offset: 2px; }
  .rail-widget .rw-ico { flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: #fff3cd; font-size: 15px; }
  .rail-widget.mistakes .rw-ico { background: #f2e8ff; color: #7d3fd4; }
  .rail-widget .rw-txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
  .rail-widget .rw-txt b { font-size: 12.5px; font-weight: 800; color: var(--text); }
  .rail-widget .rw-txt small { font-size: 10.5px; font-weight: 600; color: var(--text-dim); font-family: var(--font-body, inherit); }
  /* the rail shows the mistakes widget — hide the in-path duplicate chip */
  .fin-scroll .mistake-chip { display: none; }

  /* ---------- transitions cover the app CARD, not the whole page ---------- */
  .swim-trans {
    top: var(--page-pad);
    bottom: var(--page-pad);
    left: calc(var(--rail-w) + 40px);
    right: 40px;
    max-width: var(--col-w);
    margin-inline: auto;
    border-radius: var(--card-r);
  }
  .swim-trans .st-fish { width: 120px; height: 86px; }
  #app > .ring-trans {
    left: calc(var(--rail-w) + 40px);
    right: 40px;
    max-width: var(--col-w);
    margin-inline: auto;
  }

  /* ---------- slim scrollbars that stay inside the card's rounded corners ---------- */
  #app * { scrollbar-width: thin; scrollbar-color: rgba(12, 62, 92, 0.28) transparent; }
  #app *::-webkit-scrollbar { width: 10px; }
  #app *::-webkit-scrollbar-track { background: transparent; margin: 8px 0 30px; }
  #app *::-webkit-scrollbar-thumb {
    background: rgba(var(--sea-ink), 0.18);
    border-radius: 8px;
    border: 3px solid transparent;
    background-clip: padding-box;
  }
  #app *::-webkit-scrollbar-thumb:hover { background-color: rgba(var(--sea-ink), 0.32); }
}

/* wider screens: give the column more room to breathe */
@media (min-width: 1400px) {
  :root { --col-w: 720px; --page-pad: 34px; }
}
@media (min-width: 1750px) {
  :root { --col-w: 780px; }
}

@media (prefers-reduced-motion: reduce) {
  .sea-ray, .sea-fish, .sea-bub, .sea-kelp .blade { animation: none !important; }
  .sea-bub { opacity: 0.35; }
  .sea-fish { translate: 30vw 0; }
}
