/* Daylight for reading, and the lights go down while someone talks. They come back up
   on their own words. Serif carries what people said; the sans is only for the place
   itself. */

@font-face {
  font-family: 'Noto Serif';
  src: url('/fonts/NotoSerif_400Regular.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'Noto Serif';
  font-style: italic;
  src: url('/fonts/NotoSerif_400Regular_Italic.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'Public Sans';
  src: url('/fonts/PublicSans_600SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-display: swap;
}

:root {
  --bg: #f8f2e4;
  --surface: #fffaf0;
  --text: #1d1f1a;
  --soft: rgba(29, 31, 26, 0.66);
  --line: rgba(29, 31, 26, 0.13);
  --accent: #006241;
  --button: #006241;
  --button-ink: #f8f2e4;
  --button-hover: #00523a;
  --tint: rgba(0, 98, 65, 0.075);
  --alert: #9c4a2f;
  --sun-wash: rgba(255, 216, 138, 0.34);
  --sky-wash: rgba(207, 227, 241, 0.3);
  --serif: 'Noto Serif', 'Songti TC', 'Noto Serif TC', 'PMingLiU', Georgia, serif;
  --sans: 'Public Sans', -apple-system, 'PingFang TC', 'Noto Sans TC', 'Helvetica Neue', sans-serif;
  --gutter: clamp(1.4rem, 5vw, 2.25rem);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121a1b;
    --surface: #1b2526;
    --text: #ece6d6;
    --soft: rgba(236, 230, 214, 0.68);
    --line: rgba(236, 230, 214, 0.14);
    --accent: #84cdac;
    --button: #1f7a5a;
    --button-ink: #f3efe2;
    --button-hover: #278b67;
    --tint: rgba(132, 205, 172, 0.1);
    --alert: #e7a285;
    --sun-wash: rgba(255, 216, 138, 0.05);
    --sky-wash: rgba(207, 227, 241, 0.03);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 400 1.0625rem/1.58 var(--serif);
  -webkit-font-smoothing: antialiased;
  transition: background-color 1.5s ease, color 1.5s ease;
}

/* The film's daylight: a little sky above, sun from the upper right. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(60rem 34rem at 108% -8%, var(--sun-wash), transparent 70%),
    linear-gradient(to bottom, var(--sky-wash), transparent 15rem);
  transition: opacity 1.5s ease;
}

body[data-mood='night'] {
  --bg: #0f1a1c;
  --text: #e9e3d3;
  --soft: rgba(233, 227, 211, 0.62);
  --line: rgba(233, 227, 211, 0.3);
  --accent: #e9e3d3;
}
body[data-mood='night']::before { opacity: 0; }

a { color: inherit; }
button { -webkit-tap-highlight-color: transparent; font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* The bar */

.top {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.5rem;
  padding: calc(env(safe-area-inset-top) + 0.5rem) var(--gutter) 0.25rem;
}
.mark, .clock, .label {
  font: 600 0.74rem/1.4 var(--sans);
  letter-spacing: 0.13em;
  text-transform: uppercase;
}
.mark { color: var(--accent); text-decoration: none; transition: color 1.5s ease; }
body[data-mood='night'] .mark { color: var(--soft); pointer-events: none; }
.clock { color: var(--soft); font-variant-numeric: tabular-nums; letter-spacing: 0.06em; }

.top-actions { display: flex; align-items: center; gap: 0.2rem; margin-right: -0.55rem; }
.popover { position: relative; }
.icon-button, .avatar {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  transition: background-color 0.18s ease;
}
.icon-button:hover { background: var(--tint); }
.avatar { position: relative; font: 600 0.85rem/1 var(--sans); }
.avatar::before {
  content: '';
  position: absolute;
  inset: 0.45rem;
  border-radius: 50%;
  background: var(--tint);
  transition: background-color 0.18s ease;
}
.avatar:hover::before { background: rgba(0, 98, 65, 0.15); }
.avatar span { position: relative; }

.menu {
  position: absolute;
  z-index: 4;
  top: calc(100% + 0.25rem);
  right: 0.25rem;
  display: flex;
  flex-direction: column;
  min-width: 13.5rem;
  padding: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: var(--surface);
  box-shadow: 0 0.9rem 2.4rem rgba(29, 31, 26, 0.14);
  animation: pop 0.16s var(--ease);
}
#lang-menu { min-width: 8.5rem; }
@keyframes pop { from { opacity: 0; transform: translateY(-0.25rem) scale(0.985); } }
.menu button {
  padding: 0.62rem 0.75rem;
  border: 0;
  border-radius: 0.55rem;
  background: transparent;
  color: var(--text);
  font: 600 0.9rem/1.3 var(--sans);
  text-align: left;
  cursor: pointer;
}
.menu button:hover { background: var(--tint); }
.menu button[aria-current='true'] { color: var(--accent); }
.menu-note {
  margin: 0 0 0.3rem;
  padding: 0.45rem 0.75rem 0.65rem;
  border-bottom: 1px solid var(--line);
  color: var(--soft);
  font: 600 0.8rem/1.3 var(--sans);
  overflow-wrap: anywhere;
}

/* The pages */

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.sheet-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
  max-width: 33rem;
  margin: 0 auto;
  padding: clamp(1.75rem, 8vh, 4.5rem) var(--gutter) calc(env(safe-area-inset-bottom) + 2.5rem);
}
.sheet-page > * { animation: rise 0.65s var(--ease) both; }
.sheet-page > *:nth-child(2) { animation-delay: 0.05s; }
.sheet-page > *:nth-child(3) { animation-delay: 0.1s; }
.sheet-page > *:nth-child(4) { animation-delay: 0.15s; }
.sheet-page > *:nth-child(n + 5) { animation-delay: 0.2s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(0.55rem); }
  to { opacity: 1; transform: none; }
}

h1 {
  margin: 0;
  font: 400 clamp(1.8rem, 7vw, 2.3rem)/1.22 var(--serif);
  letter-spacing: -0.012em;
  text-wrap: balance;
}
h1:focus { outline: none; }
.lede { margin: 0.95rem 0 0; color: var(--soft); overflow-wrap: anywhere; }
.label { margin: 2.25rem 0 0; color: var(--accent); }

.ways { margin: 0.8rem 0 0; padding: 0; list-style: none; counter-reset: way; }
.ways li {
  position: relative;
  padding: 0.7rem 0 0.7rem 1.9rem;
  border-top: 1px solid var(--line);
  counter-increment: way;
}
.ways li::before {
  content: counter(way);
  position: absolute;
  left: 0;
  top: 0.92rem;
  color: var(--accent);
  font: 600 0.85rem/1.4 var(--sans);
}

form { margin-top: 2rem; }
.field { display: block; margin-bottom: 1.1rem; }
.field > span:not(.visually-hidden) { display: block; color: var(--soft); font: 600 0.8rem/1.4 var(--sans); }
.field input {
  width: 100%;
  padding: 0.5rem 0 0.6rem;
  border: 0;
  border-bottom: 1.5px solid var(--line);
  border-radius: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: 400 1.125rem/1.4 var(--serif);
  transition: border-color 0.2s ease;
}
.field input:focus { border-color: var(--accent); }
.code-input {
  font: 600 2rem/1.2 var(--sans) !important;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.42em;
}
.error { margin: -0.4rem 0 0.9rem; color: var(--alert); font-size: 0.95rem; }

.primary, .ghost {
  width: 100%;
  min-height: 3.5rem;
  padding: 0.8rem 1.25rem;
  border-radius: 0.95rem;
  font: 600 1.03rem/1.2 var(--sans);
  cursor: pointer;
  transition: transform 0.14s ease, background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}
.primary { border: 0; background: var(--button); color: var(--button-ink); }
.primary:hover { background: var(--button-hover); }
.primary:active, .ghost:active { transform: scale(0.985); }
.primary[aria-busy='true'] { opacity: 0.6; pointer-events: none; }
form .primary { margin-top: 0.5rem; }
.ghost { border: 1px solid var(--line); background: transparent; color: var(--text); }
.ghost:hover { border-color: var(--soft); }

.quiet {
  padding: 0.5rem 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: 600 0.9rem/1.4 var(--sans);
  cursor: pointer;
}
.quiet-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem 1.5rem; margin-top: 0.85rem; }
.fine { margin: 1.1rem 0 0; color: var(--soft); font-size: 0.875rem; line-height: 1.55; }
.fine + .fine { margin-top: 0.6rem; }

