:root {
  --ink: #16231f;
  --muted: #62716b;
  --faint: #87948f;
  --paper: #f4f7f5;
  --surface: #ffffff;
  --line: #d9e2dc;
  --line-strong: #becbc3;
  --primary: #116b57;
  --primary-dark: #0b5142;
  --primary-soft: #e2f1eb;
  --accent: #e8842e;
  --accent-soft: #fff0df;
  --danger: #b73e35;
  --danger-soft: #fbe9e6;
  --blue: #2f6f9f;
  --shadow: 0 18px 50px rgba(23, 45, 36, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(17, 107, 87, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(17, 107, 87, 0.025) 1px, transparent 1px);
  background-size: 24px 24px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: rgba(17, 107, 87, 0.12);
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
  -webkit-appearance: none;
}

button:focus,
textarea:focus,
a:focus {
  outline: 3px solid rgba(47, 111, 159, 0.34);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 13px 22px;
  padding: 13px max(22px, env(safe-area-inset-left)) 13px max(22px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
  background: rgba(244, 247, 245, 0.96);
}

.brand {
  display: flex;
  align-items: center;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 43px;
  height: 43px;
  margin-right: 11px;
  color: #fff;
  background: var(--primary);
  border-radius: 12px;
  box-shadow: 0 7px 18px rgba(17, 107, 87, 0.2);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 19px;
  letter-spacing: 0;
}

.brand small {
  margin-top: -1px;
  color: var(--muted);
  font-size: 12px;
}

.service-status {
  display: flex;
  align-items: center;
  min-height: 34px;
  padding: 5px 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
}

.history-launch {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 5px 10px;
  margin-right: 8px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  font-family: inherit;
  font-size: 12px;
}

.history-launch svg {
  margin-right: 5px;
}

.history-count {
  min-width: 18px;
  padding: 1px 5px;
  margin-left: 6px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  border-radius: 9px;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}

button.service-status {
  font-family: inherit;
  cursor: pointer;
}

.status-dot {
  width: 7px;
  height: 7px;
  margin-right: 7px;
  background: var(--accent);
  border-radius: 50%;
}

.service-status.ready .status-dot {
  background: var(--primary);
  box-shadow: 0 0 0 4px rgba(17, 107, 87, 0.1);
}

.service-status.error .status-dot {
  background: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 44%) minmax(0, 56%);
  width: calc(100% - 44px);
  max-width: 1380px;
  min-height: calc(100vh - 148px);
  margin: 22px auto;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.capture-panel {
  padding: 34px 34px 28px;
  border-right: 1px solid var(--line);
}

.heading-block {
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.11em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: 31px;
  line-height: 1.18;
  letter-spacing: 0;
}

.intro {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 3px;
  padding: 3px;
  margin-top: 18px;
  background: #e8eeea;
  border: 1px solid #d8e1db;
  border-radius: 7px;
}

.mode-switch button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 8px 10px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 5px;
  font-size: 14px;
  font-weight: 650;
}

.mode-switch button svg {
  margin-right: 7px;
}

.mode-switch button.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(24, 47, 38, 0.08);
}

.mode-fields {
  margin-top: 20px;
}

.ask-mode-fields {
  margin-bottom: 20px;
}

.question-field > label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
}

.question-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  grid-gap: 9px;
}

.question-input-row textarea {
  min-height: 172px;
  font-size: 16px;
}

