/* The Paper theme color. It is the Suyo theme (suyo.css draws its glass
   for both) on a different wall: a sky over five cut-paper hills with soft
   shadows between them, and paper grain over the whole scene.
   theme-suyo.ts builds the scene the first time Paper is chosen;
   theme-boot.ts sets the sky (--suyo-top, --suyo-base, --suyo-deep,
   --suyo-glow), the hills (--hill-1, farthest, to --hill-5) and their
   grain through the day, and the list cards' glass (--paper-card).

   The hills rise highest behind the chat, sit a little lower behind each
   list, and drop lowest under Settings on a desk, moving as the view changes;
   nothing in a view gives up room for them. Replies and cards carry the
   reading: a list's cards are glass just opaque enough to read over any
   hill. Text straight on the wall (a day, a heading, a message's time)
   takes a light chip where it crosses the hills. On a desk the chip's
   color is fixed to the window, clear above the hills; a phone, and any
   iPhone or iPad, paints a fixed background as if it scrolled, so there
   the chip is always on. */

@layer theme {
  :root[data-palette="paper"] {
    --paper-hills-h: 30vh;
    --paper-chip: color-mix(in srgb, var(--suyo-bubble) 84%, transparent);
    /* Paper, drawn in code, every tile mid-grey on average so soft light
       keeps each sheet's color. Tooth: fine bumps lit from the top left.
       Fibre: short ridged strands, one tile running across and one
       running more loosely, so neighboring sheets differ. Cloud: the slow
       unevenness of a pressed sheet. */
    --paper-tooth: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='g' x='0' y='0' width='100%25' height='100%25' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3CfeDiffuseLighting lighting-color='%23ffffff' surfaceScale='1.8' diffuseConstant='0.58'%3E%3CfeDistantLight azimuth='225' elevation='60'/%3E%3C/feDiffuseLighting%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
    --paper-fibre-a: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='480' height='480'%3E%3Cfilter id='f' x='0' y='0' width='100%25' height='100%25' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='turbulence' baseFrequency='0.07 0.32' numOctaves='2' seed='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0.32 0 0 0 0.42 0.32 0 0 0 0.42 0.32 0 0 0 0.42 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
    --paper-fibre-b: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='420' height='420'%3E%3Cfilter id='f' x='0' y='0' width='100%25' height='100%25' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='turbulence' baseFrequency='0.16 0.2' numOctaves='2' seed='9' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0.32 0 0 0 0.42 0.32 0 0 0 0.42 0.32 0 0 0 0.42 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
    --paper-cloud: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='640' height='640'%3E%3Cfilter id='f' x='0' y='0' width='100%25' height='100%25' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.006 0.012' numOctaves='4' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0.36 0 0 0 0.32 0.36 0 0 0 0.32 0.36 0 0 0 0.32 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");

    /* The scene paints the wall. */
    background-image: none;

    /* The scene paints its own sky, so the grain blends with it (the
       scene is its own stacking context): deeper at the top, paler at the
       horizon, warm light behind the hills. */
    & .paper-scene {
      position: fixed;
      inset: 0;
      z-index: -1;
      display: block;
      overflow: hidden;
      background-color: var(--suyo-base);
      background-image:
        radial-gradient(ellipse 80% 46% at var(--suyo-bloom-x, 60%) 100%, var(--suyo-glow) 0%, color-mix(in srgb, var(--suyo-glow) 40%, transparent) 45%, transparent 75%),
        linear-gradient(to bottom in oklab, var(--suyo-deep) 0%, var(--suyo-top) 30%, var(--suyo-base) 82%);
      pointer-events: none;
    }
    & .paper-hills {
      position: absolute;
      bottom: 0;
      left: 50%;
      width: max(100%, 1000px);
      height: var(--paper-hills-h);
      transform: translateX(-50%);
      transition: height 0.5s ease;
    }
    /* Each hill is its own sheet: its color under its own tooth and
       fibre, a little lighter where the cut catches the light and a little
       deeper toward its foot, cut to its torn shape (theme-suyo.ts), with a
       tight shadow and a soft one on the sheet behind. */
    & .paper-hill {
      position: absolute;
      inset: 0;
      filter: drop-shadow(0 -1px 1px color-mix(in srgb, var(--suyo-shade) 30%, transparent)) drop-shadow(0 -4px 10px color-mix(in srgb, var(--suyo-shade) 18%, transparent));
    }
    & .paper-sheet {
      position: absolute;
      inset: 0;
      background-color: var(--paper-color);
      background-image: linear-gradient(to bottom, rgb(255 255 255 / 0.07), transparent 22%, rgb(0 0 0 / 0.05));
      -webkit-mask: var(--paper-shape) 0 0 / 100% 100% no-repeat;
      mask: var(--paper-shape) 0 0 / 100% 100% no-repeat;
      /* The sheet's grain, as strong as theme-boot.ts finds right for its
         color: full on the pale sand, a little less on the deep and
         saturated sheets. */
      &::before {
        content: "";
        position: absolute;
        inset: 0;
        background-image: var(--paper-fibre), var(--paper-tooth), var(--paper-cloud);
        background-size: var(--paper-sizes, 480px 480px, 300px 300px, 640px 640px);
        background-position: var(--paper-offsets, 0 0);
        background-blend-mode: soft-light;
        mix-blend-mode: soft-light;
        opacity: var(--paper-strength, 1);
      }
    }
    & .paper-hill-1 { --paper-color: var(--hill-1); --paper-strength: var(--hill-1-grain, 1); --paper-fibre: var(--paper-fibre-a); }
    & .paper-hill-2 { --paper-color: var(--hill-2); --paper-strength: var(--hill-2-grain, 1); --paper-fibre: var(--paper-fibre-b); --paper-offsets: 90px 30px, 140px 60px, 200px 0; }
    & .paper-hill-3 { --paper-color: var(--hill-3); --paper-strength: var(--hill-3-grain, 1); --paper-fibre: var(--paper-fibre-a); --paper-sizes: 400px 400px, 260px 260px, 640px 640px; --paper-offsets: 40px 110px, 30px 90px, 320px 120px; }
    & .paper-hill-4 { --paper-color: var(--hill-4); --paper-strength: var(--hill-4-grain, 1); --paper-fibre: var(--paper-fibre-b); --paper-sizes: 360px 360px, 340px 340px, 640px 640px; --paper-offsets: 170px 0, 60px 150px, 80px 260px; }
    & .paper-hill-5 { --paper-color: var(--hill-5); --paper-strength: var(--hill-5-grain, 1); --paper-fibre: var(--paper-fibre-a); --paper-sizes: 540px 540px, 320px 320px, 640px 640px; --paper-offsets: 250px 70px, 190px 10px, 400px 40px; }
    & .paper-hill-line {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      overflow: visible;
    }
    & .paper-hill-edge { fill: none; stroke: rgb(255 255 255 / 0.32); stroke-width: 1.1px; }
    /* The sky's sheet: tooth and cloud, no fibre. */
    & .paper-grain {
      position: absolute;
      inset: 0;
      background-image: var(--paper-tooth), var(--paper-cloud);
      background-size: 300px 300px, 640px 640px;
      background-blend-mode: soft-light;
      mix-blend-mode: soft-light;
      opacity: 0.55;
    }

    /* Each view has its own hill height, purely for the look, and the
       hills rise or settle as the view changes: highest behind the chat,
       a little lower behind each list, lowest under Settings on a desk. Nothing in
       a view gives up room for them; its cards carry the reading. */
    &:has(#view-feed:not([hidden])) { --paper-hills-h: 31vh; }
    &:has(#view-todo:not([hidden])) { --paper-hills-h: 28vh; }
    &:has(#view-ideas:not([hidden])) { --paper-hills-h: 33vh; }
    &:has(#view-goals:not([hidden])) { --paper-hills-h: 26vh; }
    &:has(#view-artifacts:not([hidden])) { --paper-hills-h: 30vh; }
    &:has(#view-health:not([hidden])) { --paper-hills-h: 25vh; }
    &:has(#view-agents:not([hidden]), body[data-signin], body[data-first-run]) { --paper-hills-h: 36vh; }
    @media (max-width: 719.98px) {
      &:has(#view-feed:not([hidden]), #view-todo:not([hidden]), #view-ideas:not([hidden]), #view-goals:not([hidden]), #view-artifacts:not([hidden]), #view-health:not([hidden])) { --paper-hills-h: 32vh; }
      &:has(#view-agents:not([hidden]), body[data-signin], body[data-first-run]) { --paper-hills-h: 40vh; }
    }
    /* On a phone Settings covers the whole screen with an opaque sheet,
       so the hills stay where they are under it. */
    @media (min-width: 720px) {
      &:has(#settings-overlay:not([hidden])) { --paper-hills-h: 20vh; }
    }
    @media (prefers-reduced-motion: reduce) {
      & .paper-hills { transition: none; }
    }
    /* A phone draws a lighter scene: each sheet without its fibre tile or
       its soft shadow, and its tooth and cloud at one size, which cost
       least to redraw as a list scrolls or the hills move. */
    @media (max-width: 719.98px) {
      & .paper-hill { filter: drop-shadow(0 -1px 1px color-mix(in srgb, var(--suyo-shade) 30%, transparent)); }
      & .paper-sheet::before {
        background-image: var(--paper-tooth), var(--paper-cloud);
        background-size: 300px 300px, 640px 640px;
      }
    }

    /* A list's cards and rows are glass over the hills, as the replies
       are in the chat: as clear as their text allows over the deepest
       hill (--paper-card), blurring what is under them; an open fold's
       rows too. A chosen Feed post keeps its lighter fill. */
    section.view :is(.card, .todo-card, .text-card, .feed-item, .collection-new, .ideas-item, .goal-row, .goal-open, .artifact-open, .artifact-card, .drawer .drawer-rows:not(:empty)) {
      background: var(--paper-card);
      -webkit-backdrop-filter: blur(18px) saturate(1.25);
      backdrop-filter: blur(18px) saturate(1.25);
    }
    section.view .feed-item[data-feed-target] { background: var(--suyo-hi); }
    /* A considered row in Todo sits on a card of its own. */
    section.view .todo-candidate {
      border-radius: 16px;
      background: var(--paper-card);
      -webkit-backdrop-filter: blur(18px) saturate(1.25);
      backdrop-filter: blur(18px) saturate(1.25);
    }

    /* Text straight on the wall takes a light chip where it crosses the
       hills: in a list (a day, a heading, a fold, an empty state), a
       message's time, the chat's day, and on a desk the rail's icons. The
       chip's color is fixed to the window, clear above the hills and solid
       from 16px into them. */
    section.view :is(.section-heading, .todo-heading, .fold, .todo-candidate-group, .status-line, .collection-empty, .collection-end, .health-heading, .usage-empty) {
      width: fit-content;
      border-radius: 999px;
    }
    section.view :is(.section-heading, .todo-heading, .todo-candidate-group, .status-line, .fold, .health-heading, .usage-empty) { margin-inline: -10px; padding-inline: 10px; }
    section.view .fold { width: max-content; }
    .chat-message-meta > span {
      margin: 0 -8px;
      padding: 1px 8px;
      border-radius: 999px;
    }
    .chat-day {
      padding: 1px 10px;
      border-radius: 999px;
    }
    section.view :is(.section-heading, .todo-heading, .fold, .todo-candidate-group, .status-line, .collection-empty, .collection-end, .health-heading, .usage-empty),
    .chat-message-meta > span,
    .chat-day {
      background: linear-gradient(to bottom, transparent calc(100vh - var(--paper-hills-h) - 8px), var(--paper-chip) calc(100vh - var(--paper-hills-h) + 16px)) fixed;
    }
    @media (min-width: 720px) {
      .nav :is(a, .nav-more):not([aria-current="page"]) {
        background-image: linear-gradient(to bottom, transparent calc(100vh - var(--paper-hills-h) - 8px), var(--paper-chip) calc(100vh - var(--paper-hills-h) + 16px));
        background-attachment: fixed;
      }
    }
    /* A phone, and an iPhone or iPad at any width, shows the chip
       wherever the text is; the line under a phone's composer sits on the
       hills too, so it takes the same chip. */
    @media (max-width: 719.98px) {
      section.view :is(.section-heading, .todo-heading, .fold, .todo-candidate-group, .status-line, .collection-empty, .collection-end, .health-heading, .usage-empty),
      .chat-message-meta > span,
      .chat-day { background: var(--paper-chip); }
      .composer-reason {
        padding: 2px 10px;
        border-radius: 14px;
        background: var(--paper-chip);
      }
    }
    @supports (-webkit-touch-callout: none) {
      section.view :is(.section-heading, .todo-heading, .fold, .todo-candidate-group, .status-line, .collection-empty, .collection-end, .health-heading, .usage-empty),
      .chat-message-meta > span,
      .chat-day { background: var(--paper-chip); }
      .nav :is(a, .nav-more):not([aria-current="page"]) { background-image: linear-gradient(var(--paper-chip), var(--paper-chip)); }
    }

    /* What a page an agent built gets for its cards. */
    --frame-paper: var(--paper-card);

    /* The person's own messages: frosted rose glass over the hills. */
    .chat-message-user .chat-message-text {
      -webkit-backdrop-filter: blur(18px) saturate(1.3);
      backdrop-filter: blur(18px) saturate(1.3);
    }

    /* Reduced transparency: theme-boot.ts paints the cards and the
       person's glass opaque, the chip is the replies' fill itself, and
       nothing blurs. */
    @media (prefers-reduced-transparency: reduce) {
      --paper-chip: var(--suyo-bubble);
      section.view :is(.card, .todo-card, .text-card, .feed-item, .collection-new, .ideas-item, .todo-candidate, .goal-row, .goal-open, .artifact-open, .artifact-card, .drawer .drawer-rows),
      .chat-message-user .chat-message-text {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
      }
    }
  }

  /* The scene (theme-suyo.ts) belongs to the Paper look. */
  .paper-scene { display: none; }
}
