:root {
  --paper: #f4efe6;
  --paper-soft: #ece6d8;
  --ink: #2a2823;
  --ink-soft: #5a564d;
  --ink-mute: #9b9486;
  --hairline: #d8d1c1;
  --accent: #6b5a3e;
  --focus: rgba(107, 90, 62, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1a1814;
    --paper-soft: #221f1a;
    --ink: #e9e3d4;
    --ink-soft: #b8b1a0;
    --ink-mute: #6f6a5e;
    --hairline: #312d26;
    --accent: #c8b48a;
    --focus: rgba(200, 180, 138, 0.35);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family:
    "Songti SC", "STSong", "Source Han Serif SC", "Noto Serif SC",
    "Songti TC", -apple-system, BlinkMacSystemFont,
    "Iowan Old Style", "Apple Garamond", Baskerville, "Times New Roman",
    "Droid Serif", Times, serif;
  font-size: 17px;
  line-height: 1.75;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
  overflow-wrap: break-word;
  word-break: break-word;
}

html[lang^="en"] body {
  letter-spacing: 0.005em;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

.view {
  width: 100%;
  max-width: 36rem;
  padding:
    max(clamp(1.5rem, 6vw, 4.5rem), env(safe-area-inset-top))
    max(clamp(1.25rem, 5vw, 2rem), env(safe-area-inset-right))
    max(clamp(1.5rem, 5vw, 3rem), env(safe-area-inset-bottom))
    max(clamp(1.25rem, 5vw, 2rem), env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  animation: fade-in 900ms ease-out;
}
.view[hidden] { display: none; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

p { margin: 0 0 1em; }
h1, h2, h3 { margin: 0; font-weight: 500; letter-spacing: 0.08em; }

button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus);
  border-radius: 4px;
}

.quiet { color: var(--ink-mute); }
.small { font-size: 0.86em; line-height: 1.7; }
.meta {
  color: var(--ink-mute);
  font-size: 0.78em;
  letter-spacing: 0.3em;
  margin-bottom: 1.6em;
}
html[lang^="en"] .meta {
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

/* ----- Language toggle ----- */
.lang-toggle {
  position: absolute;
  top: max(clamp(0.5rem, 2vw, 1.2rem), env(safe-area-inset-top));
  right: max(clamp(0.75rem, 3vw, 1.5rem), env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--ink-mute);
  letter-spacing: 0.1em;
  z-index: 2;
}
.lang-toggle button {
  padding: 0.6rem 0.5rem;
  min-width: 2rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-mute);
  transition: color 400ms ease;
}
.lang-toggle button[aria-current="true"] { color: var(--ink); }
@media (hover: hover) {
  .lang-toggle button:hover { color: var(--ink); }
}

/* ----- Home ----- */
.view[data-view="home"] { position: relative; }
.home-header {
  text-align: center;
  margin: clamp(1.5rem, 6vw, 3rem) 0 clamp(2rem, 8vw, 3.5rem);
}
.brand {
  font-size: clamp(3.2rem, 13vw, 5.5rem);
  letter-spacing: 0.3em;
  margin-bottom: 1.2rem;
  font-weight: 400;
  line-height: 1;
}
html[lang^="en"] .brand {
  letter-spacing: 0.04em;
  font-style: italic;
  font-weight: 400;
}
.tagline {
  color: var(--ink-soft);
  font-size: 0.95rem;
  margin: 0 auto;
  max-width: 24em;
  padding: 0 0.5rem;
}
.menu {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-top: 1px solid var(--hairline);
}
.menu-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1.4rem 0.25rem;
  min-height: 56px;
  border-bottom: 1px solid var(--hairline);
  text-align: left;
  width: 100%;
  transition: padding 600ms ease, background 600ms ease;
}
@media (hover: hover) {
  .menu-item:hover {
    padding-left: 0.75rem;
    background: linear-gradient(to right, var(--paper-soft), transparent 70%);
  }
}
.menu-item:active {
  background: var(--paper-soft);
}
.menu-title {
  font-size: 1.2rem;
  letter-spacing: 0.15em;
}
html[lang^="en"] .menu-title { letter-spacing: 0.05em; }
.menu-sub {
  color: var(--ink-mute);
  font-size: 0.88rem;
  text-align: right;
  flex-shrink: 1;
}
.time-note {
  margin: 0 0 1.5rem !important;
  text-align: center;
  font-style: italic;
  letter-spacing: 0.01em;
  opacity: 0.85;
}
.time-note:empty { display: none; }

.home-foot {
  margin-top: auto;
  padding-top: clamp(2rem, 8vw, 4rem);
  text-align: center;
  font-size: 0.85em;
}
.home-foot p { margin: 0.3em 0; }

.foot-affirm {
  margin-top: 1.2rem !important;
}
.foot-affirm .link {
  color: var(--ink-mute);
  font-size: 0.86em;
  letter-spacing: 0.16em;
  font-style: italic;
  padding: 0.5rem 0.75rem;
  min-height: 36px;
  border-radius: 999px;
  transition: color 500ms ease, background 600ms ease;
}
html[lang^="en"] .foot-affirm .link { letter-spacing: 0.06em; }
@media (hover: hover) {
  .foot-affirm .link:hover {
    color: var(--ink);
    background: var(--paper-soft);
  }
}
.foot-affirm .link:active {
  color: var(--ink);
  background: var(--paper-soft);
}

/* ----- Affirmation overlay ----- */
.affirm-overlay {
  position: fixed;
  inset: 0;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 900ms ease;
}
.affirm-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.affirm-content {
  text-align: center;
  padding: 2rem clamp(1.5rem, 6vw, 3rem);
  max-width: 32rem;
}
.affirm-line {
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  line-height: 1.6;
  letter-spacing: 0.06em;
  color: var(--ink);
  margin: 0.4em 0;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 1500ms ease, transform 1500ms ease;
}
html[lang^="en"] .affirm-line { letter-spacing: 0.01em; }
.affirm-line.visible {
  opacity: 1;
  transform: translateY(0);
}
.affirm-line[data-line="0"] { font-weight: 500; }
.affirm-line[data-line="1"],
.affirm-line[data-line="2"] {
  font-size: clamp(1.2rem, 4.5vw, 1.5rem);
  color: var(--ink-soft);
}

@media (prefers-reduced-motion: reduce) {
  .affirm-overlay,
  .affirm-line { transition-duration: 200ms; }
}

/* ----- Leave button (top-left) ----- */
.leave {
  position: absolute;
  top: max(clamp(0.25rem, 2vw, 1rem), env(safe-area-inset-top));
  left: max(clamp(0.25rem, 2vw, 1rem), env(safe-area-inset-left));
  font-size: 1.3rem;
  color: var(--ink-mute);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border-radius: 50%;
  transition: color 400ms ease, transform 400ms ease;
  z-index: 2;
}
@media (hover: hover) {
  .leave:hover {
    color: var(--ink);
    transform: translateX(-3px);
  }
}
.leave:active { color: var(--ink); }

.view[data-view="sit"],
.view[data-view="observe"],
.view[data-view="undo"],
.view[data-view="read"],
.view[data-view="enough"] {
  position: relative;
}

/* ----- Sit ----- */
.view[data-view="sit"] {
  min-height: 100vh;
  min-height: 100dvh;
  justify-content: center;
  align-items: center;
  padding:
    max(3.5rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(3.5rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}
.sit-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(1.5rem, 5vmin, 3rem);
  width: 100%;
}
.breath {
  width: min(55vmin, 18rem);
  height: min(55vmin, 18rem);
  display: flex;
  align-items: center;
  justify-content: center;
}
.breath-orb {
  width: 50%;
  height: 50%;
  background: radial-gradient(circle at 35% 35%,
    var(--paper-soft) 0%,
    var(--hairline) 60%,
    var(--accent) 130%);
  border-radius: 50%;
  opacity: 0.55;
  animation: breathe 11s ease-in-out infinite;
  will-change: transform, opacity;
  box-shadow: 0 0 80px -20px var(--accent);
}
@keyframes breathe {
  0%   { transform: scale(0.55); opacity: 0.45; }
  40%  { transform: scale(1.6);  opacity: 0.85; }
  55%  { transform: scale(1.6);  opacity: 0.85; }
  100% { transform: scale(0.55); opacity: 0.45; }
}
.breath-hint {
  color: var(--ink-mute);
  font-size: 0.9rem;
  letter-spacing: 0.2em;
  margin: 0;
  text-align: center;
  padding: 0 1rem;
}
html[lang^="en"] .breath-hint { letter-spacing: 0.08em; }
.sit-foot {
  position: absolute;
  bottom: max(clamp(1rem, 4vw, 2rem), env(safe-area-inset-bottom));
  left: 1rem;
  right: 1rem;
  text-align: center;
  min-height: 1.5em;
  pointer-events: none;
}
#sit-nudge {
  margin: 0;
  font-size: 0.86em;
  opacity: 0;
  transition: opacity 2000ms ease;
  padding: 0 0.5rem;
}
#sit-nudge.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .breath-orb { animation-duration: 22s; }
}

