:root {
  --lilac: #E6D7FF;
  --ink: #08415C;
  --paper: #FFFBF4;
  --pink: #F7C3EC;
  --sky: #A9D4F2;
  --mint: #B8EBAC;
  --butter: #F8DC72;
  --coral: #F7A58A;
  --coral-strong: #EF7652;
  --violet: #BCAAF6;
  --aqua: #D3F1EC;
  --plum: #8169C2;
  --bw: 2.5px;
  --sh: 5px 5px 0 var(--ink);
  --r: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Rubik', system-ui, sans-serif;
  color: var(--ink);
  background-color: var(--lilac);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .03 0 0 0 0 .25 0 0 0 0 .36 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px calc(130px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ---------- window ---------- */
.win {
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  border-radius: var(--r);
  box-shadow: var(--sh);
  overflow: hidden;
}
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  background: var(--c, var(--pink));
  border-bottom: var(--bw) solid var(--ink);
  font-weight: 700;
  font-size: 15px;
}
.ctrls { display: flex; gap: 6px; direction: ltr; flex: none; }
.ctrls i {
  width: 15px; height: 15px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  position: relative;
  background: var(--coral);
}
.ctrls .sq { border-radius: 3px; background: var(--pink); }
.ctrls .mn { background: var(--violet); }
.ctrls .x::before, .ctrls .x::after {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 8px; height: 2px; background: var(--ink);
  transform: translate(-50%, -50%) rotate(45deg);
}
.ctrls .x::after { transform: translate(-50%, -50%) rotate(-45deg); }
.ctrls .mn::before {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 7px; height: 2px; background: var(--ink); transform: translate(-50%, -50%);
}

/* ---------- hero ---------- */
.screen {
  position: relative;
  aspect-ratio: 1 / 0.86;
  background:
    radial-gradient(circle at 50% 62%, #fff8 0 34%, transparent 34.5%),
    var(--aqua);
  border-bottom: var(--bw) solid var(--ink);
  overflow: hidden;
}
.screen::before { /* pixel sparkles */
  content: '';
  position: absolute; inset: 0;
  background-image:
    radial-gradient(var(--plum) 0 0), radial-gradient(var(--plum) 0 0),
    radial-gradient(var(--coral-strong) 0 0), radial-gradient(var(--plum) 0 0),
    radial-gradient(var(--coral-strong) 0 0);
  background-size: 6px 6px;
  background-repeat: no-repeat;
  background-position: 12% 18%, 86% 12%, 9% 64%, 92% 58%, 78% 30%;
  opacity: .7;
}
.me {
  position: absolute;
  left: 50%; bottom: -2px;
  width: 78%;
  height: auto;
  transform: translateX(-50%);
  image-rendering: pixelated;
  transition: opacity .8s ease;
}
.me-calm { opacity: 0; }
body.playing .me-calm { opacity: 1; }
body.playing .me-smile { opacity: 0; }
.sticker {
  position: absolute;
  top: 16px; right: 14px;
  padding: 5px 12px;
  background: var(--butter);
  border: var(--bw) solid var(--ink);
  border-radius: 999px;
  box-shadow: 3px 3px 0 var(--ink);
  font-weight: 800;
  font-size: 14px;
  transform: rotate(4deg);
}
.hero-body { padding: 16px 18px 20px; }
h1 {
  margin: 0;
  font-size: clamp(34px, 10vw, 46px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -.5px;
}
.lead { margin: 8px 0 14px; font-size: 17px; }
.hero-body h1 { text-align: right; margin-bottom: 16px; }
.explain-cta { display: flex; gap: 10px; }
.explain-cta .big { flex: 1; flex-direction: column; align-items: flex-start; text-align: right; line-height: 1.25; padding: 10px 16px; }
.cta-t { font-size: 18px; font-weight: 800; }
.cta-s { font-size: 14px; font-weight: 500; }

/* ---------- section label ---------- */
.label {
  margin: 8px 2px -8px;
  font-size: 24px;
  font-weight: 800;
}

/* ---------- situations ---------- */
.sits {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.sit {
  display: flex;
  flex-direction: column;
  text-align: right;
  padding: 0;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.sit:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--ink); }
.sit .bar { font-size: 16px; padding: 8px 11px; }
.sit .bar .ctrls i { width: 12px; height: 12px; }
.sit .bar .ctrls .x::before, .sit .bar .ctrls .x::after { width: 6px; }
.sit-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 11px 12px 12px;
  background: var(--paper);
}
.sit-sub { font-size: 14.5px; line-height: 1.35; flex: 1; }
.sit-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sit-mix { font-size: 12.5px; opacity: .75; }
.play {
  flex: none;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: var(--bw) solid var(--ink);
  border-radius: 50%;
  background: var(--coral-strong);
  box-shadow: 2px 2px 0 var(--ink);
}
.play::before { /* triangle, pointing right like every play button */
  content: '';
  margin-left: 3px;
  border-left: 11px solid var(--paper);
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
}
.is-on .play::before {
  margin: 0;
  width: 11px; height: 12px;
  border: 0;
  border-left: 4px solid var(--paper);
  border-right: 4px solid var(--paper);
}
.sit.is-cur { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--ink); }
.sit.is-cur .sit-sub { font-weight: 500; }

.sit-detail { grid-column: 1 / -1; }
.detail-body { padding: 13px 15px 15px; font-size: 15.5px; line-height: 1.5; }
.sit-detail p { margin: 0; }
.sit-detail .trick {
  margin-top: 10px;
  padding: 8px 11px;
  border: 2px dashed var(--ink);
  border-radius: 10px;
  background: var(--lilac);
  font-weight: 500;
}
.sit-detail[hidden], .sit-detail [hidden] { display: none !important; }

/* breathing (SOS) */
.breath { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 4px 0 14px; }
.breath-ring {
  --s: .5;
  width: 76px; height: 76px; flex: none;
  border: var(--bw) solid var(--ink);
  border-radius: 50%;
  background: var(--pink);
  transform: scale(var(--s));
  box-shadow: 0 0 0 6px var(--paper), 0 0 0 8.5px var(--ink);
}
.breath-word { font-size: 24px; font-weight: 800; min-width: 70px; }

/* ---------- library ---------- */
.rows { list-style: none; margin: 0; padding: 0; background: var(--sky); }
.rows li + li { border-top: var(--bw) solid var(--ink); }
.row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  background: none;
  border: 0;
  text-align: right;
  cursor: pointer;
}
.row-text { flex: 1; min-width: 0; }
.row-name { display: block; font-weight: 700; font-size: 16.5px; }
.row-desc { display: block; font-size: 14px; opacity: .85; }
.row .play { width: 34px; height: 34px; background: var(--pink); box-shadow: none; }
.row .play::before { border-left-color: var(--plum); }
.row.is-cur { background: var(--paper); }
.row.is-on .play::before { border-left-color: var(--plum); border-right-color: var(--plum); }

