:root {
  color-scheme: light;
  --bg: #f7f7f2;
  --ink: #1e2528;
  --muted: #66706f;
  --panel: #ffffff;
  --line: #d9ded8;
  --accent: #146c63;
  --accent-dark: #0d4e48;
  --code: #f0f4f3;
  --good: #176b3a;
  --bad: #a42d2d;
  --soft: #edf8f6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.45;
  overflow-x: hidden;
}

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

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  padding: 10px 0 22px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 8px;
  font-size: 34px;
}

h2 {
  margin-bottom: 16px;
  font-size: 20px;
}

.controls-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
  margin-bottom: 16px;
}

.controls-title h2 {
  margin-bottom: 0;
}

.status-badge {
  display: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-badge:not(:empty) {
  display: inline-flex;
}

.status-badge.good {
  border-color: #a8d7bb;
  background: #edf8f1;
  color: var(--good);
}

.status-badge.warn {
  border-color: #e2c49d;
  background: #fff7ec;
  color: #8a520e;
}

.status-badge.bad {
  border-color: #e7aaaa;
  background: #fff0f0;
  color: var(--bad);
}

h3 {
  margin-bottom: 10px;
  font-size: 16px;
}

.intro {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
}

.status-box {
  min-width: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
}

.status-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 18px 0 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.tab-button {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--accent-dark);
  white-space: nowrap;
}