.voice-button {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  min-height: 172px;
  padding: 10px 6px;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid #bfdbcf;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

.voice-button svg {
  margin-bottom: 8px;
}

.voice-button.listening {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.voice-button.listening svg {
  animation: voice-pulse 900ms ease-in-out infinite;
}

@keyframes voice-pulse {
  0%,
  100% {
    opacity: 0.55;
    transform: scale(0.92);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.voice-hint {
  padding: 8px 10px;
  margin: 8px 0 0;
  color: #34564a;
  background: #edf6f1;
  border-left: 3px solid var(--primary);
  font-size: 12px;
  line-height: 1.55;
}

.photo-frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 260px;
  margin-bottom: 13px;
  overflow: hidden;
  color: var(--muted);
  background: #f9fbfa;
  border: 1px dashed var(--line-strong);
  border-radius: 7px;
}

.photo-frame.has-photo {
  background: #eef2ef;
  border-style: solid;
}

#preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.empty-photo {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  padding: 22px;
  text-align: center;
}

.empty-photo svg {
  margin-bottom: 10px;
  color: var(--primary);
}

.empty-photo span {
  display: block;
  margin-bottom: 3px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
}

.empty-photo small {
  color: var(--faint);
  font-size: 12px;
}

.photo-remove {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 50%;
}

.photo-busy {
  position: absolute;
  right: 16px;
  bottom: 14px;
  left: 16px;
  padding: 9px 12px;
  color: #fff;
  background: rgba(22, 35, 31, 0.86);
  border-radius: 5px;
  text-align: center;
  font-size: 13px;
}

.capture-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 10px;
  margin-bottom: 21px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  transition: background-color 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.button:active {
  transform: translateY(1px);
}

.button svg {
  flex: 0 0 auto;
  margin-right: 7px;
}

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

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

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

.button-secondary:hover {
  background: #f7faf8;
}

.field-group {
  min-width: 0;
  padding: 0;
  margin: 0 0 19px;
  border: 0;
}

.field-group legend,
.note-field > span {
  display: block;
  width: 100%;
  padding: 0;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.segmented button,
.choice-row button {
  min-height: 40px;
  padding: 7px 9px;
  color: var(--muted);
  background: var(--surface);
  border: 0;
  font-size: 14px;
}

.segmented button + button {
  border-left: 1px solid var(--line);
}

.segmented button.active,
.choice-row button.active {
  color: #fff;
  background: var(--primary);
}

.choice-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.choice-row button + button {
  border-left: 1px solid var(--line);
}

.note-field {
  display: block;
  margin-bottom: 18px;
}

.note-field em {
  margin-left: 4px;
  color: var(--faint);
  font-size: 11px;
  font-style: normal;
  font-weight: 400;
}

textarea {
  display: block;
  width: 100%;
  min-height: 68px;
  padding: 11px 12px;
  resize: vertical;
  color: var(--ink);
  background: #fbfcfb;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  line-height: 1.45;
}

textarea::placeholder {
  color: #9aa69f;
}

.button-solve {
  width: 100%;
  min-height: 50px;
  color: #fff;
  background: var(--ink);
  border: 1px solid var(--ink);
  font-size: 16px;
}

.button-solve:disabled {
  color: #8b9791;
  background: #e7ece9;
  border-color: #e0e6e2;
  cursor: not-allowed;
  transform: none;
}

.button-solve:not(:disabled):hover {
  background: #0d1714;
}

.privacy-note {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px 0 0;
  color: var(--faint);
  font-size: 11px;
}

.privacy-note svg {
  flex: 0 0 auto;
  margin-right: 5px;
}

.result-panel {
  min-width: 0;
  padding: 34px 40px 40px;
  background: linear-gradient(180deg, #fff 0%, #fbfcfb 100%);
}

.result-state {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  min-height: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 70px 20px;
  text-align: center;
}

.result-state h2 {
  margin-bottom: 10px;
  font-size: 22px;
}

.result-state p {
  max-width: 400px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

.result-illustration {
  position: relative;
  width: 178px;
  height: 112px;
  margin-bottom: 26px;
}

.result-illustration::before {
  position: absolute;
  top: 20px;
  right: 15px;
  bottom: 4px;
  left: 15px;
  content: "";
  background: #edf4f0;
  border: 1px solid var(--line);
  border-radius: 5px;
  transform: rotate(-2deg);
}

.result-illustration span {
  position: absolute;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 49px;
  height: 49px;
  color: var(--primary);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  box-shadow: 0 7px 20px rgba(30, 60, 48, 0.08);
  font-weight: 700;
}

.result-illustration span:nth-child(1) {
  top: 25px;
  left: 12px;
  transform: rotate(-8deg);
}

.result-illustration span:nth-child(2) {
  top: 8px;
  left: 66px;
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.result-illustration span:nth-child(3) {
  top: 36px;
  right: 5px;
  transform: rotate(7deg);
}

.loading-state {
  padding-top: 40px;
}

.step-loader {
  display: flex;
  align-items: flex-end;
  height: 44px;
  margin-bottom: 28px;
}

.step-loader span {
  width: 10px;
  height: 16px;
  margin: 0 4px;
  background: var(--primary);
  border-radius: 2px;
  animation: load-bars 900ms ease-in-out infinite;
}

.step-loader span:nth-child(2) {
  height: 28px;
  background: var(--accent);
  animation-delay: 120ms;
}

.step-loader span:nth-child(3) {
  height: 21px;
  animation-delay: 240ms;
}

@keyframes load-bars {
  0%,
  100% {
    transform: scaleY(0.55);
    opacity: 0.5;
  }
  50% {
    transform: scaleY(1);
    opacity: 1;
  }
}

.error-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  margin-bottom: 22px;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: 50%;
  font-size: 26px;
  font-weight: 700;
}

.error-state .button {
  margin-top: 20px;
}

.result-content {
  max-width: 780px;
  margin: 0 auto;
}

.result-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  margin-bottom: 20px;
}

.result-actions {
  display: flex;
  align-items: center;
  margin-left: auto;
}

.speech-toggle {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 5px 9px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 650;
}

.speech-toggle[aria-pressed="true"] {
  color: var(--primary-dark);
  background: var(--primary-soft);
  border-color: #c8e0d5;
}

.speech-toggle > svg {
  margin-right: 5px;
}

.switch-track {
  position: relative;
  display: inline-block;
  width: 31px;
  height: 18px;
  margin-left: 7px;
  background: #c5cec9;
  border-radius: 9px;
  transition: background-color 120ms ease;
}

.switch-track > span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(21, 38, 31, 0.22);
  transition: transform 120ms ease;
}

.speech-toggle[aria-pressed="true"] .switch-track {
  background: var(--primary);
}

.speech-toggle[aria-pressed="true"] .switch-track > span {
  transform: translateX(13px);
}

.speech-pause {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
}

.demo-badge {
  padding: 4px 9px;
  color: #8a4c0d;
  background: var(--accent-soft);
  border: 1px solid #f3d3af;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 650;
}

.confidence-badge {
  padding: 4px 8px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  border: 1px solid #c4dfd3;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 650;
}

.confidence-badge.warn {
  color: #7b4514;
  background: var(--accent-soft);
  border-color: #efd0ad;
}

.result-meta {
  display: flex;
  align-items: center;
}

.record-status {
  margin-left: 7px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 650;
}

.text-button {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 5px 9px;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-size: 13px;
}

.text-button svg {
  margin-right: 5px;
}

.result-content > h2 {
  margin-bottom: 22px;
  font-size: 27px;
  line-height: 1.25;
}

.notice-block {
  padding: 13px 15px;
  margin-bottom: 17px;
  color: #704013;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
}

.notice-block strong {
  display: block;
  margin-bottom: 2px;
  font-size: 13px;
}

.notice-block p {
  margin-bottom: 0;
  font-size: 13px;
}

.question-block,
.steps-block,
.answer-block,
.study-grid > section,
.followup-block {
  margin-bottom: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.block-label {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.transcript {
  margin-bottom: 0;
  white-space: pre-wrap;
  font-size: 16px;
  line-height: 1.75;
}

.block-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.block-heading .block-label {
  margin-bottom: 0;
}

#stepCount {
  color: var(--faint);
  font-size: 11px;
}

.steps-list {
  padding: 0;
  margin: 15px 0 0;
  list-style: none;
  counter-reset: solution-step;
}

.steps-list li {
  position: relative;
  min-height: 42px;
  padding: 0 0 20px 44px;
  counter-increment: solution-step;
}

.steps-list li:last-child {
  padding-bottom: 0;
}

.steps-list li::before {
  position: absolute;
  top: 1px;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 29px;
  height: 29px;
  content: counter(solution-step);
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
}

.steps-list li::after {
  position: absolute;
  top: 34px;
  bottom: 6px;
  left: 14px;
  width: 1px;
  content: "";
  background: var(--line);
}

.steps-list li:last-child::after {
  display: none;
}

.step-label {
  display: block;
  margin-bottom: 3px;
  font-size: 14px;
  font-weight: 700;
}

.step-text {
  display: block;
  color: #33433d;
  font-size: 15px;
  line-height: 1.65;
}

.answer-block {
  background: var(--primary-soft);
  border-color: #c8e4d8;
}

.answer-text {
  margin-bottom: 0;
  color: var(--primary-dark);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.5;
  white-space: pre-wrap;
}

.study-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 14px;
  margin-bottom: 18px;
}

.study-grid > section {
  margin-bottom: 0;
}

.study-grid p:last-child {
  margin-bottom: 0;
  color: #33433d;
  font-size: 14px;
}

.check-section {
  grid-column: 1 / -1;
  background: #f7faf8;
}

.followup-block {
  padding-bottom: 18px;
}

.followup-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 13px;
}

.followup-heading h3 {
  margin-bottom: 0;
  font-size: 18px;
}

.followup-hint {
  max-width: 48%;
  color: var(--faint);
  font-size: 11px;
  text-align: right;
}

.followup-form {
  display: grid;
  grid-template-columns: 1fr 48px;
  grid-gap: 8px;
}

.followup-form textarea {
  min-height: 48px;
  max-height: 130px;
}

.button-dark {
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  color: #fff;
  background: var(--ink);
  border: 1px solid var(--ink);
}

.button-dark svg {
  margin: 0;
}

.button-dark:disabled {
  background: #a9b3ae;
  border-color: #a9b3ae;
}

.followup-answer {
  padding: 14px 15px;
  margin-top: 12px;
  color: #273731;
  background: #f3f7f5;
  border-left: 3px solid var(--blue);
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.7;
}

.page-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: calc(100% - 44px);
  max-width: 1380px;
  margin: 0 auto;
  padding: 0 3px calc(18px + env(safe-area-inset-bottom));
  color: var(--faint);
  font-size: 11px;
}

.page-footer a,
.setup-hint {
  color: var(--primary);
}

.toast {
  position: fixed;
  z-index: 20;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 20px;
  display: none;
  width: fit-content;
  max-width: 520px;
  padding: 10px 14px;
  margin: 0 auto;
  color: #fff;
  background: rgba(22, 35, 31, 0.94);
  border-radius: 5px;
  font-size: 13px;
  text-align: center;
}

.toast.visible {
  display: block;
}

.modal-backdrop {
  position: fixed;
  z-index: 30;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(18, 31, 26, 0.62);
}

.settings-dialog {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 40px);
  padding: 28px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(10, 25, 19, 0.28);
}

