:root {
  color-scheme: light;
  --primary: #0b57d0;
  --on-primary: #ffffff;
  --primary-container: #d7e3ff;
  --surface: #f8fafd;
  --surface-container: #f0f4f9;
  --surface-high: #e9eef6;
  --on-surface: #1f1f1f;
  --on-surface-variant: #444746;
  --outline: #747775;
  --outline-variant: #c4c7c5;
  --scope: #38424c;
  --success: #146c2e;
  --success-container: #c4eed0;
  --error: #b3261e;
  --error-container: #f9dedc;
  --font:
    "Roboto", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui,
    sans-serif;
  --formula-font: "STIX Two Math", "Cambria Math", "Noto Sans Math", serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--surface);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--surface);
  color: var(--on-surface);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

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

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

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 30;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  text-decoration: none;
  transform: translateY(-160%);
}

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

.top-app-bar {
  height: 64px;
  background: var(--surface);
}

.top-app-bar__content,
.page {
  width: min(1120px, calc(100% - 48px));
  margin-inline: auto;
}

.top-app-bar__content {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.top-app-bar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 500;
  line-height: 28px;
}

.top-app-bar nav {
  display: flex;
  align-items: center;
}

.text-link {
  min-height: 40px;
  padding-inline: 12px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  color: var(--primary);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}

.text-link:hover {
  background: color-mix(in srgb, var(--primary) 8%, transparent);
}

.page {
  padding: 20px 0 calc(72px + env(safe-area-inset-bottom));
}

.workspace {
  overflow: clip;
  border: 1px solid var(--outline-variant);
  border-radius: 20px;
  background: var(--surface-container);
}

.proof-section {
  padding: 24px;
}

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

.section-heading--proof {
  margin-bottom: 12px;
}

.section-heading h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 500;
  line-height: 26px;
}

.section-heading p {
  margin: 2px 0 0;
  color: var(--on-surface-variant);
  font-size: 13px;
  line-height: 20px;
}

.section-heading__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.mode-switch {
  margin: 0;
  padding: 3px;
  display: inline-flex;
  border: 0;
  border-radius: 999px;
  background: var(--surface-high);
}

.mode-switch label {
  position: relative;
  cursor: pointer;
}

.mode-switch input {
  width: 1px;
  height: 1px;
  position: absolute;
  opacity: 0;
}

.mode-switch span {
  min-height: 44px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  color: var(--on-surface-variant);
  font-size: 13px;
  font-weight: 500;
}

.mode-switch input:checked + span {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 3px rgb(60 64 67 / 18%);
}

.mode-switch input:focus-visible + span {
  outline: 3px solid color-mix(in srgb, var(--primary) 28%, transparent);
  outline-offset: 1px;
}

.challenge-panel {
  min-height: 72px;
  margin-bottom: 12px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: minmax(130px, 0.7fr) minmax(260px, 2fr) auto;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--outline-variant);
  border-radius: 12px;
  background: var(--surface);
}

.challenge-panel h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
}

.challenge-panel p {
  margin: 2px 0 0;
  color: var(--on-surface-variant);
  font-size: 12px;
}

