/* Breathe the Square: one cedar deck over a misty lake, a caption of still water along the bottom. */

:root {
  --status: max(var(--ac-status-h, 0px), 60px);
  --rim: color-mix(in srgb, var(--ak-ink) 72%, var(--ak-accent));
  --gold: var(--ak-accent-2);
  --pill-line: color-mix(in srgb, var(--ak-accent-2) 55%, var(--ak-ink));
  --edge-l: max(12px, env(safe-area-inset-left));
  --edge-r: max(12px, env(safe-area-inset-right));
}

[hidden] { display: none !important; }

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer, var(--ak-bg-art));
  background-size: cover;
  background-position: center bottom;
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  font-size: 18px;
  -webkit-tap-highlight-color: transparent;
}

/* The painted lake shows at the sky and the shore; the middle, where words sit, keeps the washed page. */
.lake {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(color-mix(in srgb, var(--ak-bg) 30%, transparent), color-mix(in srgb, var(--ak-bg) 30%, transparent)),
    url("./art/dawn-lake.jpg");
  background-size: cover;
  background-position: center bottom;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, transparent 24%, transparent 60%, #000 88%);
  mask-image: linear-gradient(to bottom, #000 0%, transparent 24%, transparent 60%, #000 88%);
}

.mark {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: var(--edge-l);
  z-index: 31;
  width: auto;
  height: 48px;
  pointer-events: none;
}

.close {
  position: fixed;
  top: calc(var(--status) + 6px);
  right: var(--edge-r);
  z-index: 33;
  min-width: 72px;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font: 400 18px/1 var(--ak-font-body);
  letter-spacing: 0.06em;
  cursor: pointer;
  touch-action: manipulation;
}

/* Music is a quiet text label like Close, not another pill. */
.pill.music {
  --h: 48px;
  position: fixed;
  top: calc(var(--status) + 6px);
  left: var(--edge-l);
  z-index: 31;
  outline: 0;
  font-weight: 400;
  letter-spacing: 0.06em;
}

/*
 * While breathing, the square is the one thing to look at: Pause is the plan's soft sand pill with no
 * hard edge, and the painted logo steps back. Everything stays where it is and works as before.
 */
.room[data-mode="session"] #go {
  border-image: none;
  outline: 0;
  background: color-mix(in srgb, var(--gold) 34%, var(--ak-surface));
  box-shadow: 0 2px 14px color-mix(in srgb, var(--gold) 30%, transparent);
  font-weight: 400;
}

.mark { transition: opacity 1200ms ease-in-out; }
body:has(.room[data-mode="session"]) .mark { opacity: 0.45; }

#hint[aria-pressed="true"] { text-decoration-color: var(--ak-ink); text-decoration-thickness: 2px; }

.close:focus-visible,
.pill:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 3px;
}

/* Before the opening has been through, only the misty lake shows behind it. */
body.opening .room,
body.opening #activity-chrome-status,
body.opening .pill.music,
body.opening .close,
body.opening .mark { visibility: hidden; }

/* Upright: the scene on top, its word right under it, the tools below, the caption along the bottom like still water. */
.room {
  position: relative;
  box-sizing: border-box;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto auto;
  grid-template-areas: "stage" "word" "tools" "caption";
  width: 100%;
  max-width: 720px;
  height: 100dvh;
  margin: 0 auto;
  padding-top: calc(var(--status) + 60px);
  touch-action: manipulation;
}

.stage {
  grid-area: stage;
  container-type: size;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 4px var(--edge-r) 4px var(--edge-l);
}

.deck-box {
  position: relative;
  width: min(84cqmin, 80dvw, 58dvh, 560px);
  aspect-ratio: 384 / 378;
}

.deck-fade {
  position: absolute;
  inset: 0;
  opacity: 0.92;
  transition: opacity var(--fade-in, 1200ms) ease-in-out;
}

.room:not([data-mode="idle"]) .deck-fade {
  --fade-in: 3000ms;
  opacity: 1;
}

/* Still by default: the deck deepens on the full breath and pales on the empty one, in place. */
.deck {
  position: absolute;
  inset: 0;
  transform: scale(0.8);
  filter: var(--tone, none);
  transition: filter var(--dur, 1200ms) ease-in-out;
}

.stage[data-size="big"] .deck { --tone: saturate(1.18) brightness(0.95); }
.stage[data-size="small"] .deck { --tone: saturate(0.78) brightness(1.08) opacity(0.82); }

