:root {
  --bg: #f3f7fb;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --surface-soft: #eef5ff;
  --text: #17304a;
  --text-muted: #587086;
  --line: #d6e0eb;
  --primary: #0f6ba8;
  --primary-strong: #0b4f7c;
  --accent: #f4b942;
  --accent-soft: #fff4d7;
  --success: #1e8a63;
  --success-soft: #e8f8f1;
  --danger: #b54a3f;
  --danger-soft: #fde9e7;
  --shadow: 0 18px 40px rgba(19, 51, 80, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", "Segoe UI", sans-serif;
  color: var(--text);
  overflow-x: hidden;
  background:
    radial-gradient(circle at top right, rgba(244, 185, 66, 0.18), transparent 32%),
    linear-gradient(180deg, #f8fbff 0%, #eef4f9 100%);
}

button,
input {
  font: inherit;
}

.page-background {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 14%, rgba(15, 107, 168, 0.08), transparent 18%),
    radial-gradient(circle at 88% 20%, rgba(244, 185, 66, 0.12), transparent 14%),
    radial-gradient(circle at 70% 82%, rgba(15, 107, 168, 0.08), transparent 16%);
  z-index: -1;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  background: rgba(245, 249, 253, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(214, 224, 235, 0.8);
}

.nav-toggle {
  display: none;
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1rem;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.logo-placeholder {
  flex: 0 0 126px;
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  border: 2px dashed rgba(15, 107, 168, 0.35);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(238, 245, 255, 0.95));
  color: var(--primary-strong);
}

.university-logo {
  display: block;
  width: 100%;
  max-width: 100px;
  height: auto;
  object-fit: contain;
}

.brand-copy h1 {
  margin: 0;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: clamp(1.75rem, 2.5vw, 2.45rem);
  line-height: 1.1;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.subtitle {
  margin: 0.45rem 0 0;
  max-width: 78ch;
  color: var(--text-muted);
}

.app-shell {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  gap: 1.5rem;
  padding: 1.5rem;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 8.6rem;
  border-radius: var(--radius-xl);
  background: var(--surface);
  border: 1px solid rgba(214, 224, 235, 0.9);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.sidebar-head h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}

.sidebar-head p {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

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

.nav-list button {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 0.95rem 1rem;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  transition: 160ms ease;
}

.nav-list button:hover,
.nav-list button:focus-visible {
  background: var(--surface-soft);
  border-color: rgba(15, 107, 168, 0.18);
  outline: none;
}

.nav-list button.active {
  background: linear-gradient(135deg, rgba(15, 107, 168, 0.14), rgba(244, 185, 66, 0.15));
  border-color: rgba(15, 107, 168, 0.2);
  color: var(--primary-strong);
}

.main-content {
  display: grid;
  gap: 1.25rem;
  min-width: 0;
}

.hero-card,
.card {
  border: 1px solid rgba(214, 224, 235, 0.9);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 1.4rem;
  min-width: 0;
}

.hero-card {
  background:
    linear-gradient(135deg, rgba(15, 107, 168, 0.92), rgba(18, 126, 105, 0.88)),
    var(--surface);
  color: #fff;
  overflow: hidden;
}

.hero-card h2 {
  margin: 0 0 0.5rem;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: clamp(1.45rem, 2vw, 2rem);
}

.hero-card p {
  margin: 0;
  max-width: 70ch;
  color: rgba(255, 255, 255, 0.88);
}

.module-grid {
  display: grid;
  gap: 1.25rem;
}

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

.card h3,
.card h4 {
  margin-top: 0;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.card-head p {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  background: var(--accent-soft);
  color: #7f5900;
  font-size: 0.85rem;
  font-weight: 800;
}

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

.field {
  display: grid;
  gap: 0.45rem;
}

.field label,
.checkbox-row label {
  font-weight: 700;
}

.field input[type="number"],
.field input[type="text"],
.manual-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.9rem;
  background: var(--surface-strong);
  color: var(--text);
}

.field input:focus,
.manual-input:focus {
  outline: 2px solid rgba(15, 107, 168, 0.18);
  border-color: rgba(15, 107, 168, 0.42);
}

.field small {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-top: 1rem;
}

.button-row.tight {
  margin-top: 0;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 0.82rem 1.1rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.btn:hover,
.btn:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 12px 24px rgba(15, 107, 168, 0.22);
}

.btn-secondary {
  background: #edf5fc;
  color: var(--primary-strong);
}

.btn-accent {
  background: var(--accent);
  color: #4c3500;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  background: #f8fbfe;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.checkbox-row p {
  margin: 0.2rem 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.feedback {
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  border: 1px solid transparent;
  font-weight: 700;
}

.feedback.error {
  background: var(--danger-soft);
  border-color: rgba(181, 74, 63, 0.24);
  color: #7b2f27;
}

.feedback.success {
  background: var(--success-soft);
  border-color: rgba(30, 138, 99, 0.22);
  color: #156548;
}

.feedback.info {
  background: #edf5fc;
  border-color: rgba(15, 107, 168, 0.16);
  color: var(--primary-strong);
}

.table-scroll {
  overflow-x: auto;
  padding-bottom: 0.35rem;
}

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

.manual-table {
  min-width: 740px;
}

th,
td {
  border: 1px solid var(--line);
  padding: 0.7rem 0.8rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.92);
}

th {
  background: #f4f8fc;
  font-weight: 800;
}

.manual-table th:first-child,
.manual-table td:first-child,
.data-table th:first-child,
.data-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #eef5fd;
}

.manual-input {
  min-width: 90px;
  text-align: center;
  padding: 0.65rem 0.5rem;
}

.data-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.chip {
  padding: 0.55rem 0.8rem;
  border-radius: 999px;
  background: #f1f7fd;
  color: var(--primary-strong);
  font-weight: 700;
}

.stats-table td:first-child {
  text-align: left;
  font-weight: 800;
}

.stats-table td:nth-child(2) {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: var(--primary-strong);
}

.stats-table td:nth-child(3) {
  text-align: left;
  color: var(--text-muted);
}

.hint-box {
  margin-top: 1rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(244, 185, 66, 0.14), rgba(244, 185, 66, 0.05));
  border: 1px solid rgba(244, 185, 66, 0.34);
}

.hint-box p,
.note-list li {
  color: var(--text-muted);
}

.math-overline {
  text-decoration: overline;
}

.math-overline-symbol,
.mean-symbol {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-width: 0.8em;
  line-height: 1;
  vertical-align: middle;
}

.mean-symbol-line {
  display: block;
  width: 0.82em;
  border-top: 1.5px solid currentColor;
  margin-bottom: 0.06em;
}

.mean-symbol-char {
  display: block;
  text-align: center;
}

.formula-stack {
  display: grid;
  gap: 0.8rem;
  margin-top: 0.9rem;
}

.formula-block {
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(88, 112, 134, 0.2);
}

.formula-label {
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.formula-expression {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

.math-fraction {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  min-width: 4.5rem;
  text-align: center;
  vertical-align: middle;
}

.math-fraction-top {
  display: block;
  padding: 0 0.25rem 0.14rem;
  border-bottom: 1.5px solid currentColor;
  line-height: 1.15;
}

.math-fraction-bottom {
  display: block;
  padding: 0.14rem 0.25rem 0;
  line-height: 1.15;
}

.math-binomial {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  min-width: 1.6rem;
  padding: 0 0.3rem;
  line-height: 1;
  vertical-align: middle;
}

.math-binomial::before,
.math-binomial::after {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.45em;
  line-height: 1;
}

.math-binomial::before {
  content: "(";
  left: 0;
}

.math-binomial::after {
  content: ")";
  right: 0;
}

.math-binomial-top,
.math-binomial-bottom {
  display: block;
  text-align: center;
  padding: 0 0.25rem;
}

.formula-note {
  margin-top: 0.55rem;
  color: var(--text-muted);
}

.option-grid {
  display: grid;
  gap: 0.85rem;
  margin-top: 1rem;
}

.option-card {
  display: grid;
  gap: 0.3rem;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  cursor: pointer;
}

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

.option-card.selected {
  border-color: rgba(15, 107, 168, 0.45);
  box-shadow: 0 0 0 1px rgba(15, 107, 168, 0.16);
  background: linear-gradient(180deg, rgba(15, 107, 168, 0.08), rgba(255, 255, 255, 0.92));
}

.option-card-title {
  font-weight: 800;
  color: var(--text-main);
}

.option-card-text {
  color: var(--text-muted);
  font-size: 0.96rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
}

.summary-item {
  display: grid;
  gap: 0.35rem;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
}

.summary-item strong {
  color: var(--text-muted);
  font-size: 0.88rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.z-table-scroll {
  max-height: 540px;
}

.z-table-reference th,
.z-table-reference td {
  white-space: nowrap;
  text-align: right;
}

.z-table-reference td.z-hit {
  background: rgba(15, 107, 168, 0.14);
  color: #0f6ba8;
  font-weight: 800;
}

.quartile-method-image {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: #fff;
  object-fit: contain;
}

.note-list {
  margin: 0;
  padding-left: 1.1rem;
}

.canvas-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #f7fbff);
  padding: 0.6rem;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

.empty-state {
  border: 1px dashed rgba(88, 112, 134, 0.45);
  border-radius: var(--radius-md);
  padding: 1rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.55);
}

.solution-sheet td:last-child {
  min-width: 180px;
  height: 38px;
  background: #fffef8;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag {
  border-radius: 999px;
  padding: 0.38rem 0.68rem;
  background: #eef5fc;
  color: var(--primary-strong);
  font-weight: 700;
  font-size: 0.88rem;
}

.footer-note {
  color: var(--text-muted);
  font-size: 0.92rem;
}

tfoot th,
tfoot td {
  background: #eef5fd;
  font-weight: 800;
}

@media (max-width: 1120px) {
  .module-grid.cols-2,
  .results-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 7rem auto 1rem 1rem;
    width: min(320px, calc(100vw - 2rem));
    transform: translateX(-115%);
    transition: transform 180ms ease;
    z-index: 30;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

@media (max-width: 780px) {
  .app-header,
  .app-shell {
    padding: 1rem;
  }

  .brand-block {
    align-items: flex-start;
    flex-direction: column;
  }

  .logo-placeholder {
    width: 100%;
    max-width: 180px;
  }

  .button-row .btn {
    width: 100%;
  }

  .checkbox-row {
    align-items: flex-start;
  }
}
