:root {
  color-scheme: dark;
  --bg: #07111f;
  --bg-2: #0d1729;
  --surface: rgba(255, 255, 255, 0.08);
  --surface-strong: rgba(255, 255, 255, 0.12);
  --text: #f5f7ff;
  --muted: #9fb0cc;
  --accent: #5bd6ff;
  --accent-2: #7f7cff;
  --success: #33d17a;
  --warning: #ffb347;
  --danger: #ff6b6b;
  --border: rgba(255, 255, 255, 0.15);
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: radial-gradient(circle at top, #14213d 0%, var(--bg) 55%, #060b12 100%);
  color: var(--text);
  min-height: 100vh;
}

.app-shell {
  width: min(1200px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

.glass-card {
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.hero-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  padding: 2rem;
  border-radius: 24px;
  margin-bottom: 1.5rem;
  background: linear-gradient(135deg, rgba(91, 214, 255, 0.2), rgba(127, 124, 255, 0.16));
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.eyebrow {
  margin: 0 0 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.75rem;
  color: var(--accent);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(1.8rem, 3vw, 2.5rem);
  margin-bottom: 0.6rem;
}

.hero-text {
  max-width: 680px;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 0;
}

.hero-badge {
  min-width: 180px;
  padding: 0.85rem 1rem;
  text-align: center;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--text);
  font-weight: 600;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  padding: 1.2rem 1.1rem;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.stat-card strong {
  font-size: 1.6rem;
}

.main-grid {
  display: grid;
  grid-template-columns: 1.5fr 0.9fr;
  gap: 1.2rem;
}

.task-card,
.explanation-card {
  border-radius: 24px;
  padding: 1.4rem;
}

.task-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
}

.field-label {
  font-weight: 600;
}

select,
input {
  width: 100%;
  padding: 0.9rem 1rem;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(7, 17, 34, 0.76);
  color: var(--text);
  font-size: 1rem;
}

select:focus,
input:focus {
  outline: 2px solid rgba(91, 214, 255, 0.35);
  border-color: var(--accent);
}

.input-invalid {
  border-color: rgba(255, 107, 107, 0.7) !important;
  box-shadow: inset 0 0 0 1px rgba(255, 107, 107, 0.35);
}

.task-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.7rem;
}

.task-ip-pill {
  padding: 0.75rem 1rem;
  border-radius: 999px;
  background: rgba(91, 214, 255, 0.15);
  color: var(--accent);
  font-weight: 700;
}

.task-copy {
  color: var(--muted);
  margin-bottom: 1rem;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.input-group span {
  font-weight: 600;
  color: var(--muted);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.2rem;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 0.85rem 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.card-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.8rem;
}

.explanation-toggle,
.history-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.history-section h3 {
  margin: 0;
  font-size: 1.1rem;
}

.history-content {
  overflow: hidden;
  transition: max-height 220ms ease, opacity 220ms ease;
}

.history-content.collapsed {
  max-height: 0;
  opacity: 0;
}

.history-content.expanded {
  max-height: 500px;
  opacity: 1;
}

.feedback-box,
.explanation-box {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.feedback-box:empty,
.explanation-box:empty {
  display: none;
}

.explanation-toggle[aria-expanded="true"] .calc-toggle-icon,
.history-toggle[aria-expanded="true"] .history-toggle-icon {
  transform: rotate(180deg);
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.85rem;
}

.history-item {
  padding: 0.95rem 1rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  line-height: 1.5;
}

.history-item strong {
  color: var(--text);
}

.explanation-hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.feedback-success {
  border-color: rgba(51, 209, 122, 0.28);
  color: #c2ffd2;
}

.feedback-warning {
  border-color: rgba(255, 179, 71, 0.28);
  color: #ffe1b7;
}

.feedback-danger {
  border-color: rgba(255, 107, 107, 0.28);
  color: #ffd7d7;
}

.explanation-list {
  padding-left: 1rem;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.helper-note {
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.calculator-section {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.calc-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.calc-toggle-icon {
  transition: transform 180ms ease;
}

.calculator-content {
  margin-top: 0.85rem;
  overflow: hidden;
  transition: max-height 220ms ease, opacity 220ms ease;
}

.calculator-content.collapsed {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}

.calculator-content.expanded {
  max-height: 700px;
  opacity: 1;
}

.calc-form {
  display: grid;
  grid-template-columns: 1.4fr 0.7fr auto;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 0.85rem;
}

.calc-result {
  display: grid;
  gap: 0.55rem;
}

.study-mode {
  margin: 0.85rem 0 0;
}

.study-mode button {
  width: 100%;
}

.study-mode-content {
  margin-top: 0.7rem;
  overflow: hidden;
  transition: max-height 220ms ease, opacity 220ms ease;
}

.study-mode-content.collapsed {
  max-height: 0;
  opacity: 0;
}

.study-mode-content.expanded {
  max-height: 600px;
  opacity: 1;
}

.calc-toggle[aria-expanded="true"] .calc-toggle-icon {
  transform: rotate(180deg);
}

.calc-result-item {
  padding: 0.8rem 0.9rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
}

.calc-label {
  color: var(--muted);
  display: block;
  font-size: 0.9rem;
}

.calc-value {
  display: block;
  font-weight: 700;
  margin-top: 0.2rem;
}

.history-section {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.history-section h3 {
  margin-bottom: 0.7rem;
  font-size: 1rem;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.55rem;
}

.history-item {
  padding: 0.7rem 0.8rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 0.92rem;
}

.history-item strong {
  color: var(--text);
}

.input-correct {
  border-color: rgba(51, 209, 122, 0.65) !important;
  box-shadow: inset 0 0 0 1px rgba(51, 209, 122, 0.35);
}

.input-wrong {
  border-color: rgba(255, 107, 107, 0.7) !important;
  box-shadow: inset 0 0 0 1px rgba(255, 107, 107, 0.35);
}

@media (max-width: 900px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .hero-card,
  .task-card,
  .explanation-card {
    padding: 1.1rem;
  }

  .stats-grid,
  .answer-grid {
    grid-template-columns: 1fr;
  }

  .task-head,
  .task-toolbar,
  .calc-form {
    flex-direction: column;
    align-items: flex-start;
  }

  .calc-form {
    grid-template-columns: 1fr;
  }

  .hero-card {
    align-items: flex-start;
  }
}
