:root {
  color-scheme: light;
  --bg: #f7f4ee;
  --panel: #ffffff;
  --text: #21312b;
  --muted: #64716c;
  --line: #d9ded8;
  --primary: #2f7d68;
  --primary-dark: #225c4d;
  --accent: #f7c948;
  --soft: #edf7f2;
  --danger: #c94b4b;
  --shadow: 0 14px 34px rgba(34, 49, 43, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.app {
  width: min(640px, calc(100% - 20px));
  margin: 0 auto;
  padding: 14px 0 40px;
}

.topbar {
  display: flex;
  align-items: stretch;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 18px;
}

.top-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.app-tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 0 0 14px;
  padding: 8px;
  background: rgba(247, 244, 238, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(10px);
}

.app-tab {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
  padding: 8px 6px;
}

.app-tab.active {
  color: #fff;
  background: var(--primary);
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 34px;
  line-height: 1.15;
}

.topbar p,
.section-head p,
.small-note,
.image-caption {
  margin: 0;
  color: var(--muted);
}

.layout {
  display: block;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.app-view[hidden] {
  display: none;
}

h2 {
  margin: 0 0 14px;
  font-size: 22px;
  line-height: 1.25;
}

h3 {
  margin: 0 0 10px;
  font-size: 17px;
}

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

.status-pill {
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--primary-dark);
  font-size: 14px;
  border: 1px solid #cde7dc;
}

.settings-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-weight: 700;
}

select,
input[type="time"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 86px;
  line-height: 1.5;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.switch-row input {
  width: 20px;
  height: 20px;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.record-btn {
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  padding: 12px 16px;
  font-weight: 800;
}

.primary-btn {
  color: #fff;
  background: var(--primary);
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.secondary-btn {
  color: var(--primary-dark);
  background: var(--soft);
  border: 1px solid #cde7dc;
}

.ghost-btn {
  color: var(--primary-dark);
  background: transparent;
  border: 1px solid var(--line);
}

.full-width {
  width: 100%;
}

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

.story-image-panel {
  position: relative;
  margin: 0;
  min-width: 0;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #eef2ea;
}

.story-image-panel:only-child {
  grid-column: 1 / -1;
  aspect-ratio: 900 / 560;
}

.story-image-panel img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.story-image-index {
  position: absolute;
  top: 8px;
  left: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--primary-dark);
  border: 1px solid rgba(34, 92, 77, 0.18);
  font-weight: 900;
  font-size: 16px;
}

.image-caption {
  margin-top: 10px;
  font-size: 16px;
}

.practice-box {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}

.chat-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  padding: 12px;
}

.chat-list {
  display: grid;
  gap: 12px;
}

.chat-message {
  display: grid;
  gap: 6px;
  max-width: 86%;
}

.chat-message.child {
  justify-self: end;
}

.chat-message.has-audio {
  width: 320px;
  max-width: 86%;
}

.chat-message.coach {
  justify-self: start;
}

.chat-message.system {
  justify-self: center;
  max-width: 100%;
}

.chat-role {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.chat-bubble {
  border-radius: 8px;
  padding: 11px 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.chat-message.child .chat-bubble {
  background: var(--primary);
  color: #fff;
}

.chat-message.coach .chat-bubble {
  background: var(--soft);
  color: var(--text);
  border: 1px solid #cde7dc;
}

.chat-message.system .chat-bubble {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--line);
  text-align: center;
}

.chat-bubble audio {
  display: block;
  width: 100%;
  margin-top: 8px;
}

.chat-bubble.audio-bubble {
  width: 100%;
}

.chat-bubble.audio-only audio {
  margin-top: 0;
}

.tts-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid #b9d8cb;
  border-radius: 8px;
  background: #ffffff;
  color: var(--primary-dark);
  font-size: 14px;
  font-weight: 800;
}

.tts-btn:disabled {
  cursor: wait;
  color: var(--muted);
  background: #f3f5f2;
}

.record-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.record-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--accent);
  color: #3a2d00;
  min-height: 58px;
  font-size: 19px;
}

.record-btn.recording {
  background: var(--danger);
  color: #fff;
}

#recordIcon {
  font-size: 22px;
  line-height: 1;
}

.manual-label {
  margin-top: 2px;
}

.text-link-btn {
  justify-self: center;
  border: 0;
  background: transparent;
  color: var(--primary-dark);
  font-weight: 800;
  min-height: 36px;
  padding: 4px 8px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.quiet-link-btn {
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
}

.reference-answer {
  border: 1px solid #cde7dc;
  border-radius: 8px;
  background: var(--soft);
  padding: 12px;
}

.reference-answer[hidden] {
  display: none;
}

.reference-answer-title {
  color: var(--primary-dark);
  font-weight: 900;
  margin-bottom: 8px;
}

.reference-answer ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
}

.reference-answer li {
  line-height: 1.55;
}

.reference-answer strong {
  display: block;
  color: var(--primary-dark);
}

.reference-answer span {
  display: block;
}

.manual-entry {
  display: grid;
  gap: 10px;
}

.manual-entry[hidden] {
  display: none;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fffdf8;
}

.empty-box {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 22px;
  text-align: center;
  background: #fffdf8;
}

.report-content dl {
  margin: 0;
  display: grid;
  gap: 10px;
}

.report-content dt {
  font-weight: 900;
  color: var(--primary-dark);
}

.report-content dd {
  margin: -6px 0 6px;
  line-height: 1.65;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: grid;
  gap: 4px;
}

.history-item strong {
  font-size: 17px;
}

.history-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100% - 32px));
  background: #21312b;
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.toast.show {
  opacity: 1;
}

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(247, 244, 238, 0.94);
}

.access-gate[hidden] {
  display: none;
}

.access-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.access-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.access-card p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.5;
}

.access-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  margin-bottom: 12px;
}

@media (min-width: 900px) {
  .app {
    width: min(1180px, calc(100% - 32px));
    padding-top: 24px;
  }

  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .app-tabs {
    width: min(640px, 100%);
    margin-left: auto;
    margin-right: auto;
  }

  .record-row {
    grid-template-columns: minmax(180px, 1fr) auto;
  }
}
