:root {
  color-scheme: light;
  --paper: #f4f6f3;
  --surface: #ffffff;
  --surface-soft: #f8faf7;
  --ink: #172622;
  --muted: #64736d;
  --faint: #89958f;
  --line: #dce4de;
  --line-strong: #c7d3cb;
  --accent: #176b57;
  --accent-dark: #0f5141;
  --accent-soft: #e6f1ec;
  --danger: #a43c37;
  --danger-soft: #fbefed;
  --warning: #8a5a16;
  --warning-soft: #fff7e8;
  --shadow: 0 12px 36px rgba(25, 48, 39, 0.06);
  --radius: 18px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 100% 0%, rgba(210, 228, 218, 0.42), transparent 28rem),
    var(--paper);
  line-height: 1.6;
}

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

button,
select,
input[type="checkbox"] {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

button,
input,
textarea,
select {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(23, 107, 87, 0.24);
  outline-offset: 3px;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 18px calc(24px + env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  border-bottom: 1px solid rgba(199, 211, 203, 0.72);
}

.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 9px;
  color: #fff;
  background: var(--accent);
  font-size: 15px;
  font-weight: 800;
}

.brand-divider {
  margin: 0 3px;
  color: var(--line-strong);
  font-weight: 400;
}

.header-label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.setup-view {
  padding: 34px 0 12px;
}

.setup-intro {
  max-width: 680px;
  margin-bottom: 28px;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.16em;
}

.setup-intro h1,
.live-heading h1 {
  margin: 0;
  font-size: clamp(28px, 7vw, 42px);
  font-weight: 720;
  letter-spacing: -0.035em;
  line-height: 1.24;
}

.intro-copy {
  max-width: 620px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.8;
}

.session-form {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.form-section {
  padding: 24px 20px;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
}

.section-heading h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 680;
}

.section-number {
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
}

.field-grid {
  display: grid;
  gap: 18px;
}

.field {
  margin-top: 18px;
}

.field-grid .field {
  margin-top: 0;
}

.field-grid + .field {
  margin-top: 18px;
}

.field label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
  color: #2a3b35;
  font-size: 13px;
  font-weight: 650;
}

.required,
.optional {
  color: var(--faint);
  font-size: 10px;
  font-weight: 450;
}

.required::before {
  content: "*";
  margin-right: 3px;
  color: var(--danger);
}

input[type="text"],
input[type="password"],
textarea,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  color: var(--ink);
  background: var(--surface-soft);
  font-size: 16px;
  transition: border-color 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}

input[type="text"],
input[type="password"],
select {
  padding: 11px 13px;
}

textarea {
  min-height: 76px;
  padding: 11px 13px;
  line-height: 1.65;
  resize: vertical;
}

input[type="text"]::placeholder,
textarea::placeholder {
  color: #98a39d;
}

input[type="text"]:hover,
textarea:hover,
select:hover {
  border-color: #aebfb4;
}

input[type="text"]:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(23, 107, 87, 0.08);
}

input[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

select {
  padding-right: 36px;
}

.field-help,
.source-note {
  margin: 7px 1px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.source-note {
  padding: 10px 12px;
  border-radius: 9px;
  color: var(--warning);
  background: var(--warning-soft);
}

.consent-block {
  margin: 20px;
  border: 1px solid #c8dbd1;
  border-radius: 12px;
  background: var(--accent-soft);
}

.consent-label {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 15px;
  cursor: pointer;
}

.consent-label input {
  flex: 0 0 auto;
  width: 21px;
  height: 21px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.consent-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
}

.consent-copy strong {
  font-weight: 680;
}

.consent-copy span {
  color: var(--muted);
  font-size: 12px;
}

.form-error,
.live-error {
  margin: 0 20px 16px;
  padding: 11px 13px;
  border: 1px solid #efd0cb;
  border-radius: 10px;
  color: var(--danger);
  background: var(--danger-soft);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border: 0;
  border-radius: 12px;
  color: #fff;
  background: var(--accent);
  font-size: 15px;
  font-weight: 680;
  box-shadow: 0 6px 16px rgba(23, 107, 87, 0.16);
  transition: background-color 150ms ease, transform 150ms ease;
}

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

.primary-button:active:not(:disabled) {
  transform: translateY(1px);
}

#start-button {
  width: calc(100% - 40px);
  margin: 0 20px;
}

.button-arrow {
  position: absolute;
  right: 22px;
  font-size: 20px;
  font-weight: 400;
}

#start-button {
  position: relative;
}

.submit-note {
  margin: 10px 20px 20px;
  color: var(--faint);
  font-size: 11px;
  text-align: center;
}

.live-view {
  padding: 26px 0 12px;
}

.live-heading {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
}

.live-heading-copy {
  min-width: 0;
}

.live-heading h1 {
  max-width: 100%;
  font-size: clamp(24px, 6vw, 34px);
  overflow-wrap: anywhere;
}