/* ----- Observe / Undo / Read shared layout ----- */
.observe-wrap, .undo-wrap, .read-wrap {
  margin-top: clamp(2rem, 8vw, 3.5rem);
}
.prompt {
  font-size: clamp(1.3rem, 5vw, 1.75rem);
  line-height: 1.55;
  font-weight: 400;
  color: var(--ink);
  margin-bottom: 1.2em;
  letter-spacing: 0.04em;
  min-height: 3em;
  transition: opacity 600ms ease;
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: auto;
}
html[lang^="en"] .prompt { letter-spacing: 0.005em; }

.scratch {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--hairline);
  resize: none;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  padding: 0.75rem 0;
  line-height: 1.85;
  margin-bottom: 1.5rem;
  transition: border-color 800ms ease;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 0;
}
.scratch:focus { border-bottom-color: var(--ink-mute); }
.scratch::placeholder { color: var(--ink-mute); opacity: 0.6; }
.scratch.releasing {
  /* Lets the writing drift down and fade — a small ritual of release. */
  transform: translateY(2.5rem);
  opacity: 0;
  transition: transform 1700ms cubic-bezier(0.4, 0.1, 0.3, 1), opacity 1700ms ease-in;
  pointer-events: none;
}

/* 'let it go' is hidden until the scratch has something to release. */
#let-go {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-2px);
  transition: opacity 500ms ease, transform 500ms ease, visibility 0s linear 500ms;
}
#let-go.has-content {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 500ms ease, transform 500ms ease, visibility 0s;
}

