:root {
  color-scheme: dark;
  font-family: "Segoe UI Variable", "Inter", "Segoe UI", sans-serif;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  --night: #080f20;
  --panel: #101b32;
  --panel-deep: #0c172c;
  --line: #293b61;
  --text: #edf2ff;
  --muted: #a6b5d2;
  --blue: #75b8ff;
  --violet: #a990ff;
  --mint: #82dfbf;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(ellipse 580px 470px at 13% -9%, #243d8559, transparent 72%),
    radial-gradient(ellipse 540px 610px at 100% 21%, #6246af31, transparent 71%),
    radial-gradient(ellipse 570px 500px at 0% 76%, #155f9050, transparent 76%),
    var(--night);
}
button, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
em, i { font-style: normal; }
button:focus-visible, textarea:focus-visible { outline: 2px solid #a9c9ff; outline-offset: 3px; }
button, .cell { transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease; }
[hidden], .stop-button[hidden], .run-line[hidden], #lesson-teaching[hidden], .lesson-actions[hidden] { display: none !important; }

.site-header { position: relative; width: min(1320px, calc(100% - 64px)); min-height: 154px; margin: auto; padding-top: 31px; }
.site-title { max-width: calc(100% - 126px); font-size: clamp(31px, 4.2vw, 60px); font-weight: 680; line-height: 1.13; letter-spacing: -.047em; text-wrap: balance; }
.main-layout { width: min(1050px, calc(100% - 72px)); margin: 0 auto 110px; }
.editor-panel, .board-panel, .lesson-actions { width: min(760px, 100%); margin-inline: auto; }
.editor-panel h1, .board-panel h2 { margin: 0 0 18px; text-align: center; font-size: clamp(44px, 5.5vw, 66px); font-weight: 660; line-height: 1.1; letter-spacing: -.06em; }

.lesson-panel { margin: 0 0 58px; padding: 0 0 42px; border-bottom: 1px solid #3042669c; }
.lesson-meta { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin: 0 0 19px; color: var(--blue); font-size: 13px; font-weight: 670; letter-spacing: .06em; }
.text-button { padding: 7px 0; border: 0; background: transparent; color: var(--muted); font-size: 13px; font-weight: 550; text-decoration: underline; text-decoration-color: #7187b1; text-underline-offset: 4px; }
.text-button:hover { color: var(--text); }
.lesson-panel h2 { margin: 0 0 10px; font-size: clamp(30px, 3.3vw, 40px); font-weight: 660; letter-spacing: -.045em; }
.lesson-goal { max-width: 720px; margin: 0 0 27px; color: #c8d4ea; font-size: 17px; line-height: 1.6; }
.lesson-teaching { display: grid; grid-template-columns: minmax(0, .95fr) minmax(0, 1fr); gap: clamp(32px, 6vw, 72px); align-items: start; }
.lesson-label { display: block; margin: 0 0 12px; color: #8299c4; font-size: 11px; font-weight: 730; letter-spacing: .13em; text-transform: uppercase; }
.target-board { display: grid; grid-template-columns: repeat(20, minmax(0, 1fr)); width: 100%; max-width: 440px; aspect-ratio: 2 / 1; overflow: hidden; border: 1px solid #5d7296; border-radius: 14px; background: #e6edfa; box-shadow: 0 18px 38px #02091658, 0 0 27px #5c86dc27; }
.target-cell { min-width: 0; min-height: 0; }
.lesson-command, .lesson-example, .run-line { font-family: "Cascadia Code", Consolas, "Courier New", monospace; }
.lesson-command, .lesson-example { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.65; }
.lesson-command { color: #c0d5ff; font-weight: 700; }
.lesson-explanation { margin: 10px 0 24px; color: var(--muted); font-size: 14px; line-height: 1.65; }
.lesson-example { padding: 18px 19px; border: 1px solid #2d4068; border-radius: 14px; background: #0e1a32; color: #c4d2f4; box-shadow: inset 3px 0 0 #817af2; }
.lesson-notes .lesson-label:not(:first-child) { margin-top: 0; }
.lesson-stage { margin: 15px 0 0; color: #8db7ff; font-size: 13px; line-height: 1.5; }

.editor-wrap { display: flex; flex-direction: column; height: 410px; overflow: hidden; border: 1px solid #4e6594; border-radius: 24px; background: linear-gradient(155deg, #142442, #0d1930 55%, #111a33); box-shadow: 0 0 0 5px #5589e010, 0 24px 68px #0109169c, inset 0 1px 0 #89b0ff21; }
.editor-wrap:focus-within { border-color: #80a7f3; box-shadow: 0 0 0 5px #598af326, 0 24px 68px #0109169c, 0 0 34px #705bdb28; }
textarea { width: 100%; min-height: 0; flex: 1; resize: vertical; border: 0; outline: 0; padding: 24px 26px 12px; background: transparent; color: #e9f0ff; font-family: "Cascadia Code", Consolas, "Courier New", monospace; font-size: 16px; line-height: 1.63; tab-size: 4; caret-color: #9dbeff; }
textarea:focus-visible { outline: 0; }
textarea::selection { background: #6d68bf96; color: #fff; }
.editor-actions { display: flex; align-items: end; justify-content: space-between; gap: 12px; padding: 10px 12px 12px; }
.button { display: flex; align-items: center; justify-content: center; flex: none; border-radius: 14px; font-size: 14px; font-weight: 650; line-height: 1.2; }
.button-example { min-width: 148px; min-height: 60px; padding: 8px 20px; border: 1px solid #6486c7; background: #192c50; color: #dbeaff; }
.button-example:hover:not(:disabled) { border-color: #a2baff; background: #223961; box-shadow: 0 0 20px #6c8dee3b; transform: translateY(-1px); }
.run-actions { display: flex; align-items: end; gap: 10px; }
.button-run { min-width: 138px; min-height: 60px; gap: 9px; padding: 8px 15px; border: 1px solid #9a9bff; background: linear-gradient(120deg, #4167ca, #6c58bd); color: #fff; box-shadow: 0 0 23px #776df657, inset 0 1px 0 #ffffff4d; }
.button-run svg { width: 24px; height: 24px; }
.button-run span { font-size: 16px; }
.button-run:hover:not(:disabled) { border-color: #c1c9ff; box-shadow: 0 0 31px #8a75ff85; transform: translateY(-1px); }
.button-run:disabled { opacity: .55; }
.stop-button { min-height: 45px; padding: 7px 15px; border: 1px solid #ac607f; border-radius: 12px; background: #372139; color: #ffd6e4; font-size: 13px; }
.stop-button:hover { background: #4e2a44; }
.status { margin: 13px 4px 0; color: var(--mint); font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.status:not(.error) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.status.error { color: #ffabb9; }
.run-line { margin: 14px 3px 0; padding: 10px 13px; border-left: 3px solid #a18dff; border-radius: 0 10px 10px 0; background: #1b2546; color: #e8e4ff; font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }

.board-panel { margin-top: 66px; }
.board-panel h2 { margin-bottom: 22px; }
.board-shell { --axis: 0px; display: grid; grid-template-columns: var(--axis) minmax(0, 1fr); grid-template-rows: var(--axis) auto; width: 100%; transition: grid-template-columns .2s ease, grid-template-rows .2s ease; }
.board-shell.show-grid { --axis: 25px; }
.board-axis { color: #8da4d5; font-family: "Cascadia Code", Consolas, monospace; font-size: 10px; font-weight: 700; line-height: 1; opacity: 0; pointer-events: none; }
.board-shell.show-grid .board-axis { opacity: 1; }
.board-axis-x { display: grid; grid-column: 2; grid-row: 1; grid-template-columns: repeat(20, minmax(0, 1fr)); height: var(--axis); }
.board-axis-x span { display: grid; place-items: center; }
.board-axis-y { display: grid; grid-column: 1; grid-row: 2; grid-template-rows: repeat(10, minmax(0, 1fr)); width: var(--axis); }
.board-axis-y span { display: grid; place-items: center; }
.board { display: grid; grid-column: 2; grid-row: 2; grid-template-columns: repeat(20, minmax(0, 1fr)); width: 100%; aspect-ratio: 2 / 1; overflow: hidden; border: 1px solid #7590ba; border-radius: 18px; background: #e6edfa; box-shadow: 0 0 0 6px #5278cf1c, 0 22px 60px #030919a8, 0 0 45px #5f74e52b; }
.cell { min-width: 0; min-height: 0; }
.show-grid .cell { box-shadow: inset 0 0 0 .75px #263a6091; }
.grid-toggle { display: flex; align-items: center; justify-content: center; gap: 9px; min-height: 40px; margin: 24px 0 0 auto; padding: 9px 14px; border: 1px solid #405782; border-radius: 11px; background: #14223d; color: #b9cff4; font-size: 13px; font-weight: 620; }
.grid-toggle::before { content: ""; width: 14px; height: 14px; flex: none; border: 1px solid currentColor; border-radius: 2px; background: linear-gradient(90deg, transparent 46%, currentColor 47% 53%, transparent 54%), linear-gradient(0deg, transparent 46%, currentColor 47% 53%, transparent 54%); opacity: .78; }
.grid-toggle:hover, .grid-toggle[aria-pressed="true"] { border-color: #8c8be7; color: #e7e2ff; box-shadow: 0 0 18px #716cf043; }

.lesson-actions { margin-top: 36px; }
.lesson-feedback { min-height: 24px; margin: 0 0 16px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.lesson-feedback.success { color: var(--mint); }
.lesson-feedback.error { color: #ffabb9; }
.lesson-buttons { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; }
.quiet-button { min-height: 44px; padding: 10px 17px; border: 1px solid #425b87; border-radius: 11px; background: #16243f; color: #dbe7ff; font-size: 13px; font-weight: 630; }
.quiet-button:hover:not(:disabled) { border-color: #849fe1; background: #203356; box-shadow: 0 0 17px #557bd536; }
.quiet-button:disabled { opacity: .42; }
.primary-button { border-color: #766fe2; background: #2e3667; color: #eeeaff; }

.book-button { position: absolute; top: 14px; right: 12px; display: flex; align-items: stretch; width: 100px; height: 130px; padding: 0; border: 0; background: transparent; transform: rotate(5deg); z-index: 2; }
.book-button:hover { transform: rotate(2deg) translateY(-4px); }
.book-coil { position: absolute; top: 10px; bottom: 10px; left: 0; z-index: 2; width: 18px; border-radius: 7px; background: repeating-linear-gradient(to bottom, transparent 0 10px, #8a95bf 10px 13px, #303c60 13px 15px, transparent 15px 23px); }
.book-cover { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; width: 100%; margin-left: 11px; border: 1px solid #6963be; border-radius: 4px 12px 12px 4px; background: linear-gradient(135deg, #18284d, #25315b 58%, #151d3d); box-shadow: 3px 6px 0 #c8c7e1, 7px 11px 22px #01071899, 0 0 28px #7568ec47; color: #eef0ff; }
.book-mark { color: #a99bff; font-size: 28px; text-shadow: 0 0 16px #a58aff; }
.book-word { font-size: 13px; font-weight: 700; letter-spacing: -.02em; }
.theory-dialog { width: min(690px, calc(100vw - 30px)); max-width: none; max-height: min(850px, calc(100dvh - 28px)); padding: 0; overflow: auto; border: 1px solid #8586af; border-radius: 8px; background: transparent; box-shadow: 0 30px 90px #000b, 0 0 42px #817cf34a; }
.theory-dialog::backdrop { background: #030714d9; backdrop-filter: blur(5px); }
.notebook-page { position: relative; min-height: 760px; padding: 50px 50px 68px 110px; color: #30374b; border: 1px solid #e5ddbd; background: linear-gradient(to right, transparent 0 86px, #d6a399 86px 87px, transparent 87px), repeating-linear-gradient(to bottom, #faf5df 0 32px, #cdd0bb 33px, #faf5df 34px); box-shadow: inset 12px 0 20px #8a7a5830; }
.notebook-page::before { content: ""; position: absolute; top: 38px; bottom: 38px; left: 31px; width: 14px; background: radial-gradient(circle, #77798a 0 6px, transparent 7px) center top / 14px 126px repeat-y; }
.notebook-page h2 { margin: 0 0 28px; font-size: 34px; font-weight: 690; line-height: 1.4; letter-spacing: -.04em; }
.notebook-lead { margin: 0 0 28px; font-size: 17px; line-height: 34px; }
.dialog-close { position: absolute; top: 17px; right: 18px; display: grid; place-items: center; width: 42px; height: 42px; padding: 0; border: 0; border-radius: 50%; background: #ddd6bb; color: #293146; font-size: 31px; line-height: 1; }
.dialog-close:hover { background: #d0c7ab; }
.theory-list { margin: 0; }
.theory-list > div { margin: 0 0 17px; }
.theory-list dt { font-size: 15px; font-weight: 730; line-height: 34px; overflow-wrap: anywhere; }
.theory-list dd { margin: 0; font-size: 15px; line-height: 34px; }
.theory-list code, .theory-colors code { font-family: "Cascadia Code", Consolas, monospace; }
.theory-colors { font-size: 15px; line-height: 34px; }

@media (max-width: 1250px) {
  .book-button { top: 26px; right: 8px; width: 80px; height: 105px; }
  .book-coil { width: 14px; }
  .book-cover { margin-left: 7px; }
  .book-mark { font-size: 25px; }
  .book-word { font-size: 11px; }
}
@media (max-width: 850px) {
  .site-header { width: calc(100% - 32px); min-height: 122px; padding-top: 24px; }
  .site-title { max-width: calc(100% - 64px); font-size: clamp(28px, 5.7vw, 47px); }
  .main-layout { width: min(760px, calc(100% - 40px)); margin-bottom: 76px; }
  .lesson-panel { margin-bottom: 48px; }
  .lesson-teaching { gap: 28px; }
  .book-button { right: 0; }
}
@media (max-width: 680px) {
  .site-header { width: calc(100% - 28px); min-height: 124px; padding-top: 21px; }
  .site-title { max-width: calc(100% - 55px); font-size: clamp(25px, 6.2vw, 34px); line-height: 1.18; }
  .book-button { top: 20px; width: 42px; height: 51px; transform: none; }
  .book-button:hover { transform: none; }
  .book-coil { top: 5px; bottom: 5px; width: 7px; background: repeating-linear-gradient(to bottom, #8993b9 0 2px, transparent 2px 7px); }
  .book-cover { gap: 0; margin-left: 5px; border-radius: 2px 5px 5px 2px; box-shadow: 1px 2px 0 #c8c7e1, 0 0 14px #746dee5c; }
  .book-mark { font-size: 18px; }
  .book-word { display: none; }
  .main-layout { width: calc(100% - 28px); margin-bottom: 60px; }
  .lesson-panel { margin-bottom: 38px; padding-bottom: 34px; }
  .lesson-meta { margin-bottom: 14px; font-size: 11px; }
  .lesson-panel h2 { font-size: 28px; }
  .lesson-goal { margin-bottom: 22px; font-size: 15px; }
  .lesson-teaching { display: block; }
  .lesson-visual { margin-bottom: 25px; }
  .target-board { max-width: 390px; }
  .lesson-example, .lesson-command { font-size: 12px; }
  .editor-panel h1, .board-panel h2 { margin-bottom: 13px; font-size: 45px; }
  .editor-wrap { height: 380px; border-radius: 19px; }
  textarea { padding: 18px 17px 8px; font-size: 14px; }
  .editor-actions { padding: 8px; }
  .button-example { min-width: 110px; min-height: 52px; padding: 7px 12px; font-size: 12px; }
  .button-run { min-width: 103px; min-height: 52px; gap: 6px; padding: 7px 10px; }
  .button-run svg { width: 20px; height: 20px; }
  .button-run span { font-size: 14px; }
  .run-actions { gap: 6px; }
  .stop-button { min-height: 40px; padding: 7px 9px; font-size: 11px; }
  .board-panel { margin-top: 49px; }
  .board { border-radius: 12px; }
  .board-shell.show-grid { --axis: 18px; }
  .board-axis { font-size: 8px; }
  .grid-toggle { min-height: 38px; margin-top: 19px; font-size: 12px; }
  .lesson-buttons { justify-content: center; }
  .quiet-button { flex: 1 1 auto; min-width: 82px; padding: 9px 11px; }
  .notebook-page { min-height: 700px; padding: 50px 22px 44px 64px; background: linear-gradient(to right, transparent 0 47px, #d6a399 47px 48px, transparent 48px), repeating-linear-gradient(to bottom, #faf5df 0 32px, #cdd0bb 33px, #faf5df 34px); }
  .notebook-page::before { left: 15px; }
  .notebook-page h2 { font-size: 28px; }
  .theory-list dt { font-size: 13px; }
  .theory-list dd, .theory-colors, .notebook-lead { font-size: 13px; }
}
@media (max-width: 390px) {
  .site-title { font-size: 24px; }
  .editor-wrap { height: 355px; }
  textarea { font-size: 13px; }
  .button-example { min-width: 98px; }
  .button-run { min-width: 90px; }
  .grid-toggle { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  button, .cell, .board-shell { transition: none; }
}
