:root {
  color-scheme: light;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --surface: rgba(255, 255, 255, 0.92);
  --background: linear-gradient(160deg, #f9fafb 0%, #e2e8f0 40%, #f9fafb 100%);
  --shadow: 0 18px 35px rgba(15, 23, 42, 0.12);
  --success: #16a34a;
  --line: #2563eb;
  --triangle: #f97316;
  --m: #16a34a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 0 2rem;
  background: var(--background);
  color: var(--text-primary);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

.page {
  width: min(1180px, 100%);
  padding: clamp(1.5rem, 4vw, 3rem) clamp(0.75rem, 3vw, 2rem) 3rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem;
}

.page__header {
  text-align: center;
  display: grid;
  gap: 0.6rem;
}

.page__header h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3rem);
}

.page__header p {
  margin: 0;
  color: var(--text-secondary);
}

/* ---------- Modes ---------- */

.modes {
  display: inline-flex;
  justify-self: center;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.06);
}

.modes button {
  border: none;
  background: none;
  padding: 0.55rem 1.3rem;
  border-radius: 999px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.modes button[aria-selected="true"] {
  background: #fff;
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

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

/* ---------- Layout ---------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.card {
  background: var(--surface);
  border-radius: 24px;
  padding: clamp(0.9rem, 2.5vw, 1.5rem);
  box-shadow: var(--shadow);
}

.plane-card {
  display: grid;
  gap: 0.25rem;
}

.plane {
  display: block;
  width: 100%;
  height: auto;
  max-height: 80vh;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}

.plane.is-dragging {
  cursor: grabbing;
}

.hover-readout {
  margin: 0;
  text-align: center;
  font-weight: 700;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  min-height: 1.4em;
}

.side {
  display: grid;
  gap: 1.1rem;
}

.settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.field select {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 12px;
  padding: 0.55rem 0.7rem;
  background: #fff;
  font-size: 1rem;
  color: var(--text-primary);
}

.panel {
  display: grid;
  gap: 0.9rem;
}

.hint {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.6rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 140ms ease, transform 100ms ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn--primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.28);
}

.btn--primary:hover {
  background: var(--accent-hover);
}

.btn--ghost {
  background: #fff;
  border-color: var(--border);
  color: var(--text-secondary);
}

.btn--ghost:hover {
  border-color: #cbd5e1;
  color: var(--text-primary);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.check input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

.checks {
  display: grid;
  gap: 0.4rem;
}

/* ---------- SVG plane ---------- */

.grid__line {
  stroke: #e2e8f0;
  stroke-width: 1;
}

.grid__line--major {
  stroke: #cbd5e1;
}

.axis {
  stroke: #0f172a;
  stroke-width: 2;
}

.axis__arrow {
  fill: #0f172a;
}

.axis__name {
  font-size: 17px;
  font-weight: 700;
  font-style: italic;
  fill: #0f172a;
}

.tick {
  font-size: 11px;
  font-weight: 600;
  fill: #475569;
  font-variant-numeric: tabular-nums;
}

.pt__dot {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 2.5;
}

.pt--draggable {
  cursor: grab;
}

.pt--q .pt__dot {
  fill: #7c3aed;
}

.pt--task .pt__dot {
  fill: #0f172a;
}

.pt--right .pt__dot {
  fill: var(--success);
}

.pt--wrong .pt__dot {
  fill: #dc2626;
}

.pt__label,
.triangle__label,
.m-mark__label {
  font-size: 14px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 4px;
  stroke-linejoin: round;
  fill: #0f172a;
}

.line {
  stroke: var(--line);
  stroke-width: 3;
}

.triangle {
  fill: rgba(249, 115, 22, 0.08);
  stroke: var(--triangle);
  stroke-width: 2.5;
  stroke-dasharray: 7 5;
}

.triangle__label {
  fill: #c2410c;
}

.m-mark rect {
  fill: var(--m);
  stroke: #fff;
  stroke-width: 2;
}

.m-mark__label {
  fill: #166534;
}

/* ---------- Side panels ---------- */

.point-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
  max-height: 16rem;
  overflow-y: auto;
}

.point-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.4rem 0.35rem 0.7rem;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--border);
}

.point-list__name {
  font-weight: 800;
  color: var(--accent);
  min-width: 1.6rem;
}

.point-list__coord {
  flex: 1;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.point-list__remove {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: none;
  font-size: 1.2rem;
  color: var(--text-muted);
  cursor: pointer;
}

.point-list__remove:hover {
  background: #fef2f2;
  color: #dc2626;
}

.point-list .point-list__empty {
  justify-content: center;
  color: var(--text-muted);
  background: none;
  border-style: dashed;
}

.line-info {
  display: grid;
  gap: 0.45rem;
  padding: 1rem;
  border-radius: 16px;
  background: rgba(37, 99, 235, 0.05);
  font-variant-numeric: tabular-nums;
}

.line-info__points {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
  font-weight: 700;
}

.line-info__points span:first-child {
  color: var(--accent);
}

.line-info__points span:last-child {
  color: #7c3aed;
}

.line-info__row {
  color: #c2410c;
  font-weight: 600;
}

.line-info__big {
  font-size: 1.35rem;
  font-weight: 800;
}

.line-info__equation {
  margin-top: 0.2rem;
  padding: 0.5rem 0.8rem;
  border-radius: 12px;
  background: #fff;
  font-size: clamp(1.4rem, 3vw, 1.9rem);
  font-weight: 800;
  color: var(--line);
  text-align: center;
}

.line-info__note {
  margin: 0;
  color: var(--text-secondary);
}

.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  line-height: 1.05;
  font-size: 0.85em;
  margin: 0 0.1em;
}

.frac span:first-child {
  border-bottom: 2px solid currentColor;
  padding: 0 0.15em;
}

.frac span:last-child {
  padding: 0 0.15em;
}

.km-form,
.task__form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.km-form__title {
  flex-basis: 100%;
  font-weight: 700;
  color: var(--text-secondary);
}

.km-form label,
.task__form label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 700;
  font-style: italic;
}

.km-form input,
.task__form input {
  width: 5.2rem;
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
  font-size: 1.05rem;
  font-weight: 700;
  font-style: normal;
  background: #fff;
}

.km-form input:focus,
.task__form input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.task {
  display: grid;
  gap: 0.6rem;
}

.task__prompt {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.task__target {
  font-size: clamp(2rem, 5vw, 2.8rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.feedback {
  margin: 0;
  min-height: 1.4em;
  font-weight: 600;
}

.feedback.is-right {
  color: var(--success);
}

.feedback.is-wrong {
  color: #dc2626;
}

.feedback.is-hint {
  color: var(--text-secondary);
}

.score {
  margin: 0;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ---------- Notes ---------- */

.notes {
  background: rgba(255, 255, 255, 0.7);
  border-radius: 20px;
  padding: 1.5rem;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
  display: grid;
  gap: 1rem;
}

.notes h2 {
  margin: 0;
  font-size: 1.25rem;
}

.notes ul {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.5rem;
}

.notes li {
  color: var(--text-secondary);
}

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