:root {
  --bg0-hard: #1d2021;
  --bg0: #282828;
  --bg1: #3c3836;
  --bg2: #504945;
  --bg3: #665c54;
  --fg: #ebdbb2;
  --fg-soft: #d5c4a1;
  --yellow: #d79921;
  --green: #98971a;
  --aqua: #689d6a;
  --orange: #fe8019;
  --red: #fb4934;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "SFMono-Regular", "JetBrains Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
  color: var(--fg);
  background:
    radial-gradient(1200px 500px at 90% -10%, rgba(215, 153, 33, 0.13), transparent 45%),
    radial-gradient(900px 500px at -15% 95%, rgba(152, 151, 26, 0.15), transparent 40%),
    linear-gradient(170deg, var(--bg0-hard), var(--bg0) 30%, #242322 100%);
}

a {
  color: var(--yellow);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.72rem 1rem;
  border-bottom: 1px solid var(--bg2);
  background: rgba(40, 40, 40, 0.94);
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg);
}

.topbar nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.topbar a {
  text-decoration: none;
  color: var(--fg-soft);
  border: 1px solid var(--bg3);
  border-radius: 999px;
  padding: 0.35rem 0.72rem;
  font-size: 0.88rem;
  line-height: 1.1;
  background: rgba(60, 56, 54, 0.65);
  white-space: nowrap;
}

.topbar a:hover {
  border-color: var(--yellow);
  color: var(--yellow);
  box-shadow: 0 0 0 2px rgba(215, 153, 33, 0.2);
}

.topbar-filter-form {
  margin: 0;
  display: flex;
  align-items: center;
}

.topbar-filter-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  border: 1px solid var(--bg3);
  border-radius: 999px;
  padding: 0.27rem 0.6rem 0.27rem 0.42rem;
  background: linear-gradient(180deg, rgba(73, 67, 63, 0.82), rgba(50, 48, 47, 0.88));
  color: var(--fg-soft);
  user-select: none;
  box-shadow: inset 0 1px 0 rgba(235, 219, 178, 0.06), 0 6px 16px rgba(0, 0, 0, 0.2);
}

.topbar-filter-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  margin: 0;
}