.settings-dialog h2 {
  margin: 0 0 7px;
  font-size: 26px;
}

.settings-intro,
.settings-warning {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.settings-intro {
  margin-bottom: 20px;
}

.settings-warning {
  padding: 11px 13px;
  margin: 15px 0 0;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
}

.settings-dialog label {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 650;
}

.settings-dialog input {
  display: block;
  width: 100%;
  height: 46px;
  padding: 0 12px;
  color: var(--ink);
  background: #fbfcfb;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.settings-status {
  min-height: 20px;
  margin: 7px 0 14px;
  color: var(--muted);
  font-size: 12px;
}

.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 9px;
}

.settings-actions .button {
  width: 100%;
}

.modal-close {
  position: absolute;
  top: 15px;
  right: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 50%;
}

.modal-open {
  overflow: hidden;
}

.crop-modal {
  position: fixed;
  z-index: 40;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  background: rgba(10, 18, 15, 0.82);
}

.crop-dialog {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 960px;
  height: calc(100vh - 24px);
  max-height: 900px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
}

.crop-header {
  position: relative;
  flex: 0 0 auto;
  padding: 19px 52px 13px 22px;
  border-bottom: 1px solid var(--line);
}

.crop-header h2 {
  margin: 0;
  font-size: 23px;
}

