:root {
  --safe-ink: #172033;
  --safe-muted: #66718a;
  --safe-line: #dbe5f6;
  --safe-page: #f8faff;
  --safe-work: #eef4ff;
  --safe-panel: #ffffff;
  --safe-blue: #3b68f2;
  --safe-green: #d9f5ee;
  --safe-green-mark: #a7e8dc;
  --safe-purple: #d8c8ff;
  --safe-purple-soft: #eee8ff;
  --safe-yellow: #fff0a9;
  --safe-red: #d94d61;
  --safe-red-soft: #fff0f2;
  --safe-shell: min(1320px, calc(100vw - 24px));
  --safe-side: 300px;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  padding: 10px 0 20px;
  background: var(--safe-page);
  color: var(--safe-ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.date-panel,
.topbar,
.app-shell,
.app-shell.sidebar-collapsed {
  width: var(--safe-shell) !important;
  max-width: var(--safe-shell) !important;
  margin-right: auto !important;
  margin-left: auto !important;
  transform: none !important;
}

.date-panel,
.app-shell.sidebar-collapsed .date-panel {
  position: relative !important;
  top: auto !important;
  display: grid !important;
  grid-template-columns: 118px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 52px;
  margin-bottom: 8px !important;
  padding: 0 !important;
  overflow: hidden;
  border: 0 !important;
  background: transparent !important;
  backdrop-filter: none !important;
}

.sidebar-toggle,
.app-shell.sidebar-collapsed .sidebar-toggle {
  display: none !important;
}

.panel-head,
.app-shell.sidebar-collapsed .panel-head {
  display: block !important;
  min-width: 0;
}

.panel-head .eyebrow {
  margin: 0 0 2px;
  color: var(--safe-blue);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel-head h1 {
  margin: 0;
  color: var(--safe-ink);
  font-size: 15px;
  font-weight: 620;
  line-height: 1.05;
}

.date-list,
.app-shell.sidebar-collapsed .date-list {
  display: flex !important;
  gap: 8px;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0 2px 2px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.date-list::-webkit-scrollbar {
  display: none;
}

.date-button {
  width: auto;
  min-width: 136px;
  min-height: 48px;
  flex: 0 0 auto;
  align-items: center;
  padding: 7px 10px;
  border: 1px solid var(--safe-line);
  border-radius: 12px;
  background: var(--safe-panel);
  color: var(--safe-muted);
  box-shadow: none;
}

.date-button strong {
  color: inherit;
  font-size: 16px;
  font-weight: 650;
}

.date-button span span,
.date-score {
  color: inherit;
  font-size: 12px;
  font-weight: 560;
}

.date-button.active {
  border-color: var(--safe-blue);
  background: #edf4ff;
  color: var(--safe-ink);
}

.date-button.completed {
  border-color: #bfe8de;
  background: var(--safe-green);
  color: var(--safe-ink);
}

.topbar {
  position: relative !important;
  top: auto !important;
  min-height: 84px !important;
  margin-top: 0 !important;
  padding: 14px 24px !important;
  border: 1px solid var(--safe-line) !important;
  border-radius: 18px 18px 0 0 !important;
  background: var(--safe-panel) !important;
  box-shadow: none !important;
}

.brand {
  gap: 12px;
}

.brand-mark {
  width: 50px;
  height: 50px;
  border-radius: 14px;
  background: var(--safe-blue);
  color: #fff;
  font-size: 15px;
  font-weight: 520;
}

.brand strong {
  color: var(--safe-ink);
  font-size: 21px;
  font-weight: 620;
  line-height: 1.08;
}

.brand small {
  margin-top: 4px;
  color: var(--safe-muted);
  font-size: 14px;
  font-weight: 500;
}

.header-tools,
.header-progress {
  display: flex;
  align-items: center;
}

.header-tools {
  gap: 14px;
}

.header-progress {
  gap: 12px;
}

.header-progress-track {
  width: 130px;
  height: 8px;
  border-radius: 999px;
  background: #e7eefb;
}

.header-progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--safe-blue);
}

.header-progress strong {
  min-width: 82px;
  color: var(--safe-ink);
  font-size: 20px;
  font-weight: 620;
  white-space: nowrap;
}

.user-button {
  min-width: 50px;
  min-height: 50px;
  padding: 0 14px;
  border: 1px solid var(--safe-line);
  border-radius: 15px;
  background: #fff;
  color: var(--safe-ink);
  font-weight: 620;
}

.user-button.is-authenticated {
  width: 50px;
  min-width: 50px;
  max-width: 50px;
  height: 50px;
  padding: 0;
  border-radius: 15px;
  font-size: 0;
}

.app-shell,
.app-shell.sidebar-collapsed {
  display: block !important;
  min-height: 0 !important;
  height: auto !important;
  overflow: visible !important;
  border: 1px solid var(--safe-line) !important;
  border-top: 0 !important;
  border-radius: 0 0 18px 18px !important;
  background: var(--safe-panel) !important;
  box-shadow: none !important;
}

.task-panel {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) var(--safe-side) !important;
  grid-template-areas:
    "hero steps"
    "task steps" !important;
  align-items: start !important;
  gap: 14px !important;
  width: 100% !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 16px !important;
  background: var(--safe-work) !important;
}

.lesson-hero {
  grid-area: hero !important;
  display: block !important;
  min-width: 0;
  padding: 16px 18px !important;
  border: 1px solid var(--safe-line) !important;
  border-radius: 14px !important;
  background: var(--safe-panel) !important;
  box-shadow: none !important;
}

.lesson-hero h2 {
  margin: 3px 0 10px;
  color: var(--safe-ink);
  font-size: 24px;
  font-weight: 620;
  line-height: 1.12;
}

.lesson-summary-row {
  display: flex !important;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

#lessonSummary {
  display: grid;
  gap: 8px;
  margin: 0;
}

.dictionary-label {
  color: var(--safe-blue);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

.dictionary-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.dictionary-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 6px 9px;
  border: 1px solid var(--safe-line);
  border-radius: 999px;
  background: #f7faff;
  color: var(--safe-ink);
  font-size: 13px;
}

.dictionary-chip strong {
  font-weight: 650;
  white-space: nowrap;
}

.dictionary-chip em {
  color: var(--safe-muted);
  font-style: normal;
}

.lesson-tools {
  display: flex;
  flex: 0 0 auto;
  gap: 7px;
}

.task-card {
  grid-area: task !important;
  min-height: 0 !important;
  padding: 0 !important;
  overflow: visible !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

.task-card::before {
  display: none !important;
}

#taskContent,
.task-actions {
  width: min(860px, 100%) !important;
}

.task-title {
  margin: 0 0 8px;
  color: var(--safe-ink);
  font-size: 34px;
  font-weight: 560;
  line-height: 1.12;
}

.task-note {
  margin: 0 0 18px;
  color: var(--safe-muted);
  font-size: 18px;
  line-height: 1.35;
}

.focus-card,
.chatgpt-card {
  display: grid;
  gap: 14px;
  width: 100%;
  padding: 22px 28px 0;
  border: 0 !important;
  border-radius: 18px 18px 0 0;
  background: var(--safe-panel);
  box-shadow: none;
}

.focus-head,
.task-inline-tools {
  display: flex;
  align-items: center;
}

.focus-head {
  justify-content: space-between;
  gap: 14px;
}

.focus-head .micro-head {
  color: var(--safe-muted);
  font-size: 16px;
  font-weight: 520;
  text-transform: none;
}

.focus-head .micro-head strong {
  display: none;
}

.task-inline-tools {
  gap: 8px;
}

.listen-button,
.task-inline-tools .listen-button {
  width: 42px;
  height: 42px;
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--safe-line);
  border-radius: 12px;
  background: #fff;
  color: var(--safe-ink);
  box-shadow: none;
}

.lesson-chatgpt-button {
  border-color: transparent;
  background: var(--safe-purple);
}

.prompt-word {
  min-height: 58px;
  display: flex;
  align-items: center;
  padding: 14px 18px;
  border: 0;
  border-radius: 12px;
  background: #e7efff;
  color: var(--safe-ink);
  font-size: 28px;
  font-weight: 650;
}

.gap-sentence {
  padding: 2px 0 6px;
  border: 0;
  background: transparent;
  color: var(--safe-ink);
  font-size: 28px;
  font-weight: 520;
  line-height: 1.28;
}

.gap-blank {
  display: inline-block;
  width: 70px;
  height: .85em;
  margin: 0 9px -3px;
  border-bottom: 4px solid var(--safe-blue);
}

.answer-label {
  margin: 0 0 -8px;
  color: var(--safe-ink);
  font-size: 16px;
  font-weight: 560;
}

input,
textarea {
  min-height: 58px;
  padding: 0 18px;
  border: 1px solid var(--safe-line);
  border-radius: 13px;
  background: #f7faff;
  color: var(--safe-ink);
  font-size: 18px;
}

input.answer-correct,
textarea.answer-correct {
  border-color: #74d8bf;
  background: var(--safe-green);
}

input.answer-incorrect,
textarea.answer-incorrect {
  border-color: #f0a5ae;
  background: var(--safe-red-soft);
}

.option-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.option-chip {
  min-height: 38px;
  padding: 7px 13px;
  border: 0;
  border-radius: 999px;
  background: #e8f0ff;
  color: var(--safe-ink);
  font-size: 15px;
  font-weight: 560;
}

.option-chip:nth-child(2n) {
  background: var(--safe-green);
}

.option-chip:nth-child(3n) {
  background: var(--safe-purple-soft);
}

.option-chip:nth-child(4n) {
  background: var(--safe-yellow);
}

.task-actions {
  display: flex !important;
  justify-content: space-between;
  gap: 10px;
  margin: 0 !important;
  padding: 14px 28px 20px !important;
  border: 0 !important;
  border-top: 1px solid var(--safe-line) !important;
  border-radius: 0 0 18px 18px !important;
  background: var(--safe-panel) !important;
}

.primary-button,
.ghost-button {
  min-height: 44px;
  padding: 0 22px;
  border-radius: 13px;
  font-size: 17px;
  font-weight: 520;
}

.primary-button {
  border-color: transparent;
  background: var(--safe-blue);
  color: #fff;
}

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

.primary-button:disabled,
.ghost-button:disabled {
  opacity: .5;
}

#prevBtn::before {
  content: "←";
  margin-right: 10px;
}