.topbar-filter-track {
  position: relative;
  width: 2.05rem;
  height: 1.2rem;
  flex: 0 0 auto;
  border-radius: 999px;
  border: 1px solid #7c6f64;
  background: linear-gradient(180deg, #3c3836, #32302f);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

.topbar-filter-thumb {
  position: absolute;
  top: 50%;
  left: 2px;
  width: 0.86rem;
  height: 0.86rem;
  border-radius: 999px;
  transform: translateY(-50%);
  background: linear-gradient(180deg, #a89984, #928374);
  transition: left 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.topbar-filter-text {
  display: grid;
  gap: 0.08rem;
  line-height: 1;
}

.topbar-filter-label {
  font-size: 0.61rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #a89984;
}

.topbar-filter-value {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--fg-soft);
  letter-spacing: 0.02em;
}

.topbar-filter-toggle:hover {
  border-color: var(--yellow);
}

.topbar-filter-toggle:hover .topbar-filter-value {
  color: var(--yellow);
}

.topbar-filter-toggle:focus-within {
  border-color: var(--yellow);
  box-shadow: inset 0 1px 0 rgba(235, 219, 178, 0.09), 0 0 0 2px rgba(215, 153, 33, 0.22);
}

.topbar-filter-input:checked + .topbar-filter-track {
  border-color: #d79921;
  background: linear-gradient(180deg, #b57614, #9d5f0f);
}

.topbar-filter-input:checked + .topbar-filter-track .topbar-filter-thumb {
  left: calc(100% - 0.86rem - 2px);
  background: linear-gradient(180deg, #fbf1c7, #ebdbb2);
  box-shadow: 0 0 0 1px rgba(215, 153, 33, 0.3), 0 1px 3px rgba(0, 0, 0, 0.45);
}

.topbar-filter-input:checked ~ .topbar-filter-text .topbar-filter-label {
  color: #d5c4a1;
}

.topbar-filter-input:checked ~ .topbar-filter-text .topbar-filter-value {
  color: #fbf1c7;
}

main {
  width: min(1200px, 100% - 1.2rem);
  margin: 0.95rem auto;
  display: grid;
  gap: 0.9rem;
}

.split {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 0.9rem;
}

.preferences-layout {
  grid-template-areas:
    "add recent"
    "search search";
}

.preferences-layout .add-preference-panel {
  grid-area: add;
}

.preferences-layout .recent-preferences-panel {
  grid-area: recent;
}

.preferences-layout .student-search-panel {
  grid-area: search;
}

.preferences-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(320px, 1fr) minmax(320px, 1fr);
  gap: 0.9rem;
  align-items: start;
}

.panel {
  background: linear-gradient(180deg, rgba(60, 56, 54, 0.62), rgba(50, 48, 47, 0.76));
  border: 1px solid var(--bg2);
  border-radius: 12px;
  padding: 0.88rem;
  box-shadow: inset 0 1px 0 rgba(235, 219, 178, 0.04), 0 14px 30px rgba(10, 9, 8, 0.3);
  min-width: 0;
}

h2 {
  margin: 0 0 0.7rem;
  font-size: 0.98rem;
  color: var(--yellow);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.grid-form {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
}

.compact-form {
  align-items: end;
}

label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.84rem;
  color: var(--fg-soft);
  letter-spacing: 0.02em;
}

.class-select-wrap {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.class-choice-select {
  white-space: normal;
  overflow-wrap: anywhere;
}

.class-choice-select option {
  white-space: normal;
}

.clear-class-btn {
  width: 2.1rem;
  min-width: 2.1rem;
  min-height: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border-radius: 4px;
  line-height: 1;
  font-size: 0.95rem;
  font-weight: 800;
  background: #cc241d;
  border-color: #cc241d;
  color: #fbf1c7;
}

.class-select-wrap input:not([type="hidden"]) {
  flex: 1 1 auto;
  min-width: 0;
}

input:not([type="radio"]):not([type="hidden"]),
select,
button {
  width: 100%;
  border-radius: 9px;
  border: 1px solid var(--bg3);
  padding: 0.52rem 0.58rem;
  min-height: 2.25rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--fg);
  background: #32302f;
}

input::placeholder {
  color: #a89984;
}

input:not([type="radio"]):not([type="hidden"]):focus,
select:focus,
button:focus {
  outline: 2px solid transparent;
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px rgba(215, 153, 33, 0.2);
}

button {
  cursor: pointer;
  background: linear-gradient(180deg, #d79921, #b57614);
  border-color: #d79921;
  color: #1d2021;
  font-weight: 700;
  letter-spacing: 0.03em;
}

button:hover {
  filter: brightness(1.08);
}

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

.form-error {
  margin: 0;
  min-height: 1.15em;
  font-size: 0.82rem;
  color: var(--red);
  grid-column: 1 / -1;
}

.form-info {
  margin: 0;
  min-height: 1.15em;
  font-size: 0.8rem;
  color: var(--aqua);
  grid-column: 1 / -1;
}

.form-info.error {
  color: var(--red);
}

.student-suggestion-box {
  position: relative;
  margin-top: 0.72rem;
  border: 1px solid var(--bg2);
  border-radius: 10px;
  padding: 0.72rem 2.55rem 0.72rem 0.72rem;
  background: rgba(40, 40, 40, 0.44);
}

.student-suggestion-reroll {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 1.85rem;
  min-width: 1.85rem;
  min-height: 1.85rem;
  height: 1.85rem;
  padding: 0;
  border-radius: 999px;
  border-color: var(--bg3);
  background: rgba(60, 56, 54, 0.55);
  color: var(--fg-soft);
  font-size: 1rem;
  line-height: 1;
}

.student-suggestion-reroll:hover:not(:disabled) {
  border-color: var(--yellow);
  color: var(--yellow);
  transform: rotate(22deg);
}

.student-suggestion-title {
  margin: 0;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--aqua);
}

.student-suggestion-body {
  margin: 0.4rem 0 0;
  font-size: 0.86rem;
  color: var(--fg);
}

.student-suggestion-side {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  margin-right: 0.18rem;
}

.student-suggestion-side-left {
  color: var(--aqua);
}

.student-suggestion-side-right {
  color: var(--orange);
}

.student-suggestion-class {
  font-weight: 700;
}

.student-suggestion-class-left {
  color: #8ec07c;
}

.student-suggestion-class-right {
  color: #fe8019;
}

.student-suggestion-vs {
  margin: 0 0.34rem;
  color: var(--fg-soft);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.student-suggestion-meta {
  margin: 0.34rem 0 0;
  font-size: 0.77rem;
  color: var(--fg-soft);
}

.student-suggestion-actions {
  margin-top: 0.55rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.student-suggestion-btn {
  width: 100%;
}

.student-suggestion-btn-left {
  background: linear-gradient(180deg, #8ec07c, #689d6a);
  border-color: #8ec07c;
  color: #1d2021;
}

.student-suggestion-btn-right {
  background: linear-gradient(180deg, #fe8019, #d65d0e);
  border-color: #fe8019;
  color: #1d2021;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.55rem;
}

.stat-card {
  margin: 0;
  padding: 0.6rem 0.65rem;
  border: 1px solid var(--bg2);
  border-radius: 10px;
  background: rgba(40, 40, 40, 0.55);
}

.stat-card-wide {
  grid-column: 1 / -1;
}

.stat-label {
  margin: 0;
  font-size: 0.76rem;
  color: var(--aqua);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stat-value {
  margin: 0.28rem 0 0;
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.05;
  color: var(--fg);
}

.stat-value-small {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fg-soft);
  line-height: 1.25;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--bg2);
  border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(235, 219, 178, 0.05);
}

table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: rgba(40, 40, 40, 0.55);
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--bg2);
  padding: 0.4rem 0.45rem;
  white-space: nowrap;
}

th {
  color: var(--aqua);
  font-size: 0.79rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: #32302f;
}

.sort-link {
  color: inherit;
  text-decoration: none;
}

.sort-link:hover {
  color: var(--yellow);
  text-decoration: underline;
}

tbody tr:nth-child(2n) {
  background: rgba(80, 73, 69, 0.35);
}

tbody tr.required-class-row td {
  background: rgba(251, 73, 52, 0.08);
}

tbody tr.required-class-row td:first-child {
  border-left: 2px solid #fb4934;
}

tbody tr.required-class-row td:last-child {
  border-right: 2px solid #fb4934;
}

.message {
  margin: 0;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid #7c6f64;
  color: var(--fg);
  background: rgba(104, 157, 106, 0.2);
  font-size: 0.87rem;
}

.confirm-box {
  margin-bottom: 0.7rem;
  padding: 0.72rem;
  border: 1px solid #b57614;
  border-radius: 8px;
  background: rgba(215, 153, 33, 0.15);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.confirm-box p {
  margin: 0 0 0.5rem;
  font-size: 0.86rem;
  color: var(--fg);
}

.confirm-form {
  display: flex;
  justify-content: flex-start;
}

.edit-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.edit-nav-panel {
  padding: 0.62rem 0.7rem;
}

.edit-nav {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.edit-nav a {
  text-decoration: none;
  color: var(--fg-soft);
  border: 1px solid var(--bg3);
  border-radius: 999px;
  padding: 0.3rem 0.62rem;
  font-size: 0.82rem;
  line-height: 1.1;
  background: rgba(60, 56, 54, 0.55);
}

.edit-nav a:hover {
  color: var(--yellow);
  border-color: var(--yellow);
}

.edit-nav a.active {
  color: #1d2021;
  border-color: #d79921;
  background: linear-gradient(180deg, #d79921, #b57614);
  font-weight: 700;
}

.edit-list {
  display: grid;
  gap: 0.7rem;
}

.edit-pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.65rem;
  font-size: 0.82rem;
  color: var(--fg-soft);
}

.pager-actions {
  display: flex;
  gap: 0.45rem;
}

.pager-actions a {
  text-decoration: none;
  color: var(--fg-soft);
  border: 1px solid var(--bg3);
  border-radius: 999px;
  padding: 0.24rem 0.55rem;
  background: rgba(60, 56, 54, 0.55);
}

.pager-actions a:hover {
  color: var(--yellow);
  border-color: var(--yellow);
}

.edit-card {
  margin: 0;
  padding: 0.7rem;
  border: 1px solid var(--bg2);
  border-radius: 10px;
  background: rgba(40, 40, 40, 0.45);
}

.edit-meta {
  margin: 0 0 0.55rem;
  color: var(--fg-soft);
  font-size: 0.8rem;
}

.edit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.55rem;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.card-actions button {
  flex: 1 1 130px;
}

.danger {
  background: linear-gradient(180deg, #fb4934, #cc241d);
  border-color: #fb4934;
  color: #1d2021;
}

.grade-picker {
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 0.3rem;
}

.grade-picker legend {
  margin: 0;
  padding: 0;
  font-size: 0.84rem;
  color: var(--fg-soft);
}

.grade-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
}

.grade-option {
  margin: 0;
}

.grade-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.grade-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.3rem;
  border: 1px solid var(--bg3);
  border-radius: 9px;
  background: #32302f;
  color: var(--fg);
  font-size: 0.95rem;
  font-weight: 700;
}

.grade-option input:focus + span {
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px rgba(215, 153, 33, 0.2);
}

.grade-option input:checked + span {
  border-color: #d79921;
  background: linear-gradient(180deg, #d79921, #b57614);
  color: #1d2021;
}

.viz-page {
  padding: 1rem;
}

.viz-intro {
  margin: 0 0 0.9rem;
  font-size: 0.86rem;
  color: var(--fg-soft);
}

.viz-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
  gap: 0.9rem;
  align-items: start;
}

.viz-canvas-shell {
  position: relative;
  border: 1px solid var(--bg2);
  border-radius: 12px;
  overflow: hidden;
  background:
    radial-gradient(500px 220px at 10% 0%, rgba(104, 157, 106, 0.16), transparent 55%),
    radial-gradient(680px 260px at 100% 0%, rgba(215, 153, 33, 0.14), transparent 58%),
    #1e2227;
}

.viz-canvas {
  width: 100%;
  min-height: 440px;
}

.viz-canvas canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
}

.viz-hover-label {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  transform: translate(-50%, -125%);
  max-width: min(320px, 70vw);
  padding: 0.26rem 0.5rem;
  border: 1px solid rgba(235, 219, 178, 0.42);
  border-radius: 7px;
  background: rgba(20, 24, 28, 0.94);
  color: #fbf1c7;
  font-size: 0.78rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viz-canvas-help {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  border-top: 1px solid rgba(235, 219, 178, 0.12);
  font-size: 0.8rem;
  color: var(--fg-soft);
  background: rgba(20, 24, 28, 0.65);
}

.viz-canvas-help button {
  width: auto;
  min-height: 1.9rem;
  padding: 0.35rem 0.75rem;
}

.viz-sidebar {
  display: grid;
  gap: 0.55rem;
}

.viz-metric {
  margin: 0;
  padding: 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--bg2);
  background: rgba(40, 40, 40, 0.48);
}

.viz-metric-label {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--aqua);
}

.viz-metric-value {
  margin: 0.23rem 0 0;
  font-size: 1.28rem;
  font-weight: 800;
}

.viz-details {
  min-height: 140px;
  padding: 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--bg2);
  background: rgba(40, 40, 40, 0.48);
}

.viz-details-title {
  margin: 0 0 0.45rem;
  color: var(--yellow);
  font-size: 0.86rem;
  font-weight: 700;
}

.viz-details-line {
  margin: 0.28rem 0 0;
  font-size: 0.82rem;
  color: var(--fg-soft);
}

.viz-legend {
  padding: 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--bg2);
  background: rgba(40, 40, 40, 0.48);
  font-size: 0.8rem;
}

.viz-legend p {
  margin: 0.34rem 0;
  display: flex;
  align-items: center;
  gap: 0.44rem;
  color: var(--fg-soft);
}

.affinity-summary {
  margin: 0 0 0.7rem;
  font-size: 0.84rem;
  color: var(--fg-soft);
}

.affinity-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.affinity-card {
  border: 1px solid var(--bg2);
  border-radius: 10px;
  padding: 0.7rem;
  background: rgba(40, 40, 40, 0.44);
}

.affinity-card h3 {
  margin: 0 0 0.55rem;
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--yellow);
}

.affinity-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.45rem;
}

