:root {
  --bg: #ffffff;
  --bg-2: #f4f4f4;
  --ink: #111111;
  --ink-dim: #444444;
  --ink-faint: #888888;
  --gold: #111111;
  --gold-2: #222222;
  --celadon: #1f6b45;
  --clay: #9a331f;
  --line: rgba(17, 17, 17, 0.14);
  --serif: "Songti SC", "STSong", "Hiragino Mincho ProN", "Noto Serif SC", "Times New Roman", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", -apple-system, system-ui, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --pad: clamp(20px, 4vw, 48px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { background: var(--bg); }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  background: var(--bg);
  min-height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
}
button { cursor: pointer; }
textarea, input[type="text"], input[type="number"], input[type="password"] {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 2px;
  padding: 14px 16px;
  outline: none;
  resize: vertical;
  color: #111;
}
textarea:focus, input:focus {
  border-color: #111;
}
::placeholder { color: var(--ink-faint); }

.grain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.035;
  z-index: 8;
  mix-blend-mode: multiply;
}
.wash {
  position: fixed;
  inset: -20%;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(0, 0, 0, 0.03), transparent 45%),
    radial-gradient(ellipse at 80% 100%, rgba(0, 0, 0, 0.025), transparent 40%);
  pointer-events: none;
  z-index: 0;
  animation: drift 28s var(--ease) infinite alternate;
}
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(-2%, 1.5%, 0) scale(1.05); }
}

#app {
  position: relative;
  z-index: 1;
  height: 100dvh;
}
[data-view] {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 12px) var(--pad) calc(env(safe-area-inset-bottom) + 24px);
}
[data-view][hidden] { display: none !important; }

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  min-height: 36px;
}
.topbar .mark { justify-self: center; }
.topbar .text-btn:last-child,
.top-nav { justify-self: end; }
.top-nav { display: flex; gap: 18px; }

.mark {
  font-family: var(--serif);
  letter-spacing: 0.4em;
  font-size: 13px;
  color: var(--gold);
}
.kicker {
  font-family: var(--serif);
  letter-spacing: 0.45em;
  color: var(--gold);
  font-size: 12px;
  margin: 0 0 18px;
}
.display {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(32px, 5vw, 56px);
  line-height: 1.25;
  margin: 0 0 18px;
  letter-spacing: 0.04em;
}
.display.small { font-size: clamp(26px, 4vw, 40px); }
.lede {
  color: var(--ink-dim);
  line-height: 1.85;
  max-width: 36em;
  margin: 0 0 36px;
  font-size: 16px;
}
.small-label {
  display: block;
  color: var(--ink-dim);
  font-size: 12px;
  letter-spacing: 0.14em;
  margin-bottom: 10px;
}

.frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}
.frame-narrow { max-width: 520px; }
.frame-form {
  justify-content: flex-start;
  padding-top: 24px;
  overflow: auto;
  max-width: 640px;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.row.end { justify-content: flex-end; margin-top: 28px; }

.btn {
  min-height: 44px;
  padding: 0 22px;
  letter-spacing: 0.18em;
  font-size: 13px;
  border: 1px solid transparent;
  transition: background 0.25s var(--ease), color 0.25s, border-color 0.25s;
}
.btn.solid {
  background: var(--ink);
  color: var(--bg);
}
.btn.solid:hover { background: #000; }
.btn.ghost {
  border-color: var(--line);
  color: var(--ink-dim);
}
.btn.ghost:hover { color: var(--ink); border-color: var(--ink-dim); }
.btn.danger { color: var(--clay); border-color: rgba(192, 112, 88, 0.35); }
.text-btn {
  color: var(--ink-dim);
  letter-spacing: 0.16em;
  font-size: 12px;
  padding: 8px 0;
}
.text-btn:hover { color: var(--ink); }

.home-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 40px; }

.resume-card, .experiment-strip, .insight {
  border-top: 1px solid var(--line);
  padding-top: 22px;
  margin-top: 8px;
}
.resume-goal {
  font-family: var(--serif);
  font-size: 20px;
  margin: 8px 0 18px;
}
.day-pips {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.day-pips span {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 11px;
  color: var(--ink-faint);
}
.day-pips span.done {
  border-color: var(--celadon);
  color: var(--celadon);
}
.day-pips span.today {
  border-color: var(--gold);
  color: var(--gold);
}

.field { margin: 0 0 22px; }
.hint {
  margin: -8px 0 18px;
  color: var(--gold);
  font-size: 13px;
  line-height: 1.6;
}
.hint.quiet { color: var(--ink-faint); }
.suggest {
  display: block;
  text-align: left;
  width: 100%;
  margin: -6px 0 22px;
  padding: 12px 14px;
  border: 1px dashed var(--line);
  color: var(--ink);
  line-height: 1.6;
  font-size: 14px;
}
.suggest:hover { background: var(--bg-2); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chips button,
.chip {
  border: 1px solid var(--line);
  padding: 8px 14px;
  font-size: 13px;
  color: var(--ink-dim);
  letter-spacing: 0.06em;
}
.chips button.is-on,
.chip.is-on {
  border-color: #111;
  background: #111;
  color: #fff;
}

input[type="range"] {
  width: 100%;
  appearance: none;
  height: 2px;
  background: linear-gradient(90deg, #6a7a8a 0%, var(--celadon) 45%, var(--gold) 62%, var(--clay) 100%);
  outline: none;
  margin: 16px 0 10px;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--gold);
}
.challenge-meta {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}
.band { color: var(--celadon); letter-spacing: 0.12em; font-size: 12px; }
.band.warn { color: var(--clay); }
.custom-min {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: var(--ink-dim);
}
.custom-min input { width: 100px; }

.check {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  color: var(--ink-dim);
  line-height: 1.6;
  font-size: 14px;
  margin: 8px 0 12px;
}
.check input { margin-top: 4px; accent-color: #111; }

.rites {
  padding: 0;
  margin: 0 0 32px;
  list-style: none;
  counter-reset: rite;
}
.rites li {
  counter-increment: rite;
  padding: 14px 0 14px 42px;
  border-bottom: 1px solid var(--line);
  position: relative;
  color: var(--ink);
  line-height: 1.7;
}
.rites li::before {
  content: counter(rite);
  position: absolute;
  left: 0;
  top: 14px;
  color: var(--gold);
  font-family: var(--serif);
}

.goal-echo {
  font-family: var(--serif);
  font-size: clamp(18px, 2.4vw, 24px);
  line-height: 1.6;
  margin: 0 0 32px;
}
.goal-echo.dim { color: var(--ink-dim); font-size: 16px; }

.session-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  user-select: none;
}
.phase-label {
  letter-spacing: 0.5em;
  color: var(--gold);
  font-size: 12px;
  margin: 0 0 24px;
}
.phase-label.stealth { color: var(--ink-faint); }

.ring-wrap {
  position: relative;
  width: min(280px, 62vw);
  height: min(280px, 62vw);
  margin-bottom: 28px;
}
.ring { width: 100%; height: 100%; }
.ring-track, .ring-progress {
  fill: none;
  stroke-width: 1.2;
}
.ring-track { stroke: rgba(17, 17, 17, 0.12); }
.ring-progress {
  stroke: #111;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  stroke-dasharray: 552.92;
  stroke-dashoffset: 552.92;
}
.ring-progress.breath {
  stroke: rgba(17, 17, 17, 0.5);
  stroke-dashoffset: 320;
  animation: breathe 10s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { stroke-dashoffset: 380; opacity: 0.4; }
  40% { stroke-dashoffset: 200; opacity: 0.9; }
  50% { stroke-dashoffset: 200; opacity: 0.9; }
}
.ring-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
}
.time-num {
  font-variant-numeric: tabular-nums;
  font-size: 42px;
  letter-spacing: 0.08em;
  margin: 0;
  font-weight: 300;
}
.time-caption, .breath-word {
  margin: 4px 0 0;
  color: var(--ink-faint);
  letter-spacing: 0.4em;
  font-size: 12px;
}
.session-copy {
  color: var(--ink-dim);
  min-height: 3em;
  max-width: 22em;
  line-height: 1.8;
}

.hold-btn {
  margin-top: 8px;
  color: var(--ink-faint);
  letter-spacing: 0.2em;
  font-size: 12px;
  position: relative;
  padding: 10px 18px;
}
.hold-btn::after {
  content: "";
  position: absolute;
  left: 0; bottom: 0;
  height: 1px;
  width: var(--hold, 0%);
  background: var(--clay);
}
.session-dock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  margin-top: 8px;
}
.flow-tools {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  display: flex;
  gap: 18px;
  align-items: center;
  opacity: 0;
  transition: opacity 0.4s;
}
body:hover .flow-tools, .flow-tools:focus-within { opacity: 1; }
.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  letter-spacing: 0.1em;
  font-size: 13px;
}
.icon-btn:hover, .icon-btn.is-on { color: var(--gold); border-color: var(--gold); }

.music-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
  max-width: 360px;
  margin: 8px 0 18px;
  padding: 12px 0;
  text-align: left;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.music-switch-copy { min-width: 0; }