/* The breath itself: one large soft shape of pale sand under the deck, swelling and settling with it. */
.halo {
  position: absolute;
  inset: -9%;
  border-radius: 30%;
  background: color-mix(in srgb, var(--ak-accent-2) 42%, var(--ak-surface));
  opacity: 0.55;
  transition: opacity var(--dur, 1200ms) ease-in-out;
}

.stage[data-size="big"] .halo { opacity: 1; }

.planks,
.frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  user-select: none;
}

.rim {
  fill: none;
  stroke: var(--rim);
  stroke-width: 17;
}

.side {
  fill: none;
  stroke: var(--gold);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 1 1;
  stroke-dashoffset: 0;
  opacity: 0;
  transition: opacity 1400ms ease-in-out;
}

.side.lit { opacity: 1; }

/* The heron is folded paper, side-on; one picture holds both poses, head up and head down. */
.heron {
  position: absolute;
  top: 5%;
  right: 8%;
  width: 27%;
  aspect-ratio: 192 / 321;
}

.pose {
  position: absolute;
  inset: 0;
  background-image: url("./art/paper-heron.png");
  background-repeat: no-repeat;
  background-size: 200% 100%;
  transition: opacity var(--head, 1200ms) ease-in-out;
}

.pose-up { background-position: 0 0; clip-path: inset(0 2% 0 0); }
.pose-down { background-position: 100% 0; }
.stage[data-head="up"] .pose-down,
.stage[data-head="down"] .pose-up { opacity: 0; }

.ring {
  position: absolute;
  inset: -10px;
  border: 3px solid var(--ak-accent);
  border-radius: 20%;
  pointer-events: none;
}

.tools > * { flex-shrink: 0; }

.tools {
  grid-area: tools;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px var(--edge-r) 12px var(--edge-l);
}

.word {
  grid-area: word;
  display: grid;
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 4px var(--edge-r) 0 var(--edge-l);
  line-height: 1.2;
  text-align: center;
  font-family: var(--ak-font-display);
  font-size: 32px;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: lowercase;
}

.room[data-mode="idle"] .word { font-size: 22px; letter-spacing: 0.08em; }

/*
 * The old words fade right out before the new ones fade in, so two lines never sit on top of each
 * other. Both share one grid cell, so the box is as tall as its words and nothing below is covered.
 */
.w,
.c {
  grid-area: 1 / 1;
  align-self: center;
  opacity: 0;
  transition: opacity 600ms ease-in-out;
}

.w.is-on,
.c.is-on {
  opacity: 1;
  transition: opacity 600ms ease-in-out 600ms;
}

.aside {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 64px;
}

/* While the deck waits there is often nothing under the word, so the square takes that room. */
.room[data-mode="idle"] .aside { min-height: 0; }

.guide {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  max-width: 24em;
  margin: 0;
  padding: 6px 20px;
  border: 2px solid var(--ak-accent);
  border-radius: 26px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 18px;
  line-height: 1.35;
  text-align: center;
}

