:root {
  color-scheme: light;
  --bg: #f7f4ee;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #1f2328;
  --muted: #69717d;
  --line: #ded8ce;
  --accent: #196b69;
  --accent-strong: #0f504f;
  --accent-soft: #dceeed;
  --warning: #9f5b16;
  --good: #167247;
  --bad: #b33a2e;
  --shadow: 0 14px 40px rgba(31, 35, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.55;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px 40px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
}

.title-stack {
  position: relative;
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

.date-trigger {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 28px;
  margin: 0 0 4px;
  padding: 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 0.76rem;
  font-weight: 800;
  text-align: left;
  text-transform: uppercase;
}

.date-trigger::after {
  content: "";
  width: 0;
  height: 0;
  margin-left: 7px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
}

.date-trigger:focus-visible,
.calendar-nav:focus-visible,
.calendar-day:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.date-picker {
  position: absolute;
  z-index: 20;
  top: 32px;
  left: 0;
  width: min(360px, calc(100vw - 32px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.date-picker-head {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.calendar-nav {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-strong);
  background: var(--surface);
  font-size: 1.2rem;
  font-weight: 900;
}

.calendar-month {
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 850;
  text-align: center;
}

.calendar-weekdays,
.date-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.calendar-weekdays {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-align: center;
}

.calendar-day {
  display: grid;
  min-width: 0;
  min-height: 46px;
  padding: 5px 3px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  text-align: center;
}

.calendar-day.in-month {
  color: var(--ink);
}

.calendar-day.has-study {
  border-color: #c7deda;
  background: #f3fbfa;
}

.calendar-day.selected {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.calendar-day.today:not(.selected) {
  border-color: #d6b36f;
}

.calendar-date {
  display: block;
  font-size: 0.82rem;
  font-weight: 850;
  line-height: 1;
}

.calendar-progress {
  display: block;
  min-height: 14px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1;
}

.day-summary {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  line-height: 1.12;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.6rem, 8vw, 2.6rem);
}

h2 {
  font-size: 1.42rem;
}

.sync-state {
  flex: 0 0 auto;
  max-width: 44%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
  font-size: 0.82rem;
  text-align: right;
}

.sync-state.saved {
  color: var(--good);
  border-color: #b6dac8;
}

.sync-state.offline {
  color: var(--warning);
  border-color: #e6c99f;
}

.overview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 12px;
}

.metric {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric-value,
.metric-label {
  display: block;
}

.metric-value {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1;
}

.metric-label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.article-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 14px;
}

.article-tab {
  min-height: 72px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  text-align: left;
}

.article-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tab-number {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.tab-title {
  display: block;
  margin-top: 4px;
  font-size: 0.92rem;
  font-weight: 750;
  line-height: 1.2;
}

.tab-status {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.76rem;
}

.study-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.empty-day {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.empty-day p:last-child {
  margin: 10px 0 0;
  color: var(--muted);
}

.empty-day-actions {
  display: flex;
  margin-top: 14px;
}

.create-day-button {
  min-width: min(220px, 100%);
}

.empty-day-status {
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.empty-day-status[data-status="ready"] {
  color: var(--good);
}

.empty-day-status[data-status="error"] {
  color: var(--warning);
}

.article-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.icon-button {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  background: var(--surface);
  font-size: 1.15rem;
  font-weight: 800;
}

.icon-button:active,
.primary-button:active,
.ghost-button:active,
.mode-button:active,
.article-tab:active {
  transform: translateY(1px);
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: #f2eee6;
}

.mode-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-weight: 750;
}

.mode-button.active {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--surface-strong);
}

.mode-view {
  display: none;
  padding: 16px;
}

.mode-view.active {
  display: block;
}

.word-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 16px;
}

.word-chip {
  padding: 6px 9px;
  border: 1px solid #c7deda;
  border-radius: 8px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 0.84rem;
  font-weight: 750;
}

.word-chip,
.story-word {
  cursor: pointer;
}

.word-chip:focus-visible,
.story-word:focus-visible,
.target-word:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.story {
  display: grid;
  gap: 14px;
  font-size: 1.04rem;
}

.story p {
  margin: 0;
}

.story-word {
  display: inline;
  padding: 0;
  border: 0;
  border-radius: 3px;
  color: inherit;
  background: transparent;
  font: inherit;
  text-align: inherit;
}

.story-word:hover {
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.target-word {
  color: var(--accent-strong);
  font-weight: 850;
}

.word-coach-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.word-coach-actions .icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

.word-coach-title-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 10px;
  min-width: 0;
}

.word-coach-phonetic {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 800;
  white-space: nowrap;
}

.word-coach-actions svg {
  display: block;
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.word-coach-backdrop {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: end center;
  padding: 18px;
  background: rgba(31, 35, 40, 0.38);
  overscroll-behavior: contain;
}

.word-coach-panel {
  width: min(720px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  overflow: hidden;
  overscroll-behavior: contain;
}

.word-coach-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.word-coach-body {
  min-height: min(520px, calc(100vh - 180px));
  max-height: min(590px, calc(100vh - 160px));
  overflow-y: auto;
  padding: 16px;
  color: var(--ink);
  overscroll-behavior: contain;
}

body.coach-open {
  position: fixed;
  width: 100%;
  overflow: hidden;
}

.word-coach-body.loading,
.word-coach-body.error {
  color: var(--muted);
  font-weight: 750;
}

.word-coach-body.error {
  color: var(--warning);
}

.coach-combined {
  display: grid;
  gap: 18px;
}

.coach-section {
  display: grid;
  gap: 10px;
}

.coach-section h3 {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.98rem;
  line-height: 1.2;
}

.coach-section-body {
  display: grid;
  gap: 12px;
}

.coach-section-body.loading {
  min-height: 150px;
  align-content: start;
  color: var(--muted);
  font-weight: 750;
}

.coach-section-body.error {
  color: var(--warning);
  font-weight: 750;
}

.coach-loading {
  display: grid;
  gap: 12px;
}

.coach-loading-text {
  color: var(--muted);
}

.coach-loading-lines {
  display: grid;
  gap: 9px;
}

.coach-loading-line {
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ece7dd 0%, #f7f4ee 52%, #ece7dd 100%);
  background-size: 220% 100%;
  animation: loading-shimmer 1.2s ease-in-out infinite;
}

.coach-loading-line:nth-child(2) {
  width: 88%;
}

.coach-loading-line:nth-child(3) {
  width: 72%;
}

.coach-loading-line:nth-child(4) {
  width: 54%;
}

@keyframes loading-shimmer {
  0% {
    background-position: 100% 0;
  }

  100% {
    background-position: -100% 0;
  }
}

.coach-content {
  display: grid;
  gap: 12px;
}

.coach-content h2,
.coach-content h3 {
  margin: 6px 0 0;
  line-height: 1.2;
}

.coach-content h2 {
  font-size: 1.28rem;
}

.coach-content h3 {
  font-size: 1.03rem;
}

.coach-content p,
.coach-content ul,
.coach-content ol,
.coach-content blockquote {
  margin: 0;
}

.coach-content ul,
.coach-content ol {
  padding-left: 1.3rem;
}

.coach-content blockquote {
  padding-left: 12px;
  border-left: 3px solid var(--accent);
  color: #3f464d;
}

.summary-block {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.summary-block summary {
  color: var(--accent-strong);
  font-weight: 800;
}

.summary-block p {
  margin: 10px 0 0;
  color: #3f464d;
}

.cloze-form {
  display: grid;
  gap: 12px;
}

.cloze-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf6;
}

.cloze-prompt {
  margin: 0;
  font-weight: 700;
}

.cloze-input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface-strong);
}

.cloze-input {
  min-height: 42px;
  padding: 9px 10px;
}

.cloze-input.correct {
  border-color: #85c7a6;
  background: #f0fbf4;
}

.cloze-input.incorrect {
  border-color: #e0a39b;
  background: #fff5f4;
}

.answer-line {
  display: none;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.answer-line.visible {
  display: block;
}

.quiz-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.primary-button,
.ghost-button {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  border: 1px solid var(--accent);
  color: white;
  background: var(--accent);
}

.ghost-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
}

.result-line {
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 750;
}

.retell-list {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.retell-prompt {
  margin: 0;
  padding: 11px 12px;
  border-left: 4px solid var(--accent);
  background: #f5f1e9;
  border-radius: 0 8px 8px 0;
  font-weight: 700;
}

.note-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

textarea {
  display: block;
  min-height: 148px;
  margin-bottom: 12px;
  padding: 11px 12px;
  resize: vertical;
}

@media (min-width: 820px) {
  .app-shell {
    padding-top: 24px;
  }

  main {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 16px;
    align-items: start;
  }

  .overview {
    grid-column: 1 / -1;
  }

  .article-tabs {
    grid-template-columns: 1fr;
    margin: 0;
  }

  .study-panel {
    min-width: 0;
  }
}

@media (max-width: 760px) {
  .word-coach-backdrop {
    place-items: center;
    padding: 6px;
  }

  .word-coach-panel {
    display: flex;
    width: 100%;
    height: calc(100vh - 12px);
    height: calc(100dvh - 12px);
    max-height: calc(100vh - 12px);
    max-height: calc(100dvh - 12px);
    flex-direction: column;
  }

  .word-coach-head {
    flex: 0 0 auto;
  }

  .word-coach-body {
    flex: 1;
    min-height: 0;
    max-height: none;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .date-picker {
    position: absolute;
    top: 32px;
    left: 0;
    width: min(360px, calc(100vw - 24px));
    margin: 0;
  }

  .sync-state {
    max-width: none;
    text-align: left;
  }

  .article-tabs {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
    scroll-snap-type: x mandatory;
  }

  .article-tab {
    flex: 0 0 74%;
    scroll-snap-align: start;
  }

  .quiz-actions {
    display: grid;
  }
}