.music-switch-title {
  display: block;
  letter-spacing: 0.18em;
  font-size: 13px;
  color: var(--ink);
}
.music-switch-state {
  display: block;
  margin-top: 6px;
  color: var(--ink-faint);
  font-size: 12px;
  letter-spacing: 0.28em;
}
.switch-ui {
  width: 46px;
  height: 26px;
  border: 1px solid var(--line);
  position: relative;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.03);
}
.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--ink-faint);
  transition: transform 0.28s var(--ease), background 0.28s;
}
.music-switch[aria-pressed="true"] .switch-ui {
  border-color: #111;
  background: #111;
}
.music-switch[aria-pressed="true"] .switch-knob {
  transform: translateX(20px);
  background: #fff;
}
.music-switch[aria-pressed="true"] .music-switch-state { color: var(--gold); }
.music-switch.compact {
  width: auto;
  max-width: none;
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--line);
  gap: 10px;
}
.music-switch.compact .music-switch-title {
  letter-spacing: 0.14em;
  font-size: 12px;
  color: var(--ink-dim);
}
.music-switch.compact[aria-pressed="true"] .music-switch-title { color: var(--gold); }
.music-switch.compact .music-switch-state { display: none; }
.music-switch.compact .switch-ui { width: 40px; height: 22px; }
.music-switch.compact .switch-knob { width: 16px; height: 16px; }
.music-switch.compact[aria-pressed="true"] .switch-knob { transform: translateX(18px); }

.pulse, .adjust {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.86);
  display: grid;
  place-items: center;
  z-index: 5;
  padding: 24px;
}
.pulse[hidden], .adjust[hidden] { display: none !important; }
.pulse-card {
  max-width: 440px;
  width: 100%;
  text-align: center;
}
.pulse-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.pulse-row button {
  border: 1px solid var(--line);
  padding: 18px 8px;
  font-family: var(--serif);
  font-size: 18px;
}
.pulse-row button:hover { border-color: #111; color: #111; }
.pulse-row button[data-feel="bored"]:hover { border-color: #555; color: #555; }
.pulse-row button[data-feel="anxious"]:hover { border-color: var(--clay); color: var(--clay); }
.pulse-row button[data-feel="in"]:hover { border-color: var(--celadon); color: var(--celadon); }

.recover-time { margin: 8px 0 32px; color: var(--gold-2); }

.log {
  list-style: none;
  padding: 0;
  margin: 28px 0 0;
}
.log li {
  border-top: 1px solid var(--line);
  padding: 16px 0;
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 16px;
  align-items: start;
}
.log .when { color: var(--ink-faint); font-size: 12px; letter-spacing: 0.08em; padding-top: 4px; }
.log .what { margin: 0; font-family: var(--serif); font-size: 18px; }
.log .meta { color: var(--ink-dim); font-size: 13px; margin: 6px 0 0; }
.log .tags { color: var(--ink-dim); font-size: 12px; text-align: right; line-height: 1.7; }
.log .empty {
  grid-column: 1 / -1;
  color: var(--ink-faint);
  padding: 40px 0;
  text-align: center;
}

.insight {
  color: var(--ink-dim);
  line-height: 1.8;
  white-space: pre-line;
}

.guide-dots {
  display: flex;
  gap: 8px;
  margin: 8px 0 28px;
}
.guide-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-faint);
  display: block;
}
.guide-dots i.on { background: var(--gold); }

.help {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  color: var(--ink-dim);
  font-size: 12px;
  letter-spacing: 0.08em;
  background: #fff;
  padding: 10px 16px;
  border: 1px solid var(--line);
}
.help kbd {
  font-family: var(--sans);
  color: var(--gold);
}
.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  font-size: 13px;
  letter-spacing: 0.08em;
}

body[data-view="flow"],
body[data-view="loading"] {
  cursor: none;
}
body[data-view="flow"]:hover,
body[data-view="loading"]:hover { cursor: default; }

@media (max-width: 640px) {
  .log li { grid-template-columns: 1fr; gap: 6px; }
  .log .tags { text-align: left; }
  .pulse-row { grid-template-columns: 1fr; }
  .display { font-size: 32px; }
  body[data-view="flow"],
  body[data-view="loading"] { cursor: default; }
  .flow-tools { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .wash, .ring-progress.breath { animation: none; }
}

body.hide-cursor,
body.hide-cursor * { cursor: none !important; }
body.hide-cursor .flow-tools { opacity: 0 !important; }

.auth-tabs {
  display: flex;
  gap: 8px;
  margin: 0 0 22px;
}
.auth-msg {
  min-height: 1.4em;
  margin: 8px 0 0;
}
.account-card {
  border: 1px solid var(--line);
  padding: 18px 16px;
  margin-bottom: 22px;
}
.now-playing {
  letter-spacing: 0.2em;
  font-size: 12px;
  color: var(--ink-dim);
  cursor: pointer;
  padding: 6px 0;
}
.switch-ui {
  background: #fff;
}