.affinity-list li {
  border: 1px solid var(--bg2);
  border-radius: 8px;
  padding: 0.45rem 0.5rem;
  background: rgba(50, 48, 47, 0.62);
}

.affinity-class {
  display: block;
  font-weight: 700;
  color: var(--fg);
  margin-bottom: 0.18rem;
}

.affinity-meta {
  display: block;
  font-size: 0.79rem;
  color: var(--fg-soft);
}

.affinity-empty {
  margin: 0;
  font-size: 0.82rem;
  color: var(--fg-soft);
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.65rem;
}

.suggestion-card {
  border: 1px solid var(--bg2);
  border-radius: 10px;
  padding: 0.7rem;
  background: rgba(40, 40, 40, 0.46);
}

.suggestion-title {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--aqua);
}

.suggestion-class {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--fg);
}

.suggestion-class span {
  color: var(--fg-soft);
  font-weight: 500;
}

.suggestion-vs {
  margin: 0.22rem 0;
  font-size: 0.74rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--orange);
}

.exclusions-form {
  display: grid;
  gap: 0.65rem;
}

.exclusions-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.exclusions-toggle-btn {
  width: auto;
  min-height: 1.95rem;
  padding: 0.32rem 0.74rem;
}

.exclusions-list {
  display: grid;
  gap: 0.44rem;
}