.observe-actions, .read-actions {
  display: flex;
  gap: clamp(1rem, 4vw, 2rem);
  justify-content: flex-end;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}
.link {
  color: var(--ink-mute);
  font-size: 0.9rem;
  letter-spacing: 0.12em;
  padding: 0.5rem 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  transition: color 500ms ease;
}
html[lang^="en"] .link { letter-spacing: 0.04em; }
@media (hover: hover) {
  .link:hover { color: var(--ink); }
}
.link:active { color: var(--ink); }

/* ----- Not-doing ----- */
.undo-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem;
  min-height: 4rem;
}
.undo-list li {
  padding: 0.85rem 0;
  border-bottom: 1px dashed var(--hairline);
  color: var(--ink);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  animation: fade-in 700ms ease;
}
.undo-list li .text {
  flex: 1;
  overflow-wrap: anywhere;
}
.undo-list li button {
  color: var(--ink-mute);
  font-size: 0.78em;
  letter-spacing: 0.1em;
  padding: 0.5rem 0.25rem;
  min-height: 36px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 400ms ease, opacity 400ms ease;
}
@media (hover: hover) {
  .undo-list li button {
    opacity: 0;
  }
  .undo-list li:hover button,
  .undo-list li:focus-within button { opacity: 1; }
  .undo-list li button:hover { color: var(--ink); }
}
.undo-list li button:active { color: var(--ink); }
.undo-list.is-empty::before {
  content: attr(data-empty);
  color: var(--ink-mute);
  font-size: 0.9em;
  display: block;
  padding: 1rem 0;
}
.undo-add { margin: 1rem 0 1.5rem; }
.undo-add input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--hairline);
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  padding: 0.6rem 0;
  transition: border-color 800ms ease;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 0;
}
.undo-add input:focus { border-bottom-color: var(--ink-mute); }
.undo-add input::placeholder { color: var(--ink-mute); opacity: 0.55; }

