:root {
  color-scheme: light;
  --paper: #f7f3ea;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #211f1b;
  --muted: #706a60;
  --line: #ddd4c6;
  --line-strong: #b7aa98;
  --blue: #2f68c9;
  --blue-soft: #dfeaff;
  --green: #237a4b;
  --green-soft: #e1f3e7;
  --red: #b63a32;
  --red-soft: #fae4e0;
  --gold: #b47b1d;
  --gold-soft: #fff1cf;
  --shadow: 0 22px 70px rgba(36, 29, 18, 0.16);
  --radius: 8px;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(135deg, rgba(47, 104, 201, 0.08), transparent 35%),
    linear-gradient(315deg, rgba(35, 122, 75, 0.08), transparent 40%),
    var(--paper);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 0 20px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 2.6vw, 2.75rem);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 1rem;
  letter-spacing: 0;
}

.topbar-controls,
.table-tools,
.classification-row,
.theater-controls {
  display: flex;
  align-items: center;
  gap: 9px;
}

.select-label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

select,
.tool-button,
.primary-button,
.icon-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--ink);
  font-weight: 750;
}

select {
  min-width: 92px;
  padding: 0 34px 0 12px;
}

.tool-button,
.primary-button {
  padding: 0 13px;
}

.primary-button {
  border-color: #1d55af;
  background: var(--blue);
  color: #fff;
}

.icon-button {
  display: inline-grid;
  width: 38px;
  min-width: 38px;
  place-items: center;
  padding: 0;
  font-size: 1.25rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(310px, 390px);
  gap: 18px;
  align-items: start;
}

.table-zone,
.classification-card,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.86);
  box-shadow: 0 12px 40px rgba(36, 29, 18, 0.08);
}

.table-zone {
  min-width: 0;
  padding: 16px;
}

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

.section-heading p,
.classification-card p {
  margin-bottom: 0;
  color: var(--muted);
}

.math {
  font-family: "STIX Two Text", Georgia, serif;
  font-size: 1.03em;
}

.op {
  padding: 0 0.1em;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  padding: 5px;
}

.cayley-table {
  --n: 4;
  display: grid;
  /* The first column carries the row headers, which hold the identity badges. */
  grid-template-columns: 58px repeat(var(--n), minmax(48px, 1fr));
  width: min(100%, 760px);
  min-width: calc(58px + var(--n) * 48px);
  margin: 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--line);
}

/* Keeps grid > row > cell semantics for assistive technology without adding a layout box. */
.grid-row {
  display: contents;
}

.cell,
.header-cell,
.corner-cell {
  display: grid;
  min-height: clamp(42px, 7.4vw, 68px);
  place-items: center;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-family: "STIX Two Text", Georgia, serif;
  font-size: clamp(1.08rem, 2vw, 1.42rem);
  line-height: 1;
}

.header-cell,
.corner-cell {
  background: #eee6d8;
  color: #4b4439;
  font-style: italic;
  font-weight: 600;
}

.header-cell.has-badge {
  align-content: center;
  gap: 2px;
  background: var(--green-soft);
  color: var(--green);
}

.header-badge {
  font-family: Inter, system-ui, sans-serif;
  font-size: 0.58rem;
  font-style: normal;
  font-weight: 850;
  letter-spacing: 0.04em;
  line-height: 1;
  text-transform: uppercase;
}

.corner-cell {
  color: var(--muted);
  font-size: 0.9rem;
  font-style: normal;
}

.cell {
  background: var(--surface-strong);
  color: var(--ink);
  transition:
    background-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.cell:hover,
.cell:focus-visible {
  position: relative;
  z-index: 1;
  outline: none;
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 2px var(--blue);
}

/* An undefined product. Kept faintly distinct so a blank grid still reads as a grid. */
.cell.is-empty {
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 6px,
    rgba(183, 170, 152, 0.14) 6px,
    rgba(183, 170, 152, 0.14) 12px
  );
}

