* {
  box-sizing: border-box;
}

:root {
  --bg: #070b14;
  --panel: rgba(15, 23, 42, 0.92);
  --soft: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.13);
  --text: #eef4ff;
  --muted: #94a3b8;
  --green: #32d583;
  --blue: #5b8cff;
  --purple: #9b7cff;
  --red: #ff5c7a;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 20%, rgba(91, 140, 255, 0.25), transparent 30%),
    radial-gradient(circle at 82% 12%, rgba(50, 213, 131, 0.17), transparent 32%),
    radial-gradient(circle at 50% 95%, rgba(155, 124, 255, 0.14), transparent 34%),
    var(--bg);
}

.page {
  width: min(950px, 100%);
  margin: auto;
  padding: 28px;
}

.top-actions {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 24px;
}

.back,
.learn-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 12px 18px;
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
  background: rgba(255,255,255,.08);
  border: 1px solid var(--border);
  font-weight: 900;
}

.learn-btn {
  background: linear-gradient(135deg, var(--blue), var(--purple));
  border: 0;
}

.panel {
  padding: 34px;
  border-radius: 34px;
  background: linear-gradient(145deg, rgba(15,23,42,.96), rgba(17,24,39,.84));
  border: 1px solid var(--border);
  box-shadow: 0 30px 90px rgba(0,0,0,.45);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(38px, 7vw, 66px);
  line-height: .95;
  letter-spacing: -0.06em;
}

.muted {
  color: var(--muted);
  line-height: 1.6;
}

.small {
  margin: 6px 0 0;
  font-size: 14px;
}

.layout.single {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: 30px;
}

.task-card,
.work-card,
.result-box {
  padding: 28px;
  border-radius: 28px;
  background: var(--soft);
  border: 1px solid var(--border);
}

.task-card h2,
.work-card h2,
.result-box h2 {
  margin: 0 0 18px;
  font-size: 28px;
  letter-spacing: -0.04em;
}

.pill {
  display: inline-block;
  margin: 0 0 18px;
  padding: 8px 13px;
  border-radius: 999px;
  color: #b9ccff;
  background: rgba(91,140,255,.14);
  font-weight: 900;
}

#task {
  margin-bottom: 22px;
  line-height: 1.3;
}

input {
  width: 100%;
  height: 58px;
  margin-bottom: 14px;
  padding: 0 18px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(7,11,20,.72);
  color: var(--text);
  font-size: 17px;
  outline: none;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(91,140,255,.16);
}

button {
  width: 100%;
  margin-top: 14px;
  padding: 15px;
  border-radius: 18px;
  border: 0;
  background: linear-gradient(135deg, var(--green), #12b76a);
  color: #03130b;
  font-weight: 900;
  cursor: pointer;
}

.secondary {
  background: rgba(255,255,255,.08);
  color: var(--text);
  border: 1px solid var(--border);
}

button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

#feedback {
  min-height: 28px;
  margin: 20px 0 6px;
  font-size: 20px;
  font-weight: 900;
}

.work-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 18px;
}

.tool-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-btn {
  width: 48px;
  height: 48px;
  margin: 0;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: rgba(255,255,255,.08);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 20px;
}

.icon-btn.active {
  background: linear-gradient(135deg, var(--blue), var(--purple));
  border-color: transparent;
}

.icon-btn.danger {
  background: rgba(255, 92, 122, 0.13);
  color: #ff9aae;
}

.math-paper {
  position: relative;
  width: 100%;
  min-height: 310px;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid rgba(91,140,255,.35);
  background-color: #f8fbff;
  background-image:
    linear-gradient(rgba(91, 140, 255, 0.22) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 140, 255, 0.22) 1px, transparent 1px);
  background-size: 28px 28px;
}

#workArea,
#drawCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#workArea {
  z-index: 2;
  resize: none;
  padding: 18px;
  border: 0;
  outline: none;
  background: transparent;
  color: #0f172a;
  font-size: 18px;
  line-height: 28px;
  font-family: "Courier New", monospace;
}

#drawCanvas {
  z-index: 3;
  display: none;
  touch-action: none;
}

.math-paper.draw-mode #workArea {
  pointer-events: none;
  opacity: 0.25;
}

.math-paper.draw-mode #drawCanvas {
  display: block;
}

.work-card.expanded {
  position: fixed;
  inset: 14px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  padding: 22px;
  border-radius: 28px;
  background: rgba(15,23,42,.98);
  box-shadow: 0 40px 120px rgba(0,0,0,.7);
}

.work-card.expanded .math-paper {
  flex: 1;
  min-height: 0;
}

.rotate-hint {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(250, 204, 21, 0.13);
  border: 1px solid rgba(250, 204, 21, 0.3);
  color: #fde68a;
  font-weight: 800;
}

.formula-box {
  margin-top: 18px;
  padding: 20px;
  border-radius: 22px;
  background: rgba(91,140,255,.13);
  border: 1px solid rgba(91,140,255,.35);
}

#formulaText {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  font-weight: 900;
  line-height: 1.5;
}

.result-box {
  margin-top: 22px;
}

.hidden {
  display: none;
}

ul {
  padding: 0;
  margin: 18px 0 0;
  list-style: none;
}

li {
  margin: 10px 0;
  padding: 16px;
  border-radius: 18px;
  background: rgba(7,11,20,.45);
  border: 1px solid var(--border);
  line-height: 1.6;
}

@media (max-width: 700px) {
  .page {
    padding: 20px 14px;
  }

  .top-actions,
  .work-header {
    flex-direction: column;
  }

  .back,
  .learn-btn {
    width: 100%;
  }

  .panel {
    padding: 22px;
    border-radius: 26px;
  }

  .task-card,
  .work-card,
  .result-box {
    padding: 20px;
    border-radius: 22px;
  }

  .tool-buttons {
    width: 100%;
    justify-content: space-between;
  }

  .icon-btn {
    flex: 1;
  }

  .math-paper {
    min-height: 280px;
  }
}
body.no-scroll {
  overflow: hidden;
  height: 100vh;
}

.icon-btn.disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.icon-btn.eraser-active {
  background: linear-gradient(135deg, #ff5c7a, #f97316);
  border-color: transparent;
  color: white;
}

.work-card.expanded {
  overflow: hidden;
}

.work-card.expanded .work-header {
  flex-shrink: 0;
}

.work-card.expanded .formula-box,
.work-card.expanded .rotate-hint {
  flex-shrink: 0;
}