.exclusion-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.16rem 0.55rem;
  align-items: center;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--bg2);
  border-radius: 8px;
  background: rgba(40, 40, 40, 0.45);
}

.exclusion-item input[type="checkbox"] {
  width: auto;
  min-height: 0;
  margin: 0;
  accent-color: var(--red);
  grid-row: 1 / span 2;
}

.exclusion-class {
  font-weight: 700;
  color: var(--fg);
}

.exclusion-meta {
  font-size: 0.78rem;
  color: var(--fg-soft);
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
}

.swatch-stronger {
  background: #78d291;
}

.swatch-weaker {
  background: #f06e6e;
}

.swatch-even {
  background: #58b7ff;
}

.swatch-uncompared {
  background: #56606e;
}

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

  .preferences-layout {
    grid-template-areas:
      "add"
      "search"
      "recent";
  }

  .preferences-grid {
    grid-template-columns: 1fr;
  }

  .edit-layout {
    grid-template-columns: 1fr;
  }

  .viz-layout {
    grid-template-columns: 1fr;
  }

  .viz-canvas {
    min-height: 380px;
  }

  .affinity-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .topbar {
    padding: 0.5rem 0.6rem;
  }

  .topbar nav {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    gap: 0.28rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .topbar nav::-webkit-scrollbar {
    display: none;
  }

  .topbar a {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 0.72rem;
    padding: 0.24rem 0.44rem;
    min-height: 1.7rem;
  }

  .topbar-filter-toggle {
    flex: 0 0 auto;
    gap: 0.42rem;
    min-height: 1.7rem;
    padding: 0.24rem 0.44rem 0.24rem 0.34rem;
  }

  .topbar-filter-track {
    width: 1.78rem;
    height: 1.06rem;
  }

  .topbar-filter-thumb {
    width: 0.74rem;
    height: 0.74rem;
  }

  .topbar-filter-input:checked + .topbar-filter-track .topbar-filter-thumb {
    left: calc(100% - 0.74rem - 2px);
  }

  .topbar-filter-label {
    font-size: 0.56rem;
  }

  .topbar-filter-value {
    font-size: 0.7rem;
  }

  .edit-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .edit-nav::-webkit-scrollbar {
    display: none;
  }

  .edit-nav a {
    flex: 0 0 auto;
  }

  main {
    width: calc(100% - 0.7rem);
    margin: 0.6rem auto;
    gap: 0.6rem;
  }

  .panel {
    padding: 0.72rem;
  }

  .stat-card {
    padding: 0.52rem 0.55rem;
  }

  .stat-value {
    font-size: 1.35rem;
  }

  table {
    font-size: 0.83rem;
  }

  .viz-page {
    padding: 0.78rem;
  }

  .viz-canvas {
    min-height: 320px;
  }

  .viz-canvas-help {
    padding: 0.5rem 0.6rem;
    font-size: 0.74rem;
  }
}

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

  .grade-option span {
    min-height: 2.7rem;
    font-size: 1rem;
  }

  .clear-class-btn {
    width: 2.6rem;
    min-width: 2.6rem;
    min-height: 2.6rem;
    height: 2.6rem;
    font-size: 1.05rem;
  }

  .compact-form button {
    grid-column: 1 / -1;
  }

  .edit-grid {
    grid-template-columns: 1fr;
  }

  .card-actions button {
    flex: 1 1 100%;
  }

  .edit-pager {
    flex-direction: column;
    align-items: flex-start;
  }

  .table-wrap {
    overflow: visible;
    border: none;
  }

  table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  .table-wrap thead {
    display: none;
  }

  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td {
    display: block;
    width: 100%;
  }

  .table-wrap tr {
    margin-bottom: 0.55rem;
    border: 1px solid var(--bg2);
    border-radius: 8px;
    padding: 0.35rem 0.45rem;
    background: rgba(50, 48, 47, 0.72);
  }

  .table-wrap tr.required-class-row {
    border-color: #fb4934;
    box-shadow: inset 0 0 0 1px rgba(251, 73, 52, 0.4);
  }

  .table-wrap td {
    border: none;
    white-space: normal;
    padding: 0.26rem 0;
    display: grid;
    grid-template-columns: minmax(102px, 40%) 1fr;
    gap: 0.5rem;
    align-items: baseline;
    word-break: break-word;
  }

  .table-wrap td::before {
    content: attr(data-label);
    color: var(--aqua);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    font-size: 0.7rem;
  }

  .table-wrap td[colspan] {
    display: block;
    text-align: center;
    padding: 0.45rem 0.2rem;
  }

  .table-wrap td[colspan]::before {
    content: none;
  }

  .recent-prefs-table tr {
    margin-bottom: 0.28rem;
    padding: 0.2rem 0.3rem;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.14rem 0.35rem;
  }

  .recent-prefs-table td {
    display: block;
    padding: 0.02rem 0;
    min-width: 0;
    font-size: 0.87rem;
  }

  .recent-prefs-table td::before {
    display: block;
    font-size: 0.7rem;
    letter-spacing: 0.015em;
    margin-bottom: 0.04rem;
  }

  .recent-prefs-table td:nth-child(5) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 420px) {
  .topbar a {
    font-size: 0.68rem;
    padding: 0.22rem 0.38rem;
  }
}

/* Prevent iOS Safari from auto-zooming when focusing form fields. */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 760px) {
    input:not([type="radio"]):not([type="hidden"]),
    select,
    textarea {
      font-size: 16px;
    }
  }
}