/* ----- Enough (permission slips) ----- */
.enough-wrap {
  margin-top: clamp(2rem, 8vw, 3.5rem);
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.slip {
  position: relative;
  background: var(--paper-soft);
  border: 1px solid var(--hairline);
  padding: clamp(2rem, 7vw, 3rem) clamp(1.5rem, 6vw, 2.5rem);
  margin: 0.25rem 0 2rem;
  min-height: 9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow:
    0 1px 0 var(--hairline),
    0 18px 40px -28px rgba(0, 0, 0, 0.18);
  transition: opacity 600ms ease, transform 900ms cubic-bezier(0.2, 0.8, 0.3, 1.1);
  opacity: 1;
  /* Slight per-slip rotation — set by JS via --slip-rot. */
  transform: translateY(0) rotate(var(--slip-rot, 0deg));
  overflow: hidden;
}
.slip.fading {
  opacity: 0;
  transform: translateY(6px) rotate(var(--slip-rot, 0deg));
  transition: opacity 500ms ease, transform 500ms ease;
}
.slip::before {
  content: "";
  position: absolute;
  inset: 0.5rem;
  border: 1px solid var(--hairline);
  pointer-events: none;
  opacity: 0.55;
}
.slip-text {
  font-size: clamp(1.1rem, 4.3vw, 1.4rem);
  line-height: 1.85;
  letter-spacing: 0.04em;
  color: var(--ink);
  margin: 0;
  max-width: 28em;
  overflow-wrap: break-word;
  /* Slip texts are short and crafted — let them wrap on word boundaries.
     Auto-hyphenation breaks words like "reason" into "rea-/son", which
     then looks visually off-centre next to the seal in the corner. */
  hyphens: manual;
}
html[lang^="en"] .slip-text { letter-spacing: 0.005em; }

/* A small, red seal that lands in the lower-right of the slip after a beat. */
.slip-seal {
  position: absolute;
  right: clamp(1rem, 4vw, 1.5rem);
  bottom: clamp(0.9rem, 3.5vw, 1.4rem);
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border: 1.5px solid #a14a3a;
  color: #a14a3a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Songti SC", "STSong", "Source Han Serif SC", serif;
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: 0;
  opacity: 0;
  transform: rotate(-6deg) scale(0.7);
  transition: opacity 700ms ease, transform 700ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.15) 0%, transparent 60%),
    rgba(161, 74, 58, 0.04);
  /* slightly rough edges via inset shadow */
  box-shadow:
    inset 0 0 0 1px rgba(161, 74, 58, 0.15),
    0 0 0 0.5px rgba(161, 74, 58, 0.12);
}
.slip-seal::after {
  content: "许";
  display: block;
  line-height: 1;
}
html[lang^="en"] .slip-seal::after {
  content: "ok";
  font-size: 0.75rem;
  font-style: italic;
  letter-spacing: 0.04em;
}
.slip.settled .slip-seal {
  opacity: 0.9;
  transform: rotate(-6deg) scale(1);
}
@media (prefers-color-scheme: dark) {
  .slip-seal {
    border-color: #d88671;
    color: #d88671;
    background:
      radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.08) 0%, transparent 60%),
      rgba(216, 134, 113, 0.06);
    box-shadow:
      inset 0 0 0 1px rgba(216, 134, 113, 0.15),
      0 0 0 0.5px rgba(216, 134, 113, 0.12);
  }
  .slip {
    box-shadow:
      0 1px 0 var(--hairline),
      0 18px 40px -28px rgba(0, 0, 0, 0.55);
  }
}
.enough-actions {
  display: flex;
  gap: clamp(1rem, 4vw, 2rem);
  justify-content: flex-end;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  transition: opacity 1400ms ease;
}
/* While the slip is arriving, soften the action links so the eye stays on
   the slip itself for a few breaths. They remain clickable. */
