/* Second Hand Breath: moss and stone, made as a poster. One huge flat watch face, one huge number,
   the tools on a flat stone band along the bottom edge (the right edge when the phone turns). */

:root {
  --sage-pale: color-mix(in srgb, var(--ak-accent) 30%, var(--ak-surface));
  --stone: var(--ak-accent-2);
  --breath-ease: cubic-bezier(0.45, 0, 0.55, 1);
  --slow: 600ms;
  --settle: 1600ms;
  --edge: 12px;
  --tap: 48px;
}

* { box-sizing: border-box; }

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;
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  font-size: 18px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

button {
  margin: 0;
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

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

[hidden] { display: none !important; }

/* The painted scene's own stones and moss, cropped from the backdrop and set at the corners. */
.deco {
  position: fixed;
  z-index: 0;
  pointer-events: none;
  background-image: url("art/stone-floor.jpg");
  background-repeat: no-repeat;
}

.crescent {
  top: 0;
  left: 0;
  width: min(34vw, 24dvh, 260px);
  aspect-ratio: 250 / 195;
  background-size: 307.2% auto;
  background-position: 0% 0%;
  -webkit-mask-image: radial-gradient(ellipse 100% 100% at 0% 0%, #000 70%, transparent 100%);
  mask-image: radial-gradient(ellipse 100% 100% at 0% 0%, #000 70%, transparent 100%);
}

.stone { bottom: calc(var(--band-h, 140px) - 34px); }

.stone-left {
  left: 0;
  width: min(30vw, 22dvh, 220px);
  aspect-ratio: 1;
  background-size: 333.9% auto;
  background-position: 0% 88.8%;
  -webkit-mask-image: radial-gradient(ellipse 100% 100% at 0% 100%, #000 72%, transparent 100%);
  mask-image: radial-gradient(ellipse 100% 100% at 0% 100%, #000 72%, transparent 100%);
}

.stone-right {
  right: 0;
  width: min(22vw, 17dvh, 160px);
  aspect-ratio: 148 / 165;
  background-size: 518.9% auto;
  background-position: 100% 89.6%;
  -webkit-mask-image: radial-gradient(ellipse 100% 100% at 100% 100%, #000 72%, transparent 100%);
  mask-image: radial-gradient(ellipse 100% 100% at 100% 100%, #000 72%, transparent 100%);
}

/* Close: always there, top left, lower case. start.js keeps the top right for its help button. */
.close {
  position: fixed;
  top: max(var(--edge), env(safe-area-inset-top));
  left: max(var(--edge), env(safe-area-inset-left));
  z-index: 33;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 10px;
  border-radius: 999px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 18px;
  letter-spacing: 0.04em;
}

.close:active { background: var(--ak-choice-bg); }

/* The play area: the face above, the words and tools below. */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--ac-status-h, 60px) + 2px) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  touch-action: manipulation;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
}

.logo {
  flex: none;
  height: clamp(32px, 5.5dvh, 56px);
  width: auto;
  max-width: 60%;
  object-fit: contain;
}

.face-box {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
}

.face {
  --size: min(84cqw, 96cqh);
  position: relative;
  width: var(--size);
  aspect-ratio: 1;
  transform: scale(0.82);
  transform-origin: 50% 50%;
}

.face-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
}

/* Less motion: the circle keeps its size and lightens on the in-breath, deepens on the out-breath. */
.face-tone {
  position: absolute;
  inset: 3%;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}

.face-lift { background: var(--ak-surface); }
.face-deep { background: var(--ak-accent); }

.ticks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.ticks line {
  stroke: var(--ak-surface);
  stroke-width: 2.8;
  stroke-linecap: round;
  opacity: 0;
  transition: opacity var(--slow) ease-in-out;
}

.ticks line.is-lit { opacity: 1; }

/* The second hand's trail: the rim the dot has already gone round this breath, cream on the deep rim. */
.sweep {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  rotate: -90deg;
  pointer-events: none;
}

.sweep circle {
  fill: none;
  stroke: var(--ak-surface);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-dasharray: 0 100;
  opacity: 0.9;
}

.is-still .sweep,
.app:not([data-mode="breathing"]) .sweep { display: none; }

/* One minute mark per session kept, between the ticks; a new one fades in. */
.marks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.marks circle {
  fill: var(--ak-accent);
  opacity: 0;
  transition: opacity var(--settle) ease-in-out;
}

.marks circle.is-on { opacity: 1; }

.hand {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
}

.rim-dot {
  position: absolute;
  top: 2.4%;
  left: 50%;
  width: 10%;
  aspect-ratio: 1;
  translate: -50% -50%;
  user-select: none;
}

.is-still .hand { display: none; }

/* The one poster number: the breath, counting up, part of the picture. */
.count {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--ak-accent);
  font-family: var(--ak-font-display);
  font-size: calc(min(84cqw, 96cqh) * 0.44);
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: lining-nums;
  letter-spacing: -0.02em;
  pointer-events: none;
}

/* The words under the face, then the band. */
.side {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.words {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 4px 16px 6px;
  text-align: center;
}

.phase {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 46px;
  margin: 0;
  place-items: center;
  color: var(--ak-accent);
  font-family: var(--ak-font-display);
  font-size: 36px;
  font-weight: 500;
  line-height: 1.2;
}

.phase span {
  grid-area: 1 / 1;
  transition: opacity var(--slow) ease-in-out;
}

.phase span.is-out { opacity: 0; }

.phase.is-quiet {
  color: var(--ak-ink-muted);
  font-family: var(--ak-font-body);
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.act {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 56px;
}

.breathe {
  min-width: 200px;
  min-height: 56px;
  padding: 0 36px;
  border-radius: 999px;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.breathe:active { background: var(--ak-btn-active); }

.soft-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 22px;
  border-radius: 999px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 18px;
  letter-spacing: 0.04em;
}

.soft-btn:active { background: var(--ak-choice-bg); }
.hint { color: var(--ak-ink-muted); }

.guide {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 24em;
  margin: 2px 0;
  padding: 10px 18px;
  border: 2px solid var(--ak-accent);
  border-radius: 28px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  text-align: left;
}

.guide-arrow {
  flex: none;
  width: 28px;
  height: 28px;
  color: var(--ak-accent);
}

.guide-text {
  margin: 0;
  font-size: 19px;
  line-height: 1.35;
}

.guide-ring {
  position: fixed;
  z-index: 20;
  border: 3px solid var(--ak-accent);
  border-radius: 999px;
  pointer-events: none;
}

.session {
  margin: 0;
  color: var(--ak-ink-muted);
  font-size: 18px;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
}

.session:empty { display: none; }

.note,
.kept {
  margin: 0;
  color: var(--ak-ink-muted);
  font-size: 18px;
  line-height: 1.35;
  transition: opacity var(--slow) ease-in-out;
}

.note:empty { display: none; }

/* While breathing, the circle and the cue have the room: where saves go is said before and after. */
.app[data-mode="breathing"] .kept { display: none; }
.note.is-faded { opacity: 0; }

.kept {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px 12px;
  text-align: center;
}

/* A small settled mark when a save lands. */
.kept-mark {
  width: 10px;
  height: 10px;
  border: 2px solid var(--ak-accent);
  border-radius: 50%;
  opacity: 0;
  transition: opacity var(--slow) ease-in-out, background-color var(--slow) ease-in-out;
}

.kept.is-saved .kept-mark {
  opacity: 1;
  background: var(--ak-accent);
}

.kept.is-trouble { color: var(--ak-ink); }

/* The stone band: flat, soft-topped, the tools sitting on it in their own fills. */
.band {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px max(12px, env(safe-area-inset-left)) calc(14px + env(safe-area-inset-bottom));
  border-radius: 44px 44px 0 0;
  background: var(--stone);
}

.patterns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 60px;
  padding: 6px 8px;
  border: 2px solid var(--ak-ink-muted);
  border-radius: 999px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  text-align: left;
}

.pill svg {
  flex: none;
  width: 20px;
  height: 20px;
}

.pill .mark { fill: var(--ak-accent-2); stroke: var(--ak-ink-muted); stroke-width: 1.5; }
.pill-words { display: flex; flex-direction: column; line-height: 1.1; }
.pill-name { font-size: 18px; font-weight: 600; }
.pill-nums { font-size: 18px; color: var(--ak-ink-muted); font-variant-numeric: tabular-nums; }

.pill[aria-checked="true"] {
  border-color: var(--ak-accent);
  background: var(--sage-pale);
}

.pill[aria-checked="true"] .mark { fill: var(--ak-surface); stroke: var(--ak-accent); stroke-width: 2.5; }
.pill[aria-checked="true"] .pill-nums { color: var(--ak-ink); }
.pill.is-next { border-style: dashed; border-color: var(--ak-accent); }

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.lengths {
  display: flex;
  gap: 6px;
}

.len,
.try,
.music {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 14px;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 18px;
  white-space: nowrap;
}

.len { padding: 0 12px; }

.len[aria-checked="true"] {
  border-color: var(--ak-accent);
  background: var(--sage-pale);
  font-weight: 600;
}

.try { color: var(--ak-link); }

.music svg { width: 20px; height: 20px; color: var(--ak-ink-muted); }
.music[aria-pressed="true"] { border-color: var(--ak-accent); background: var(--sage-pale); }
.music[aria-pressed="true"] svg { color: var(--ak-accent); }

/* The ending: the face goes still and pale, the number rises to fill the screen, and the tools step
   back so only the poster and its reason line are left. */
.is-poster .face { opacity: 0.45; }
/* The stone band stays as the poster's floor (the stones rest against it); only its tools step away. */
.is-poster .act,
.is-poster .guide,
.is-poster .note,
.is-poster .kept,
.is-poster .band > * { opacity: 0; visibility: hidden; }

/* Under the ending and the settings sheet, nothing of the play screen's words ghosts through. */
.is-covered .stage,
.is-covered .words,
.is-covered .kept,
.is-covered .band > * { opacity: 0; visibility: hidden; }

.stage,
.words,
.band > * { transition: opacity var(--slow) ease-in-out, visibility var(--slow); }

/* chrome.js's ending, kept in its frame but readable: lines at this site's 18px, a roomier circle. */
#activity-chrome-ending#activity-chrome-ending.site-insighfulness .ac-card { --ac-circle: min(80vmin, 440px); }
#activity-chrome-ending#activity-chrome-ending.site-insighfulness .ac-verdict { font-size: clamp(22px, 3.6vw, 28px); }
#activity-chrome-ending#activity-chrome-ending.site-insighfulness .ac-lines { font-size: 18px; line-height: 1.45; }

.act,
.guide,
.note,
.kept { transition: opacity var(--slow) ease-in-out, visibility var(--slow); }
.is-poster .count { transform: scale(1.75); }
.is-poster .logo { opacity: 0.4; }

.face,
.logo { transition: opacity var(--settle) ease-out; }

@media (prefers-reduced-motion: no-preference) {
  :root:not(.ac-still) .count { transition: transform var(--settle) cubic-bezier(0.22, 1, 0.36, 1); }
  :root:not(.ac-still) .count.is-new { animation: count-in var(--slow) ease-out; }
  :root:not(.ac-still) .guide-ring { animation: ring-breathe 1800ms ease-in-out infinite alternate; }
  :root:not(.ac-still) .guide { animation: guide-in var(--slow) ease-out; }
  :root:not(.ac-still) .app[data-mode="idle"] .breathe { animation: invite 4000ms ease-in-out infinite; }
}

@keyframes count-in { from { opacity: 0.25; } to { opacity: 1; } }
@keyframes ring-breathe { from { scale: 1; opacity: 0.95; } to { scale: 1.06; opacity: 0.55; } }
@keyframes guide-in { from { opacity: 0; translate: 0 6px; } to { opacity: 1; translate: 0 0; } }
@keyframes invite { 0%, 100% { scale: 1; } 50% { scale: 1.04; } }

/* Short phones upright: the words tighten so the face keeps its room. */
@media (orientation: portrait) and (max-height: 700px) {
  .words { gap: 4px; padding-bottom: 8px; }
  .phase { min-height: 40px; font-size: 32px; }
  .band { gap: 8px; padding-top: 12px; }
  .pill { min-height: 54px; }
  /* While the first-visit guide speaks, the two quiet lines step aside so the face keeps its room. */
  .app.is-guided .note,
  .app.is-guided .kept { display: none; }
}

/* Sideways: the face fills the left column with the kept line under it. On the right the words, and
   beside them the stone band as a tall panel with the patterns stacked. The logo rests in the top row,
   between close and the status bar, so it can be larger without taking the face's height. */
@media (orientation: landscape) {
  .app {
    grid-template-rows: minmax(0, 1fr);
    grid-template-columns: minmax(0, 1fr) minmax(400px, 60%);
    column-gap: 12px;
    max-width: 1180px;
  }

  .stage { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }

  .logo {
    position: fixed;
    top: max(var(--edge), env(safe-area-inset-top));
    left: calc(max(var(--edge), env(safe-area-inset-left)) + 72px);
    z-index: 31;
    height: 52px;
    max-width: none;
  }

  .side {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(190px, 1fr);
    column-gap: 12px;
    min-height: 0;
  }

  .words {
    justify-content: center;
    gap: 10px;
    min-height: 0;
    padding: 0 4px 12px;
    overflow-y: auto;
  }

  .band {
    justify-content: center;
    min-height: 0;
    padding: 16px 12px calc(12px + env(safe-area-inset-bottom));
    border-radius: 44px 0 0 0;
    overflow-y: auto;
  }

  .patterns { grid-template-columns: minmax(0, 1fr); }
  .pill { justify-content: flex-start; padding: 4px 16px; }

  .row {
    flex-direction: column;
    align-items: stretch;
  }

  .lengths {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .len { padding: 0 6px; }

  /* The kept line rests under the face, across the left column. */
  .side > .kept {
    position: absolute;
    left: 0;
    bottom: max(6px, env(safe-area-inset-bottom));
    width: calc(100% - max(400px, 60%) - 12px);
    padding: 0 2px;
  }

  #kept-text {
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--ak-bg);
    white-space: nowrap;
  }

  .stone { bottom: 0; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .words { gap: 8px; }
  .act { min-height: 52px; }
  .guide { padding: 8px 14px; }
  .guide-text { font-size: 18px; }
  .band { gap: 8px; padding-top: 14px; }
  .patterns { gap: 6px; }
  .pill { min-height: 52px; }
  /* While the guide speaks, the quiet line steps aside so the column keeps its room. */
  .app.is-guided .note { display: none; }
}

/* The shortest phones sideways: a little less air, never less type. */
@media (orientation: landscape) and (max-height: 380px) {
  .words { gap: 6px; padding-bottom: 2px; }
  .pill { min-height: 50px; }
  .band { gap: 6px; padding-top: 12px; }
}

/* The ending sideways: the circle as tall as the screen allows, its two buttons beside it rather than
   squeezed underneath, so the message and the choices both stay clear. */
@media (orientation: landscape) and (max-height: 500px) {
  #activity-chrome-ending#activity-chrome-ending.site-insighfulness {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 12px max(24px, env(safe-area-inset-right)) 12px max(24px, env(safe-area-inset-left));
  }

  #activity-chrome-ending#activity-chrome-ending.site-insighfulness .ac-card {
    --ac-circle: min(84dvh, 400px);
    margin-right: 230px;
  }

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

/* start.js's duration screen, sideways on a phone: its Begin button is pinned to the bottom of a
   scrolling sheet and floats over the length pills. Here the circle sits beside the choices and
   Begin follows them in the flow, so every pill stays readable and tappable. */
@media (orientation: landscape) and (max-height: 500px) {
  #activity-start#activity-start#activity-start.site-insighfulness.is-setup .ak-sheet {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "head groups" "head go" "head how";
    align-content: center;
    align-items: center;
    column-gap: 40px;
    width: min(100%, 760px);
    min-height: 100%;
    margin: 0 auto;
  }

  #activity-start#activity-start#activity-start.site-insighfulness.is-setup .ak-head {
    grid-area: head;
    width: min(200px, 52dvh);
    margin: 0;
  }

  #activity-start#activity-start#activity-start.site-insighfulness.is-setup .ak-groups { grid-area: groups; }

  #activity-start#activity-start#activity-start.site-insighfulness.is-setup .ak-go {
    grid-area: go;
    position: static;
    margin: 20px auto 0;
  }

  #activity-start#activity-start#activity-start.site-insighfulness.is-setup .ak-how {
    grid-area: how;
    margin: 8px auto 0;
  }
}