/* ---------- airpods ---------- */
.tips { margin: 0; padding: 14px 16px 16px; list-style: none; counter-reset: t; display: grid; gap: 14px; }
.tips li {
  counter-increment: t;
  position: relative;
  padding-right: 36px;
  font-size: 15px;
}
.tips li::before {
  content: counter(t);
  position: absolute; right: 0; top: 1px;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: var(--butter);
  font-weight: 800; font-size: 14px;
}
.tips code {
  display: block;
  margin-top: 6px;
  padding: 6px 9px;
  font: 500 12.5px/1.45 ui-monospace, 'SF Mono', Menlo, monospace;
  text-align: left;
  background: var(--aqua);
  border: 2px solid var(--ink);
  border-radius: 8px;
  word-break: break-word;
}

/* ---------- offline ---------- */
.offline-body { padding: 14px 16px 18px; }
.offline-body > p { margin: 0 0 12px; font-size: 16px; }
.a2hs { margin: 16px 0 0; padding: 0; list-style: none; counter-reset: a; display: grid; gap: 10px; }
.a2hs li { counter-increment: a; position: relative; padding-right: 34px; font-size: 15px; }
.a2hs li::before {
  content: counter(a);
  position: absolute; right: 0; top: 0;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border: 2px solid var(--ink); border-radius: 50%;
  background: var(--mint);
  font-weight: 800; font-size: 13px;
}
.a2hs code {
  display: inline-block;
  margin-inline-start: 4px;
  padding: 1px 7px;
  font: 500 12.5px/1.5 ui-monospace, 'SF Mono', Menlo, monospace;
  background: var(--aqua);
  border: 2px solid var(--ink);
  border-radius: 7px;
}
.saved-note { margin: 14px 0 0 !important; font-weight: 700; }
.saved-note + .a2hs { margin-top: 10px; }
#install[hidden], .a2hs[hidden], .saved-note[hidden] { display: none; }
.a2hs .btn.small { min-height: 38px; padding: 6px 14px; font-size: 15px; margin: 6px 0 2px; box-shadow: 2px 2px 0 var(--ink); }
.linkish { display: block; margin-top: 6px; padding: 0; border: 0; background: none; font-size: 13.5px; text-decoration: underline; cursor: pointer; }

/* ---------- explainer sheet ---------- */
.sheet {
  width: 100%;
  max-width: 560px;
  height: 100%;
  max-height: 100%;
  margin: 0 auto;
  padding: 0;
  border: 0;
  background: var(--lilac);
  color: var(--ink);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet::backdrop { background: var(--lilac); }
.sheet-top {
  position: sticky; top: 0; z-index: 1;
  display: flex; justify-content: space-between; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--lilac);
}
.sheet-body { padding: 4px 16px calc(32px + env(safe-area-inset-bottom)); display: grid; gap: 18px; }
#install[data-state="saving"] { opacity: .7; pointer-events: none; }

