:root {
  color-scheme: light;
  font-family: Manrope, ui-sans-serif, system-ui, sans-serif;
  background: oklch(0.965 0.018 82);
  color: oklch(0.25 0.025 70);
  --canvas: oklch(0.965 0.018 82);
  --surface: oklch(0.985 0.012 82);
  --surface-subtle: oklch(0.945 0.018 82);
  --surface-selected: oklch(0.925 0.035 82);
  --ink: oklch(0.25 0.025 70);
  --muted: oklch(0.49 0.025 70);
  --line: oklch(0.84 0.025 75);
  --line-strong: oklch(0.72 0.035 75);
  --accent: oklch(0.48 0.12 210);
  --accent-strong: oklch(0.4 0.13 210);
  --accent-soft: color-mix(in oklch, var(--accent) 12%, var(--surface));
  --success: oklch(0.49 0.13 145);
  --danger: oklch(0.52 0.14 25);
  --warning: oklch(0.55 0.13 75);
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;
  --space-3xl: 48px;
  --radius-sm: 8px;
  --radius-md: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
}

button,
input {
  font: inherit;
}

.loading-shell,
.proof-shell,
.room-shell {
  min-height: 100vh;
}

.loading-shell {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.proof-shell {
  width: min(1180px, calc(100vw - var(--space-2xl)));
  margin: 0 auto;
  padding: var(--space-3xl) 0;
}

.proof-header {
  max-width: 760px;
  margin-bottom: var(--space-2xl);
}

.proof-kicker,
.muted-label {
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.proof-header h2 {
  margin: var(--space-sm) 0 var(--space-md);
  color: var(--ink);
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.98;
  letter-spacing: -0.055em;
}

.proof-copy {
  max-width: 68ch;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.formula-bar,
.status-panel,
.trace-panel,
.evidence-panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 1px 0 color-mix(in oklch, var(--line) 70%, transparent);
}

.formula-bar {
  display: grid;
  grid-template-columns: minmax(130px, 0.35fr) minmax(220px, 1fr) auto;
  gap: var(--space-md);
  align-items: center;
  padding: var(--space-lg);
  border-radius: var(--radius-md);
}

.formula-cell {
  display: grid;
  gap: var(--space-xs);
}

.cell-address {
  font-family: Iosevka, ui-monospace, SFMono-Regular, monospace;
  font-size: 1.5rem;
  font-weight: 600;
}

.formula-input,
.cell-inline-input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: Iosevka, ui-monospace, SFMono-Regular, monospace;
  outline: none;
}

.formula-input {
  min-height: 48px;
  padding: 0 var(--space-md);
  font-size: 1.05rem;
}

.formula-input:focus,
.cell-inline-input:focus,
.sheet-grid:focus {
  border-color: var(--accent);
  outline: 3px solid color-mix(in oklch, var(--accent) 28%, transparent);
  outline-offset: 2px;
}

.formula-actions,
.example-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.formula-actions {
  justify-content: flex-end;
}

button {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  background: var(--surface-subtle);
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

button:focus-visible {
  outline: 3px solid color-mix(in oklch, var(--accent) 28%, transparent);
  outline-offset: 2px;
}

.primary-action {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  color: oklch(0.98 0.008 82);
}

.primary-action:hover {
  border-color: var(--accent-strong);
  background: var(--accent);
}

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

.example-strip {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  align-items: center;
  padding-top: var(--space-xs);
}

.example-chip {
  padding: 7px 10px;
  font-family: Iosevka, ui-monospace, SFMono-Regular, monospace;
  font-size: 0.9rem;
}

.sheet-stage {
  margin-top: var(--space-xl);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.sheet-grid {
  display: grid;
  grid-template-columns: 54px repeat(50, minmax(96px, 1fr));
  min-width: 4854px;
  outline: none;
}

.sheet-corner,
.sheet-column-header,
.sheet-row-header,
.sheet-cell {
  min-height: 54px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.sheet-corner,
.sheet-column-header,
.sheet-row-header {
  display: grid;
  place-items: center;
  background: var(--surface-subtle);
  color: var(--muted);
  font-family: Iosevka, ui-monospace, SFMono-Regular, monospace;
  font-weight: 500;
}

.sheet-cell {
  position: relative;
  display: grid;
  align-items: center;
  padding: var(--space-sm) 10px;
  background: var(--surface);
  font-family: Iosevka, ui-monospace, SFMono-Regular, monospace;
}

.sheet-cell:hover {
  background: var(--surface-selected);
}

.sheet-cell.is-selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--accent-soft);
}

.sheet-cell.is-dirty::after {
  content: '';
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--success);
}

.sheet-cell--error,
.error-line {
  color: var(--danger);
}

.cell-value {
  min-height: 1.25rem;
}

.cell-inline-input {
  min-height: 44px;
  padding: 0 var(--space-sm);
}

.status-panel,
.trace-panel,
.evidence-panel {
  margin-top: var(--space-lg);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
}

.status-line {
  font-weight: 650;
}

.hint-line,
.error-line,
.trace-panel p {
  margin: var(--space-sm) 0 0;
  color: var(--muted);
}

.error-line {
  color: var(--danger);
}

.trace-panel h3,
.evidence-panel h3 {
  margin: 0 0 var(--space-md);
}

.trace-bucket {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: var(--space-sm);
  padding: var(--space-sm) 0;
  border-top: 1px solid var(--line);
}

.trace-values,
.trace-edit,
.snapshot-count,
.evidence-cell-id,
.evidence-cell-classification,
.evidence-cell-before,
.evidence-cell-after {
  font-family: Iosevka, ui-monospace, SFMono-Regular, monospace;
}

.evidence-cells {
  display: grid;
  gap: var(--space-sm);
}

.evidence-cell {
  display: grid;
  grid-template-columns: 72px 100px minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-sm);
  align-items: baseline;
  padding: var(--space-sm) 0;
  border-top: 1px solid var(--line);
}