/* Forced by the Latin square constraint: exactly one element can still go here. */
.cell.is-forced {
  box-shadow: inset 0 0 0 1px rgba(47, 104, 201, 0.45);
}

.ghost-value {
  color: var(--blue);
  font-style: italic;
  opacity: 0.42;
}

/* No element can go here any more without repeating one. Advisory, not an error:
   the user may not be aiming for a Latin square at all. */
.cell.is-dead-end {
  background: var(--gold-soft);
  box-shadow: inset 0 0 0 1px rgba(180, 123, 29, 0.45);
}

.candidate-marks {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px 3px;
  color: var(--muted);
  font-size: 0.5rem;
  font-style: italic;
  line-height: 1.1;
  opacity: 0.75;
}

.hints-bar {
  display: flex;
  align-items: center;
  gap: 11px;
  width: min(100%, 760px);
  margin: 12px auto 0;
}

.hints-bar .tool-button {
  flex: none;
  min-height: 34px;
  font-size: 0.8rem;
}

.hint-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

/* The typing cursor. Always present, so the grid always shows where a keystroke lands. */
.cell.is-cursor {
  position: relative;
  z-index: 2;
  box-shadow: inset 0 0 0 2px var(--blue);
}

.cell.is-witness,
.header-cell.is-witness {
  background: var(--red-soft);
  box-shadow: inset 0 0 0 2px var(--red);
}

/* A scan rather than a point: every cell here was checked and none worked. */
.cell.is-witness-wash {
  background: var(--red-soft);
}

/* Associativity heat: how many failing triples this entry takes part in. Capped at
   half opacity so even the hottest cell keeps its letter readable. */
.cell.is-heat {
  background: rgba(182, 58, 50, calc(var(--heat) * 0.55));
}

/* Every product of two members lands back in the block: closure, visible. */
.cell.is-subgroup {
  background: var(--green-soft);
  box-shadow: inset 0 0 0 1px rgba(35, 122, 75, 0.45);
}

.header-cell.has-coset {
  background: hsl(var(--coset-hue) 62% 90%);
  color: hsl(var(--coset-hue) 55% 28%);
}

.cell.is-result {
  background: var(--green-soft);
  box-shadow: inset 0 0 0 2px var(--green);
}

.elements-panel {
  display: grid;
  gap: 9px;
  width: min(100%, 760px);
  margin: 13px auto 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.78);
  padding: 10px;
}

.palette-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.active-element-label {
  color: var(--blue);
  letter-spacing: 0;
  text-transform: none;
}

.element-palette {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(42px, 1fr));
  gap: 7px;
}

.element-button {
  display: grid;
  min-height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--ink);
  font-family: "STIX Two Text", Georgia, serif;
  font-size: 1.25rem;
  font-style: italic;
  font-weight: 600;
  transition:
    background-color 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.element-button:hover,
.element-button:focus-visible {
  outline: none;
  border-color: var(--blue);
  background: var(--blue-soft);
}

.element-button.is-selected {
  border-color: #1d55af;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 8px 22px rgba(47, 104, 201, 0.2);
}

.side-panel {
  display: grid;
  gap: 12px;
}

.classification-card {
  padding: 14px;
}

.classification-row {
  justify-content: space-between;
  align-items: center;
}

#classification {
  margin-bottom: 2px;
  font-size: 1.65rem;
}

.badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.badge.is-good {
  border-color: rgba(35, 122, 75, 0.3);
  background: var(--green-soft);
  color: var(--green);
}

.badge.is-note {
  border-color: rgba(180, 123, 29, 0.35);
  background: var(--gold-soft);
  color: #7c5515;
}

.panel {
  overflow: hidden;
}

.panel-trigger {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  width: 100%;
  min-height: 46px;
  gap: 8px;
  border: 0;
  background: transparent;
  padding: 0 13px;
  color: var(--ink);
  font-weight: 800;
  text-align: left;
}

