:root {
  --cream: #F8F1EA;
  --cream-deep: #EFE3D6;
  --paper: #FFFCF8;
  --blush: #E8B4B8;
  --blush-soft: #F2C6C2;
  --blush-deep: #C9898E;
  --sage: #A8B5A0;
  --sage-deep: #7E8C76;
  --gold: #D4A574;
  --gold-soft: #E6C49A;
  --ink: #3D2C2E;
  --ink-soft: #6A5658;
  --ink-faint: rgba(61, 44, 46, 0.48);
  --shadow: 0 16px 40px rgba(61, 44, 46, 0.08);
  --font-display: "Fraunces", "Noto Serif TC", "Songti TC", serif;
  --font-serif: "Noto Serif TC", "Songti TC", "Fraunces", serif;
  --font-ui: "Nunito", "Noto Sans TC", "PingFang TC", sans-serif;
  --safe-t: max(1.25rem, env(safe-area-inset-top));
  --safe-b: max(1.25rem, env(safe-area-inset-bottom));
  --safe-l: max(1.25rem, env(safe-area-inset-left));
  --safe-r: max(1.25rem, env(safe-area-inset-right));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  min-height: 100dvh;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  appearance: none;
  -webkit-appearance: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.wake-video {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  bottom: 0;
  left: 0;
}

/* Atmosphere */
.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.wash {
  position: absolute;
  inset: -10%;
  background:
    radial-gradient(ellipse 80% 60% at 18% 88%, rgba(168, 181, 160, 0.22), transparent 60%),
    radial-gradient(ellipse 70% 50% at 88% 12%, rgba(242, 198, 194, 0.32), transparent 58%),
    radial-gradient(ellipse 50% 40% at 70% 80%, rgba(212, 165, 116, 0.12), transparent 60%),
    radial-gradient(ellipse 90% 80% at 50% 40%, var(--cream), var(--cream-deep));
}

.grain, .vellum {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.grain {
  background: url("/img/grain.png") repeat;
  background-size: 256px 256px;
  opacity: 0.14;
  mix-blend-mode: multiply;
}

.vellum {
  background: url("/img/vellum.png") repeat;
  background-size: 280px 280px;
  opacity: 0.55;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(30px);
  opacity: 0.45;
  animation: drift 28s ease-in-out infinite;
}

.orb-a {
  width: 28vw;
  height: 28vw;
  left: -6vw;
  top: 18vh;
  background: rgba(242, 198, 194, 0.55);
  animation-duration: 34s;
}

.orb-b {
  width: 22vw;
  height: 22vw;
  right: -4vw;
  top: 8vh;
  background: rgba(168, 181, 160, 0.42);
  animation-duration: 40s;
  animation-delay: -8s;
}

.orb-c {
  width: 18vw;
  height: 18vw;
  right: 16vw;
  bottom: 6vh;
  background: rgba(230, 196, 154, 0.38);
  animation-duration: 32s;
  animation-delay: -16s;
}

.orb-d {
  width: 14vw;
  height: 14vw;
  left: 28vw;
  bottom: 18vh;
  background: rgba(232, 180, 184, 0.35);
  animation-duration: 26s;
  animation-delay: -4s;
}

@keyframes drift {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  40% { transform: translate3d(3vw, -2.5vh, 0) scale(1.08); }
  70% { transform: translate3d(-2vw, 2vh, 0) scale(0.96); }
}

.petals {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.app {
  position: relative;
  z-index: 2;
  min-height: 100dvh;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  padding-left: max(var(--safe-l), 1.75rem);
  padding-right: max(var(--safe-r), 1.75rem);
  animation: fade-in 0.7s ease both;
  overflow-y: auto;
  overflow-x: hidden;
}

.screen.is-active {
  display: flex;
}

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

/* Setup */
.hero {
  text-align: center;
  max-width: 40rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  text-transform: none;
  color: var(--ink-soft);
  font-weight: 500;
}

h1 {
  margin: 0;
  font-weight: 400;
  color: var(--ink);
  line-height: 1.15;
}

h1 .name {
  display: block;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(3.1rem, 8.5vw, 5.4rem);
  letter-spacing: -0.03em;
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 60, "WONK" 0.7, "opsz" 144;
}

h1 .title-zh {
  display: block;
  margin-top: 0.15rem;
  font-family: var(--font-serif);
  font-style: normal;
  font-weight: 500;
  font-size: clamp(1.35rem, 3.4vw, 1.9rem);
  letter-spacing: 0.32em;
  text-indent: 0.32em;
}

.botanical {
  display: block;
  width: min(26rem, 78vw);
  height: auto;
  margin: 0.15rem auto 0;
  pointer-events: none;
  user-select: none;
}

.prompt {
  margin: 0.4rem 0 1.15rem;
  font-family: var(--font-serif);
  font-size: clamp(1rem, 2.4vw, 1.2rem);
  color: var(--ink-soft);
  letter-spacing: 0.08em;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  justify-content: center;
  max-width: 36rem;
}

.preset {
  min-width: 5.4rem;
  min-height: 4.7rem;
  padding: 0.55rem 0.85rem 0.6rem;
  border-radius: 1.45rem;
  background: rgba(255, 252, 248, 0.62);
  border: 1px solid rgba(212, 165, 116, 0.28);
  box-shadow: 0 8px 22px rgba(61, 44, 46, 0.04);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.05rem;
  transition: transform 0.25s ease, background 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.preset .num {
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 400;
  line-height: 1;
  font-variation-settings: "opsz" 36, "SOFT" 40;
}

.preset .unit {
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
}

.preset.is-on {
  background: linear-gradient(180deg, #F8E4E0 0%, #F2C6C2 100%);
  border-color: rgba(201, 137, 142, 0.55);
  box-shadow: 0 10px 26px rgba(232, 180, 184, 0.38);
}

.preset:active { transform: scale(0.97); }

.custom {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.95rem;
  padding: 0.4rem 0.55rem;
  border-radius: 999px;
  background: rgba(255, 252, 248, 0.5);
  border: 1px solid rgba(168, 181, 160, 0.28);
}

.custom.is-on {
  border-color: rgba(201, 137, 142, 0.5);
  background: rgba(242, 198, 194, 0.22);
}

.custom-label, .custom-unit {
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  padding-left: 0.4rem;
}

.custom-unit { padding-left: 0; padding-right: 0.2rem; }

.custom-input {
  width: 3.2rem;
  border: 0;
  background: transparent;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.45rem;
  padding: 0.15rem 0;
  -moz-appearance: textfield;
}

.custom-input::-webkit-outer-spin-button,
.custom-input::-webkit-inner-spin-button { appearance: none; margin: 0; }

.stepper {
  width: 2.55rem;
  height: 2.55rem;
  border-radius: 50%;
  background: rgba(255, 252, 248, 0.8);
  border: 1px solid rgba(212, 165, 116, 0.32);
  font-size: 1.25rem;
  line-height: 1;
  color: var(--ink);
  display: grid;
  place-items: center;
}

.stepper:active { transform: scale(0.94); background: var(--blush-soft); }

.prefs {
  width: min(28rem, 100%);
  margin: 1.15rem 0 0;
  display: grid;
  gap: 0.7rem;
}

.pref {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0.15rem;
}

.pref-label {
  font-size: 0.92rem;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  flex: 0 0 auto;
}

.pref-control {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.pref-value {
  min-width: 5.2rem;
  text-align: center;
  font-family: var(--font-serif);
  font-size: 1.02rem;
}

.select-wrap {
  position: relative;
  min-width: 9.5rem;
}

.select-wrap::after {
  content: "";
  position: absolute;
  right: 0.9rem;
  top: 50%;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 1.5px solid var(--ink-soft);
  border-bottom: 1.5px solid var(--ink-soft);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(212, 165, 116, 0.32);
  background: rgba(255, 252, 248, 0.7);
  border-radius: 999px;
  padding: 0.55rem 2.1rem 0.55rem 1rem;
  letter-spacing: 0.06em;
}

.volume-row { min-width: 11rem; }

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 8.5rem;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blush-soft), var(--gold-soft));
  outline: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--gold);
  box-shadow: 0 2px 6px rgba(61, 44, 46, 0.15);
}

.icon-btn {
  width: 2.7rem;
  height: 2.7rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 252, 248, 0.7);
  border: 1px solid rgba(212, 165, 116, 0.3);
}

.icon-btn .icon {
  width: 1.2rem;
  height: 1.2rem;
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: var(--ink);
}

.icon-btn .icon path[fill="none"] { fill: none; }

.icon-btn .icon-off { display: none; }
.icon-btn.is-muted .icon-on { display: none; }
.icon-btn.is-muted .icon-off { display: block; }

.btn-start {
  margin-top: 1.4rem;
  min-height: 3.9rem;
  min-width: 12.5rem;
  padding: 0.85rem 2.6rem;
  border-radius: 999px;
  background: linear-gradient(180deg, #F6D2CE 0%, #E8B4B8 100%);
  color: var(--ink);
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  box-shadow:
    0 12px 30px rgba(232, 180, 184, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-start:active {
  transform: scale(0.98);
  box-shadow: 0 6px 16px rgba(232, 180, 184, 0.35);
}

.home-hint {
  margin: 1rem 0 0;
  font-size: 0.78rem;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}

/* Study */
.phase {
  margin: 0 0 0.6rem;
  font-family: var(--font-serif);
  font-size: 0.95rem;
  letter-spacing: 0.46em;
  text-indent: 0.46em;
  color: var(--ink-soft);
}

.timer-wrap {
  position: relative;
  width: min(26rem, 78vw, 78vh);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track, .ring-progress {
  fill: none;
  stroke-width: 1.6;
}

.ring-track { stroke: rgba(168, 181, 160, 0.28); }

.ring-progress {
  stroke: url(#none);
  stroke: var(--gold);
  stroke-linecap: round;
  stroke-dasharray: 578.05;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.2s linear;
}

.time {
  position: relative;
  z-index: 1;
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(4.6rem, 16vw, 9.2rem);
  letter-spacing: -0.04em;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 70, "opsz" 144, "WONK" 0.2;
  color: var(--ink);
}

.encouragement {
  margin: 0.7rem 0 0;
  min-height: 1.6em;
  font-family: var(--font-serif);
  font-size: clamp(0.98rem, 2.2vw, 1.15rem);
  color: var(--ink-soft);
  letter-spacing: 0.1em;
  transition: opacity 0.8s ease;
}

.encouragement.is-fading { opacity: 0; }

.controls {
  display: flex;
  gap: 0.8rem;
  margin-top: 1.5rem;
}

.btn-ghost {
  min-height: 3.1rem;
  min-width: 6.8rem;
  padding: 0.55rem 1.4rem;
  border-radius: 999px;
  border: 1px solid rgba(212, 165, 116, 0.4);
  background: rgba(255, 252, 248, 0.55);
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  font-weight: 600;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.btn-ghost:active { background: rgba(242, 198, 194, 0.45); }

.btn-solid {
  min-height: 3.1rem;
  min-width: 7.2rem;
  padding: 0.55rem 1.5rem;
  border-radius: 999px;
  background: linear-gradient(180deg, #F6D2CE, #E8B4B8);
  font-weight: 700;
  letter-spacing: 0.18em;
  text-indent: 0.18em;
  box-shadow: 0 8px 20px rgba(232, 180, 184, 0.35);
}

/* Rest / game */
.screen-rest {
  justify-content: stretch;
  padding: 0;
  overflow: hidden;
}

.game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  touch-action: none;
}

.rest-bar {
  position: relative;
  z-index: 3;
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(var(--safe-t) + 0.6rem) max(var(--safe-r), 1.4rem) 0 max(var(--safe-l), 1.4rem);
  pointer-events: none;
}

.rest-kicker {
  margin: 0;
  font-family: var(--font-serif);
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

.rest-hint {
  margin: 0.25rem 0 0;
  font-size: 0.86rem;
  color: var(--ink-faint);
  transition: opacity 1.2s ease;
}

.rest-hint.is-faded { opacity: 0; }

.rest-time {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2rem, 6vw, 2.8rem);
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  font-variation-settings: "opsz" 72, "SOFT" 50;
  padding: 0.15rem 0.7rem;
  border-radius: 1rem;
  background: rgba(255, 252, 248, 0.62);
  border: 1px solid rgba(212, 165, 116, 0.28);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.rest-tools {
  position: absolute;
  z-index: 3;
  right: max(var(--safe-r), 1.2rem);
  bottom: max(var(--safe-b), 1.2rem);
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0.55rem 0.4rem 0.4rem;
  border-radius: 999px;
  background: rgba(255, 252, 248, 0.62);
  border: 1px solid rgba(212, 165, 116, 0.28);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(61, 44, 46, 0.22);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: fade-in 0.45s ease both;
}

.overlay[hidden], .screen[hidden] { display: none !important; }

.card {
  width: min(26rem, 100%);
  text-align: center;
  padding: 2.1rem 1.6rem 1.6rem;
  border-radius: 1.8rem;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(242, 198, 194, 0.35), transparent 60%),
    var(--paper);
  border: 1px solid rgba(212, 165, 116, 0.32);
  box-shadow: var(--shadow);
}

.card-kicker {
  margin: 0 0 0.4rem;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.card-title {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 1.7rem;
  letter-spacing: 0.16em;
  text-indent: 0.16em;
}

.card-body {
  margin: 0.7rem 0 0;
  color: var(--ink-soft);
  line-height: 1.7;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.7rem;
  margin-top: 1.5rem;
}

.setup-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

/* Landscape: split title and controls so the start button stays on screen */
@media (orientation: landscape) and (max-height: 1100px) {
  #screen-setup.is-active {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: clamp(1.5rem, 4vw, 4rem);
  }
  #screen-setup .hero {
    flex: 0 1 42%;
    max-width: 28rem;
  }
  #screen-setup .setup-panel {
    flex: 0 1 48%;
    max-width: 32rem;
  }
  h1 .name { font-size: clamp(2.6rem, 9vh, 4.6rem); }
  h1 .title-zh { font-size: clamp(1.15rem, 3.6vh, 1.6rem); }
  .botanical { width: min(22rem, 42vw); margin-top: 0.1rem; }
  .prompt { margin: 0 0 0.75rem; }
  .preset { min-width: 4.7rem; min-height: 4rem; }
  .preset .num { font-size: 1.65rem; }
  .prefs { margin-top: 0.8rem; }
  .btn-start { margin-top: 1rem; min-height: 3.4rem; }
  .home-hint { display: none; }
  .timer-wrap { width: min(22rem, 68vh); }
  .time { font-size: clamp(4.2rem, 18vh, 8rem); }
  .encouragement { margin-top: 0.35rem; }
  .controls { margin-top: 0.85rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .orb { opacity: 0.22; }
}