.enough-actions.settling { opacity: 0.45; }
.enough-note {
  margin-top: 0.25rem;
}

@media (max-width: 540px) {
  .enough-actions {
    justify-content: space-between;
    margin-top: 0.25rem;
  }
  .slip {
    min-height: 8rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .slip, .slip-seal { transition-duration: 0ms; }
}

/* ----- Read ----- */
.passage {
  font-size: clamp(1.1rem, 4.3vw, 1.4rem);
  line-height: 1.85;
  letter-spacing: 0.04em;
  margin: 0 0 2rem;
  padding: 0 0 0 1.25rem;
  color: var(--ink);
  border-left: 2px solid var(--hairline);
  min-height: 6em;
  animation: fade-in 1400ms ease;
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: auto;
}
html[lang^="en"] .passage { letter-spacing: 0.005em; }
.passage.fading { opacity: 0; transition: opacity 600ms ease; }

/* ----- Small screens ----- */
@media (max-width: 540px) {
  body { font-size: 16.5px; line-height: 1.72; }
  /* English carries less visual weight per character than Chinese at the same
     size, so it gets a small additional bump on mobile for comfortable reading. */
  html[lang^="en"] body { font-size: 17px; }

  .menu-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.45rem;
    padding: 1.25rem 0.1rem;
  }
  .menu-title { font-size: 1.15rem; }
  .menu-sub {
    text-align: left;
    font-size: 0.95rem;        /* was 0.82rem — too small at iPhone widths */
  }

  /* Meta labels (TODAY'S QUESTION / 今日许可 / RILKE) were stacking down to ~12px.
     Hold them at ~14px so the hierarchy reads. */
  .meta { font-size: 0.86em; letter-spacing: 0.22em; }
  html[lang^="en"] .meta { letter-spacing: 0.18em; }

  /* The footer used to be 0.85em and its children added more em-reductions on top,
     so the time-note and 'say it once' link compounded down to ~12px. Hold the
     footer at a single, comfortable size and don't reduce its children further. */
  .home-foot { font-size: 0.95em; }
  .home-foot .small,
  .home-foot .quiet.small { font-size: 1em; }
  .foot-affirm .link { font-size: 0.95em; }

  /* Standalone secondary text — disclaimers under prompts, etc. */
  .small { font-size: 0.92em; }

  /* Reading content uses the same clamp as the slip — see base rules. */
  .scratch { font-size: 17px; }

  /* Action links should be tappable and readable. */
  .link { font-size: 0.96rem; }

  .observe-actions, .read-actions {
    justify-content: space-between;
    margin-top: 0.25rem;
  }
  .home-header { margin-top: 3rem; }
  .lang-toggle { font-size: 0.85rem; }
}

@media (max-width: 360px) {
  .brand { font-size: 2.8rem; }
  .tagline { font-size: 0.88rem; }
}

/* Short viewport (landscape phone) */
@media (max-height: 480px) and (orientation: landscape) {
  .view[data-view="sit"] { padding-top: 3rem; padding-bottom: 3rem; }
  .breath { width: min(40vmin, 12rem); height: min(40vmin, 12rem); }
  .sit-stage { gap: 1rem; }
  .home-header { margin: 1rem 0 1.5rem; }
  .brand { font-size: 2.5rem; margin-bottom: 0.5rem; }
}

/* Avoid the iOS-safari address-bar jump from making layout look off */
@supports (-webkit-touch-callout: none) {
  .view[data-view="sit"] { min-height: -webkit-fill-available; }
}