#nextBtn::after {
  content: "→";
  margin-left: 10px;
}

.steps {
  grid-area: steps !important;
  position: sticky !important;
  top: 12px !important;
  display: grid !important;
  align-content: start;
  gap: 10px;
  max-height: calc(100vh - 24px);
  margin: 0 !important;
  padding: 18px 14px !important;
  overflow: auto !important;
  border: 1px solid var(--safe-line) !important;
  border-radius: 14px !important;
  background: var(--safe-panel) !important;
  box-shadow: none !important;
}

.steps::before {
  content: attr(data-caption);
  display: block;
  margin: 0 7px 10px;
  color: var(--safe-muted);
  font-size: 16px;
  font-weight: 520;
}

.step-tab.route-group {
  width: 100%;
  min-height: 72px;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 11px;
  padding: 10px 11px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--safe-muted);
}

.step-tab.route-group span {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #edf4ff;
  color: var(--safe-blue);
  font-size: 18px;
  font-weight: 600;
}

.step-tab.route-group small strong,
.step-tab.route-group small em {
  display: block;
  font-style: normal;
}

.step-tab.route-group small strong {
  margin-bottom: 3px;
  color: inherit;
  font-size: 18px;
  font-weight: 580;
}

.step-tab.route-group small em {
  color: inherit;
  font-size: 15px;
  font-weight: 460;
}

