:root {
  color-scheme: only light;
  --background: #f3f2f2;
  --surface: #ffffff;
  --surface-muted: #e8e6e6;
  --foreground: #201e1d;
  --muted: #5f5b59;
  --border: #8f8b89;
  --border-soft: #c9c5c3;
  --brand: #ec3013;
  --brand-text: #971c09;
  --brand-action: #cf280e;
  --brand-action-hover: #b8230c;
  --primary: #201e1d;
  --recording: #a81f0a;
  --success: #17633f;
  --danger: #941f1b;
  --danger-surface: #fbe9e7;
  --focus: #8d1a08;
  --shadow: 0 18px 50px rgb(32 30 29 / 10%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button,
a,
input,
summary {
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  touch-action: manipulation;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  background: var(--foreground);
  color: #fff;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: rgb(243 242 242 / 96%);
}

.brand {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  color: inherit;
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  text-decoration: none;
}

.brand-mark {
  display: block;
  width: 32px;
  height: 32px;
  flex: none;
}

.brand > span {
  display: block;
  transform: translateY(0.5px);
}

.brand-mark rect:first-child {
  fill: var(--brand);
}

.brand-mark path,
.brand-mark .sample {
  fill: #fff;
}

.app-shell {
  width: min(100%, 640px);
  margin: 0 auto;
}

.screen {
  min-height: calc(100vh - 65px);
  min-height: calc(100dvh - 65px);
  padding: 22px max(18px, env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.screen-layout {
  display: flex;
  min-height: calc(100vh - 115px);
  min-height: calc(100dvh - 115px);
  flex-direction: column;
}

.screen-content {
  width: 100%;
}

.screen-actions {
  display: grid;
  gap: 10px;
  margin-top: auto;
  padding-top: 28px;
}

.collection-cancel {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.collection-cancel-link {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 0.2em;
  cursor: pointer;
}

.collection-cancel-link:hover,
.collection-cancel-link:focus-visible {
  color: var(--danger);
}

.collection-cancel-link:disabled {
  color: var(--border);
  cursor: not-allowed;
}

.collection-cancel-confirmation {
  margin-top: 32px;
  padding: 20px;
  border-left: 4px solid var(--danger);
  background: var(--danger-surface);
}

.collection-cancel-confirmation h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.collection-cancel-confirmation p {
  margin: 0;
}

.collection-cancel-actions {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.collection-cancel-error {
  margin-top: 12px !important;
  color: var(--danger);
  font-weight: 600;
}

#task-actions {
  display: grid;
  gap: 18px;
}

.task-control-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.task-control-button {
  min-width: 0;
  padding-right: 8px;
  padding-left: 8px;
  font-size: 14px;
  line-height: 1.2;
}

.task-control-button:disabled {
  border-color: #bbb7b5;
  background: var(--surface-muted);
  color: var(--muted);
  opacity: 1;
}

body.text-entry-active .screen-layout {
  min-height: auto;
}

body.text-entry-active .screen-actions {
  margin-top: 16px;
  padding-top: 0;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

h1,
h2,
h3,
p {
  overflow-wrap: break-word;
}

h1,
h2,
h3 {
  margin-top: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(1.75rem, 8vw, 2.25rem);
  line-height: 1.08;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.25rem;
}

p {
  margin: 0 0 14px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--brand-text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.progress {
  display: flex;
  gap: 4px;
  margin-bottom: 22px;
}

.progress-segment {
  height: 4px;
  flex: 1;
  background: #d1cecc;
}

.progress-segment[data-state="current"] {
  background: var(--recording);
}

.progress-segment[data-state="done"] {
  background: var(--foreground);
}

.field {
  margin-top: 24px;
}

.field label {
  display: block;
  margin-bottom: 7px;
  font-weight: 700;
}

.input {
  width: 100%;
  min-height: 50px;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
  color: var(--foreground);
  font-size: 16px;
}

.input[aria-invalid="true"] {
  border: 2px solid var(--danger);
}

.field-help,
.field-error {
  margin-top: 7px;
  font-size: 14px;
}

.field-help {
  color: var(--muted);
}

.field-error {
  min-height: 22px;
  color: var(--danger);
  font-weight: 700;
}

.button {
  display: inline-flex;
  min-height: 50px;
  width: 100%;
  align-items: center;
  justify-content: center;
  padding: 13px 16px;
  border: 2px solid var(--brand-action);
  border-radius: 0;
  background: var(--brand-action);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}

.button:not(.button-secondary, .button-reset-task, .button-recording):active {
  border-color: #b8230c;
  background: #b8230c;
}

.button-recording {
  border-color: var(--recording);
  background: var(--recording);
  color: #fff;
}

.button-recording:active {
  border-color: #861806;
  background: #861806;
}

.button-secondary:active {
  border-color: var(--foreground);
  background: #d5d2d0;
}

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

.button-secondary {
  border-color: var(--border);
  background: transparent;
  color: var(--foreground);
}

.button-save-next {
  border-color: var(--brand-action);
  background: var(--brand-action);
  color: #fff;
}

.button-arrow {
  display: inline-block;
  margin-left: 4px;
  font-size: 1.55em;
  line-height: 0;
  vertical-align: -0.08em;
}

.button-review-playing {
  border-color: var(--brand-action);
  background: var(--brand-action);
  color: #fff;
}

.button-small {
  min-height: 44px;
  width: auto;
  padding: 9px 12px;
  font-size: 14px;
}

.task-journey {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 28px 0 0;
  padding: 0;
  list-style: none;
}

.task-journey::before {
  position: absolute;
  top: 15px;
  right: 16.66%;
  left: 16.66%;
  height: 2px;
  background: var(--border);
  content: "";
}

.task-journey-step {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.task-journey-marker {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: var(--background);
  color: var(--muted);
}

.task-journey-step[data-state="current"] {
  color: var(--foreground);
}

.task-journey-step[data-state="current"] .task-journey-marker {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.task-journey-step[data-state="done"] {
  color: var(--success);
}

.task-journey-step[data-state="done"] .task-journey-marker {
  border-color: var(--success);
  background: var(--background);
  color: var(--success);
}

.button-reset-task {
  min-height: 44px;
  width: auto;
  justify-self: start;
  padding: 8px 14px;
  border-color: #4a4644;
  background: #4a4644;
  color: #fff;
  font-size: 14px;
}

.button-reset-task:active {
  border-color: var(--primary);
  background: var(--primary);
}

.reset-confirmation {
  padding-top: 2px;
}

.reset-confirmation p {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
}

.reset-confirmation-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.reset-confirmation-actions .button {
  width: auto;
}

.checkbox-label {
  display: flex;
  min-height: 50px;
  align-items: flex-start;
  gap: 12px;
  margin-top: 18px;
  padding: 8px 0;
  cursor: pointer;
}

.checkbox-label input {
  position: absolute;
  opacity: 0;
}

.checkbox-box {
  display: grid;
  width: 23px;
  height: 23px;
  flex: none;
  place-items: center;
  border: 2px solid var(--border);
  background: var(--surface);
}

.checkbox-label input:checked + .checkbox-box {
  border-color: var(--primary);
  background: var(--primary);
}

.checkbox-label input:checked + .checkbox-box::after {
  width: 10px;
  height: 5px;
  border-bottom: 2px solid #fff;
  border-left: 2px solid #fff;
  content: "";
  transform: rotate(-45deg) translate(1px, -1px);
}

.checkbox-label input:focus-visible + .checkbox-box {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.consent-summary-list {
  margin: 24px 0 0;
  padding-left: 30px;
}

.consent-summary-item {
  margin-bottom: 22px;
  padding-left: 4px;
}

.consent-summary-item::marker {
  color: var(--brand-text);
  font-weight: 700;
}

.consent-summary-item h2 {
  margin: 0 0 7px;
  font-size: 18px;
  line-height: 1.25;
}

.consent-summary-item p {
  margin: 0 0 9px;
}

.consent-original {
  margin-top: 10px;
  padding: 14px 0;
  border-top: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
}

.consent-original summary {
  min-height: 44px;
  color: var(--brand-text);
  cursor: pointer;
  font-weight: 700;
  line-height: 44px;
}

.consent-original summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.consent-copy {
  max-height: 290px;
  margin-top: 16px;
  padding: 15px 0;
  overflow: auto;
  border-top: 2px solid var(--border);
  border-bottom: 2px solid var(--border);
}

.consent-section + .consent-section {
  margin-top: 24px;
}

.consent-section h2 {
  margin: 0 0 10px;
  font-size: 18px;
  line-height: 1.25;
}

.consent-section p {
  margin: 0 0 12px;
}

.consent-draft-warning {
  margin: 16px 0;
  padding: 12px 14px;
  border-left: 4px solid var(--danger);
  background: #fff0ed;
  color: var(--danger);
  font-weight: 700;
}

.consent-error:empty {
  display: none;
}

.check-list,
.review-list {
  margin: 20px 0 0;
  padding: 0;
  border-top: 2px solid var(--border);
  list-style: none;
}

.check-row {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.check-result {
  flex: 0 0 96px;
  color: var(--success);
  font-size: 14px;
  font-weight: 700;
  text-align: right;
}

.check-result-danger {
  color: var(--danger);
}

.compatibility-toggle {
  display: block;
  margin: 26px auto 10px;
  padding: 8px;
  border: 0;
  background: transparent;
  color: var(--success);
  cursor: pointer;
  touch-action: manipulation;
}

.compatibility-toggle .result-icon {
  width: 72px;
  height: 72px;
  margin: 0;
  font-size: 38px;
}

.compatibility-message {
  color: var(--success);
  font-weight: 700;
  text-align: center;
}

.browser-switch {
  margin: 20px 0;
  padding: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.browser-switch p:first-child {
  margin-top: 0;
}

.browser-switch .button {
  margin-top: 14px;
  text-decoration: none;
}

.browser-switch .field-help,
.browser-switch .field-error {
  margin-top: 12px;
}

.browser-address {
  overflow-wrap: anywhere;
}

.review-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}

.stimulus {
  margin-top: 18px;
  padding: 20px 18px;
  background: var(--surface-muted);
  font-size: clamp(1.5rem, 8vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.meter {
  margin-top: 22px;
}

.meter-canvas {
  display: block;
  height: 64px;
  width: 100%;
  border-bottom: 2px solid var(--border);
}

.timer-row {
  margin-top: 12px;
}

.timer {
  font-size: clamp(2rem, 11vw, 2.75rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.task-guidance {
  margin: 18px 0 0;
  padding: 0;
  border: 0;
  background: transparent;
  font-weight: 600;
}

.task-guidance-error {
  padding: 12px 14px;
  border-left: 4px solid var(--danger);
  background: var(--danger-surface);
  color: var(--danger);
}

.review-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.review-title {
  font-weight: 700;
}

.review-state {
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

.review-item .button-small {
  margin-top: 10px;
}

.rating-fieldset {
  min-width: 0;
  margin: 28px 0 0;
  padding: 0;
  border: 0;
}

.rating-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.rating-choice {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 92px;
  padding: 8px 2px;
  align-content: start;
  justify-items: center;
  border: 2px solid transparent;
  cursor: pointer;
  text-align: center;
  touch-action: manipulation;
}

.rating-choice input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.rating-star {
  color: var(--border);
  font-size: clamp(2rem, 10vw, 2.75rem);
  line-height: 1;
}

.rating-number {
  margin-top: 5px;
  font-weight: 700;
}

.rating-label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.15;
}

.rating-choice:has(input:checked) {
  border-color: var(--brand-action);
  background: var(--surface-muted);
}

.rating-choice:has(input:checked) .rating-star {
  color: var(--brand-action);
}

.rating-choice:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.result-icon {
  display: grid;
  width: 48px;
  height: 48px;
  margin-bottom: 20px;
  place-items: center;
  border: 2px solid currentColor;
  font-size: 24px;
  font-weight: 700;
}

.result-success {
  color: var(--success);
}

.result-danger {
  color: var(--danger);
}

.loading-state {
  display: flex;
  min-height: calc(100vh - 135px);
  min-height: calc(100dvh - 135px);
  flex-direction: column;
  justify-content: center;
}

.spinner {
  width: 40px;
  height: 40px;
  margin-bottom: 22px;
  border: 4px solid #d1cecc;
  border-top-color: var(--foreground);
  animation: spin 900ms linear infinite;
}

.noscript-message,
.fatal-error {
  width: min(calc(100% - 32px), 640px);
  margin: 24px auto;
  padding: 16px;
  border-left: 5px solid var(--danger);
  background: var(--danger-surface);
  color: var(--danger);
  font-weight: 700;
}

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

[hidden] {
  display: none !important;
}

.capture-position-visual {
  width: 100%;
  margin: 22px 0 18px;
  padding: 10px;
  border-left: 5px solid var(--brand);
  background: var(--surface-muted);
}

.capture-position-visual svg {
  display: block;
  width: 100%;
  max-height: 225px;
}

.position-head,
.position-phone {
  fill: var(--surface);
  stroke: var(--foreground);
  stroke-width: 6;
}

.position-person,
.position-face,
.position-phone-detail {
  fill: none;
  stroke: var(--foreground);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 6;
}

.position-distance,
.position-arrow {
  fill: none;
  stroke: var(--brand);
  stroke-linecap: round;
  stroke-width: 5;
}

.position-distance-label {
  fill: var(--foreground);
  font-size: 24px;
  font-weight: 700;
}

.position-distance-hint {
  fill: var(--muted);
  font-size: 16px;
  font-weight: 600;
}

.capture-position-rules {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
  list-style: none;
}

.capture-position-rules li {
  display: grid;
  grid-template-columns: minmax(105px, 0.8fr) minmax(0, 1.7fr);
  gap: 16px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}

.capture-position-rules strong {
  color: var(--brand-text);
}

@media (max-width: 359px) {
  .capture-position-rules li {
    display: block;
  }

  .capture-position-rules span {
    display: block;
    margin-top: 2px;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Width alone is not a desktop signal: landscape phones can exceed 700 px
   while retaining a very short viewport. */
@media (min-width: 700px) and (min-height: 700px) {
  .site-header {
    padding-right: max(28px, env(safe-area-inset-right));
    padding-left: max(28px, env(safe-area-inset-left));
  }

  .app-shell {
    margin-top: 32px;
    margin-bottom: 48px;
    border: 1px solid var(--border);
    background: var(--background);
    box-shadow: var(--shadow);
  }

  .screen {
    min-height: 760px;
    padding: 36px 42px 42px;
  }

  .screen-layout {
    min-height: 680px;
  }

  h1 {
    font-size: 2.4rem;
  }
}

@media (hover: hover) and (pointer: fine) {
  .button:not(:disabled, .button-secondary, .button-reset-task, .button-recording):hover,
  .button-save-next:not(:disabled):hover,
  .button-review-playing:not(:disabled):hover {
    border-color: var(--brand-action-hover);
    background: var(--brand-action-hover);
  }

  .button-recording:not(:disabled):hover {
    border-color: #861806;
    background: #861806;
  }

  .button-secondary:not(:disabled):hover {
    border-color: var(--foreground);
    background: #e2dfdd;
  }

  .button-reset-task:not(:disabled):hover {
    border-color: #34312f;
    background: #34312f;
  }
}

@media (max-width: 359px) {
  .site-header {
    padding-right: 12px;
    padding-left: 12px;
  }

  .screen {
    padding-right: 16px;
    padding-left: 16px;
  }

  .task-control-grid {
    gap: 6px;
  }

  .task-control-button {
    padding-right: 5px;
    padding-left: 5px;
    font-size: 13px;
  }

}

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