:root {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #192832;
  background: #f4f7f8;
  --surface: #ffffff;
  --surface-alt: #f7fafb;
  --muted: #52636f;
  --line: #dce5e7;
  --accent: #12685f;
  --accent-dark: #0e534c;
  --active: #e0f3ed;
  --active-border: #92c8b8;
  --active-ink: #114c43;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }

main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 40px 30px 54px;
}

/* Header */
.welcome-cover {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(340px, 2fr);
  overflow: hidden;
  border: 1px solid #34475e;
  border-top: 3px solid #67d9bf;
  background: #142337;
}

.welcome-cover img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: cover;
}

.campaign-intro {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(22px, 3.5vw, 44px);
  color: #edf6f6;
}

.campaign-intro h1 {
  margin: 0;
  color: #91f4d7;
  font: 800 clamp(29px, 4.2vw, 53px)/1.1 ui-monospace, "SFMono-Regular", Consolas, monospace;
  letter-spacing: -0.06em;
}

.campaign-intro p {
  margin: 15px 0 0;
  max-width: 56ch;
  font-size: clamp(15px, 1.55vw, 17px);
  line-height: 1.52;
}

.campaign-start {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-top: 21px;
  padding: 11px 15px;
  color: #10252e;
  background: #91f4d7;
  box-shadow: 3px 3px 0 #357867;
  font-weight: 750;
  text-decoration: none;
}

.campaign-start:hover {
  background: #c4ffeb;
}

.campaign-start:focus-visible {
  outline: 2px solid #f7cd82;
  outline-offset: 5px;
}

@media (max-width: 760px) {
  .welcome-cover { grid-template-columns: 1fr; }
  .welcome-cover img { height: auto; max-height: 330px; }
}

/* Kyu belt strip */
.kyu-bar {
  margin: 22px 0 16px;
}

.kyu-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

button, select { cursor: pointer; }

button, select, input {
  min-height: 38px;
  border: 1px solid #ccd8dc;
  background-color: #fff;
  border-radius: 8px;
}

button {
  padding: 7px 12px;
  font-weight: 600;
  transition: border-color 0.14s ease, background-color 0.14s ease, color 0.14s ease;
}