.arrow {
  width: 24px;
  height: 14px;
  fill: none;
  stroke: var(--ak-accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.guide[data-point="up"] .arrow-down,
.guide[data-point="down"] .arrow-up { display: none; }

/* The hint the player asked for is a warm gold card, unlike the guide's outline, so asking visibly answers. */
.hintbox {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  max-width: 24em;
  margin: 0;
  padding: 8px 22px 10px;
  border-radius: 26px;
  background: color-mix(in srgb, var(--gold) 55%, var(--ak-surface));
  box-shadow: 0 0 0 2px var(--pill-line);
  color: var(--ak-ink);
  font-size: 17px;
  line-height: 1.35;
  text-align: center;
}

.hint-cue {
  font-family: var(--ak-font-display);
  font-size: 22px;
  letter-spacing: 0.04em;
  text-transform: lowercase;
}

/* While the hint is open, the gold side it names stands out on the deck. */
.room[data-hint="on"] .side.lit { stroke-width: 20; }

.about {
  margin: 0;
  padding: 4px 18px;
  color: var(--ak-ink-muted);
  font-size: 18px;
  line-height: 1.35;
  text-align: center;
  text-transform: lowercase;
}

.room[data-mode="idle"] .about,
.room[data-mode="ending"] .about { display: none; }

/*
 * With the ending card up, the play screen steps back so nothing shows through around the circle.
 * Only the caption stays, above the card's wash, holding the last line of the story.
 */
.room > *,
.pill.music {
  transition: opacity 700ms ease-in-out, visibility 0s;
}

body.behind .room > :not(.caption),
body.behind .pill.music {
  visibility: hidden;
  opacity: 0;
  transition: opacity 700ms ease-in-out, visibility 0s 700ms;
}

body.behind .caption { z-index: 33; }

/* The status bar and logo would show faintly through the ending's wash and cross its circle; they step back too. */
body.behind #activity-chrome-status,
body.behind .mark {
  visibility: hidden;
  opacity: 0;
  transition: opacity 700ms ease-in-out, visibility 0s 700ms;
}

/* The ending's lines in full ink and a readable size, a little air between the kind line and what was kept. */
html body #activity-chrome-ending#activity-chrome-ending.site-insighfulness .ac-lines {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--ak-ink);
  font-size: 17px;
}

/* During the one-second beat before the card, only the settled deck, its word and the caption remain. */
/* The moment a session ends, the controls and the time line go; the settling square, the kind line and what was kept remain. */
.room[data-mode="ending"] .acts { display: none; }

.closing {
  max-width: 24em;
  margin: 0;
  padding: 8px 20px;
  border-radius: 26px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 18px;
  line-height: 1.4;
  text-align: center;
}

.nudge {
  margin: 0;
  padding: 8px 20px;
  border-radius: 999px;
  background: var(--ak-bg);
  color: var(--ak-ink);
  font-size: 18px;
}

.acts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

/* Changing the practice is a quiet word, not another pill beside Begin. */
.quiet {
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ak-ink);
  font: 400 18px/1 var(--ak-font-body);
  letter-spacing: 0.04em;
  text-decoration: underline;
  text-decoration-color: var(--ak-outline);
  text-underline-offset: 6px;
  text-transform: lowercase;
  cursor: pointer;
  touch-action: manipulation;
}

.quiet:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 3px;
}

