:root {
  --bg: #f6f8fc;
  --panel: #ffffff;
  --line: #d7deea;
  --text: #10223a;
  --accent: #2563eb;
  --accent-soft: #e9f0ff;
  --ok-soft: #e7fbef;
  --warn-soft: #fff7dd;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: radial-gradient(circle at 10% 0%, #eef3ff 0%, var(--bg) 45%);
  color: var(--text);
}

.app {
  max-width: 1260px;
  margin: 0 auto;
  padding: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(16, 34, 58, 0.05);
}

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

h1 { margin-bottom: 10px; font-size: 30px; }

h2 { margin-bottom: 12px; font-size: 21px; }

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

p { margin: 0; line-height: 1.55; }

.controls {
  display: grid;
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
}

select, button { font: inherit; }

select {
  width: 100%;
  max-width: 460px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

button {
  width: fit-content;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid #1d4ed8;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:hover { filter: brightness(1.05); }
button:disabled { opacity: 0.7; cursor: wait; }

.fixed-info,
.formula,
.meta-box,
.theory-card,
.answer,
.note-box,
.preview-card,
.anim-box {
  background: #f8fbff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.fixed-info,
.formula,
.meta-box,
.note-box,
.answer,
.anim-box {
  padding: 10px 12px;
}

.badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  margin: 0;
  padding: 5px 10px;
  background: var(--accent-soft);
  border: 1px solid #c3d7ff;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.badge.accent {
  background: var(--ok-soft);
  border-color: #a2dbb5;
  color: #0f6339;
}

.task-text, .theory-wrap { display: grid; gap: 8px; }

.theory-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.theory-card { padding: 12px; }

.theory-card ul { margin: 8px 0 0 18px; padding: 0; }

.layout {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 14px;
}

.side-stack {
  display: grid;
  gap: 14px;
}

.preview-wrap {
  display: grid;
  gap: 12px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.preview-card { padding: 10px; }

.preview-title,
.matrix-title,
.code-title,
.anim-title {
  font-weight: 700;
  margin-bottom: 8px;
}

canvas,
svg {
  display: block;
  width: 100%;
  height: auto;
  background: #fbfcff;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.matrix-grid {
  display: grid;
  gap: 10px;
}

.files-table,
.meta-table {
  width: 100%;
  border-collapse: collapse;
}

.files-table th,
.files-table td,
.meta-table th,
.meta-table td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: center;
  vertical-align: top;
}

.files-table th,
.meta-table th {
  background: var(--accent-soft);
}

a {
  color: #1958ce;
  text-decoration: none;
  font-weight: 600;
}

a:hover { text-decoration: underline; }

.solution details {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fbff;
  padding: 10px 12px;
}

.solution summary {
  cursor: pointer;
  font-weight: 700;
}

.solution-list {
  margin: 10px 0 0 20px;
  padding: 0;
  line-height: 1.55;
}

.solution-list li { margin-bottom: 8px; }

.code-block {
  margin: 0;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #c7d6f6;
  background: #f4f8ff;
  color: #0f2340;
  font-family: "Consolas", "Menlo", monospace;
  font-size: 12px;
  line-height: 1.45;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.answer {
  margin-top: 10px;
  font-weight: 700;
  white-space: pre-wrap;
  background: #eef4ff;
  border-color: #c9dafd;
}

.note-box { margin-top: 10px; }

.anim-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin: 8px 0 10px;
}

.anim-small-btn {
  padding: 6px 10px;
  font-size: 14px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 13px;
  margin-top: 8px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.08);
}

.error {
  color: #b12020;
  font-weight: 700;
}

.small-muted {
  font-size: 13px;
  color: #536887;
}

@media (max-width: 1040px) {
  .layout,
  .preview-grid,
  .theory-grid {
    grid-template-columns: 1fr;
  }
}