button:hover:not(:disabled), select:hover { border-color: #849b9f; }
button:disabled { cursor: default; opacity: 0.45; }
:focus-visible { outline: 3px solid #238278; outline-offset: 2px; }

.kyu-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  color: #2f434d;
  padding: 7px 12px;
}

.kyu-btn .cnt {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.kyu-btn[aria-pressed="true"] {
  background: var(--active);
  color: var(--active-ink);
  border-color: var(--active-border);
  box-shadow: 0 1px 3px rgba(18, 104, 95, 0.12);
}

.kyu-btn[aria-pressed="true"] .cnt {
  color: var(--active-ink);
}

.kyu-hint {
  margin: 8px 0 0;
  min-height: 20px;
  font-size: 13px;
  color: var(--muted);
}

/* Main Panel */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(25, 40, 50, 0.03);
}

/* Topic chips */
.topics-box {
  padding: 15px 20px 14px;
  border-bottom: 1px solid var(--line);
  background: #fafcfd;
}

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

.topics-label {
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #465b66;
}

.topic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.topic-chip {
  min-height: 31px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 550;
  color: #324853;
  background: #fff;
  border: 1px solid #d4e0e3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.topic-chip .cnt {
  font-size: 11.5px;
  color: #6b7f8a;
  font-variant-numeric: tabular-nums;
}

.topic-chip[aria-pressed="false"]:hover {
  border-color: #7ea3a6;
  background: #f2f8f7;
}

.topic-chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.topic-chip[aria-pressed="true"]:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.topic-chip[aria-pressed="true"] .cnt {
  color: #d6f3ee;
}

.topic-chip.zero {
  opacity: 0.45;
}

/* Filters row */
.filters {
  display: grid;
  grid-template-columns: 2.2fr 1.5fr 0.9fr 0.8fr;
  gap: 12px;
  padding: 16px 20px 14px;
}

.filter {
  display: grid;
  align-content: start;
  gap: 5px;
  color: #384c56;
  font-size: 12.5px;
  font-weight: 650;
  min-width: 0;
}

input, select {
  min-width: 0;
  width: 100%;
  padding: 7px 10px;
  font-size: 14px;
  font-weight: 450;
}

input::placeholder { color: #718490; }

/* Result bar */
.result-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 20px;
  padding: 0 20px 14px;
  font-size: 13px;
  color: var(--muted);
}

.result-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.result-bar strong {
  color: #213640;
  font-variant-numeric: tabular-nums;
}

.plain {
  border: 0;
  padding: 4px 2px;
  min-height: 28px;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
}

.plain:hover { text-decoration: underline; }
.small-link { font-size: 12.5px; }

.sort {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.sort select {
  min-height: 34px;
  width: auto;
  font-size: 13px;
}

/* Table */
.table-wrap { width: 100%; overflow-x: auto; }

table {
  table-layout: fixed;
  border-collapse: collapse;
  width: 100%;
}

.id-col { width: 94px; }
.kyu-col { width: 96px; }
.title-col { width: auto; }
.topic-col { width: 22%; }
.solved-col { width: 92px; }

thead { background: #edf3f4; }

th, td {
  padding: 12px 13px;
  text-align: left;
  border-top: 1px solid var(--line);
  vertical-align: top;
}

th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }

th {
  color: #405661;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

td {
  line-height: 1.42;
  font-size: 14px;
}

tbody tr {
  cursor: pointer;
  transition: background-color 0.1s ease;
}

tbody tr:hover { background: #f4faf8; }

td.cell-id {
  color: #536b76;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding-top: 14px;
}

.difficulty-battery {
  --charge-color: #75b49b;
  --battery-outline: #71878b;
  --battery-track: #f1f6f5;
  position: relative;
  display: inline-block;
  flex: none;
  width: 42px;
  height: 20px;
  margin-right: 5px;
  vertical-align: middle;
  border: 1.5px solid var(--battery-outline);
  border-radius: 7px;
  background: var(--battery-track);
  forced-color-adjust: none;
}

.difficulty-battery::before {
  content: "";
  position: absolute;
  inset: 2px auto 2px 2px;
  width: calc((100% - 4px) * var(--charge) / 8);
  border-radius: 4px;
  background: var(--charge-color);
}

.difficulty-battery::after {
  content: "";
  position: absolute;
  top: 50%;
  left: calc(100% + 2px);
  width: 3px;
  height: 7px;
  transform: translateY(-50%);
  border-radius: 0 4px 4px 0;
  background: var(--battery-outline);
}

.difficulty-battery:is([data-rank="4"], [data-rank="5"]) {
  --charge-color: #d8aa5e;
}

.difficulty-battery:is([data-rank="6"], [data-rank="7"], [data-rank="8"]) {
  --charge-color: #d88f88;
}

@media (forced-colors: active) {
  .difficulty-battery[data-rank] {
    --charge-color: CanvasText;
    --battery-outline: CanvasText;
    --battery-track: Canvas;
  }
}

/* Task title cell */
.title-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.task-link {
  color: #142c36;
  text-decoration: none;
  font-weight: 680;
  font-size: 14.5px;
  overflow-wrap: anywhere;
}

.task-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.kind-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 650;
  padding: 1px 6px;
  border-radius: 5px;
  background: #eef3f5;
  color: #4b616c;
  white-space: nowrap;
}

.kind-tag[data-kind="Мини-проект"] {
  background: #eaf4f2;
  color: #165e54;
}

.kind-tag[data-kind="Проект"] {
  background: #edeaf8;
  color: #493884;
}

.kind-tag[data-kind="Закрепление"] {
  background: #fff0d6;
  color: #8a5410;
  border: 1px solid #f0d49a;
}

.new-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 5px;
  background: #e8f7e9;
  color: #1d6b2f;
  border: 1px solid #b5e0ba;
  white-space: nowrap;
}

.funny-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 650;
  padding: 1px 6px;
  border-radius: 5px;
  background: #fff4e0;
  color: #8a5410;
  white-space: nowrap;
}

/* View switcher: all / core / new / reinforcement */
.view-bar { margin: 18px 0 0; }
.view-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.view-btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13.5px; color: #2f434d; padding: 7px 13px;
}
.view-btn .cnt { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.view-btn[aria-pressed="true"] {
  background: #192832; color: #fff; border-color: #192832;
}
.view-btn[aria-pressed="true"] .cnt { color: #cfe3e8; }

.basedon-card {
  background: #fffaf0;
  border: 1px solid #f0d49a;
  border-radius: 10px;
  padding: 13px 15px;
}
.basedon-text { margin: 0 0 9px; font-size: 14px; color: #4a380f; }
.basedon-btn { min-height: 34px; font-size: 13px; }

.task-preview {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.task-entry {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.task-entry-text { min-width: 0; }

.task-thumbnail {
  display: block;
  flex: none;
  width: clamp(60px, 7vw, 88px);
  height: auto;
  border-radius: 4px;
}

.mobile-meta { display: none; }

/* Topic tags inside table */
.row-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.mini-topic {
  min-height: 0;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 550;
  background: #f0f5f6;
  border: 1px solid #dde7ea;
  color: #364e59;
}

.mini-topic:hover {
  background: var(--active);
  border-color: var(--active-border);
  color: var(--active-ink);
}

.solved-cell input {
  width: 24px;
  height: 24px;
  min-height: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.empty {
  padding: 36px 20px;
  margin: 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 13px 20px;
  color: var(--muted);
  font-size: 13px;
}

.pagination span { font-variant-numeric: tabular-nums; }

/* Modal Dialog */
dialog {
  width: min(760px, calc(100% - 28px));
  max-height: min(88dvh, 860px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: inherit;
  box-shadow: 0 22px 70px rgba(20, 43, 51, 0.32);
}

dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog::backdrop {
  background: rgba(22, 45, 55, 0.58);
  backdrop-filter: blur(2px);
}

.task-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--line);
}

.dialog-head-main { min-width: 0; }

.dialog-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
  font-size: 12.5px;
  color: var(--muted);
}

.dialog-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: #536b76;
  background: #f0f4f5;
  padding: 2px 7px;
  border-radius: 5px;
}

.task-header h2 {
  margin: 0;
  font-size: clamp(20px, 3vw, 26px);
  line-height: 1.22;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.close {
  width: 36px;
  min-height: 36px;
  font-size: 22px;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}

.task-content {
  overflow-y: auto;
  min-height: 0;
  padding: 20px 24px 12px;
  line-height: 1.56;
}

.dialog-section { margin-bottom: 18px; }

.task-lesson {
  display: flex;
  align-items: flex-start;
  gap: 18px;
}

.task-lesson > section { flex: 1; min-width: 0; }

.task-cover-button {
  position: relative;
  display: block;
  flex: none;
  width: clamp(128px, 28%, 200px);
  padding: 0;
  border: 0;
  border-radius: 5px;
  cursor: zoom-in;
}

.task-cover {
  display: block;
  width: 100%;
  height: auto;
  border-radius: inherit;
}

.task-cover-button span {
  position: absolute;
  inset: auto 0 0;
  padding: 4px 6px;
  border-radius: 0 0 5px 5px;
  background: rgba(16, 27, 36, 0.88);
  color: #fff;
  font-size: 12px;
}

.task-cover-button:hover span,
.task-cover-button:focus-visible span {
  background: #101b24;
}

.cover-dialog {
  width: min(calc(100% - 24px), calc(94dvh - 66px), 1100px);
  max-height: 94dvh;
  background: #fbf4e5;
}

.cover-dialog::backdrop {
  background: rgba(14, 20, 27, 0.72);
}

.cover-dialog-header {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
}

.cover-dialog-header h2 {
  margin: 0;
  font-size: clamp(14px, 2.5vw, 19px);
  overflow-wrap: anywhere;
}

.cover-dialog img {
  display: block;
  width: 100%;
  height: auto;
}

.task-content h3,
.solution-card summary {
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #465d69;
}

.task-content h3 { margin: 0 0 7px; }

.dialog-desc {
  margin: 0;
  font-size: 15px;
  color: #1a2d37;
}

/* Terminal */
.io-terminal {
  border: 1px solid #253946;
  border-radius: 10px;
  background: #101b24;
  color: #e7f0f3;
}

.terminal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 14px;
  border-radius: 9px 9px 0 0;
  background: #1c2e3b;
  color: #c2d5df;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.terminal-lights {
  width: 7px;
  height: 7px;
  margin-right: 22px;
  border-radius: 50%;
  background: #f28880;
  box-shadow: 11px 0 #ebc47b, 22px 0 #7ec8a8;
}

.io-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.io-card { padding: 13px 15px; }

.io-out { border-left: 1px solid #304350; }

.io-terminal h3 {
  text-transform: none;
  letter-spacing: normal;
  color: #9fd8f4;
}

.io-terminal .io-out h3 { color: #8ee0bd; }

.io-description {
  margin: 0;
  font-size: 14px;
  color: #d4e2e9;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.io-example {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 7px;
  background: #1c2e3b;
  color: #f0f7fa;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.io-example code { font: inherit; }

.solution-card {
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.solution-card summary {
  padding: 11px 15px;
  border-radius: 9px;
  cursor: pointer;
}

.solution-card summary:hover {
  background: #eef5f5;
}

.solution-content {
  padding: 0 15px 13px;
}

.solution-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin-bottom: 10px;
}

.demo-caption a {
  color: var(--accent);
  font-size: 14px;
  font-weight: 650;
}

.solution-actions code {
  padding: 3px 7px;
  border-radius: 5px;
  background: #f0f4f5;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.solution-run-input { margin-bottom: 12px; }
.solution-run-input p { margin: 0 0 6px; }
.solution-run-input pre { white-space: pre-wrap; overflow-wrap: anywhere; }

.solution-code {
  max-height: 24rem;
  overflow: auto;
  margin: 0;
  padding: 14px 16px;
  border: 1px solid #333c4e;
  border-radius: 8px;
  background: #181d29;
  color: #e4e9f2;
  font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  tab-size: 4;
}

.solution-code code { font: inherit; }

.solution-code .token.comment { color: #9aa6bd; }
.solution-code .token.keyword { color: #d8acff; }
.solution-code .token.string { color: #b9df91; }
.solution-code .token:is(.number, .boolean, .format-spec) { color: #ffc58a; }
.solution-code .token:is(.builtin, .function, .annotation, .class-name) { color: #8ed1ff; }
.solution-code .token.operator { color: #8bdfdb; }
.solution-code .token.punctuation { color: #b8c5da; }

.console-demo { margin: 0 0 14px; }

.demo-caption {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px 12px;
  margin-bottom: 7px;
}

.demo-caption h3 { margin: 0; }

.console-demo img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 7px;
}

.dialog-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.task-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid var(--line);
  background: #fbfdfd;
}

.nav-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dialog-pos {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.primary:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

/* Responsive */
@media (max-width: 980px) {
  main { padding: 28px 18px 40px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .topic-col { width: 24%; }
}

@media (max-width: 720px) {
  .filters { grid-template-columns: 1fr; }
  .id-col, .topic-col,
  th:nth-child(1), td:nth-child(1),
  th:nth-child(4), td:nth-child(4) {
    display: none;
  }
  .kyu-col { width: 90px; }
  .difficulty-heading { padding-inline: 10px; letter-spacing: 0; }
  .title-col { width: auto; }
  .mobile-meta {
    display: block;
    margin: 5px 0 0;
    font-size: 12px;
    color: var(--muted);
  }
  .io-grid { grid-template-columns: 1fr; }
  .io-out { border-left: 0; border-top: 1px solid #304350; }
  .task-footer { justify-content: center; }
}

@media (max-width: 460px) {
  .task-lesson { flex-direction: column; }
  .task-cover-button { width: min(100%, 190px); }
  .task-entry { gap: 8px; }
}