.chevron {
  color: var(--muted);
  transition: transform 160ms ease;
}

.panel.is-open .chevron {
  transform: rotate(180deg);
}

.panel-content {
  display: none;
  padding: 0 13px 13px;
}

.panel.is-open .panel-content {
  display: block;
}

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

.property-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 7px 8px;
  color: inherit;
  text-align: left;
}

.property-row.is-selected {
  border-color: var(--red);
  background: var(--red-soft);
}

.property-main {
  display: grid;
  flex: 1;
  grid-template-columns: 28px 1fr;
  gap: 9px;
  align-items: center;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 0;
  color: inherit;
  text-align: left;
}

.property-row[data-state="fail"] .property-main {
  cursor: pointer;
}

.property-show {
  flex: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 5px 9px;
  color: var(--blue);
  font-size: 0.74rem;
  font-weight: 850;
  text-transform: uppercase;
}

.property-show:hover,
.property-show:focus-visible {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.property-row[data-state="pending"] {
  border-style: dashed;
  background: transparent;
}

.property-icon {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 50%;
  font-size: 0.86rem;
  font-weight: 900;
}

.property-row[data-state="pass"] .property-icon {
  background: var(--green-soft);
  color: var(--green);
}

.property-row[data-state="fail"] .property-icon {
  background: var(--red-soft);
  color: var(--red);
}

.property-row[data-state="pending"] .property-icon {
  background: #ece5d9;
  color: var(--muted);
}

.property-row[data-state="pending"] .progress-fill {
  background: var(--line-strong);
}

.property-title {
  display: block;
  font-weight: 800;
}

.property-detail {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
}

.property-progress {
  display: grid;
  grid-template-columns: minmax(88px, 1fr) 36px;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
}

.progress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8dfd1;
}

.progress-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.property-row[data-state="pass"] .progress-fill {
  background: var(--green);
}

.progress-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-align: right;
}

.count-pill {
  display: inline-grid;
  min-width: 26px;
  height: 24px;
  place-items: center;
  border-radius: 999px;
  background: var(--blue-soft);
  color: #1d55af;
  font-size: 0.78rem;
  font-weight: 850;
}

.discovery-list,
.preset-list {
  display: grid;
  gap: 8px;
}

.empty-state {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.discovery-item,
.preset-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 9px 10px;
  text-align: left;
}

.discovery-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  transition:
    background-color 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.groups-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 9px;
}

.groups-toolbar .tool-button {
  flex: 1;
  min-height: 34px;
  font-size: 0.8rem;
}

.discovery-item {
  width: 100%;
  color: inherit;
}

.discovery-item.is-locked {
  border-style: dashed;
  background: transparent;
}

.discovery-item.is-locked .discovery-name {
  color: var(--muted);
  letter-spacing: 0.12em;
}

.subgroup-section {
  display: grid;
  gap: 6px;
  margin-bottom: 11px;
}

.chip-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(42px, 1fr));
  gap: 6px;
}

.subgroup-readout {
  display: grid;
  gap: 6px;
  margin-bottom: 11px;
}

.subgroup-readout .hint-row {
  min-height: 34px;
  padding: 6px 10px;
}

.subgroup-readout .hint-value {
  font-size: 1rem;
}

.order-chip {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 1px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 4px 2px;
  color: inherit;
}

.order-chip:hover,
.order-chip:focus-visible {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.order-symbol {
  font-family: "STIX Two Text", Georgia, serif;
  font-size: 1.1rem;
  font-style: italic;
  line-height: 1;
}

.order-value {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 850;
}

.hint-panel {
  display: grid;
  gap: 9px;
}

.hint-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 10px 12px;
}

.hint-row.is-hidden {
  border-style: dashed;
  background: transparent;
}

.hint-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hint-value {
  font-family: "STIX Two Text", Georgia, serif;
  font-size: 1.08rem;
  text-align: right;
}

