:root {
  color-scheme: light;
  --page: #f4f7fb;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --surface-blue: #eff6ff;
  --text: #172033;
  --muted: #64748b;
  --line: #dbe3ee;
  --line-strong: #c4d0df;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --warning-bg: #fff7d6;
  --warning-text: #854d0e;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  --neutral-bg: #e9edf3;
  --neutral-text: #3d485b;
  --shadow: 0 8px 24px rgba(35, 52, 76, 0.07);
  font-family: "Segoe UI Variable Text", "Segoe UI", Aptos, Inter, system-ui, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

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

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

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1240px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

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

.intro,
form,
.results,
.table-wrap,
.rules,
.dsa-promo {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.intro {
  grid-column: 1 / -1;
  position: relative;
  overflow: hidden;
  padding: 26px 28px;
  border-top: 4px solid var(--blue);
}

.intro::after {
  position: absolute;
  inset: 0 0 0 auto;
  width: 34%;
  background: linear-gradient(90deg, transparent, var(--surface-blue));
  content: "";
  pointer-events: none;
}

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

.eyebrow {
  position: relative;
  z-index: 1;
  margin-bottom: 5px;
  color: var(--blue-dark);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin-bottom: 7px;
  font-size: clamp(1.85rem, 3vw, 2.65rem);
  font-weight: 700;
  line-height: 1.12;
}

h2 {
  margin-bottom: 15px;
  font-size: 1.05rem;
  font-weight: 700;
}

.intro > p:last-child {
  position: relative;
  z-index: 1;
  max-width: 660px;
  margin-bottom: 0;
  color: var(--muted);
}

.primary-column,
.side-column {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.side-column {
  position: sticky;
  top: 18px;
}

form {
  padding: 22px;
}

.picker-grid {
  display: grid;
  grid-template-columns: minmax(200px, 0.72fr) minmax(360px, 1.28fr);
  gap: 18px;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.semester-picker,
.exam-picker {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.semester-picker legend,
.exam-picker legend {
  margin-bottom: 3px;
  padding: 0;
  font-size: 0.92rem;
  font-weight: 700;
}

.semester-picker p,
.exam-picker p {
  min-height: 24px;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.86rem;
}

.semester-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.mode-options {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.semester-options label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 42px;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface-subtle);
  color: var(--neutral-text);
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.semester-options small {
  font-size: inherit;
  font-weight: 500;
}

.semester-options input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.semester-options label:has(input:checked) {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.semester-options label:focus-within {
  outline: 3px solid rgba(37, 99, 235, 0.2);
  outline-offset: 1px;
}

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

.course-field {
  display: grid;
  gap: 7px;
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-subtle);
}

.course-field > label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  font-size: 0.97rem;
  font-weight: 700;
}

.course-field > label > span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.credits {
  flex: none;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.mark-inputs,
.mark-inputs.single,
.mark-input {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
}

.mark-input span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
}

input[type="number"] {
  width: 100%;
  height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input[type="number"]:hover {
  border-color: #9dafc4;
}

input[type="number"]:focus {
  border-color: var(--blue);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

input[aria-invalid="true"] {
  border-color: #dc2626;
}

.error {
  min-height: 16px;
  color: var(--danger-text);
  font-size: 0.75rem;
  line-height: 1.3;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 18px;
}

button {
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
  transition: background 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.25);
  outline-offset: 2px;
}

.primary-button {
  background: var(--blue);
  color: #ffffff;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.2);
}

.primary-button:hover {
  background: var(--blue-dark);
}

.secondary-button {
  background: var(--neutral-bg);
  color: var(--neutral-text);
}

.secondary-button:hover {
  background: #dfe5ed;
}

.results {
  display: grid;
  overflow: hidden;
}

.results > div {
  min-width: 0;
  padding: 17px 18px;
}

.results > div + div {
  border-top: 1px solid var(--line);
}

.result-label {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.average-value {
  margin-bottom: 0;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
}

.gpa-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.status-pill,
.course-status {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  min-height: 28px;
  margin-bottom: 0;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.waiting,
.not-ready {
  background: var(--neutral-bg);
  color: var(--neutral-text);
}

.pass {
  background: var(--success-bg);
  color: var(--success-text);
}

.compensation {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.fail {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.table-wrap {
  padding: 20px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 700;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.empty-state {
  color: var(--muted);
}

.rules {
  padding: 18px;
}

.rules ul {
  margin: 0;
  padding-left: 18px;
}

.rules li {
  color: var(--muted);
  font-size: 0.87rem;
  line-height: 1.42;
}

.rules li + li {
  margin-top: 7px;
}

.rules li::marker {
  color: var(--blue);
}

.site-footer {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-width: 0;
}

.dsa-promo {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 11px;
  min-width: 0;
  padding: 13px 16px;
  background: var(--surface-blue);
  color: var(--text);
  text-decoration: none;
}

.dsa-promo span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
}

.dsa-promo strong {
  color: var(--blue-dark);
  font-size: 0.91rem;
  font-weight: 700;
}

.dsa-promo:hover strong,
.footer-meta a:hover {
  text-decoration: underline;
}

.footer-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px 16px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.footer-meta p {
  margin: 0;
  font-weight: 600;
  white-space: nowrap;
}

.footer-meta a {
  color: var(--blue-dark);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

@media (max-width: 980px) {
  .calculator {
    grid-template-columns: minmax(0, 1fr) 280px;
  }

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

  .semester-picker p,
  .exam-picker p {
    min-height: 0;
  }

  .semester-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mode-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .site-footer {
    grid-template-columns: 1fr;
  }

  .footer-meta {
    justify-content: flex-start;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 24px, 1240px);
    padding: 12px 0 24px;
  }

  .calculator {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .primary-column,
  .side-column {
    display: contents;
  }

  form {
    order: 1;
  }

  .results {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    order: 2;
  }

  .results > div {
    padding: 15px;
  }

  .results > div + div {
    border-top: 0;
    border-left: 1px solid var(--line);
  }

  .table-wrap {
    order: 3;
  }

  .rules {
    order: 4;
  }

  .site-footer {
    order: 5;
    gap: 12px;
  }
}

@media (max-width: 560px) {
  .intro,
  form,
  .table-wrap,
  .rules {
    padding: 16px;
  }

  .intro {
    padding-top: 18px;
  }

  h1 {
    font-size: 1.8rem;
  }

  .picker-grid {
    gap: 15px;
    margin-bottom: 16px;
    padding-bottom: 16px;
  }

  .mode-options,
  .course-grid,
  .results {
    grid-template-columns: 1fr;
  }

  .results > div + div {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  th,
  td {
    padding: 10px 6px;
    font-size: 0.84rem;
  }

  .course-status {
    white-space: normal;
  }

  .dsa-promo {
    align-items: flex-start;
    flex-direction: column;
  }

  .footer-meta {
    flex-direction: column;
    align-items: flex-start;
  }
}

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