:root {
  --bg: #edf6ff;
  --card: rgba(255, 255, 255, 0.96);
  --text: #172433;
  --muted: #607083;
  --accent: #1d6fb8;
  --accent-dark: #15578f;
  --line: #c7def2;
  --soft: #f4f8fc;
  --code-bg: #111827;
  --code-bg-2: #0b1220;
  --code-text: #f8fafc;
  --code-muted: #aab7c7;
  --active-code: #d9f7df;
  --active-code-border: #5fc878;
  --shadow: 0 12px 28px rgba(23, 55, 87, 0.11);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}
body {
  font-family: Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at 20% 0%, rgba(29, 111, 184, 0.14), transparent 32%),
    linear-gradient(180deg, #f7fbff 0%, var(--bg) 100%);
  color: var(--text);
}

.app-shell {
  width: min(1420px, 100%);
  height: 100dvh;
  margin: 0 auto;
  padding: 8px;
  overflow: hidden;
}

.card {
  background: var(--card);
  border: 1px solid rgba(199, 222, 242, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.workspace {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(330px, .95fr);
  gap: 10px;
  overflow: hidden;
}

.main-column,
.side-panel {
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.main-column {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

.side-panel {
  display: block;
}

.top-spoiler {
  padding: 0;
  overflow: hidden;
}

.top-spoiler > summary,
.status-spoiler > summary {
  cursor: pointer;
  list-style: none;
  font-weight: 800;
  color: var(--accent-dark);
  user-select: none;
}

.top-spoiler > summary::-webkit-details-marker,
.status-spoiler > summary::-webkit-details-marker { display: none; }

.top-spoiler > summary,
.status-spoiler > summary {
  padding: 8px 12px;
  font-size: 14px;
  background: #eef7ff;
}

.top-spoiler > summary::before,
.status-spoiler > summary::before { content: '▸ '; }
.top-spoiler[open] > summary::before,
.status-spoiler[open] > summary::before { content: '▾ '; }

.hero-content {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px 12px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent);
}

h1 {
  margin: 0;
  font-size: clamp(20px, 2.4vw, 30px);
  line-height: 1.08;
}

.lead {
  max-width: 820px;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.38;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.badges span,
.tiny-badge {
  padding: 5px 8px;
  border-radius: 999px;
  background: #e8f4ff;
  color: var(--accent-dark);
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}

.canvas-card {
  min-height: 0;
  height: 100%;
  padding: 10px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
  overflow: hidden;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  min-height: 0;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 15px;
  background: #fff;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  touch-action: manipulation;
}

.canvas-status {
  position: absolute;
  top: 8px;
  right: 8px;
  max-width: min(430px, calc(100% - 16px));
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .86);
  border: 1px solid rgba(199, 222, 242, .95);
  color: #37516b;
  font-size: 12px;
  line-height: 1.2;
  text-align: right;
  backdrop-filter: blur(6px);
  z-index: 4;
  pointer-events: none;
}

.canvas-step {
  position: absolute;
  top: 50%;
  z-index: 5;
  width: 50px;
  height: 62px;
  min-height: 0;
  padding: 0;
  transform: translateY(-50%);
  border-radius: 17px;
  background: rgba(17, 31, 45, .50);
  color: #fff;
  font-size: 44px;
  line-height: 1;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .14);
  -webkit-tap-highlight-color: transparent;
}

.canvas-step-left { left: 8px; }
.canvas-step-right { right: 8px; }
.canvas-step:hover { background: rgba(29, 111, 184, .78); }
.canvas-step:active { transform: translateY(-50%); }

.bottom-controls {
  display: grid;
  grid-template-columns: auto auto auto minmax(160px, 1fr);
  gap: 7px;
  align-items: center;
}

button {
  appearance: none;
  border: 0;
  border-radius: 11px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: #596b7f;
  cursor: pointer;
  min-height: 34px;
}

button.primary { background: var(--accent); }
button:hover { filter: brightness(.97); }
button:active { transform: none; }

.speed-mini {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #f7fbff;
}

input[type="range"] { width: 100%; }

.code-card {
  height: 100%;
  min-height: 0;
  padding: 10px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
  overflow: hidden;
}

.section-head {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
}

.code-head { margin: 0; }
h2 { margin: 0; font-size: 17px; }

.status-spoiler {
  padding: 0;
  overflow: hidden;
  border-radius: 13px;
  box-shadow: none;
}

.status-spoiler > summary {
  padding: 7px 10px;
  font-size: 13px;
}

.status-spoiler pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #132131;
  background: var(--soft);
  border-top: 1px solid #d8e7f4;
  padding: 9px;
  max-height: 140px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.code-list {
  min-height: 0;
  display: grid;
  grid-auto-rows: max-content;
  gap: 8px;
  overflow: auto;
  padding: 2px 4px 2px 2px;
  overscroll-behavior: contain;
}

.code-block {
  scroll-margin-top: 2px;
  border: 1px solid #273548;
  border-radius: 14px;
  background: var(--code-bg);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}

.code-block:hover { border-color: #4a6a90; }

.code-block.active {
  border-color: var(--active-code-border);
  background: var(--active-code);
  box-shadow: 0 0 0 3px rgba(95, 200, 120, .25);
}

.code-block-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  background: #0b1220;
  border-bottom: 1px solid #273548;
}

.code-block.active .code-block-head {
  background: #c7f1d0;
  border-bottom-color: #94daa4;
}

.code-block-title {
  font-weight: 800;
  font-size: 13px;
  color: #eef6ff;
}

.code-block-step {
  font-size: 12px;
  color: #b7c7d8;
  font-weight: 700;
  white-space: nowrap;
}

.code-block.active .code-block-title,
.code-block.active .code-block-step { color: #104621; }

pre,
.code-block pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 10px;
  color: var(--code-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.45;
  max-height: none;
  min-height: 0;
  overflow: visible;
}

.code-block.active pre { color: #0b2414; }

.code-explain {
  border-top: 1px solid rgba(95, 200, 120, .55);
  padding: 9px 10px 10px;
  background: rgba(255, 255, 255, .45);
  color: #173d25;
  font-size: 14px;
  line-height: 1.45;
}

.code-explain strong {
  display: block;
  margin-bottom: 3px;
}

.tok-comment { color: #78a5d6; }
.tok-string { color: #f9d371; }
.tok-call { color: #93c5fd; }
.tok-keyword { color: #c4b5fd; }
.tok-number { color: #fdba74; }
.code-block.active .tok-comment { color: #2e7350; }
.code-block.active .tok-string { color: #8a5d00; }
.code-block.active .tok-call { color: #145dc3; }
.code-block.active .tok-keyword { color: #6540b8; }
.code-block.active .tok-number { color: #9a3e0f; }

.footer-note {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1100px) {
  .app-shell { padding: 6px; }
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, auto) minmax(0, 1fr);
    gap: 8px;
  }
  .main-column {
    height: auto;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .canvas-card {
    height: min(58dvh, 560px);
    min-height: 390px;
  }
  .side-panel {
    min-height: 0;
    height: 100%;
  }
}

@media (max-width: 860px) {
  .canvas-card,
  .code-card { padding: 8px; }
  .bottom-controls { grid-template-columns: 1fr 1fr 1fr; }
  .speed-mini { grid-column: 1 / -1; }
  .hero-content { grid-template-columns: 1fr; }
  .badges { justify-content: flex-start; }
}

@media (max-width: 560px) {
  .app-shell { padding: 5px; }
  .workspace { gap: 7px; }
  .main-column { gap: 6px; }
  .top-spoiler > summary { padding: 7px 10px; }
  h1 { font-size: 21px; }
  .lead { font-size: 13px; }
  .canvas-card {
    height: 57dvh;
    min-height: 360px;
    padding: 7px;
  }
  .canvas-wrap { border-radius: 13px; }
  .canvas-status {
    top: 6px;
    right: 6px;
    max-width: calc(100% - 12px);
    font-size: 10.5px;
    padding: 4px 6px;
  }
  .canvas-step {
    width: 42px;
    height: 54px;
    border-radius: 14px;
    font-size: 38px;
  }
  .canvas-step-left { left: 5px; }
  .canvas-step-right { right: 5px; }
  .bottom-controls {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
  }
  button {
    min-height: 34px;
    padding: 6px 6px;
    font-size: 12px;
    border-radius: 10px;
  }
  .speed-mini {
    min-height: 32px;
    padding: 5px 8px;
    font-size: 12px;
  }
  .code-card {
    padding: 8px;
    gap: 6px;
  }
  .code-head {
    align-items: center;
  }
  h2 { font-size: 16px; }
  .tiny-badge { font-size: 11px; padding: 5px 7px; }
  .status-spoiler > summary {
    padding: 6px 9px;
    font-size: 12px;
  }
  .code-list { gap: 7px; }
  .code-block-head { padding: 7px 9px; }
  pre,
  .code-block pre { font-size: 12px; padding: 9px; }
  .code-explain { font-size: 13px; padding: 8px 9px; }
}