.hint-row.is-hidden .hint-value {
  color: var(--muted);
  letter-spacing: 0.12em;
}

.discovery-item.is-highlighted {
  border-color: var(--gold);
  background: var(--gold-soft);
  transform: translateY(-1px);
}

.discovery-name,
.preset-title {
  font-weight: 850;
}

.discovery-size,
.preset-description {
  color: var(--muted);
  font-size: 0.78rem;
}

.site-footer {
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding: 14px 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: var(--blue);
}

.theater[hidden] {
  display: none;
}

.theater {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
}

.theater-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(13, 15, 19, 0.76);
  backdrop-filter: blur(6px);
}

.theater-stage {
  position: relative;
  width: min(1040px, 100%);
  max-height: min(820px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  background: #fbf8f0;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.4);
}

.theater-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 248, 240, 0.94);
  padding: 15px;
}

.theater-header h2 {
  margin-bottom: 0;
  font-size: 1.28rem;
}

.theater-body {
  padding: 16px;
}

.proof-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 330px);
  gap: 16px;
  align-items: start;
}

.proof-copy {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 14px;
}

.proof-copy p {
  margin-bottom: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.equation {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f4efe5;
  padding: 11px;
  font-family: "STIX Two Text", Georgia, serif;
  font-size: 1.2rem;
  line-height: 1.35;
}

.mini-table-grid {
  overflow-x: auto;
}

.mini-table-grid .cayley-table {
  width: 100%;
  min-width: calc(40px + var(--n) * 42px);
}

.mini-table-grid .cell,
.mini-table-grid .header-cell,
.mini-table-grid .corner-cell {
  min-height: 42px;
  font-size: 1.05rem;
}

.iso-map {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.map-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-strong);
  padding: 6px 9px;
  font-family: "STIX Two Text", Georgia, serif;
  font-size: 1.05rem;
}

.iso-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.iso-board h3 {
  margin: 0 0 8px;
  font-size: 0.86rem;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.theater-controls {
  position: sticky;
  bottom: 0;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  background: rgba(251, 248, 240, 0.94);
  padding: 12px 15px;
}

.step-dots {
  display: flex;
  gap: 6px;
}

.step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
}

.step-dot.is-active {
  background: var(--blue);
}

@keyframes pulseDiscovery {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(180, 123, 29, 0);
  }

  50% {
    box-shadow: 0 0 0 7px rgba(180, 123, 29, 0.18);
  }
}

.just-discovered {
  animation: pulseDiscovery 900ms ease 2;
}

.tool-button[disabled] {
  cursor: default;
  border-color: var(--line);
  background: transparent;
  color: var(--muted);
  opacity: 0.65;
}

.preset-button[disabled] {
  cursor: default;
  border-style: dashed;
  background: transparent;
  color: var(--muted);
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .section-heading,
  .classification-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-controls,
  .table-tools {
    width: 100%;
  }

  .select-label {
    flex: 1;
  }

  select {
    width: 100%;
  }

  .table-zone {
    padding: 11px;
  }

  .cayley-table {
    grid-template-columns: 50px repeat(var(--n), minmax(42px, 1fr));
    min-width: calc(50px + var(--n) * 42px);
  }

  /* Hide the long label and render the short one, keeping the type readable
     in a 50px header. The accessible name is unaffected. */
  .header-badge {
    font-size: 0;
  }

  .header-badge::after {
    content: attr(data-short);
    font-size: 0.58rem;
  }

  .cell,
  .header-cell,
  .corner-cell {
    min-height: 42px;
  }

  .hints-bar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .hints-bar .tool-button {
    width: 100%;
  }

  .proof-layout,
  .iso-board {
    grid-template-columns: 1fr;
  }

  .theater {
    padding: 8px;
  }

  .theater-stage {
    max-height: calc(100vh - 16px);
  }
}