.connection-line {
  display: flex;
  gap: 7px;
  align-items: center;
  margin-top: 9px;
}

.connection-line p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.connection-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d19a43;
  box-shadow: 0 0 0 4px rgba(209, 154, 67, 0.12);
}

.connection-dot.is-live {
  background: #2b9475;
  box-shadow: 0 0 0 4px rgba(43, 148, 117, 0.12);
}

.connection-dot.is-error {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(164, 60, 55, 0.1);
}

.stop-button {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 8px;
  align-items: center;
  justify-content: center;
  min-width: 82px;
  min-height: 44px;
  margin-top: 17px;
  padding: 9px 14px;
  border: 1px solid #e2c4bf;
  border-radius: 11px;
  color: var(--danger);
  background: #fff;
  font-size: 13px;
  font-weight: 650;
}

.stop-button:hover:not(:disabled) {
  background: var(--danger-soft);
}

.stop-square {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: currentColor;
}

.live-error {
  margin: 0 0 16px;
}

.reconnect-button {
  width: 100%;
  min-height: 44px;
  margin: -4px 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  color: var(--accent-dark);
  background: var(--surface);
  font-size: 13px;
  font-weight: 650;
}

.connector-waiting {
  display: flex;
  gap: 13px;
  align-items: flex-start;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid #e5d6b8;
  border-radius: 12px;
  color: #694715;
  background: var(--warning-soft);
}

.connector-waiting strong {
  font-size: 13px;
}

.connector-waiting p {
  margin: 3px 0 0;
  color: #806338;
  font-size: 12px;
}

.waiting-pulse {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  margin-top: 7px;
  border-radius: 50%;
  background: #c18a35;
  animation: breathe 2s ease-in-out infinite;
}

.live-grid {
  display: grid;
  gap: 16px;
  align-items: start;
}

.panel,
.archive-panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2,
.archive-heading h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 680;
}

.panel-kicker {
  margin-bottom: 2px;
  font-size: 9px;
}

