:root {
  color-scheme: light;
  --background: #f3f5f2;
  --surface: #ffffff;
  --surface-soft: #e9eeea;
  --foreground: #18211e;
  --muted: #62706a;
  --border: #cfd7d2;
  --primary: #17684f;
  --primary-strong: #10513e;
  --primary-foreground: #ffffff;
  --accent: #d98b22;
  --accent-soft: #fff0d9;
  --danger: #b83d38;
  --danger-soft: #fde9e7;
  --camera: #111513;
  --camera-foreground: #f7faf8;
  --blue: #2f6f9f;
  --shadow: 0 12px 32px rgb(22 37 31 / 14%);
  --radius: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --background: #161a18;
    --surface: #202623;
    --surface-soft: #2a322e;
    --foreground: #eef4f0;
    --muted: #a8b7b0;
    --border: #3e4a44;
    --primary: #69bb98;
    --primary-strong: #8ed0b3;
    --primary-foreground: #10261e;
    --accent: #e4a84e;
    --accent-soft: #46341d;
    --danger: #ef827a;
    --danger-soft: #462725;
    --camera: #090b0a;
    --camera-foreground: #f7faf8;
    --blue: #79b4df;
    --shadow: 0 14px 36px rgb(0 0 0 / 35%);
  }
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--background);
  min-width: 320px;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--background);
  color: var(--foreground);
}

button,
input,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 36%, transparent);
  outline-offset: 2px;
}

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

svg {
  display: block;
  width: 20px;
  height: 20px;
  stroke-width: 1.8;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: calc(64px + var(--safe-top));
  padding: calc(10px + var(--safe-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand img {
  flex: 0 0 auto;
  border-radius: 7px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
  font-weight: 650;
}

.brand p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.header-actions,
.dialog-actions,
.password-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.capture-button,
.speak-button {
  position: relative;
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--foreground);
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  z-index: 60;
  top: calc(100% + 7px);
  right: 0;
  width: max-content;
  max-width: 180px;
  padding: 6px 8px;
  border-radius: 5px;
  background: var(--foreground);
  color: var(--surface);
  font-size: 12px;
  line-height: 1.3;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 120ms ease, transform 120ms ease;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

main {
  width: min(100%, 900px);
  margin: 0 auto;
  padding-bottom: calc(24px + var(--safe-bottom));
}

.camera-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 58vh;
  overflow: hidden;
  background: var(--camera);
  color: var(--camera-foreground);
}

#cameraVideo {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: var(--camera);
}

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  background: var(--camera);
}

.camera-placeholder[hidden] {
  display: none;
}

.camera-placeholder strong {
  font-size: 16px;
  font-weight: 600;
}

.camera-placeholder span {
  color: color-mix(in srgb, var(--camera-foreground) 70%, transparent);
  font-size: 14px;
}

.placeholder-mark {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  color: var(--accent);
}

.placeholder-mark svg {
  width: 52px;
  height: 52px;
  stroke-width: 1.3;
}

.frame-guide {
  position: absolute;
  inset: 15% 10%;
  pointer-events: none;
  opacity: 0.66;
}

.frame-guide span {
  position: absolute;
  width: 34px;
  height: 34px;
  border-color: var(--camera-foreground);
  border-style: solid;
}

.frame-guide span:nth-child(1) {
  top: 0;
  left: 0;
  border-width: 2px 0 0 2px;
}

.frame-guide span:nth-child(2) {
  top: 0;
  right: 0;
  border-width: 2px 2px 0 0;
}

.frame-guide span:nth-child(3) {
  bottom: 0;
  right: 0;
  border-width: 0 2px 2px 0;
}

.frame-guide span:nth-child(4) {
  bottom: 0;
  left: 0;
  border-width: 0 0 2px 2px;
}

.live-status {
  position: absolute;
  top: 12px;
  left: 12px;
  max-width: calc(100% - 24px);
  min-height: 34px;
  padding: 7px 10px;
  display: flex;
  align-items: center;
  gap: 7px;
  border-radius: 6px;
  background: rgb(9 15 12 / 78%);
  color: #ffffff;
  font-size: 13px;
  line-height: 1.25;
  backdrop-filter: blur(8px);
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #9da7a2;
}

.status-dot.active {
  background: #65cf9e;
}

.status-dot.busy {
  background: #f2b34e;
}

.status-dot.error {
  background: #ef746d;
}

.stability-meter {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  height: 4px;
  overflow: hidden;
  background: rgb(255 255 255 / 24%);
}

.stability-meter div {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 180ms linear;
}

.control-band {
  padding: 12px 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px auto;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 46px;
  padding: 10px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 7px;
  font-weight: 600;
  line-height: 1.25;
}

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

.primary-button.compact {
  min-width: 128px;
}

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

.danger-button {
  border: 1px solid color-mix(in srgb, var(--danger) 50%, var(--border));
  background: var(--danger-soft);
  color: var(--danger);
}

.capture-button {
  width: 48px;
  height: 48px;
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  color: color-mix(in srgb, var(--accent) 75%, var(--foreground));
}