.step-tab.route-group.completed {
  background: var(--safe-green);
  color: var(--safe-ink);
}

.step-tab.route-group.completed span {
  background: var(--safe-green-mark);
  color: var(--safe-ink);
}

.step-tab.route-group.active,
.step-tab.route-group.completed.active {
  background: var(--safe-blue);
  color: #fff;
}

.step-tab.route-group.active span,
.step-tab.route-group.completed.active span {
  background: rgba(255, 255, 255, .2);
  color: #fff;
}

@media (max-width: 980px) {
  body {
    padding: 0 0 calc(70px + env(safe-area-inset-bottom));
  }

  .date-panel,
  .topbar,
  .app-shell,
  .app-shell.sidebar-collapsed {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    border-right: 0 !important;
    border-left: 0 !important;
    border-radius: 0 !important;
  }

  .date-panel,
  .app-shell.sidebar-collapsed .date-panel {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px 10px !important;
  }

  .panel-head {
    display: flex !important;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
  }

  .topbar {
    min-height: 64px !important;
    padding: 9px 10px !important;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 11px;
    font-size: 13px;
  }

  .brand strong {
    font-size: 18px;
  }

  .brand small,
  .header-progress-track {
    display: none;
  }

  .header-progress strong {
    min-width: auto;
    font-size: 14px;
  }

  .user-button,
  .user-button.is-authenticated {
    width: 52px;
    min-width: 52px;
    max-width: 52px;
    height: 40px;
    min-height: 40px;
    border-radius: 12px;
    font-size: 13px;
  }

  .task-panel {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-areas:
      "hero"
      "steps"
      "task" !important;
    padding: 10px !important;
  }

  .lesson-summary-row {
    display: grid !important;
  }

  .dictionary-chip {
    width: 100%;
    justify-content: space-between;
    border-radius: 12px;
  }

  .steps {
    position: relative !important;
    top: auto !important;
    display: flex !important;
    max-height: none;
    padding: 8px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
  }

  .steps::before {
    display: none;
  }

  .step-tab.route-group {
    width: auto;
    min-width: 122px;
    min-height: 54px;
    flex: 0 0 auto;
    grid-template-columns: 32px minmax(0, 1fr);
    padding: 7px 8px;
  }

  .step-tab.route-group span {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }

  .step-tab.route-group small strong,
  .step-tab.route-group small em {
    font-size: 12px;
  }

  .task-card {
    padding: 0 !important;
  }

  .task-title {
    font-size: 27px;
  }

  .task-note {
    margin-bottom: 15px;
    font-size: 16px;
  }

  .focus-card,
  .chatgpt-card {
    gap: 14px;
    padding: 16px 13px 0;
    border-radius: 14px 14px 0 0;
  }

  .prompt-word,
  input,
  textarea {
    min-height: 56px;
    font-size: 18px;
  }

  .gap-sentence {
    font-size: 23px;
  }

  .task-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    width: 100% !important;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom)) !important;
    border: 0 !important;
    border-top: 1px solid var(--safe-line) !important;
    border-radius: 0 !important;
  }

  .primary-button,
  .ghost-button {
    min-height: 48px;
    padding: 0 16px;
    border-radius: 12px;
    font-size: 16px;
  }
}