.tab-button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.workspace {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
  min-width: 0;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.controls {
  align-self: start;
  position: sticky;
  top: 16px;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea,
button {
  min-height: 40px;
  border-radius: 6px;
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
}

input.input-review {
  border-color: var(--bad);
  background: #fff7f7;
  animation: review-input-pulse 900ms ease-in-out 3;
}

textarea {
  min-height: 116px;
  resize: vertical;
  line-height: 1.35;
}

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled,
button:disabled:hover {
  border-color: #b7c2bf;
  background: #e6ecea;
  color: #6d7875;
  cursor: not-allowed;
}

button.secondary {
  background: #fff;
  color: var(--accent);
}

button.secondary:disabled,
button.secondary:disabled:hover {
  border-color: #b7c2bf;
  background: #f2f5f4;
  color: #6d7875;
}

button.secondary:hover {
  background: #eef5f3;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.small-button {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

.problem-editor {
  margin: 18px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.problem-editor-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.problem-editor-head h3 {
  margin-bottom: 0;
  color: var(--accent-dark);
}

.print-problem {
  display: none;
}

.practice {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.answer-grid.two {
  grid-template-columns: repeat(2, 1fr);
}

.answer-grid label {
  margin-bottom: 8px;
}

.wide {
  width: 100%;
}

.feedback {
  margin-top: 12px;
  padding: 10px;
  border-radius: 6px;
  background: var(--code);
  color: var(--muted);
  min-height: 44px;
}

.feedback.good {
  color: var(--good);
  background: #edf8f1;
}

.feedback.bad {
  color: var(--bad);
  background: #fff0f0;
}

.solution-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 12px;
  min-width: 0;
}

.solution {
  position: relative;
}

.solution-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.solution-actions button {
  white-space: nowrap;
}

.problem-text {
  color: var(--muted);
  margin-bottom: 0;
}

.step {
  border-top: 1px solid var(--line);
  padding: 16px 0;
}

.step:first-child {
  border-top: 0;
}

.step h3 {
  color: var(--accent-dark);
}

.explain {
  color: var(--muted);
  margin-bottom: 10px;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  overflow: visible;
  background: var(--code);
  border-radius: 8px;
  padding: 12px;
  margin: 0;
  font-size: 15px;
}

.math-work {
  background: #fbfcfb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  overflow: visible;
  width: 100%;
}

.math-line {
  position: relative;
  width: fit-content;
  max-width: 100%;
  min-height: 28px;
  padding: 3px 8px;
  border-radius: 5px;
  color: #11181a;
  font-family: "Cambria Math", Cambria, "Times New Roman", serif;
  font-size: 20px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.math-gap {
  height: 10px;
}

.math-line.review-highlight {
  outline: 2px solid #d58a1f;
  background: #fff4d8;
  animation: review-line-pulse 900ms ease-in-out 4;
}

.formula-item.review-highlight {
  animation: review-line-pulse 900ms ease-in-out 4;
}

@keyframes review-line-pulse {
  0% {
    background-color: #fff4d8;
    box-shadow: 0 0 0 0 rgba(213, 138, 31, 0.55);
  }
  50% {
    background-color: #ffe0a3;
    box-shadow: 0 0 0 5px rgba(213, 138, 31, 0.16);
  }
  100% {
    background-color: #fff4d8;
    box-shadow: 0 0 0 0 rgba(213, 138, 31, 0);
  }
}

@keyframes review-input-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(164, 45, 45, 0.45);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(164, 45, 45, 0.16);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(164, 45, 45, 0);
  }
}

.explanations-on .math-line[data-tip]:hover {
  background: #edf8f6;
  outline: 1px solid #b9d6cf;
}

.explanations-on .math-line[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  z-index: 10;
  left: 0;
  top: calc(100% + 6px);
  width: min(360px, calc(100vw - 48px));
  padding: 10px 12px;
  border: 1px solid #b9d6cf;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(25, 38, 40, 0.14);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.35;
}

.polar-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfb;
}

.polar-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 14px;
}

.polar-head h3 {
  margin-bottom: 4px;
  color: var(--accent-dark);
}

.polar-head p {
  margin-bottom: 0;
  color: var(--muted);
}

.formula-stack {
  flex: 0 0 auto;
  display: grid;
  gap: 8px;
}

.formula-ref {
  border: 1px solid #b9d6cf;
  border-radius: 8px;
  padding: 10px 12px;
  background: #edf8f6;
  color: var(--accent-dark);
  font-family: "Cambria Math", Cambria, "Times New Roman", serif;
  font-size: 20px;
}

.polar-layout {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(220px, 1fr);
  gap: 16px;
  align-items: center;
}

.polar-board {
  position: relative;
  width: min(360px, 100%);
  aspect-ratio: 1;
  margin: 0 auto;
}

.polar-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.svg-bg {
  fill: #ffffff;
  stroke: #d9ded8;
}

.axis {
  stroke: #66706f;
  stroke-width: 1.4;
}

.axis-label,
.point-label,
.theta-label {
  fill: #324044;
  font: 9px Arial, Helvetica, sans-serif;
}

.vector {
  stroke: #146c63;
  stroke-width: 2.8;
  stroke-linecap: round;
}

.point {
  fill: #a42d2d;
  stroke: #ffffff;
  stroke-width: 2;
}

.guide {
  stroke: #9aa7a5;
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.angle-arc {
  fill: none;
  stroke: #9b4d12;
  stroke-width: 2;
}

.quadrant-hit {
  position: absolute;
  width: 50%;
  height: 50%;
  border: 1px solid transparent;
}

.quadrant-hit:hover {
  border-color: rgba(20, 108, 99, 0.45);
  background: rgba(20, 108, 99, 0.08);
}

.quadrant-hit:hover::after {
  content: attr(data-tip);
  position: absolute;
  z-index: 12;
  width: min(280px, calc(100vw - 60px));
  padding: 10px 12px;
  border: 1px solid #b9d6cf;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(25, 38, 40, 0.16);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.35;
}

.q1 {
  top: 0;
  right: 0;
}

.q2 {
  top: 0;
  left: 0;
}

.q3 {
  bottom: 0;
  left: 0;
}

.q4 {
  right: 0;
  bottom: 0;
}

.q1::after,
.q4::after {
  right: 8px;
}

.q2::after,
.q3::after {
  left: 8px;
}

.q1::after,
.q2::after {
  top: 8px;
}

.q3::after,
.q4::after {
  bottom: 8px;
}

.polar-notes {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-size: 15px;
}

.polar-notes div {
  border-bottom: 1px solid var(--line);
  padding-bottom: 7px;
}

.formula-panel {
  border: 1px solid #b9d6cf;
  border-radius: 8px;
  padding: 16px;
  background: #edf8f6;
}

.formula-fab {
  position: absolute;
  right: -1px;
  top: 86px;
  z-index: 8;
  min-height: 36px;
  border-radius: 6px 0 0 6px;
  padding: 8px 10px;
  writing-mode: vertical-rl;
  text-orientation: mixed;
}

.formula-drawer {
  display: none;
  position: fixed;
  z-index: 9;
  top: 96px;
  right: max(16px, calc((100vw - 1200px) / 2));
  width: min(300px, calc(100% - 24px));
  max-height: calc(100vh - 116px);
  overflow: auto;
  transform: translateX(calc(100% + 20px));
  opacity: 0;
  pointer-events: none;
  border: 1px solid #b9d6cf;
  border-radius: 8px;
  padding: 14px;
  background: #edf8f6;
  box-shadow: 0 12px 30px rgba(25, 38, 40, 0.18);
  transition: transform 160ms ease, opacity 160ms ease;
}

.formulas-open .formula-drawer {
  display: block;
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.formulas-open .formula-fab {
  opacity: 0;
  pointer-events: none;
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  color: var(--accent-dark);
}

.formula-panel h3 {
  margin-bottom: 12px;
  color: var(--accent-dark);
}

.formula-list {
  display: grid;
  gap: 10px;
}

.formula-item {
  display: grid;
  gap: 5px;
  border: 1px solid rgba(20, 108, 99, 0.18);
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
}

.formula-item span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.formula-item strong {
  color: #11181a;
  font-family: "Cambria Math", Cambria, "Times New Roman", serif;
  font-size: 19px;
  font-weight: 600;
}

.formula-item.formula-active {
  border-color: var(--accent);
  background: #dff3ee;
  box-shadow: inset 4px 0 0 var(--accent);
}

.formula-item.formula-active span,
.formula-item.formula-active strong {
  color: var(--accent-dark);
}

.final-answer {
  display: grid;
  gap: 6px;
  margin-top: 16px;
  padding: 16px;
  border: 1px solid #b9d6cf;
  border-radius: 8px;
  background: var(--soft);
}

.final-answer strong {
  color: var(--accent-dark);
}

.hidden-answer .final-answer,
.hidden-answer .answer-only {
  display: none;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  margin-top: 34px;
  padding: 18px 0 4px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.site-footer img {
  width: min(280px, 45vw);
  height: auto;
  object-fit: contain;
}

.site-footer div {
  display: grid;
  gap: 4px;
  text-align: right;
}

.site-footer strong {
  color: var(--accent-dark);
}

@media (max-width: 880px) {
  .hero,
  .solution-header {
    display: block;
  }

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

  .controls {
    position: static;
  }

  .polar-head,
  .polar-layout {
    display: block;
  }

  .formula-ref {
    margin-top: 12px;
  }

  .polar-notes {
    margin-top: 14px;
  }

  .formula-list {
    grid-template-columns: 1fr;
  }

  .site-footer {
    display: grid;
    justify-items: start;
  }

  .site-footer div {
    text-align: left;
  }

  h1 {
    font-size: 28px;
  }
}

@media (min-width: 881px) and (max-width: 1100px) {
  .workspace {
    grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
  }

  .solution-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 720px);
    padding: 18px 0 28px;
  }

  .hero {
    gap: 14px;
    align-items: stretch;
  }

  .status-box {
    min-width: 0;
    margin-top: 12px;
  }

  .tabs {
    gap: 6px;
    padding-top: 14px;
  }

  .tab-button {
    min-height: 38px;
    padding: 7px 10px;
    font-size: 14px;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 12px;
  }

  .panel {
    padding: 14px;
  }

  .controls-title,
  .problem-editor-head {
    align-items: stretch;
    flex-direction: column;
  }

  .button-row,
  .answer-grid,
  .answer-grid.two {
    grid-template-columns: 1fr;
  }

  .solution-actions {
    display: grid;
    grid-template-columns: 1fr;
    margin-top: 12px;
  }

  .solution-actions button,
  .button-row button,
  .wide {
    width: 100%;
  }

  .math-line {
    width: auto;
    font-size: 18px;
  }

  .math-work {
    padding: 10px;
  }

  .polar-card {
    padding: 12px;
  }

  .polar-board {
    width: min(320px, 100%);
  }

  .formula-fab {
    position: fixed;
    top: auto;
    right: 10px;
    bottom: 14px;
    z-index: 30;
    border-radius: 999px;
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    box-shadow: 0 8px 24px rgba(25, 38, 40, 0.22);
  }

  .formula-drawer {
    position: fixed;
    inset: auto 10px 10px 10px;
    top: auto;
    right: 10px;
    width: auto;
    max-height: 68vh;
    transform: translateY(calc(100% + 18px));
    border-radius: 10px;
    z-index: 31;
  }

  .formulas-open .formula-drawer {
    transform: translateY(0);
  }

  .drawer-head {
    align-items: stretch;
    flex-direction: column;
  }

  .site-footer img {
    width: min(260px, 100%);
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: calc(100% - 14px);
    padding-top: 12px;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 18px;
  }

  h3 {
    font-size: 15px;
  }

  .panel {
    padding: 12px;
  }

  .problem-editor {
    padding: 12px;
  }

  input,
  select,
  textarea,
  button {
    min-height: 44px;
  }

  textarea {
    min-height: 132px;
  }

  .math-line {
    font-size: 16px;
    padding: 3px 4px;
  }

  .final-answer {
    padding: 12px;
  }

  .polar-notes {
    font-size: 14px;
  }

  .quadrant-hit:hover::after,
  .explanations-on .math-line[data-tip]:hover::after {
    width: min(300px, calc(100vw - 28px));
  }
}

@media (max-width: 380px) {
  .tab-button {
    font-size: 13px;
  }

  .math-line {
    font-size: 15px;
  }

  .formula-item strong {
    font-size: 16px;
  }
}

@media print {
  @page {
    size: letter;
    margin: 14mm;
  }

  * {
    box-shadow: none !important;
  }

  body {
    background: #ffffff;
    color: #000000;
    font-size: 12pt;
  }

  .hero,
  .tabs,
  .controls,
  .solution-actions,
  .problem-editor,
  .formula-fab,
  .formula-drawer,
  .feedback,
  .practice {
    display: none !important;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .tab-panel {
    display: none !important;
  }

  .tab-panel.active {
    display: block !important;
  }

  .workspace {
    display: block;
    margin: 0;
  }

  .panel,
  .solution {
    border: 0;
    padding: 0;
    background: #ffffff;
  }

  .solution-header {
    display: none;
  }

  .print-problem {
    display: block;
    margin: 0 0 10px;
    color: #000000;
    font-family: "Cambria Math", Cambria, "Times New Roman", serif;
    font-size: 12.5pt;
    line-height: 1.35;
  }

  #roots-solution::before {
    content: "1";
  }

  #cr-solution::before {
    content: "2";
  }

  #circle-solution::before {
    content: "3";
  }

  #maclaurin-solution::before {
    content: "4";
  }

  #residue-solution::before {
    content: "5";
  }

  .solution::before {
    display: block;
    margin-bottom: 8px;
    color: #000;
    font-family: "Cambria Math", Cambria, "Times New Roman", serif;
    font-size: 15pt;
    font-weight: 600;
  }

  .hidden-answer .final-answer,
  .hidden-answer .answer-only {
    display: block !important;
  }

  .step {
    break-inside: avoid;
    page-break-inside: avoid;
    border-top: 0;
    padding: 0;
    margin: 0 0 8px;
  }

  .step h3,
  .visual-step,
  .polar-card,
  .explain {
    display: none !important;
  }

  .math-work,
  .final-answer {
    border: 0;
    border-radius: 0;
    padding: 0;
    background: #ffffff;
  }

  .math-line {
    display: block;
    width: auto;
    max-width: none;
    min-height: 0;
    padding: 0;
    border-radius: 0;
    color: #000000;
    font-family: "Cambria Math", Cambria, "Times New Roman", serif;
    font-size: 14pt;
    line-height: 1.45;
  }

  .final-answer {
    display: grid;
    gap: 0;
    margin-top: 8px;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .final-answer strong {
    display: none;
  }

  .math-gap {
    height: 8px;
  }

  .site-footer {
    display: none !important;
  }
}