.btns { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px;
  padding: 10px 18px;
  border: var(--bw) solid var(--ink);
  border-radius: 12px;
  background: var(--violet);
  box-shadow: 3px 3px 0 var(--ink);
  color: var(--ink);
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
  cursor: pointer;
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn.ghost { background: var(--paper); }
.btn.big { min-height: 54px; font-size: 16.5px; padding: 10px 14px; }

/* ---------- footer ---------- */
.foot { text-align: center; font-size: 14.5px; padding: 4px 10px 0; }
.foot p { margin: 0 0 6px; }
.sign { font-weight: 800; font-size: 18px; }

/* ---------- player ---------- */
.player {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(528px, calc(100% - 24px));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  background: var(--mint);
  border: var(--bw) solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--sh);
  z-index: 10;
}
.pp {
  flex: none;
  width: 50px; height: 50px;
  display: grid; place-items: center;
  border: var(--bw) solid var(--ink);
  border-radius: 50%;
  background: var(--coral-strong);
  cursor: pointer;
}
.pp .ico {
  margin-left: 4px;
  border-left: 15px solid var(--paper);
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
}
.player[data-state="playing"] .pp .ico {
  margin: 0;
  width: 15px; height: 17px;
  border: 0;
  border-left: 5px solid var(--paper);
  border-right: 5px solid var(--paper);
}
.player[data-state="loading"] .pp .ico {
  margin: 0;
  width: 22px; height: 22px;
  border: 3px solid var(--paper);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.now { flex: 1; min-width: 0; }
.now-top { display: flex; align-items: center; gap: 7px; }
.now-name { font-weight: 800; font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-sub { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85; }
.eq { display: none; align-items: flex-end; gap: 2px; height: 14px; flex: none; }
.eq i { width: 3px; height: 4px; background: var(--ink); }
.player[data-state="playing"] .eq { display: flex; }
.player[data-state="playing"] .eq i { animation: eq 1.1s steps(4) infinite; }
.eq i:nth-child(2) { animation-delay: -.35s !important; }
.eq i:nth-child(3) { animation-delay: -.7s !important; }
.eq i:nth-child(4) { animation-delay: -.2s !important; }
@keyframes eq { 0%, 100% { height: 4px; } 33% { height: 14px; } 66% { height: 8px; } }

.tone {
  flex: none;
  display: flex;
  border: 2px solid var(--ink);
  border-radius: 10px;
  overflow: hidden;
  background: var(--paper);
}
.tone button {
  padding: 7px 8px;
  border: 0;
  background: none;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
}
.tone button + button { border-right: 2px solid var(--ink); }
.tone button.on { background: var(--ink); color: var(--paper); font-weight: 700; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  width: min(480px, calc(100% - 32px));
  padding: 12px 14px;
  background: var(--butter);
  border: var(--bw) solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 var(--ink);
  font-size: 15px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 11;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- explain page ---------- */
.doc { padding: 18px 18px 22px; font-size: 16.5px; line-height: 1.6; }
.doc h2 { margin: 22px 0 6px; font-size: 20px; font-weight: 800; }
.doc h2:first-child { margin-top: 0; }
.doc p { margin: 0 0 10px; }
.doc ul { margin: 0 0 8px; padding: 0 20px 0 0; }
.doc li { margin-bottom: 6px; }
.doc .hi { background: var(--lilac); padding: 1px 6px; border-radius: 6px; }
.doc .thanks { margin-top: 18px; font-weight: 700; }
.doc .key {
  margin: 4px 0 14px;
  padding: 14px 16px;
  background: var(--pink);
  border: var(--bw) solid var(--ink);
  border-radius: 12px;
  box-shadow: 4px 4px 0 var(--ink);
  font-size: 19px;
  font-weight: 800;
  line-height: 1.4;
}
.src { font-size: 13px; padding: 0 4px; }
.src a { color: var(--ink); }
.back { font-weight: 700; color: var(--ink); }

@media (max-width: 380px) {
  .tone button { padding: 7px 6px; font-size: 12.5px; }
  .sit-sub { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

#debugLog {
  position: fixed; top: env(safe-area-inset-top); left: 0; right: 0; z-index: 30;
  margin: 0; padding: 6px 8px;
  background: #fffbf4ee; border-bottom: 2px solid var(--ink);
  font: 11px/1.35 ui-monospace, Menlo, monospace; direction: ltr; text-align: left;
  white-space: pre-wrap; pointer-events: none;
}