.switch-control {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: var(--foreground);
  font-size: 14px;
  white-space: nowrap;
}

.switch-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  width: 42px;
  height: 24px;
  padding: 3px;
  flex: 0 0 auto;
  display: block;
  border-radius: 12px;
  background: var(--border);
  transition: background 160ms ease;
}

.switch-track span {
  width: 18px;
  height: 18px;
  display: block;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgb(0 0 0 / 22%);
  transition: transform 160ms ease;
}

.switch-control input:checked + .switch-track {
  background: var(--primary);
}

.switch-control input:checked + .switch-track span {
  transform: translateX(18px);
}

.switch-control input:focus-visible + .switch-track {
  outline: 3px solid color-mix(in srgb, var(--primary) 36%, transparent);
  outline-offset: 2px;
}

.guidance-band {
  min-height: 150px;
  padding: 18px 16px 16px;
  background: var(--background);
  border-bottom: 1px solid var(--border);
}

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

.guidance-heading > div {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.round-label {
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
}

.speak-button {
  background: transparent;
}

.guidance-text {
  min-height: 54px;
  margin-top: 10px;
  font-size: 18px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.guidance-text.muted {
  color: var(--muted);
  font-size: 15px;
}

.round-progress {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.round-progress span {
  height: 4px;
  background: var(--border);
}

.round-progress span.active {
  background: var(--primary);
}

.round-progress span.fallback {
  background: var(--accent);
}

.activity-strip {
  padding: 15px 16px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  background: var(--surface);
}

.activity-strip div {
  min-width: 0;
}

.activity-strip span,
.activity-strip strong {
  display: block;
  overflow-wrap: anywhere;
}

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

.activity-strip strong {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
}

dialog {
  width: min(620px, calc(100% - 24px));
  max-height: min(760px, calc(100vh - 24px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--foreground);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgb(8 14 11 / 58%);
  backdrop-filter: blur(3px);
}

.dialog-shell {
  max-height: min(760px, calc(100vh - 24px));
  display: flex;
  flex-direction: column;
}

.dialog-header,
.dialog-actions {
  flex: 0 0 auto;
  padding: 14px 16px;
  background: var(--surface);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.dialog-header h2 {
  margin-top: 2px;
  font-size: 20px;
  font-weight: 650;
}

.dialog-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

.split-actions {
  justify-content: space-between;
}

.settings-content {
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.field-label,
.range-heading {
  font-size: 14px;
  font-weight: 600;
}

.field-label {
  display: block;
  margin: 0 0 7px;
}

.settings-content select,
.settings-content input[type="password"],
.settings-content input[type="text"] {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--background);
  color: var(--foreground);
  font-size: 16px;
}

.password-row {
  margin-bottom: 18px;
}

.password-row input {
  flex: 1 1 auto;
}

.settings-content select {
  margin-bottom: 18px;
}

.range-heading {
  margin: 16px 0 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.range-heading output {
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.check-row {
  min-height: 56px;
  margin-top: 20px;
  display: flex;
  align-items: flex-start;
  gap: 11px;
}

.check-row input {
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  flex: 0 0 auto;
  accent-color: var(--primary);
}

.check-row strong,
.check-row small {
  display: block;
}

.check-row strong {
  font-size: 14px;
  font-weight: 600;
}

.check-row small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.history-list {
  min-height: 240px;
  padding: 12px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.empty-history {
  min-height: 220px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.history-item {
  padding: 12px 0;
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

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

.history-thumb {
  width: 76px;
  height: 58px;
  object-fit: cover;
  border-radius: 5px;
  background: var(--camera);
}

.history-copy {
  min-width: 0;
}

.history-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.history-copy p {
  margin-top: 5px;
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.history-type {
  color: var(--primary);
  font-weight: 600;
}

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  transform: translateX(-50%);
  border-radius: 6px;
  background: var(--foreground);
  color: var(--surface);
  box-shadow: var(--shadow);
  font-size: 14px;
  text-align: center;
}

.error-banner {
  position: fixed;
  z-index: 70;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-bottom));
  min-height: 52px;
  padding: 10px 10px 10px 13px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid color-mix(in srgb, var(--danger) 55%, var(--border));
  border-radius: 7px;
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: var(--shadow);
}

.error-banner span {
  flex: 1 1 auto;
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.error-banner button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: inherit;
}

@media (min-width: 700px) {
  body {
    padding-left: 18px;
    padding-right: 18px;
  }

  .app-header {
    width: min(100%, 900px);
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  main {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  .camera-stage {
    aspect-ratio: 16 / 9;
  }
}

@media (max-width: 430px) {
  .control-band {
    grid-template-columns: minmax(0, 1fr) 48px;
  }

  .switch-control {
    grid-column: 1 / -1;
    min-height: 36px;
    justify-content: flex-start;
  }

  .activity-strip {
    gap: 8px;
  }

  .activity-strip strong {
    font-size: 12px;
  }

  dialog {
    width: calc(100% - 16px);
    max-height: calc(100vh - 16px);
  }
}

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