:root {
  --ink: #26362f;
  --muted: #617068;
  --paper: #fffdf8;
  --cream: #fff5df;
  --warm: #ffb84d;
  --warm-dark: #a43b28;
  --green: #356859;
  --green-dark: #234d42;
  --green-pale: #e7f2ed;
  --blue-pale: #eaf3f7;
  --line: #dfded7;
  --danger: #a52d28;
  --shadow: 0 8px 28px rgba(44, 57, 48, 0.09);
  --radius: 22px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #f3efe6;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #f3efe6;
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  padding-bottom: calc(30px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 90% 0, rgba(255, 184, 77, 0.22), transparent 300px),
    #f7f4ec;
  color: var(--ink);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 4px solid #2b72bd;
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 8px;
  left: 8px;
  transform: translateY(-160%);
  border-radius: 10px;
  padding: 12px 16px;
  background: #fff;
  color: var(--ink);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-header,
.app-main {
  width: min(100%, 760px);
  margin-inline: auto;
}

.app-header {
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-row img {
  flex: 0 0 48px;
  border-radius: 13px;
  box-shadow: 0 4px 12px rgba(108, 62, 30, 0.12);
}

.brand-row h1 {
  margin: 1px 0 0;
  font-size: clamp(1.2rem, 5vw, 1.6rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.eyebrow,
.section-kicker,
.intro-kicker {
  margin: 0;
  color: var(--warm-dark);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 13px 0 12px;
}

.status-pill,
.section-badge,
.count-label {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 5px 11px;
  background: var(--green-pale);
  color: var(--green-dark);
  font-size: 0.8rem;
  font-weight: 750;
}

.status-pill::before {
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: #439a70;
  content: "";
}

.status-pill[data-online="false"]::before {
  background: var(--warm);
}

.recording-pill {
  background: #f4ece7;
  color: #714334;
}

.recording-pill::before {
  background: #c7664e;
}

.mode-switch {
  position: sticky;
  z-index: 20;
  top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  border: 1px solid rgba(53, 104, 89, 0.18);
  border-radius: 18px;
  padding: 5px;
  background: rgba(255, 253, 248, 0.95);
  box-shadow: 0 7px 22px rgba(44, 57, 48, 0.1);
  backdrop-filter: blur(12px);
}

.mode-switch button {
  min-width: 0;
  min-height: 64px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  font-weight: 800;
}

.mode-switch button[aria-pressed="true"] {
  background: var(--green);
  color: #fff;
  box-shadow: 0 4px 10px rgba(35, 77, 66, 0.22);
}

.app-main {
  padding: 0 12px;
}

.intro-panel,
.parent-hero,
.admin-card,
.content-section,
.scene-detail,
.privacy-note {
  border: 1px solid rgba(53, 70, 60, 0.1);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.intro-panel {
  padding: 22px 18px;
  background:
    linear-gradient(135deg, rgba(255, 184, 77, 0.18), rgba(255, 255, 255, 0.9)),
    var(--paper);
}

.intro-steps {
  margin: 7px 0 5px;
  font-size: 1.08rem;
}

.gentle-note {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.93rem;
}

.content-section,
.scene-detail,
.admin-card,
.parent-hero {
  margin-top: 14px;
  padding: 18px 14px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.section-heading > * {
  min-width: 0;
}

.section-badge,
.count-label {
  flex: 0 1 auto;
  max-width: 46%;
  text-align: center;
}

.section-heading h2,
.scene-detail h2,
.admin-card h2,
.parent-hero h2 {
  margin: 1px 0 0;
  font-size: 1.4rem;
  line-height: 1.25;
}

.phrase-grid {
  display: grid;
  gap: 12px;
}

.phrase-card {
  position: relative;
  display: grid;
  grid-template-columns: 1fr minmax(92px, 31%);
  gap: 3px 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 19px;
  padding: 16px;
  background: #fff;
}

.phrase-card::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--warm);
  content: "";
}

.phrase-number {
  grid-column: 1;
  color: #9b6b27;
  font-size: 0.76rem;
  font-weight: 800;
}

.phrase-chinese {
  grid-column: 1;
  margin: 0;
  font-size: clamp(1.28rem, 6vw, 1.65rem);
  line-height: 1.24;
}

.phrase-english {
  grid-column: 1;
  margin: 2px 0 0;
  color: var(--green-dark);
  font-size: 1rem;
  font-weight: 750;
}

.phrase-action {
  grid-column: 1 / -1;
  margin: 8px 0 0;
  border-top: 1px dashed var(--line);
  padding-top: 9px;
  color: var(--muted);
  font-size: 0.9rem;
}

.play-button {
  grid-row: 1 / 4;
  grid-column: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 92px;
  border: 0;
  border-radius: 18px;
  background: var(--green);
  color: #fff;
  font-weight: 850;
  box-shadow: 0 5px 12px rgba(53, 104, 89, 0.2);
}

.play-button:active:not(:disabled) {
  transform: scale(0.98);
}

.play-button[data-playing="true"] {
  background: var(--warm-dark);
}

.play-button:disabled {
  background: #e8e7e1;
  color: #777b77;
  box-shadow: none;
}

.play-symbol {
  margin-bottom: 3px;
  font-size: 1.7rem;
  line-height: 1;
}

.scene-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.scene-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-height: 124px;
  border: 1px solid #dcd9cf;
  border-radius: 19px;
  padding: 14px;
  background: #fff;
  text-align: left;
}

.scene-tile:active {
  transform: scale(0.98);
}

.scene-emoji {
  font-size: 1.8rem;
  line-height: 1;
}

.scene-name {
  margin-top: 8px;
  font-size: 1.16rem;
}

.scene-count {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.back-button,
.stop-audio-button {
  min-height: 64px;
  border: 1px solid #c9d3ce;
  border-radius: 15px;
  padding: 10px 16px;
  background: #fff;
  color: var(--green-dark);
  font-weight: 800;
}

.scene-detail h2 {
  margin-top: 16px;
}

.scene-detail .phrase-grid {
  margin-top: 16px;
}

.playback-feedback {
  position: fixed;
  z-index: 15;
  right: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  left: 12px;
  width: min(calc(100% - 24px), 736px);
  margin-inline: auto;
  pointer-events: none;
}

.now-playing,
.action-prompt {
  border-radius: 17px;
  padding: 15px 16px;
  box-shadow: 0 8px 22px rgba(35, 77, 66, 0.2);
  font-weight: 800;
  pointer-events: auto;
}

.now-playing {
  background: var(--green-dark);
  color: #fff;
}

.action-prompt {
  margin-top: 8px;
  background: #ffe9ad;
  color: #5c3c0d;
  font-size: 1.05rem;
}

.stop-audio-button {
  display: block;
  margin: 8px 0 0 auto;
  min-height: 64px;
  background: rgba(255, 255, 255, 0.96);
  pointer-events: auto;
}

.parent-hero {
  background: var(--green);
  color: #fff;
}

.parent-hero .section-kicker {
  color: #ffdda3;
}

.parent-hero ol {
  margin: 12px 0 0;
  padding-left: 24px;
}

.admin-card > p {
  color: var(--muted);
}

.primary-button,
.secondary-button,
.save-button,
.stop-record-button,
.danger-link {
  min-height: 60px;
  border-radius: 14px;
  padding: 10px 16px;
  font-weight: 800;
}

.primary-button,
.save-button {
  border: 1px solid var(--green);
  background: var(--green);
  color: #fff;
}

.secondary-button {
  border: 1px solid #bfc9c4;
  background: #fff;
  color: var(--green-dark);
}

.stop-record-button {
  border: 1px solid var(--danger);
  background: var(--danger);
  color: #fff;
}

.danger-link {
  border: 1px solid #e6c6c1;
  background: #fff7f5;
  color: var(--danger);
}

.primary-button:disabled,
.save-button:disabled {
  border-color: #d1d1cc;
  background: #d1d1cc;
  color: #6f746f;
}

.full-width {
  width: 100%;
}

.button-stack {
  display: grid;
  gap: 10px;
}

.recording-manager {
  margin-top: 18px;
}

.recording-scene {
  margin-top: 20px;
}

.recording-scene h3 {
  position: sticky;
  z-index: 3;
  top: 82px;
  margin: 0;
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--cream);
}

.weekly-recordings {
  margin-top: 4px;
  border: 2px solid #e6bf78;
  border-radius: 17px;
  padding: 10px;
  background: #fffaf0;
}

.other-recordings {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.other-recordings > summary {
  min-height: 60px;
  border-radius: 14px;
  padding: 17px 14px;
  background: #f1f2ee;
  color: var(--green-dark);
  font-weight: 850;
  cursor: pointer;
}

.recording-row {
  display: grid;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 14px 2px;
}

.recording-words {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 0 8px;
}

.recording-words > span:last-child {
  grid-column: 2;
  color: var(--muted);
}

.recording-number {
  grid-row: 1 / 3;
  color: var(--warm-dark);
  font-size: 0.78rem;
  font-weight: 850;
}

.recording-state {
  margin: 0;
  font-size: 0.82rem;
}

.recording-state.ready {
  color: #26714f;
}

.recording-state.missing {
  color: #8b5b42;
}

.recording-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 8px;
}

.week-selection {
  display: grid;
  gap: 12px;
}

.week-scene-group {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
}

.week-scene-group legend {
  padding: 0 7px;
  font-weight: 850;
}

.week-option {
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  min-height: 58px;
  border-bottom: 1px solid #eceae4;
  padding: 7px 3px;
}

.week-option:last-child {
  border-bottom: 0;
}

.week-option input {
  width: 24px;
  height: 24px;
  accent-color: var(--green);
}

.week-option-words {
  display: grid;
}

.week-option-words small {
  color: var(--muted);
}

.privacy-note {
  margin: 14px 0;
  padding: 16px;
  background: var(--blue-pale);
}

.privacy-note p {
  margin: 5px 0 0;
}

.install-help {
  margin: 12px 0 0;
  border-left: 5px solid var(--green);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--green-pale);
  color: var(--green-dark);
  font-weight: 750;
}

.install-help[data-type="warning"] {
  border-left-color: var(--warm);
  background: var(--cream);
  color: #67420d;
}

.install-help[data-type="success"] {
  border-left-color: #439a70;
}

.modal-backdrop {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  background: rgba(21, 30, 26, 0.65);
}

.record-dialog {
  position: relative;
  width: min(100%, 600px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  border-radius: 25px 25px 16px 16px;
  padding: 24px 18px calc(20px + env(safe-area-inset-bottom));
  background: #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.record-dialog h2 {
  margin: 6px 68px 8px 0;
}

.modal-close {
  position: absolute;
  top: 13px;
  right: 13px;
  min-width: 58px;
  min-height: 48px;
  border: 0;
  border-radius: 13px;
  background: #f0efeb;
  font-weight: 750;
}

.record-dialog-chinese {
  margin: 16px 0 0;
  font-size: 1.65rem;
  font-weight: 850;
}

.record-dialog-english {
  margin: 0;
  color: var(--green-dark);
  font-size: 1.22rem;
  font-weight: 750;
}

.record-guide {
  border-radius: 14px;
  padding: 12px;
  background: var(--cream);
}

.record-live-status {
  min-height: 52px;
  border-radius: 14px;
  padding: 13px;
  background: #f3f3ef;
  font-weight: 750;
}

.record-live-status[data-type="recording"] {
  background: #ffe3df;
  color: #872820;
}

.record-live-status[data-type="success"] {
  background: var(--green-pale);
  color: var(--green-dark);
}

.record-live-status[data-type="error"] {
  background: #ffe3df;
  color: var(--danger);
}

.record-dialog audio {
  width: 100%;
  margin-bottom: 12px;
}

.record-dialog-actions {
  display: grid;
  gap: 10px;
}

.record-dialog-actions .large {
  width: 100%;
  min-height: 62px;
}

body.modal-open {
  overflow: hidden;
}

.toast {
  position: fixed;
  z-index: 200;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  left: 14px;
  width: min(calc(100% - 28px), 560px);
  margin-inline: auto;
  border-radius: 16px;
  padding: 15px 17px;
  background: #26362f;
  color: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.24);
  font-weight: 750;
}

.toast[data-type="error"] {
  background: #842721;
}

.toast[data-type="warning"] {
  background: #74500f;
}

.toast[data-type="success"] {
  background: var(--green-dark);
}

.empty-state,
.noscript,
.boot-error {
  border-radius: 14px;
  padding: 15px;
  background: var(--cream);
}

.boot-error {
  margin-bottom: 12px;
  background: #ffe3df;
  color: var(--danger);
  font-weight: 800;
}

@media (min-width: 640px) {
  .app-header {
    padding-inline: 24px;
  }

  .app-main {
    padding-inline: 20px;
  }

  .phrase-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .phrase-card {
    grid-template-columns: 1fr;
  }

  .play-button {
    grid-row: auto;
    grid-column: 1;
    min-height: 66px;
    flex-direction: row;
    gap: 8px;
  }

  .phrase-action {
    grid-column: 1;
  }

  .scene-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .modal-backdrop {
    align-items: center;
  }

  .record-dialog {
    border-radius: 25px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