/* Home and the conversations */

.library { flex: 1; display: flex; min-height: 0; }
.side, .reader { min-width: 0; }
.side {
  flex: 1;
  width: 100%;
  padding: clamp(1rem, 4vh, 2.5rem) var(--gutter) calc(env(safe-area-inset-bottom) + 2rem);
  animation: rise 0.55s var(--ease) both;
}
.side .primary { margin-top: 1.5rem; }
.reader {
  flex: 1;
  width: 100%;
  padding: 0.25rem var(--gutter) calc(env(safe-area-inset-bottom) + 3rem);
}
.library[data-view='list'] .reader { display: none; }
.library[data-view='detail'] .side { display: none; }

.switch {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 1.15rem;
  min-height: 2rem;
  color: var(--text);
  font: 600 0.92rem/1.3 var(--sans);
  cursor: pointer;
}
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative;
  flex: none;
  width: 2.3rem;
  height: 1.38rem;
  border-radius: 1rem;
  background: var(--line);
  transition: background-color 0.2s ease;
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 0.14rem;
  left: 0.14rem;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: #fffaf0;
  box-shadow: 0 1px 3px rgba(29, 31, 26, 0.28);
  transition: transform 0.22s var(--ease);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(0.92rem); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 3px; }
.switch-note { margin-top: 0.4rem; padding-left: 3rem; color: var(--text); }
.switch-note + .fine { margin-top: 0.75rem; }