.evidence-cell-id,
.evidence-cell-classification,
.evidence-cell-before,
.evidence-cell-after {
  overflow-wrap: anywhere;
}

.evidence-cell-classification {
  color: var(--success);
  text-transform: uppercase;
}

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

.room-shell {
  width: min(920px, calc(100vw - var(--space-2xl)));
  margin: 0 auto;
  padding: clamp(var(--space-3xl), 8vh, 96px) 0 var(--space-3xl);
}

.room-header {
  max-width: 680px;
  margin-bottom: var(--space-3xl);
}

.room-header h1 {
  margin: var(--space-sm) 0 var(--space-md);
  color: var(--ink);
  font-size: clamp(2.5rem, 7vw, 4.75rem);
  line-height: 0.98;
  letter-spacing: -0.06em;
}

.room-intro,
.room-action-copy {
  max-width: 58ch;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.room-actions {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(0, 0.88fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.room-action {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: flex-start;
  padding: var(--space-2xl);
}

.room-action--create {
  background: var(--surface-subtle);
}

.room-action--join {
  border-left: 1px solid var(--line);
}

.room-action h2 {
  margin: 0 0 var(--space-sm);
  font-size: 1.5rem;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.room-action-copy {
  min-height: 3.2em;
  margin-bottom: var(--space-xl);
}

.room-main-action {
  min-width: 148px;
}

.room-created,
.room-join-form,
.room-field {
  display: grid;
  width: 100%;
}

.room-created {
  gap: var(--space-md);
  margin-top: var(--space-xl);
  padding-top: var(--space-xl);
  border-top: 1px solid var(--line);
}

.room-created[hidden] {
  display: none;
}

.room-join-form {
  gap: var(--space-md);
}

.room-field {
  gap: var(--space-sm);
}

.room-label {
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 700;
}

.room-input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0 var(--space-md);
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.room-input[readonly] {
  font-family: Iosevka, ui-monospace, SFMono-Regular, monospace;
  font-size: 0.88rem;
}

.room-input::placeholder {
  color: var(--muted);
}

.room-input:focus-visible {
  border-color: var(--accent);
  outline: 3px solid color-mix(in oklch, var(--accent) 28%, transparent);
  outline-offset: 2px;
}

.room-input[aria-invalid='true'] {
  border-color: var(--danger);
}

.room-created-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.secondary-action {
  background: var(--surface);
}

#room-copy-button[data-copied='true'] {
  border-color: var(--success);
  background: color-mix(in oklch, var(--success) 10%, var(--surface));
  color: var(--ink);
}

.room-copy-status,
.room-error {
  min-height: 1.4em;
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
}

.room-copy-status {
  color: var(--muted);
}

.room-error {
  color: var(--danger);
}

.room-capability-note {
  max-width: 68ch;
  margin-top: var(--space-xl);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--surface);
  color: var(--muted);
  line-height: 1.55;
}

.room-capability-note strong {
  color: var(--ink);
}

@media (max-width: 760px) {
  .proof-shell {
    width: min(100vw - 20px, 1180px);
    padding: var(--space-xl) 0;
  }

  .formula-bar {
    grid-template-columns: 1fr;
  }

  .formula-actions {
    justify-content: flex-start;
  }

  .room-shell {
    width: min(100vw - 20px, 920px);
    padding: var(--space-2xl) 0;
  }

  .room-header {
    margin-bottom: var(--space-2xl);
  }

  .room-header h1 {
    font-size: clamp(2.4rem, 13vw, 3.6rem);
  }

  .room-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  .room-action {
    padding: var(--space-xl);
  }

  .room-action--join {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .room-action-copy {
    min-height: auto;
  }

  .room-main-action,
  .room-created-actions button {
    width: 100%;
  }
}

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