.challenge-target {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.challenge-target > span {
  color: var(--on-surface-variant);
  font-size: 12px;
}

.challenge-target code {
  max-width: 100%;
  padding: 6px 8px;
  overflow-x: auto;
  background: var(--surface-container);
  font-family: var(--formula-font);
  font-size: 17px;
  white-space: nowrap;
}

.challenge-target code:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

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

.premise-row,
.proof-line {
  --scope-width: 0px;
  min-height: 54px;
  position: relative;
  display: grid;
  grid-template-columns:
    40px var(--scope-width) minmax(240px, 1fr) 154px 118px 36px;
  align-items: center;
  gap: 10px;
  padding: 5px 8px 5px 0;
}

.premise-row {
  --scope-width: 0px;
}

.premise-row--error {
  background: var(--error-container);
}

.premise-row--error textarea {
  border-color: var(--error);
}

.premise-row--fixed textarea,
.premise-row--fixed textarea:hover {
  background: transparent;
  cursor: text;
}

.line-number {
  color: var(--on-surface-variant);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.scope-gutter {
  min-height: 44px;
  position: static;
  align-self: stretch;
}

.scope-rail {
  width: 3px;
  position: absolute;
  z-index: 2;
  top: -1px;
  bottom: -1px;
  left: calc(45px + var(--scope-index) * 20px);
  border-radius: 0;
  background: var(--scope);
  pointer-events: none;
}

.scope-rail--start {
  top: 4px;
  border-top-left-radius: 999px;
  border-top-right-radius: 999px;
}

.scope-rail--end {
  bottom: 4px;
  border-bottom-right-radius: 999px;
  border-bottom-left-radius: 999px;
}

textarea,
.rule-select,
.citation-input {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--on-surface);
}

textarea {
  min-height: 40px;
  padding: 8px 10px;
  overflow: hidden;
  resize: none;
  font-family: var(--formula-font);
  font-size: 17px;
  line-height: 22px;
}

textarea::placeholder,
.citation-input::placeholder {
  color: color-mix(in srgb, var(--on-surface-variant) 62%, transparent);
}

.rule-select,
.citation-input {
  height: 40px;
  padding: 0 10px;
  font-size: 13px;
}

.rule-select {
  border-color: var(--outline-variant);
  background: var(--surface);
}

.rule-select:disabled {
  border-color: transparent;
  background: transparent;
  color: var(--on-surface);
  opacity: 1;
  appearance: none;
}

.citation-input {
  border-color: var(--outline-variant);
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}

textarea:hover,
textarea:focus {
  background: var(--surface);
}

textarea:focus,
.rule-select:focus,
.citation-input:focus {
  border-color: var(--primary);
  outline: 2px solid color-mix(in srgb, var(--primary) 22%, transparent);
  outline-offset: 0;
}

.premise-label {
  grid-column: 4;
  color: var(--on-surface-variant);
  font-size: 13px;
  text-align: center;
}

.remove-premise {
  grid-column: 6;
}

.premise-separator {
  height: 3px;
  margin: 0 8px 0 45px;
  border-radius: 2px;
  background: var(--scope);
}

.symbol-palette {
  min-height: 44px;
  margin-bottom: 12px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  border: 1px solid var(--outline-variant);
  border-radius: 12px;
  background: var(--surface);
}

.symbol-palette > span {
  margin: 0 8px;
  color: var(--on-surface-variant);
  font-size: 12px;
}

.symbol-palette button,
.icon-button {
  border: 0;
  background: transparent;
  color: var(--on-surface);
  cursor: pointer;
}

.symbol-palette button {
  width: 36px;
  height: 32px;
  border-radius: 8px;
  font-family: var(--formula-font);
  font-size: 18px;
}

.symbol-palette button:hover,
.icon-button:hover {
  background: var(--surface-high);
}

.proof-columns {
  min-height: 30px;
  min-width: 730px;
  padding: 0 8px 0 0;
  display: grid;
  grid-template-columns: 40px 0 minmax(240px, 1fr) 154px 118px 36px;
  align-items: center;
  gap: 10px;
  color: var(--on-surface-variant);
  font-size: 11px;
  line-height: 16px;
}

.proof-columns > span:first-child {
  text-align: right;
}

.fitch-sheet {
  overflow-x: auto;
  border-radius: 12px;
  background: var(--surface);
}

.fitch-sheet:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 28%, transparent);
  outline-offset: 2px;
}

.fitch-sheet__body {
  min-height: 64px;
  min-width: 730px;
  position: relative;
  isolation: isolate;
}

.fitch-sheet__body::before {
  content: "";
  width: 3px;
  position: absolute;
  z-index: 2;
  top: 4px;
  bottom: 4px;
  left: 45px;
  border-radius: 999px;
  background: var(--scope);
  pointer-events: none;
}

.proof-lines {
  min-height: 54px;
}

.proof-line {
  background: var(--surface);
}

.proof-line--assumption {
  background: color-mix(in srgb, var(--surface-high) 48%, var(--surface));
}

.proof-line--assumption::after {
  content: "";
  height: 3px;
  position: absolute;
  z-index: 2;
  right: 8px;
  bottom: 0;
  left: calc(45px + var(--scope-width));
  background: var(--scope);
  pointer-events: none;
}

.proof-line--assumption .scope-rail:last-child {
  bottom: -1px;
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 0;
}

.proof-line--derived:not(.proof-line--error) {
  background: color-mix(in srgb, var(--primary-container) 22%, var(--surface));
}

.line-marker {
  width: 32px;
  min-height: 22px;
  display: grid;
  place-items: center;
  visibility: hidden;
  border-radius: 999px;
  background: var(--primary-container);
  color: #041e49;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
}

.proof-line--derived .line-marker {
  visibility: visible;
}

.proof-line--error {
  background: var(--error-container);
}