.list-label { margin-top: 2.5rem; padding-bottom: 0.7rem; }
.rows { margin: 0 calc(var(--gutter) * -0.5); }
.row {
  display: block;
  padding: 0.95rem calc(var(--gutter) * 0.5);
  border-top: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
  transition: background-color 0.15s ease;
}
.row:first-child { border-top: 0; }
.row:hover { background: var(--tint); }
.row-title { display: block; font-size: 1.09rem; line-height: 1.35; }
.row-meta { display: block; margin-top: 0.22rem; color: var(--soft); font: 600 0.76rem/1.4 var(--sans); }
.row-preview {
  display: -webkit-box;
  margin-top: 0.38rem;
  overflow: hidden;
  color: var(--soft);
  font-size: 0.93rem;
  line-height: 1.48;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.row[aria-current='page'] { background: var(--tint); }
.empty { margin: 0; padding: 0.5rem 0 0; color: var(--soft); font-size: 0.95rem; }

.skeleton { display: block; height: 0.8rem; margin: 1.15rem calc(var(--gutter) * 0.5); border-radius: 0.3rem; background: var(--line); animation: shimmer 1.4s ease-in-out infinite; }
.skeleton:nth-child(3n) { width: 45%; }
.skeleton:nth-child(3n + 1) { width: 72%; }
.skeleton:nth-child(3n + 2) { width: 90%; }
@keyframes shimmer { 50% { opacity: 0.45; } }

/* Reading one conversation */

.reader-column { max-width: 40rem; margin: 0 auto; animation: rise 0.5s var(--ease) both; }
.back {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0 1.25rem -0.1rem;
  padding: 0.5rem 0;
  color: var(--accent);
  font: 600 0.9rem/1.3 var(--sans);
  text-decoration: none;
}
.back svg { flex: none; }
.banner {
  margin: 0 0 1.5rem;
  padding: 0.75rem 0.95rem;
  border-radius: 0.8rem;
  background: var(--tint);
  font: 600 0.84rem/1.45 var(--sans);
  overflow-wrap: anywhere;
}
.meta { margin: 0 0 0.45rem; color: var(--soft); font: 600 0.8rem/1.4 var(--sans); }
.reader h1 { font-size: clamp(1.7rem, 6vw, 2.2rem); }

.tabs { display: flex; gap: 1.6rem; margin-top: 1.5rem; border-bottom: 1px solid var(--line); }
.tab {
  position: relative;
  padding: 0.7rem 0;
  border: 0;
  background: transparent;
  color: var(--soft);
  font: 600 0.92rem/1.3 var(--sans);
  cursor: pointer;
  transition: color 0.18s ease;
}
.tab:hover { color: var(--text); }
.tab[aria-selected='true'] { color: var(--text); }
.tab[aria-selected='true']::after {
  content: '';
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: var(--accent);
}

.panel { padding-top: 1.9rem; animation: rise 0.4s var(--ease) both; }
.panel:focus { outline: none; }
.note-sections { display: flex; flex-direction: column; gap: 2.35rem; }
.note-sections .label { margin: 0 0 0.85rem; }
blockquote {
  margin: 0;
  font-size: clamp(1.2rem, 4.8vw, 1.36rem);
  line-height: 1.52;
  letter-spacing: -0.004em;
}
blockquote + blockquote { margin-top: 1.15rem; }

.transcript-tools { display: flex; justify-content: flex-end; margin: -0.9rem 0 0.6rem; }
.turn { margin: 0; max-width: 37rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.turn + .turn { margin-top: 1.1rem; }
.turn-coach { color: var(--accent); font-style: italic; }
.turn-hold { color: var(--soft); font-size: 0.88rem; font-style: italic; }
.turn + .turn-hold, .turn-hold + .turn { margin-top: 0.55rem; }
.turn-time {
  margin: 1.9rem 0 1rem;
  color: var(--soft);
  font: 600 0.72rem/1.3 var(--sans);
  letter-spacing: 0.06em;
}
[lang='zh-Hant'] .turn-coach, [lang='zh-Hant'] .turn-hold { font-style: normal; }

.help { margin: 0 0 1.6rem; color: var(--text); }
.reader-actions { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 2.75rem; }
.danger-link {
  align-self: flex-start;
  margin-top: 0.5rem;
  padding: 0.5rem 0;
  border: 0;
  background: transparent;
  color: var(--alert);
  font: 600 0.88rem/1.3 var(--sans);
  cursor: pointer;
}

/* The room while they talk */

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 33rem;
  margin: 0 auto;
  padding: 0 var(--gutter) calc(env(safe-area-inset-bottom) + 2rem);
  text-align: center;
}
.stage .status { min-height: 1.6em; margin: 2.5rem 0 0; color: var(--soft); font-size: 1rem; }
.stage-actions { width: 100%; margin-top: auto; padding-top: 2rem; }
.stage-actions .fine { margin: 0 0 1rem; }
.still { margin: 0 0 1rem; font-size: 1.125rem; }
.stage .quiet { display: block; margin: 0.5rem auto 0; color: var(--soft); }

.ring {
  position: relative;
  flex: none;
  width: min(46vw, 11rem);
  aspect-ratio: 1;
  margin-top: auto;
  animation: breathe 7s ease-in-out infinite;
}
.ring i { position: absolute; inset: 0; border-radius: 50%; will-change: transform, opacity; }
.ring-you {
  border: 1.5px solid rgba(233, 227, 211, 0.62);
  transform: scale(calc(1 + var(--you, 0) * 0.32));
  opacity: calc(0.55 + var(--you, 0) * 0.45);
}
.ring-coach {
  background: radial-gradient(circle, #ffd88a, rgba(255, 216, 138, 0) 68%);
  transform: scale(calc(0.8 + var(--coach, 0) * 0.5));
  opacity: calc(0.07 + var(--coach, 0) * 0.62);
}
.ring.waiting { opacity: 0.45; transition: opacity 0.8s ease; }
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.022); }
}