.count-label,
.archive-state {
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.caption-scroll {
  min-height: 260px;
  max-height: 46vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 250px;
  padding: 28px 20px;
  color: var(--muted);
  text-align: center;
}

.empty-state p {
  margin: 14px 0 3px;
  font-size: 13px;
}

.empty-state small {
  max-width: 270px;
  color: var(--faint);
  font-size: 11px;
}

.empty-lines {
  display: flex;
  gap: 5px;
  align-items: flex-end;
  height: 24px;
}

.empty-lines i {
  display: block;
  width: 4px;
  height: 12px;
  border-radius: 4px;
  background: #91b8a8;
  animation: sound-line 1.4s ease-in-out infinite;
}

.empty-lines i:nth-child(2) {
  height: 23px;
  animation-delay: 180ms;
}

.empty-lines i:nth-child(3) {
  height: 17px;
  animation-delay: 360ms;
}

.caption-list {
  padding: 5px 18px 16px;
}

.caption-item {
  position: relative;
  padding: 15px 0 15px 17px;
  border-bottom: 1px solid #edf1ee;
  content-visibility: auto;
  contain-intrinsic-size: auto 90px;
}

.caption-item:last-child {
  border-bottom: 0;
}

.caption-item::before {
  position: absolute;
  top: 22px;
  left: 1px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #a7b3ad;
  content: "";
}

.caption-item.is-partial::before {
  background: #c39246;
}

.caption-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 4px;
  color: var(--faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.caption-state {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
}

.caption-item.is-partial .caption-state {
  color: var(--warning);
}

.caption-item.is-definite .caption-state {
  color: var(--accent);
}

.caption-text {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.caption-item.is-partial .caption-text {
  color: #66746e;
}

.panel-footnote {
  margin: 0;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  background: var(--surface-soft);
  font-size: 10px;
}

.analysis-panel {
  padding-bottom: 8px;
}

.analysis-disclaimer {
  margin: 14px 16px 4px;
  padding: 11px 12px;
  border-left: 3px solid #8fb6a5;
  border-radius: 0 9px 9px 0;
  background: var(--accent-soft);
}

.analysis-disclaimer strong {
  color: var(--accent-dark);
  font-size: 12px;
}

.analysis-disclaimer p {
  margin: 3px 0 0;
  color: #567168;
  font-size: 11px;
  line-height: 1.65;
}

.analysis-empty {
  min-height: 210px;
}

.analysis-empty-mark {
  color: #85aa9a;
  font-size: 25px;
  letter-spacing: 0.12em;
}

.analysis-list {
  padding: 10px 12px 8px;
}

.analysis-card {
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  content-visibility: auto;
  contain-intrinsic-size: auto 520px;
}

.analysis-card:last-child {
  margin-bottom: 0;
}

.analysis-card-header {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.analysis-card-header span {
  color: var(--faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  overflow-wrap: anywhere;
}

.analysis-badge {
  flex: 0 0 auto;
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--accent-dark) !important;
  background: var(--accent-soft);
  font-family: inherit !important;
}

.analysis-card.is-pending .analysis-badge {
  color: var(--warning) !important;
  background: var(--warning-soft);
}

.analysis-card.is-error .analysis-badge {
  color: var(--danger) !important;
  background: var(--danger-soft);
}

.analysis-card-body {
  padding: 13px;
}

.analysis-pending,
.analysis-failure {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.analysis-failure {
  color: var(--danger);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.advice-section {
  margin-bottom: 16px;
}

.advice-section:last-child {
  margin-bottom: 0;
}

.advice-section h3 {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
}

.literal-text {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 570;
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.avoided-point {
  margin: 8px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.hypothesis-list,
.cue-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.hypothesis-item,
.cue-item {
  padding: 10px;
  border: 1px solid #e5ebe7;
  border-radius: 9px;
  background: var(--surface-soft);
}

.hypothesis-claim {
  margin: 0 0 7px;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.evidence-ids,
.falsifier,
.cue-row {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.evidence-ids {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
}

.falsifier strong,
.cue-row strong {
  color: #43564e;
  font-weight: 650;
}

.confidence-line {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0;
  font-size: 12px;
}

.confidence-value {
  padding: 2px 8px;
  border-radius: 6px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-weight: 700;
}

.uncalibrated {
  color: var(--faint);
  font-size: 10px;
}

.response-list {
  display: grid;
  gap: 8px;
}

.response-item {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
}

.response-label {
  padding: 5px 6px;
  border-radius: 7px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 11px;
  font-weight: 650;
  text-align: center;
}

.response-text {
  margin: 2px 0 0;
  font-size: 12px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.archive-panel {
  margin-top: 18px;
  padding: 20px;
}

.archive-heading {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.archive-state.is-pending {
  color: var(--warning);
  background: var(--warning-soft);
}

.archive-state.is-applied {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.archive-state.is-error {
  color: var(--danger);
  background: var(--danger-soft);
}

.archive-intro {
  margin: 10px 0 16px;
  color: var(--muted);
  font-size: 12px;
}

.archive-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.archive-stats div {
  display: flex;
  flex-direction: column;
  padding: 12px;
  border-radius: 10px;
  background: var(--surface-soft);
}

.archive-stats strong {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.archive-stats span {
  color: var(--muted);
  font-size: 11px;
}

.target-heading {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.target-paths {
  margin: 0;
  padding: 0;
  list-style: none;
}

.target-paths li {
  padding: 9px 0;
  border-bottom: 1px solid #edf1ee;
  color: #40534b;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.archive-message {
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.archive-button {
  width: 100%;
  margin-top: 16px;
}

.app-footer {
  padding: 28px 0 4px;
  color: var(--faint);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-align: center;
}

.app-footer span {
  margin: 0 5px;
}

@keyframes breathe {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

@keyframes sound-line {
  0%, 100% { transform: scaleY(0.65); opacity: 0.55; }
  50% { transform: scaleY(1); opacity: 1; }
}

@media (min-width: 640px) {
  .app-shell {
    padding-right: 28px;
    padding-left: 28px;
  }

  .setup-view {
    padding-top: 44px;
  }

  .session-form {
    max-width: 780px;
  }

  .form-section {
    padding: 28px;
  }

  .field-grid {
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }

  .consent-block {
    margin: 24px 28px;
  }

  #start-button {
    width: calc(100% - 56px);
    margin: 0 28px;
  }

  .form-error {
    margin-right: 28px;
    margin-left: 28px;
  }

  .submit-note {
    margin-bottom: 24px;
  }
}

@media (min-width: 900px) {
  .app-header {
    min-height: 82px;
  }

  .setup-view {
    display: grid;
    grid-template-columns: minmax(230px, 0.62fr) minmax(500px, 1.38fr);
    gap: 46px;
    align-items: start;
    padding-top: 50px;
  }

  .setup-intro {
    position: sticky;
    top: 36px;
    margin: 0;
    padding-top: 12px;
  }

  .session-form {
    max-width: none;
  }

  .live-view {
    padding-top: 34px;
  }

  .live-grid {
    grid-template-columns: minmax(0, 1.12fr) minmax(330px, 0.88fr);
    gap: 20px;
  }

  .caption-scroll {
    min-height: 420px;
    max-height: calc(100vh - 260px);
  }

  .analysis-panel {
    max-height: calc(100vh - 150px);
    overflow-y: auto;
  }

  .analysis-empty {
    min-height: 250px;
  }
}

@media (max-width: 420px) {
  .header-label {
    display: none;
  }

  .live-heading {
    gap: 10px;
  }

  .stop-button {
    min-width: 74px;
    padding-right: 11px;
    padding-left: 11px;
  }
}

@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;
  }
}