.crop-workspace {
  display: flex;
  align-items: center;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 12px;
  overflow: hidden;
  background: #111815;
}

.crop-viewport {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  width: 100%;
  min-height: 0;
  overflow: hidden;
}

.photo-crop-stage {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  line-height: 0;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

.photo-crop-stage img {
  display: block;
}

.photo-crop-box {
  position: absolute;
  z-index: 10;
  display: block;
  min-width: 36px;
  min-height: 36px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 9999px rgba(4, 10, 8, 0.62);
  cursor: move;
}

.photo-crop-handle {
  position: absolute;
  z-index: 11;
  width: 34px;
  height: 34px;
  background: #fff;
  border: 3px solid var(--primary);
  border-radius: 50%;
  box-shadow: 0 2px 9px rgba(0, 0, 0, 0.38);
}

.photo-crop-handle.nw {
  top: -18px;
  left: -18px;
}

.photo-crop-handle.ne {
  top: -18px;
  right: -18px;
}

.photo-crop-handle.sw {
  bottom: -18px;
  left: -18px;
}

.photo-crop-handle.se {
  right: -18px;
  bottom: -18px;
}

.photo-crop-size {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 7px;
  color: #fff;
  background: rgba(10, 22, 17, 0.76);
  border-radius: 3px;
  font-size: 10px;
}

.crop-status {
  flex: 0 0 auto;
  margin: 8px 0 0;
  color: #b9c5bf;
  font-size: 11px;
  text-align: center;
}

.crop-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  grid-gap: 8px;
  flex: 0 0 auto;
  padding: 11px 14px calc(11px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.crop-actions .button {
  min-width: 0;
  padding-right: 8px;
  padding-left: 8px;
  font-size: 13px;
}

.history-backdrop {
  padding: 12px;
}

.history-dialog {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 900px;
  height: calc(100vh - 24px);
  max-height: 900px;
  padding: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(10, 25, 19, 0.28);
}

.history-header {
  position: relative;
  padding: 24px 54px 16px 24px;
  border-bottom: 1px solid var(--line);
}

.history-header h2 {
  margin: 0;
  font-size: 27px;
}

.history-toolbar {
  display: flex;
  align-items: center;
  min-height: 47px;
  padding: 7px 24px;
  background: #f8faf9;
  border-bottom: 1px solid var(--line);
}

.history-back {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 4px 8px 4px 4px;
  margin-right: 8px;
  color: var(--primary);
  background: transparent;
  border: 0;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
}

.history-back svg {
  margin-right: 2px;
}

.history-breadcrumb {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.history-total {
  margin-left: auto;
  color: var(--faint);
  font-size: 11px;
}

.history-browser {
  flex: 1;
  min-height: 0;
  padding: 22px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.history-intro {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}

.grade-grid,
.subject-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 11px;
}

.grade-card,
.subject-card {
  min-height: 104px;
  padding: 16px;
  color: var(--ink);
  background: #f9fbfa;
  border: 1px solid var(--line);
  border-radius: 7px;
  font: inherit;
  text-align: left;
}

.grade-card:hover,
.subject-card:hover {
  border-color: var(--primary);
}

.grade-card strong,
.subject-card strong {
  display: block;
  margin-bottom: 5px;
  font-size: 18px;
}

.grade-card span,
.subject-card span {
  color: var(--muted);
  font-size: 12px;
}

.grade-card .folder-arrow,
.subject-card .folder-arrow {
  display: block;
  margin-top: 12px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
}

.record-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 11px;
}

.record-card {
  display: block;
  width: 100%;
  min-height: 150px;
  padding: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  font: inherit;
  text-align: left;
}

.record-card:hover {
  border-color: var(--primary);
}

.record-card h3 {
  display: -webkit-box;
  margin: 0 0 7px;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.record-card .record-question {
  display: -webkit-box;
  margin-bottom: 10px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.record-card .record-meta {
  color: var(--faint);
  font-size: 10px;
}

.record-detail {
  padding-bottom: 10px;
}

.record-detail h3 {
  margin-bottom: 6px;
  font-size: 24px;
  line-height: 1.3;
}

.record-detail-meta {
  margin-bottom: 17px;
  color: var(--faint);
  font-size: 11px;
}

.record-detail-question,
.record-detail-answer,
.record-detail-section {
  padding: 15px 17px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.record-detail-question {
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.7;
}

.record-detail-answer {
  background: var(--primary-soft);
  border-color: #c8e4d8;
}

.record-detail-answer strong {
  display: block;
  margin-top: 4px;
  color: var(--primary-dark);
  font-size: 20px;
}

.record-detail-section h4 {
  margin: 0 0 6px;
  font-size: 13px;
}

.record-detail-section p {
  margin: 0;
  color: #33433d;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.record-steps {
  padding: 0;
  margin: 0;
  list-style: none;
  counter-reset: record-step;
}

.record-steps li {
  position: relative;
  padding: 0 0 13px 34px;
  counter-increment: record-step;
}

.record-steps li:last-child {
  padding-bottom: 0;
}

.record-steps li::before {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  content: counter(record-step);
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
}

.record-steps strong {
  display: block;
  margin-bottom: 2px;
  font-size: 13px;
}

.record-steps span {
  color: #33433d;
  font-size: 13px;
  line-height: 1.6;
}

.record-delete-button {
  margin-top: 6px;
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #efc9c4;
}

.history-empty {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  min-height: 260px;
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.history-empty strong {
  display: block;
  margin-bottom: 7px;
  color: var(--ink);
  font-size: 18px;
}

.history-empty p {
  max-width: 360px;
  margin: 0;
  font-size: 13px;
}

.history-backup-panel {
  flex: 0 0 auto;
  max-height: 47%;
  padding: 16px 24px;
  overflow-y: auto;
  background: #f7faf8;
  border-top: 1px solid var(--line);
}

.history-backup-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.history-backup-heading h3 {
  margin: 0;
  font-size: 16px;
}

.history-backup-panel > p {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
}

.history-backup-panel textarea {
  min-height: 120px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
}

.history-backup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 8px;
  margin-top: 8px;
}

.history-footer {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 12px 24px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.history-footer-button {
  min-height: 38px;
  padding: 7px 10px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-right: 1px solid var(--line);
  font: inherit;
  font-size: 12px;
}

.history-footer-button:last-of-type {
  border-right: 0;
}

.history-footer-button.danger {
  color: var(--danger);
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    width: calc(100% - 28px);
    margin: 14px auto;
  }

  .capture-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .result-panel {
    min-height: 520px;
  }

  .result-state {
    min-height: 420px;
    padding: 50px 20px;
  }

  .page-footer {
    width: calc(100% - 28px);
  }
}

@media (max-width: 600px) {
  .topbar {
    min-height: 68px;
    padding-right: 14px;
    padding-left: 14px;
  }

  .brand-mark {
    width: 39px;
    height: 39px;
  }

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

  .service-status {
    max-width: 152px;
    font-size: 11px;
  }

  .topbar-actions {
    margin-left: 7px;
  }

  .history-launch {
    width: 38px;
    height: 38px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }

  .history-launch svg {
    margin: 0;
  }

  .history-launch > span:not(.history-count) {
    display: none;
  }

  .history-count {
    position: absolute;
    top: 5px;
    right: 4px;
    min-width: 15px;
    padding: 1px 3px;
    margin: 0;
    font-size: 9px;
  }

  .workspace {
    width: 100%;
    margin: 0;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .capture-panel,
  .result-panel {
    padding: 25px 18px;
  }

  h1 {
    font-size: 28px;
  }

  .photo-frame {
    height: 230px;
  }

  .question-input-row {
    grid-template-columns: minmax(0, 1fr) 72px;
  }

  .question-input-row textarea {
    min-height: 150px;
  }

  .voice-button {
    min-height: 150px;
  }

  .speech-toggle {
    padding-right: 6px;
    padding-left: 6px;
  }

  .speech-toggle > svg {
    display: none;
  }

  .result-panel {
    min-height: 480px;
  }

  .result-state {
    min-height: 380px;
  }

  .study-grid {
    grid-template-columns: 1fr;
  }

  .grade-grid,
  .subject-grid {
    grid-template-columns: 1fr 1fr;
  }

  .record-list {
    grid-template-columns: 1fr;
  }

  .history-backdrop {
    padding: 0;
  }

  .crop-modal {
    padding: 0;
  }

  .crop-dialog {
    height: 100vh;
    max-height: none;
    border-radius: 0;
  }

  .crop-header {
    padding-left: 17px;
  }

  .crop-actions {
    grid-template-columns: 0.8fr 1fr 1fr;
    padding-right: 10px;
    padding-left: 10px;
  }

  .history-dialog {
    height: 100vh;
    max-height: none;
    border-radius: 0;
  }

  .history-header {
    padding: 20px 50px 14px 18px;
  }

  .history-toolbar,
  .history-browser,
  .history-backup-panel {
    padding-right: 18px;
    padding-left: 18px;
  }

  .history-footer {
    padding-right: 12px;
    padding-left: 12px;
  }

  .check-section {
    grid-column: auto;
  }

  .followup-hint {
    display: none;
  }

  .page-footer {
    display: block;
    width: calc(100% - 36px);
    padding-top: 14px;
    text-align: center;
  }

  .page-footer a,
  .setup-hint {
    display: block;
    margin-top: 5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