/* Nobody has touched the phone for a while: nearly black, and the buttons step back. */
body[data-rest] { --bg: #000; }
.top, .stage-actions { transition: opacity 1.2s ease; }
body[data-rest] .top { opacity: 0.25; }
body[data-rest] .stage-actions { opacity: 0.14; pointer-events: none; }
body[data-rest] .ring { opacity: 0.75; }

/* Sheets and small notices */

.sheet {
  width: min(100% - 2rem, 27rem);
  max-height: min(85dvh, 44rem);
  padding: 1.6rem 1.5rem 1.35rem;
  overflow-y: auto;
  border: 0;
  border-radius: 1.25rem;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1.5rem 4rem rgba(15, 26, 28, 0.28);
}
.sheet[open] { animation: rise 0.28s var(--ease) both; }
@media (max-width: 859px) {
  .sheet { margin: auto auto calc(env(safe-area-inset-bottom) + 1rem); }
}
.sheet::backdrop { background: rgba(15, 26, 28, 0.42); }
.sheet h2 { margin: 0; font: 400 1.35rem/1.3 var(--serif); }
#sheet-body { color: var(--soft); }
#sheet-body p { margin: 0.65rem 0 0; }
#sheet-body .ways { margin-top: 0.75rem; color: var(--text); }
.sheet-actions { display: flex; flex-direction: column; gap: 0.55rem; margin-top: 1.35rem; }
.sheet-actions .primary, .sheet-actions .ghost { min-height: 3.05rem; font-size: 0.98rem; }
.primary.destructive { background: var(--alert); color: #fffaf0; }
@media (prefers-color-scheme: dark) { .primary.destructive { color: #1b1410; } }

.toast {
  position: fixed;
  z-index: 5;
  bottom: calc(env(safe-area-inset-bottom) + 1.25rem);
  left: 50%;
  padding: 0.6rem 1.05rem;
  border-radius: 2rem;
  background: var(--text);
  color: var(--bg);
  font: 600 0.86rem/1.2 var(--sans);
  transform: translateX(-50%);
  animation: rise 0.25s var(--ease) both;
}

/* A wider window holds the list and the page you're reading side by side. */
@media (min-width: 860px) {
  .library { height: calc(100dvh - 3.75rem); }
  .library[data-view='list'] .reader, .library[data-view='detail'] .side { display: block; }
  .side {
    flex: none;
    width: 23.5rem;
    overflow-y: auto;
    border-right: 1px solid var(--line);
    padding-top: 1.75rem;
  }
  .reader { overflow-y: auto; padding-top: 1.75rem; padding-right: 2.5rem; padding-left: 2.5rem; }
  .back { display: none; }
  .sheet-page { padding-top: clamp(3rem, 11vh, 6rem); }
}

/* Traditional Chinese reads better a little more open, and has no capitals to track. */
html[lang='zh-Hant'] body { line-height: 1.72; }
html[lang='zh-Hant'] h1 { letter-spacing: 0.01em; line-height: 1.36; }
html[lang='zh-Hant'] .label { letter-spacing: 0.08em; }
[lang='zh-Hant'] blockquote { line-height: 1.68; letter-spacing: 0.01em; }

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