.choices {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* The choices belong to the waiting deck; once breathing starts the deck takes their room. */
.room:not([data-mode="idle"]) .choices { display: none; }

.kept {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 2px 0 0;
  padding: 4px 18px;
  border-radius: 24px;
  background: var(--ak-bg);
  color: var(--ak-ink);
  font-size: 18px;
  line-height: 1.35;
  text-align: center;
  text-transform: lowercase;
}

#where { color: var(--ak-ink-muted); }

/* A pill is soft sand: outlined when it waits, the painted gold pill when it is chosen or leads. */
.pill {
  --h: 52px;
  position: relative;
  box-sizing: border-box;
  min-width: 48px;
  height: var(--h);
  margin: 0;
  padding: 0 4px;
  border: solid transparent;
  border-width: 0 calc(var(--h) / 2);
  border-radius: 999px;
  background: var(--ak-surface);
  outline: 2px solid var(--pill-line);
  outline-offset: -2px;
  color: var(--ak-ink);
  font: 600 18px/1 var(--ak-font-body);
  letter-spacing: 0.03em;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
}

.pill.solid,
.pill[aria-pressed="true"] {
  outline: 0;
  background: transparent;
  border-image: url("./art/breath-pill.png") 0 87 fill / 0 calc(var(--h) / 2) / 0 stretch;
}

.pill.big {
  --h: 60px;
  min-width: 168px;
  font-size: 20px;
}

.pill:active { filter: brightness(0.96); }

.pill.ringed::after {
  content: "";
  position: absolute;
  inset: -9px calc(var(--h) / -2 - 9px);
  border: 3px solid var(--ak-accent);
  border-radius: 999px;
  pointer-events: none;
}

.caption {
  grid-area: caption;
  position: relative;
  display: grid;
  min-height: calc(3 * 1.4em + 26px);
  margin: 0;
  padding: 13px max(20px, env(safe-area-inset-right)) calc(13px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  border-radius: 32px 32px 0 0;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 18px;
  line-height: 1.4;
  text-align: center;
}

.room[data-mode="idle"] .caption { min-height: calc(2 * 1.4em + 26px); }

/*
 * On a short upright phone the square keeps its room: the hint says just the breath to take, it stands
 * in for the time line while open, and the caption holds two lines.
 */
@media (orientation: portrait) and (max-height: 720px) {
  .hint-how { display: none; }
  .room[data-hint="on"] .about { display: none; }
  .room[data-mode] .caption { min-height: calc(2 * 1.4em + 26px); }
}

/*
 * Sideways: the square takes the whole height of the left half, so it stays the biggest thing on
 * screen; its word and the tools sit together, centred, on the right; the caption is one slim strip
 * of still water along the bottom.
 */
@media (orientation: landscape) {
  .room {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto auto minmax(0, 1fr) auto;
    grid-template-areas: "stage ." "stage word" "stage tools" "stage ." "caption caption";
    max-width: 1180px;
    padding-top: calc(var(--status) + 4px);
    padding-left: env(safe-area-inset-left);
  }

  .close {
    top: max(12px, env(safe-area-inset-top));
    right: calc(72px + env(safe-area-inset-right));
  }

  .pill.music {
    top: max(12px, env(safe-area-inset-top));
    left: calc(72px + env(safe-area-inset-left));
  }

  .tools {
    gap: 6px;
    min-height: 0;
    padding: 4px var(--edge-r) 6px 8px;
  }

  .stage { padding: 4px 8px 6px var(--edge-l); }
  .deck-box { width: min(96cqmin, 560px); }

  .aside { min-height: 0; }
  .word { min-height: 38px; padding-top: 0; }
  .kept { padding: 2px 18px; }

  .guide {
    flex-direction: row;
    gap: 10px;
    padding: 4px 18px;
    text-align: left;
  }

  /* The deck is to the left now, so the guide points there. */
  .guide[data-point="up"] .arrow-up { transform: rotate(-90deg); }

  .pill { --h: 48px; }
  .pill.big { --h: 56px; }

  .room[data-mode] .caption {
    min-height: 1.4em;
    padding: 6px max(20px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    border-radius: 24px 24px 0 0;
    font-size: 17px;
  }

  /* Sideways, the ending's buttons sit at the bottom middle, so the caption keeps to the corner. */
  body.behind .caption {
    position: fixed;
    bottom: 0;
    left: 0;
    box-sizing: border-box;
    width: min(46vw, calc(50vw - 190px));
    border-radius: 0 32px 0 0;
  }
}

/* The shortest sideways phones: while the hint is open it stands in for the time line. */
@media (orientation: landscape) and (max-height: 400px) {
  .room[data-hint="on"] .about { display: none; }
}

@media (orientation: landscape) and (min-height: 600px) {
  .tools { gap: 10px; }
  .aside { min-height: 64px; }
}

/* Moving, only for those who welcome motion: the deck grows and shrinks, the gold sweeps, the ring breathes. */
@media (prefers-reduced-motion: no-preference) {
  :root:not(.ac-still) .deck {
    filter: none;
    transform: scale(var(--k, 0.55));
    transition: transform var(--dur, 1200ms) cubic-bezier(0.45, 0, 0.55, 1);
  }

  :root:not(.ac-still) .stage[data-size="big"] .deck { --k: 1; }

  :root:not(.ac-still) .side {
    transition: opacity 1400ms ease-in-out, stroke-dashoffset var(--sweep, 1600ms) cubic-bezier(0.4, 0, 0.2, 1);
  }

  :root:not(.ac-still) .side.armed {
    stroke-dashoffset: var(--from, 1);
    transition: none;
  }

  :root:not(.ac-still) .ring,
  :root:not(.ac-still) .pill.ringed::after {
    animation: ring-breathe 1800ms ease-in-out infinite alternate;
  }

  @keyframes ring-breathe {
    from { opacity: 0.3; }
    to { opacity: 1; }
  }
}

/*
 * The opening screens come from start.js. On a phone held sideways its circle sits above everything,
 * so the words fall below the fold and its pinned Begin button floats over them. Sideways, the circle
 * goes to the left, the words and buttons to the right, and Begin follows the words instead of
 * covering them. Nothing here changes what those screens say or do.
 */
@media (orientation: landscape) and (max-height: 500px) {
  html body #activity-start#activity-start.site-insighfulness .ak-sheet,
  html body #activity-start#activity-start.site-insighfulness .ak-scene {
    display: grid;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    align-items: center;
    column-gap: 32px;
    row-gap: 10px;
    width: min(100%, 920px);
    min-height: calc(100dvh - 32px);
    margin: 0 auto;
    padding-right: max(16px, env(safe-area-inset-right));
    padding-left: max(16px, env(safe-area-inset-left));
    box-sizing: border-box;
  }

  html body #activity-start#activity-start.site-insighfulness .ak-sheet > .ak-head,
  html body #activity-start#activity-start.site-insighfulness .ak-scene > .ak-head {
    grid-column: 1;
    grid-row: 1 / span 8;
    align-self: center;
    justify-self: center;
    margin: 0;
  }

  html body #activity-start#activity-start.site-insighfulness .ak-sheet > :not(.ak-head),
  html body #activity-start#activity-start.site-insighfulness .ak-scene > :not(.ak-head) {
    grid-column: 2;
    justify-self: center;
    margin-top: 0;
    margin-bottom: 0;
  }

  html body #activity-start#activity-start.site-insighfulness .ak-go {
    position: static;
    margin: 6px 0 0;
  }

  html body #activity-start#activity-start.site-insighfulness .ak-howto { gap: 12px; }

  /* The instructions are longer than a sideways phone: Begin stays under the circle, the reading scrolls. */
  html body #activity-start#activity-start.site-insighfulness.is-instructions .ak-sheet {
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: calc(100dvh - 40px);
    min-height: 0;
  }

  html body #activity-start#activity-start.site-insighfulness.is-instructions .ak-sheet > .ak-head { grid-row: 1 / span 2; }
  html body #activity-start#activity-start.site-insighfulness.is-instructions .ak-sheet > .ak-go { grid-column: 1; grid-row: 3; }
  html body #activity-start#activity-start.site-insighfulness.is-instructions .ak-sheet > .ak-jump { grid-column: 2; grid-row: 3; align-self: center; }
  html body #activity-start#activity-start.site-insighfulness.is-instructions .ak-sheet > .ak-first { grid-column: 2; grid-row: 1; }

  html body #activity-start#activity-start.site-insighfulness.is-instructions .ak-sheet > .ak-howto {
    grid-column: 2;
    grid-row: 2;
    align-self: stretch;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 8px;
    border-top: 1px solid var(--ak-outline);
    border-bottom: 1px solid var(--ak-outline);
  }
  html body #activity-start#activity-start.site-insighfulness .ak-body { line-height: 1.5; }

  /*
   * The ending sideways: the circle sits between the story's last line (bottom left) and its buttons,
   * which stand in a column to its right instead of under it, so nothing is cut off or crossed.
   */
  html body #activity-chrome-ending#activity-chrome-ending.site-insighfulness {
    --story-w: min(46vw, calc(50vw - 190px));
    flex-direction: row;
    padding: 16px calc(252px + env(safe-area-inset-right)) 16px calc(var(--story-w) + 16px);
  }

  html body #activity-chrome-ending#activity-chrome-ending.site-insighfulness .ac-card {
    --ac-circle: min(calc(100dvh - 40px), 320px, calc(100vw - var(--story-w) - 290px));
    gap: 8px;
    padding: calc(var(--ac-circle) * 0.12);
  }

  html body #activity-chrome-ending#activity-chrome-ending.site-insighfulness .ac-verdict { font-size: 22px; }
  html body #activity-chrome-ending#activity-chrome-ending.site-insighfulness .ac-lines { font-size: 16px; line-height: 1.4; }

  html body #activity-chrome-ending#activity-chrome-ending.site-insighfulness .ac-actions {
    top: 50%;
    left: calc(100% + 24px);
    flex-direction: column;
    align-items: stretch;
    max-width: 220px;
    translate: 0 -50%;
  }
}

/* The pattern row and quiet tally this page adds to the opening's setup, in that screen's own style. */
#activity-start .bts-tally {
  max-width: 26em;
  margin: 0 auto 10px;
  color: var(--ak-ink);
  font-size: 17px;
  line-height: 1.4;
  text-align: center;
}

#activity-start .bts-tally[hidden] { display: none; }

#activity-start .bts-rhythm {
  margin: 6px 0 0;
  color: var(--ak-ink);
  font-size: 18px;
  letter-spacing: 0.06em;
  text-align: center;
}

/* On the setup screen Begin follows the choices instead of floating over them, in any orientation. */
html body #activity-start#activity-start.site-insighfulness.is-setup .ak-go {
  position: static;
}

/* Upright, the setup circle is smaller so the choices and Begin fit on one screen without scrolling. */
@media (orientation: portrait) {
  html body #activity-start#activity-start.site-insighfulness.is-setup .ak-head {
    width: min(56vw, 240px);
    margin: 24px 0 40px;
  }
}