.proof-line--error textarea,
.proof-line--error .rule-select,
.proof-line--error .citation-input {
  border-color: var(--error);
}

.empty-proof {
  min-height: 64px;
  display: grid;
  place-items: center;
  color: var(--on-surface-variant);
  font-size: 13px;
}

.editor-actions {
  min-height: 72px;
  margin: 0 -8px 10px;
  padding: 12px 16px;
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--outline-variant);
  border-bottom: 1px solid var(--outline-variant);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: 0 2px 8px rgb(60 64 67 / 8%);
  backdrop-filter: blur(10px);
}

.editor-actions__spacer {
  flex: 1;
}

.action-status {
  max-width: 260px;
  overflow: hidden;
  color: var(--on-surface-variant);
  font-size: 12px;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-status--success {
  color: var(--success);
}

.action-status--error {
  color: var(--error);
}

.line-error-message {
  margin: 0;
  padding: 0 10px 8px;
  grid-column: 3 / -1;
  color: var(--error);
  font-family: var(--font);
  font-size: 12px;
  line-height: 18px;
}

.button {
  min-height: 40px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

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

.button--primary {
  min-width: 112px;
  background: var(--primary);
  color: var(--on-primary);
}

.button--tonal {
  background: var(--primary-container);
  color: #041e49;
}

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

.button--text {
  background: transparent;
  color: var(--primary);
}

.button:hover:not(:disabled),
.text-link:hover {
  filter: brightness(0.96);
}

.button:focus-visible,
.text-link:focus-visible,
.symbol-palette button:focus-visible,
.icon-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 28%, transparent);
  outline-offset: 2px;
}

.icon-button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
}

.feedback {
  margin-top: 16px;
  padding: 18px 20px;
  display: grid;
  grid-template-columns: 5px 1fr;
  gap: 16px;
  border-radius: 14px;
  background: var(--surface-container);
}

.feedback--success {
  background: var(--success-container);
}

.feedback--error {
  background: var(--error-container);
}

.feedback__marker {
  border-radius: 999px;
  background: var(--on-surface-variant);
}

.feedback--success .feedback__marker {
  background: var(--success);
}

.feedback--error .feedback__marker {
  background: var(--error);
}

.feedback h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  line-height: 24px;
}

.feedback p {
  margin: 3px 0 0;
  font-size: 14px;
  line-height: 21px;
}

.syntax-guide {
  margin-top: 16px;
  border: 1px solid var(--outline-variant);
  border-radius: 14px;
  background: var(--surface);
}

.syntax-guide summary {
  padding: 14px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}

.syntax-guide__content {
  padding: 0 18px 14px;
  color: var(--on-surface-variant);
  font-size: 13px;
}

.syntax-guide__content p {
  margin: 8px 0 0;
}

code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--surface-container);
  color: var(--on-surface);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
}

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

[hidden] {
  display: none !important;
}

@media (max-width: 820px) {
  .top-app-bar__content,
  .page {
    width: min(100% - 24px, 1120px);
  }

  .proof-section {
    padding: 18px 14px;
  }

  .challenge-panel {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .challenge-target {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .premise-label {
    display: none;
  }

  .proof-columns {
    display: none;
  }

  .editor-actions {
    flex-wrap: wrap;
  }

  .editor-actions__spacer {
    display: none;
  }

  .action-status {
    margin-left: auto;
  }

  .editor-actions .button--primary {
    margin-left: auto;
  }
}

@media (max-width: 560px) {
  .top-app-bar {
    height: auto;
  }

  .top-app-bar__content {
    min-height: 64px;
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
    padding-block: 12px 8px;
  }

  .top-app-bar nav {
    margin-left: -12px;
  }

  .page {
    padding-top: 12px;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .section-heading .button {
    align-self: flex-start;
  }

  .section-heading__actions {
    justify-content: flex-start;
  }

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

  .challenge-target,
  .challenge-panel .button {
    grid-column: 1;
    grid-row: auto;
  }

  .challenge-panel .button {
    justify-self: start;
  }

  .symbol-palette > span {
    width: 100%;
    margin-bottom: 2px;
  }

  .editor-actions {
    padding-inline: 10px;
    gap: 6px;
  }

  .editor-actions .button {
    min-height: 38px;
    padding-inline: 12px;
  }

  .editor-actions .button--primary {
    width: 100%;
    margin-left: 0;
  }

  .action-status {
    width: 100%;
    max-width: none;
    order: 10;
    text-align: center;
  }

  .editor-actions .button--primary {
    order: 11;
  }
}

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