/* ============================================================
   Темы (светлая/тёмная, выбор пользователя; по умолчанию — системная),
   иконки, и HUD десктопа (>=1024px): плавающие окна «Карта», «Паймон», «Песочница».
   Подключается ПОСЛЕ generic_styles.css (там светлая тема страницы по умолчанию).
   Тему выставляет theme.js: <html data-theme="light|dark">.
   ============================================================ */

/* ---------- токены ---------- */
:root {                                   /* светлая */
    color-scheme: light;
    --h-bg1: #faf6e9; --h-bg2: #efe6cc;
    --h-glow1: rgba(199, 177, 131, 0.30); --h-glow2: rgba(255, 214, 120, 0.22);
    --h-panel: rgba(255, 253, 246, 0.92); --h-panel-solid: #fffdf6;
    --h-frame-a: #fffdf6; --h-frame-b: #f6efd9;
    --h-pill-a: #fffdf6; --h-pill-b: #f1e7c9;
    --h-edge: rgba(176, 146, 80, 0.60);
    --h-gold: #8a6718;                    /* золото для ТЕКСТА (на светлом — темнее) */
    --h-gold-fill: #c7b183;
    --h-text: #2f3347; --h-soft: #646b84;
    --h-hover: rgba(0, 0, 0, 0.06); --h-btn: rgba(0, 0, 0, 0.07); --h-btn-h: rgba(0, 0, 0, 0.13);
    --h-field: rgba(255, 255, 255, 0.9); --h-line: rgba(0, 0, 0, 0.11);
    --h-shadow: 0 10px 34px rgba(90, 65, 15, 0.28);
    --h-card: rgba(255, 255, 255, 0.72);
    --h-inline-code-bg: #f1ede0; --h-inline-code: #7a4f00;
    --h-link: #2f5fb3; --h-link-v: #7a4fb0;
}
html[data-theme="dark"] {                 /* тёмная */
    color-scheme: dark;
    --h-bg1: #0d1226; --h-bg2: #1d2447;
    --h-glow1: rgba(227, 201, 139, 0.16); --h-glow2: rgba(100, 130, 235, 0.18);
    --h-panel: rgba(20, 27, 52, 0.84); --h-panel-solid: #161d3a;
    --h-frame-a: rgba(30, 38, 72, 0.97); --h-frame-b: rgba(18, 24, 48, 0.97);
    --h-pill-a: rgba(40, 50, 92, 0.97); --h-pill-b: rgba(22, 29, 58, 0.97);
    --h-edge: rgba(227, 201, 139, 0.45);
    --h-gold: #e3c98b; --h-gold-fill: #e3c98b;
    --h-text: #e6e8f2; --h-soft: #aab2cc;
    --h-hover: rgba(255, 255, 255, 0.08); --h-btn: rgba(255, 255, 255, 0.08); --h-btn-h: rgba(255, 255, 255, 0.18);
    --h-field: rgba(255, 255, 255, 0.07); --h-line: rgba(255, 255, 255, 0.11);
    --h-shadow: 0 14px 44px rgba(0, 0, 0, 0.55);
    --h-card: rgba(255, 255, 255, 0.045);
    --h-inline-code-bg: rgba(255, 255, 255, 0.10); --h-inline-code: #f3dfaa;
    --h-link: #9ec5ff; --h-link-v: #c9a8ff;
}

/* ---------- фон страницы (обе темы, все ширины) ---------- */
body {
    background:
        radial-gradient(1100px 560px at 12% -8%, var(--h-glow1), transparent 62%),
        radial-gradient(900px 700px at 100% 100%, var(--h-glow2), transparent 60%),
        linear-gradient(160deg, var(--h-bg1) 0%, var(--h-bg2) 100%);
    background-attachment: fixed;
    color: var(--h-text);
}

/* ---------- тёмная тема: страница и компоненты (и на телефоне) ---------- */
html[data-theme="dark"] .slide { background: var(--h-panel); border-color: var(--h-edge); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45); }
html[data-theme="dark"] :is(p, li) { color: var(--h-text); }
html[data-theme="dark"] :is(h2, h3, .main-title, .section-title) { color: var(--h-gold); text-shadow: 0 0 18px rgba(227, 201, 139, 0.25); }
html[data-theme="dark"] h4 { color: var(--h-soft); }
html[data-theme="dark"] :is(.theory-block, .section-card, .task) {
    background: var(--h-card); border: 1px solid var(--h-line); border-left: 4px solid var(--h-gold); border-radius: 16px; box-shadow: none; }
html[data-theme="dark"] .task { border-left-color: #7fb0ff; }
html[data-theme="dark"] .section-card { border-left-width: 1px; }
html[data-theme="dark"] .example { background: rgba(255, 255, 255, 0.06); border-radius: 12px; }
html[data-theme="dark"] .hint { color: #d8c79a; border-left-color: var(--h-gold); }
html[data-theme="dark"] .warning { background: rgba(255, 214, 102, .12); border-left-color: #ffd666; color: var(--h-text); }
html[data-theme="dark"] .note { background: rgba(26, 115, 232, .16); border-left-color: #6aa8ff; color: var(--h-text); }
html[data-theme="dark"] .note-card { background: rgba(227, 201, 139, .10); border-color: var(--h-edge); }
html[data-theme="dark"] .complexity { background: rgba(92, 184, 92, .14); border-left-color: #6ccf6c; color: var(--h-text); }
html[data-theme="dark"] .file-structure { background: rgba(0, 0, 0, .28); color: var(--h-text); }
html[data-theme="dark"] code { background: var(--h-inline-code-bg); color: var(--h-inline-code); }
html[data-theme="dark"] :is(pre code, code[class*="language-"]) { background: none; color: #abb2bf; }
html[data-theme="dark"] pre[class*="language-"] { border: 1px solid rgba(255, 255, 255, .08); box-shadow: inset 0 0 24px rgba(0, 0, 0, .35); }
html[data-theme="dark"] a { color: var(--h-link); }
html[data-theme="dark"] a:visited { color: var(--h-link-v); }
html[data-theme="dark"] :is(.section-links a, .toc-items a):hover { background: var(--h-hover); color: #fff; }
html[data-theme="dark"] :is(a.back, a.forward, .gl-link) {
    background: linear-gradient(180deg, rgba(227, 201, 139, .22), rgba(227, 201, 139, .08)); border-color: var(--h-edge); color: var(--h-gold); }
html[data-theme="dark"] :is(a.back, a.forward, .gl-link):hover { background: rgba(227, 201, 139, .3); color: #fff; }
html[data-theme="dark"] .disclaimer { background: rgba(255, 255, 255, .05); border-color: var(--h-line); color: var(--h-soft); }
html[data-theme="dark"] .lead-intro { color: var(--h-text); }
html[data-theme="dark"] .slide::before { filter: brightness(1.25); --wm-opacity: 0.28; }
/* мобильное содержание (toc.js) */
html[data-theme="dark"] #toc-sidebar { background: linear-gradient(180deg, #1a2142, #121734); border-color: var(--h-edge); }
html[data-theme="dark"] :is(.toc-head, .toc-all) { border-color: var(--h-line); background: transparent; }
html[data-theme="dark"] :is(.toc-logo, .toc-sec-title, .toc-x) { color: var(--h-text); }
html[data-theme="dark"] .toc-items a { color: var(--h-soft); }
html[data-theme="dark"] .toc-current { background: rgba(227, 201, 139, .2) !important; color: var(--h-text) !important; }
html[data-theme="dark"] .toc-all { color: var(--h-gold); }
html[data-theme="dark"] #toc-toggle { background: var(--h-panel-solid); color: var(--h-gold); border-color: var(--h-edge); }
/* глоссарий, карточки, поиск */
html[data-theme="dark"] .gl:hover, html[data-theme="dark"] .gl:focus-visible { background: rgba(227, 201, 139, .22); }
html[data-theme="dark"] .gl-pop { background: linear-gradient(180deg, #232b52, #171d3a); color: var(--h-text); border-color: var(--h-edge); }
html[data-theme="dark"] .gl-pop-head b { color: var(--h-gold); }
html[data-theme="dark"] .gl-x { color: var(--h-soft); }
html[data-theme="dark"] .gl-x:hover { background: var(--h-hover); }
html[data-theme="dark"] :is(.gl-pop-where, .gl-where) { color: var(--h-soft); }
html[data-theme="dark"] .gl-pop-all { color: var(--h-gold); }
html[data-theme="dark"] .gl-kind { background: rgba(227, 201, 139, .18); color: var(--h-text); }
html[data-theme="dark"] #gl-q { background: var(--h-field); border-color: var(--h-edge); color: var(--h-text); }
html[data-theme="dark"] .gl-chip { background: var(--h-btn); border-color: var(--h-edge); color: var(--h-text); }
html[data-theme="dark"] .gl-chip.active { background: var(--h-gold); color: #2a2412; }
html[data-theme="dark"] .gl-card { background: var(--h-card); border-color: var(--h-line); box-shadow: none; }
html[data-theme="dark"] .gl-card:target { box-shadow: 0 0 0 2px var(--h-gold); }

/* ---------- иконки ---------- */
.ic { width: 1.2em; height: 1.2em; vertical-align: -0.22em; fill: none; stroke: currentColor; stroke-width: 1.7;
      stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.section-title.has-ic::before { content: none; }
.section-title .ic { width: 1.5em; height: 1.5em; margin-right: 10px; color: var(--gold); padding: 5px; box-sizing: content-box;
      border: 1px solid var(--gold); border-radius: 12px; background: rgba(199, 177, 131, .12); }
html[data-theme="dark"] .section-title .ic { color: var(--h-gold); border-color: var(--h-edge); background: rgba(227, 201, 139, .1); }

/* титульная: герой с Паймон */
.hero { display: flex; align-items: center; justify-content: center; gap: 28px; flex-wrap: wrap; margin-bottom: 6px; }
.hero img { width: 150px; height: auto; filter: drop-shadow(0 10px 16px rgba(60, 40, 0, .35)); animation: hero-bob 4s ease-in-out infinite; }
.hero-text { flex: 1 1 360px; min-width: 0; }
.hero-text .main-title { text-align: left; margin-top: 4px; }
@keyframes hero-bob { 50% { transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) { .hero img { animation: none; } }
@media (max-width: 640px) { .hero { gap: 6px; } .hero-text .main-title { text-align: center; } .hero img { width: 120px; } }

/* ---------- переключатель темы (телефон и десктоп) ---------- */
#theme-toggle {
    position: fixed; left: 14px; bottom: 14px; z-index: 1090; width: 42px; height: 42px; border-radius: 50%;
    border: 1px solid var(--h-edge); background: var(--h-panel-solid); color: var(--h-gold);
    display: grid; place-items: center; cursor: pointer; box-shadow: 0 4px 14px rgba(0, 0, 0, .25); padding: 0;
}
#theme-toggle:hover { filter: brightness(1.08); }
#theme-toggle .ic { width: 20px; height: 20px; }

/* ============================================================
   HUD десктопа
   ============================================================ */
.hud-layer { display: none; }

@media (min-width: 1024px) {

#toc-sidebar, #toc-toggle, #toc-backdrop { display: none !important; }
body.toc-on { padding-left: 0 !important; }
.hud-layer { display: block; }

body { padding: 24px 24px 90px; }
body.hud-gutter { padding-right: 392px; }

/* звёздная пыль — только в тёмной теме */
html[data-theme="dark"] body::before {
    content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
    background-image:
        radial-gradient(1.5px 1.5px at 8% 22%,  rgba(255,255,255,.55), transparent 60%),
        radial-gradient(1px   1px   at 21% 71%, rgba(255,255,255,.45), transparent 60%),
        radial-gradient(1.5px 1.5px at 34% 38%, rgba(227,201,139,.6),  transparent 60%),
        radial-gradient(1px   1px   at 47% 12%, rgba(255,255,255,.4),  transparent 60%),
        radial-gradient(1.5px 1.5px at 58% 83%, rgba(255,255,255,.5),  transparent 60%),
        radial-gradient(1px   1px   at 69% 47%, rgba(227,201,139,.5),  transparent 60%),
        radial-gradient(1.5px 1.5px at 81% 18%, rgba(255,255,255,.55), transparent 60%),
        radial-gradient(1px   1px   at 92% 64%, rgba(255,255,255,.4),  transparent 60%),
        radial-gradient(1px   1px   at 14% 91%, rgba(255,255,255,.4),  transparent 60%),
        radial-gradient(1.5px 1.5px at 76% 92%, rgba(227,201,139,.5),  transparent 60%);
    animation: hud-twinkle 7s ease-in-out infinite alternate;
}
body::after {                     /* огромная бледная «звезда-гнозис» */
    content: ""; position: fixed; z-index: 0; pointer-events: none;
    width: 900px; height: 900px; right: -260px; bottom: -300px; opacity: .07;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='-100 -100 200 200'><g fill='none' stroke='%23b08c3a' stroke-width='1.2'><circle r='90'/><circle r='70'/><path d='M0-90 L12-12 90 0 12 12 0 90 -12 12 -90 0 -12-12Z'/></g></svg>") center/contain no-repeat;
    animation: hud-spin 240s linear infinite;
}
@keyframes hud-twinkle { from { opacity: .55; } to { opacity: 1; } }
@keyframes hud-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { body::before, body::after { animation: none !important; } }

/* основной контент: «стекло» с золотой кромкой (цвета — из темы) */
.slide {
    position: relative; z-index: 1; max-width: none; width: 100%; margin: 0 auto;
    background: var(--h-panel); backdrop-filter: blur(6px);
    border: 1px solid var(--h-edge); border-radius: 28px 28px 28px 8px;
    box-shadow: var(--h-shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
    padding: 34px 48px 40px;
}
.slide > p, .theory-block > p, .task > p { max-width: 80ch; }
.main-title { font-size: 36px; letter-spacing: .5px; }
h2 { font-size: 28px; }
a.back, a.forward { border-radius: 999px; padding: 9px 20px; }

} /* /min-width:1024px */

/* ============================================================
   Окна HUD: общие стили (десктоп — плавающие окна, телефон — шторки)
   ============================================================ */
.hud-win { position: fixed; z-index: 1040; color: var(--h-text); font: 14px/1.45 "Segoe UI", Arial, sans-serif; }
.hud-win.hud-front { z-index: 1060; }
.hud-win.pai { z-index: 1100; }

.hud-frame {
    display: flex; flex-direction: column; overflow: hidden; width: 100%; height: 100%;
    background: linear-gradient(180deg, var(--h-frame-a), var(--h-frame-b));
    border: 1px solid var(--h-edge); border-radius: 20px; box-shadow: var(--h-shadow); backdrop-filter: blur(8px);
}
.hud-head {
    display: flex; align-items: center; gap: 8px; flex: 0 0 auto; padding: 9px 10px 9px 14px;
    cursor: grab; user-select: none; touch-action: none;
    background: linear-gradient(180deg, rgba(199, 177, 131, .22), rgba(199, 177, 131, .05));
    border-bottom: 1px solid var(--h-edge);
}
.hud-head:active { cursor: grabbing; }
.hud-title { flex: 1; font-weight: 700; color: var(--h-gold); letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.hud-btn { min-width: 26px; height: 26px; border: none; border-radius: 8px; cursor: pointer; background: var(--h-btn);
    color: var(--h-text); font-size: 13px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 0 6px; }
.hud-btn:hover { background: var(--h-btn-h); }
.hud-btn .ic { width: 15px; height: 15px; }
.hud-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

.hud-pill {
    display: none; align-items: center; gap: 8px; cursor: pointer; user-select: none; touch-action: none;
    padding: 9px 16px 9px 12px; border-radius: 999px; font-weight: 700; color: var(--h-gold);
    background: linear-gradient(180deg, var(--h-pill-a), var(--h-pill-b)); border: 1px solid var(--h-edge); box-shadow: var(--h-shadow);
}
.hud-pill:hover { filter: brightness(1.07); }
.hud-win.collapsed .hud-frame { display: none; }
.hud-win.collapsed .hud-pill { display: inline-flex; }

/* ---------- «Карта» ---------- */
.ctx-progress { padding: 10px 14px 4px; }
.ctx-progress .bar { height: 8px; border-radius: 8px; background: var(--h-line); overflow: hidden; }
.ctx-progress .bar > i { display: block; height: 100%; width: 0; border-radius: 8px; background: linear-gradient(90deg, #c7b183, #ffd980); transition: width .4s ease; }
.ctx-progress small { color: var(--h-soft); }
.ctx-search { margin: 8px 12px; position: relative; }
.ctx-search .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--h-soft); width: 16px; height: 16px; pointer-events: none; }
.ctx-search input { width: 100%; padding: 8px 12px 8px 34px; border-radius: 12px; font: inherit; color: var(--h-text);
    background: var(--h-field); border: 1px solid var(--h-line); outline: none; }
.ctx-search input:focus { border-color: var(--h-gold); }
.ctx-list { flex: 1; overflow-y: auto; padding: 2px 8px 8px; scroll-behavior: smooth; }
.ctx-list::-webkit-scrollbar { width: 8px; }
.ctx-list::-webkit-scrollbar-thumb { background: rgba(176, 146, 80, .35); border-radius: 8px; }
.ctx-sec { margin: 10px 6px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--h-soft); display: flex; align-items: center; gap: 7px; }
.ctx-sec .ic { color: var(--h-gold); width: 15px; height: 15px; }
.ctx-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; margin: 1px 0; border-radius: 10px;
    color: var(--h-text) !important; border: 1px solid transparent; font-size: 13.5px; }
.ctx-item:hover { background: var(--h-hover); }
.ctx-item .tick { width: 16px; color: #3f9d3f; flex: 0 0 16px; display: inline-grid; place-items: center; }
.ctx-item .tick .ic { width: 14px; height: 14px; stroke-width: 2.4; }
.ctx-item.near { background: var(--h-hover); }
.ctx-item.cur { background: linear-gradient(90deg, rgba(199, 177, 131, .4), rgba(199, 177, 131, .1)); border-color: var(--h-edge); font-weight: 700; }
.ctx-foot { display: flex; border-top: 1px solid var(--h-line); }
.ctx-foot .ctx-all { flex: 1; text-align: center; padding: 10px 4px; font-size: 13px; color: var(--h-gold) !important; font-weight: 700;
    display: flex; align-items: center; justify-content: center; gap: 6px; }
.ctx-foot .ctx-all + .ctx-all { border-left: 1px solid var(--h-line); }
.ctx-foot .ctx-all:hover { background: rgba(199, 177, 131, .15); }
.ctx-item.res { display: block; padding: 8px 10px; }
.ctx-item .r-t { display: block; font-weight: 700; }
.ctx-item .r-s { display: block; font-size: 11.5px; color: var(--h-soft); }
.ctx-item .r-x { display: block; font-size: 12px; color: var(--h-soft); margin-top: 2px; }
.ctx-item mark { background: rgba(199, 177, 131, .5); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- Паймон ---------- */
.pai-av { position: relative; cursor: pointer; width: 118px; height: 118px; border-radius: 50%; touch-action: none; user-select: none;
    background: radial-gradient(circle at 50% 30%, #fff8dc 0%, #f6dc8c 48%, #c9962f 100%);
    border: 3px solid #fff3c4;
    box-shadow: 0 0 0 2px rgba(176, 146, 80, .85), 0 10px 26px rgba(0, 0, 0, .4), 0 0 28px rgba(255, 214, 102, .5); }
.pai-av img { position: absolute; left: 50%; bottom: -4px; width: 104%; height: auto; transform: translateX(-50%); pointer-events: none;
    filter: saturate(1.25) contrast(1.06) drop-shadow(0 4px 6px rgba(60, 40, 0, .4)); animation: pai-bob 3.6s ease-in-out infinite; }
@keyframes pai-bob { 50% { transform: translateX(-50%) translateY(-5px); } }
@media (prefers-reduced-motion: reduce) { .pai-av img { animation: none; } }
.pai-bubble { position: absolute; right: 100%; top: 6px; margin-right: 12px; width: 210px; background: #fffdf3; color: #3a3f55;
    padding: 9px 12px; border-radius: 16px 16px 4px 16px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, .35); display: none; }
.hud-win.collapsed .pai-bubble.show { display: block; }
.pai-head-av { position: relative; display: inline-block; flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; overflow: hidden;
    background: radial-gradient(circle at 50% 30%, #fff8dc 0%, #f6dc8c 55%, #c9962f 100%); border: 2px solid #fff3c4;
    box-shadow: 0 0 0 1.5px rgba(176, 146, 80, .85), 0 2px 8px rgba(0, 0, 0, .3); }
.pai-head-av img { position: absolute; left: 50%; top: -3px; width: 150%; height: auto; transform: translateX(-50%);
    filter: saturate(1.25) contrast(1.05); }
.pai-head-sm { width: 26px; height: 26px; border-width: 1.5px; }
.term-row { display: inline-flex; align-items: center; gap: 8px; vertical-align: middle; }
.term-in { min-width: 12ch; width: 22ch; max-width: 60vw; padding: 3px 8px; font: inherit; color: #fff; background: rgba(255, 255, 255, .1);
    border: 1px solid rgba(227, 201, 139, .6); border-radius: 6px; outline: none; }
.term-in:focus { border-color: #ffe9ae; background: rgba(255, 255, 255, .16); }
.term-eof { padding: 2px 9px; font: 11.5px "Segoe UI", Arial, sans-serif; color: #e3c98b; background: transparent; border: 1px solid rgba(227, 201, 139, .45);
    border-radius: 999px; cursor: pointer; }
.term-eof:hover { background: rgba(227, 201, 139, .25); }
.pai-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.pai-m { max-width: 88%; padding: 8px 12px; border-radius: 14px; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.pai-m.bot { align-self: flex-start; background: #fffdf3; color: #3a3f55; border: 1px solid rgba(176, 146, 80, .3); border-bottom-left-radius: 4px; }
.pai-m.me { align-self: flex-end; background: rgba(199, 177, 131, .38); border-bottom-right-radius: 4px; }
.pai-m.bot code { background: rgba(0, 0, 0, .08); color: #6b4a00; padding: 0 4px; border-radius: 4px; font-size: 12.5px; }
.pai-m .pai-code { margin: 6px 0 2px; padding: 8px 10px; background: #282c34; color: #abb2bf; border-radius: 8px;
    font: 12.5px/1.45 Consolas, Monaco, monospace; white-space: pre; overflow-x: auto; }
.pai-m.typing { opacity: .7; animation: pai-blink 1s ease-in-out infinite; }
@keyframes pai-blink { 50% { opacity: .3; } }
.pai-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--h-line); }
.pai-form input { flex: 1; padding: 8px 12px; border-radius: 12px; font: inherit; color: var(--h-text); background: var(--h-field); border: 1px solid var(--h-line); outline: none; }
.pai-form input:focus { border-color: var(--h-gold); }
.pai-form button { padding: 0 14px; border: none; border-radius: 12px; cursor: pointer; font-weight: 700; background: var(--h-gold-fill); color: #2a2412; display: grid; place-items: center; }
.pai-form button:disabled { opacity: .5; cursor: progress; }
.pai-form button .ic { width: 17px; height: 17px; }
.pai-note { padding: 0 12px 8px; font-size: 11px; color: var(--h-soft); }
.hud-win.pai .hud-pill { display: none !important; }
.hud-win.pai.collapsed .pai-av { display: block; }
.hud-win.pai:not(.collapsed) .pai-av { display: none; }

/* ---------- песочница ---------- */
.code-win:not(.collapsed):not(.max) { overflow: hidden; border-radius: 20px; }

/* ручки изменения размера: края и углы окна (только десктоп) */
.hud-rz { position: absolute; z-index: 5; touch-action: none; }
.hud-win.collapsed .hud-rz, .hud-win.max .hud-rz { display: none; }
.rz-e { top: 14px; bottom: 14px; right: -4px; width: 9px; cursor: ew-resize; }
.rz-w { top: 14px; bottom: 14px; left: -4px; width: 9px; cursor: ew-resize; }
.rz-s { left: 14px; right: 14px; bottom: -4px; height: 9px; cursor: ns-resize; }
.rz-se { right: -4px; bottom: -4px; width: 18px; height: 18px; cursor: nwse-resize; }
.rz-sw { left: -4px; bottom: -4px; width: 18px; height: 18px; cursor: nesw-resize; }
.rz-se::after, .rz-sw::after { content: ""; position: absolute; bottom: 7px; width: 9px; height: 9px; border-bottom: 2px solid var(--h-edge); opacity: .8; }
.rz-se::after { right: 7px; border-right: 2px solid var(--h-edge); border-radius: 0 0 6px 0; }
.rz-sw::after { left: 7px; border-left: 2px solid var(--h-edge); border-radius: 0 0 0 6px; }
@media (max-width: 1023px) { .hud-rz { display: none !important; } }
.code-win.max { inset: 2.5vh 2.5vw !important; width: auto !important; height: auto !important; z-index: 1055; }
.code-ed { flex: 1; min-height: 0; margin: 10px 10px 0; padding: 10px; resize: none; tab-size: 4; font: 13.5px/1.5 Consolas, Monaco, monospace;
    color: #abb2bf; background: #282c34; border: 1px solid rgba(255, 255, 255, .1); border-radius: 12px; outline: none; white-space: pre; }
.code-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.code-run { padding: 7px 16px; border: none; border-radius: 999px; cursor: pointer; font-weight: 700; display: inline-flex; align-items: center; gap: 6px;
    background: linear-gradient(180deg, #ffe9ae, #c7b183); color: #2a2412; }
.code-run .ic { width: 14px; height: 14px; }
.code-run:disabled { opacity: .6; cursor: progress; }
.code-bar .hud-btn { width: auto; padding: 0 10px; font-size: 12px; gap: 5px; }
.code-out { flex: 0 0 auto; margin: 0 10px 10px; padding: 8px 10px; max-height: 32%; overflow: auto; white-space: pre-wrap; min-height: 40px;
    font: 12.5px/1.45 Consolas, Monaco, monospace; color: #cfe3c4; background: #1d2026; border-radius: 10px; }
.code-out.err { color: #ff9c9c; }
.code-out .e { color: #ff9c9c; } .code-out .n { color: #9aa3b5; font-style: italic; }
.code-status { font-size: 12px; color: var(--h-soft); }
.code-stdin { margin: 8px 10px 0; padding: 8px 10px; resize: vertical; font: 13px Consolas, Monaco, monospace; color: var(--h-text);
    background: var(--h-field); border: 1px solid var(--h-line); border-radius: 10px; outline: none; }
.code-stdin[hidden], .code-files[hidden] { display: none; }
.code-files { margin: 0 10px 6px; font-size: 12px; color: var(--h-soft); }
.pre-run { position: absolute; top: 8px; right: 8px; padding: 3px 10px; border-radius: 999px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
    font: 600 11.5px "Segoe UI", Arial, sans-serif; color: #e3c98b; background: rgba(0, 0, 0, .55); border: 1px solid rgba(227, 201, 139, .5); opacity: 0; transition: opacity .15s; }
.pre-run .ic { width: 12px; height: 12px; }
pre:hover .pre-run, .pre-run:focus { opacity: 1; }
.pre-run:hover { background: rgba(227, 201, 139, .35); color: #fff; }

.code-ed-host { flex: 1 1 auto; min-height: 90px; margin: 10px 10px 0; position: relative; overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .1); border-radius: 12px; background: #282c34; }
.code-ed-host .code-ed { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; border: none; border-radius: 0; }
.code-ed-host .CodeMirror { position: absolute; inset: 0; height: 100%; font: 13.5px/1.5 Consolas, Monaco, monospace; border-radius: 12px; }
.cm-s-pcurs.CodeMirror { background: #282c34; color: #abb2bf; }
.cm-s-pcurs .CodeMirror-gutters { background: #232730; border-right: 1px solid rgba(255, 255, 255, .07); }
.cm-s-pcurs .CodeMirror-linenumber { color: #5c6370; }
.cm-s-pcurs .CodeMirror-cursor { border-left: 2px solid #e3c98b; }
.cm-s-pcurs .CodeMirror-activeline-background { background: rgba(255, 255, 255, .045); }
.cm-s-pcurs .CodeMirror-selected, .cm-s-pcurs div.CodeMirror-selected { background: rgba(227, 201, 139, .25); }
.cm-s-pcurs .CodeMirror-matchingbracket { color: #fff !important; background: rgba(227, 201, 139, .35); }
.cm-s-pcurs .cm-keyword { color: #c678dd; } .cm-s-pcurs .cm-builtin { color: #56b6c2; }
.cm-s-pcurs .cm-def { color: #61afef; } .cm-s-pcurs .cm-variable-2, .cm-s-pcurs .cm-variable-3 { color: #e5c07b; }
.cm-s-pcurs .cm-string, .cm-s-pcurs .cm-string-2 { color: #98c379; } .cm-s-pcurs .cm-number { color: #d19a66; }
.cm-s-pcurs .cm-comment { color: #7c858d; font-style: italic; } .cm-s-pcurs .cm-operator { color: #c678dd; }
.cm-s-pcurs .cm-meta { color: #e5c07b; }

html body .CodeMirror-hints { z-index: 1200 !important; background: #1b2140; color: #e6e8f2; border: 1px solid rgba(227, 201, 139, .5); border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .55); font: 13px Consolas, Monaco, monospace; padding: 4px; max-height: 14em; }
html body .CodeMirror-hints li.CodeMirror-hint { color: #e6e8f2; border-radius: 6px; padding: 3px 8px; display: flex; align-items: center; gap: 8px; }
html body .CodeMirror-hints li.CodeMirror-hint-active { background: rgba(227, 201, 139, .3); color: #fff; }
.ph-ico { width: 16px; text-align: center; color: #e3c98b; flex: 0 0 16px; font-style: italic; }
.ph-kind { margin-left: auto; padding-left: 16px; color: #aab2cc; font: 11px "Segoe UI", Arial, sans-serif; }
.ph-var .ph-ico { color: #e5c07b; } .ph-mth .ph-ico, .ph-fn .ph-ico { color: #61afef; }
.ph-cls .ph-ico { color: #98c379; } .ph-kw .ph-ico { color: #c678dd; } .ph-mod .ph-ico { color: #56b6c2; }


/* ============================================================
   Телефон и планшет (<1024px): Паймон и песочница — нижние «шторки»
   ============================================================ */
@media (max-width: 1023px) {
    .hud-layer { display: block; }
    .ctx-win { display: none !important; }                     /* вместо «Карты» — боковое содержание (toc.js) */

    /* свёрнутое: кнопки-«запуски» в правом нижнем углу; положение задаёт CSS, а не JS */
    .hud-win.collapsed { left: auto !important; top: auto !important; width: auto !important; height: auto !important;
        right: 14px !important; z-index: 1085; }
    .hud-win.pai.collapsed { bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important; }
    .hud-win.code-win.collapsed { bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important; }
    .pai-av { width: 76px; height: 76px; }
    .pai-bubble { width: min(210px, 56vw); font-size: 12.5px; }
    .hud-pill { padding: 11px 16px 11px 13px; font-size: 14px; }

    /* раскрытое: шторка снизу; над экранной клавиатурой (переменные ставит hud.js из visualViewport) */
    .hud-win:not(.collapsed) {
        left: 0 !important; right: 0 !important; top: auto !important; width: auto !important;
        bottom: var(--sheet-bottom, 0px) !important;
        --normal-h: min(80dvh, 680px); height: var(--normal-h) !important; z-index: 1200;
    }
    .hud-win:not(.collapsed) .hud-frame { border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
    .hud-head { cursor: default; padding: 12px 12px 12px 16px; }
    .hud-btn { min-width: 36px; height: 36px; border-radius: 10px; }
    [data-max], [data-reset] { display: none !important; }
    /* Паймон и песочница одновременно: песочница сверху, чат снизу, вместе перекрывают страницу целиком */
    body.m-both .hud-win:not(.collapsed) { --normal-h: calc(var(--fullh, 100dvh) * .5); }
    body.m-both .code-win:not(.collapsed) { top: 0 !important; bottom: auto !important; }
    body.m-both .code-win:not(.collapsed) .hud-frame { border-radius: 0 0 18px 18px; }
    /* экранная клавиатура открыта: печатающее окно стоит над клавиатурой — обычной высоты, если помещается, иначе занимает всё свободное место;
       второе окно на это время прячется */
    body.kb-open .hud-win:not(.collapsed) { top: auto !important; bottom: var(--sheet-bottom, 0px) !important; height: min(var(--normal-h), var(--vvh, 100dvh)) !important; }
    body.kb-open .code-win:not(.collapsed) .hud-frame { border-radius: 20px 20px 0 0; }
    body.kb-open.kb-active-any.m-both .hud-win:not(.collapsed):not(.kb-active) { visibility: hidden; }
    /* панель инструментов редактора (только сенсорные экраны) */
    .code-toolwrap { display: block; position: relative; flex: 0 0 auto; }
    .code-tools { display: flex; gap: 6px; padding: 7px 10px 0; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
    .code-tools::-webkit-scrollbar { display: none; }
    .code-tools button, .code-more button { flex: 0 0 auto; min-width: 42px; height: 40px; padding: 0 11px; border: 1px solid var(--h-line); border-radius: 10px;
        background: var(--h-btn); color: var(--h-text); font: 600 17px Consolas, Monaco, monospace; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
    .code-tools button:active, .code-more button:active { background: var(--h-btn-h); }
    .code-tools .ic { width: 19px; height: 19px; }
    .code-more { position: absolute; left: 8px; right: 8px; bottom: calc(100% + 4px); z-index: 5; max-height: 48vh; overflow: auto; padding: 8px 10px 10px;
        background: var(--h-panel-solid); border: 1px solid var(--h-edge); border-radius: 14px; box-shadow: var(--h-shadow); }
    .code-more[hidden] { display: none; }
    .more-h { font: 700 12px "Segoe UI", Arial, sans-serif; color: var(--h-soft); text-transform: uppercase; letter-spacing: .7px; margin: 6px 0 4px; }
    .more-g { display: flex; flex-wrap: wrap; gap: 6px; }
    .code-more button { height: 38px; font-size: 15px; }
    body.m-both .code-ed-host { min-height: 60px; }
    body.m-both .code-out { max-height: 30%; }
    .term-in { font-size: 16px; }
    .code-win:not(.collapsed):not(.max) { resize: none; min-width: 0; min-height: 0; }
    #sheet-backdrop { position: fixed; inset: 0; z-index: 1150; background: rgba(0, 0, 0, .42); opacity: 0; pointer-events: none; transition: opacity .2s; }
    #sheet-backdrop.on { opacity: 1; pointer-events: auto; }

    /* ввод ≥16px: иначе iOS приближает страницу при фокусе */
    .pai-form input, .code-stdin, .hud-win textarea, .CodeMirror, .ctx-search input, .toc-search input { font-size: 16px !important; }
    .pai-form input { padding: 11px 14px; }
    .pai-form button { padding: 0 18px; }
    .pai-msgs { padding: 14px; }
    .pai-m { font-size: 15px; max-width: 92%; }
    .code-bar { flex-wrap: wrap; }
    .code-run { padding: 10px 18px; }
    .code-bar .hud-btn { height: 38px; }
    .code-ed-host { min-height: 120px; }
    .code-out { max-height: 38%; font-size: 13px; }
    /* на сенсорных экранах наведения нет — кнопка «в песочницу» видна всегда */
    .pre-run { opacity: 1; background: rgba(0, 0, 0, .6); padding: 5px 11px; font-size: 12px; }
    /* автодополнение: крупнее под палец */
    html body .CodeMirror-hints li.CodeMirror-hint { padding: 8px 10px; }
}

/* ============================================================
   Боковое содержание телефона/планшета (toc.js): прогресс, поиск, иконки
   ============================================================ */
#toc-toggle .ic { width: 22px; height: 22px; }
.toc-x .ic { width: 16px; height: 16px; }
.toc-progress { padding: 10px 14px 2px; }
.toc-bar { height: 7px; border-radius: 7px; background: var(--h-line); overflow: hidden; }
.toc-bar > i { display: block; height: 100%; border-radius: 7px; background: linear-gradient(90deg, #c7b183, #ffd980); }
.toc-progress small { color: var(--h-soft); font-size: 12px; }
.toc-search { position: relative; margin: 8px 12px; }
.toc-search .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--h-soft); pointer-events: none; }
.toc-search input { width: 100%; padding: 10px 12px 10px 34px; border-radius: 12px; font: inherit; font-size: 16px; color: var(--h-text);
    background: var(--h-field); border: 1px solid var(--h-line); outline: none; }
.toc-search input:focus { border-color: var(--h-gold); }
.toc-sec-title .ic { width: 18px; height: 18px; color: var(--h-gold); }
.toc-items a { display: flex; align-items: center; gap: 6px; }
.toc-tick { display: inline-grid; place-items: center; color: #3f9d3f; margin-left: -20px; width: 16px; }
.toc-tick .ic { width: 13px; height: 13px; stroke-width: 2.6; }
.toc-foot { display: flex; border-top: 1px solid var(--h-line); }
.toc-foot .toc-all { flex: 1; border-top: none; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 6px; font-size: 13px; }
.toc-foot .toc-all + .toc-all { border-left: 1px solid var(--h-line); }
.toc-results { display: flex; flex-direction: column; gap: 2px; padding: 4px 6px; }
.toc-res { display: block; padding: 9px 10px; border-radius: 10px; color: var(--h-text) !important; }
.toc-res:hover { background: var(--h-hover); }
.toc-res .r-t { display: block; font-weight: 700; font-size: 14px; }
.toc-res .r-s { display: block; font-size: 11.5px; color: var(--h-soft); }
.toc-res .r-x { display: block; font-size: 12.5px; color: var(--h-soft); margin-top: 2px; }
.toc-res mark { background: rgba(199, 177, 131, .5); color: inherit; border-radius: 3px; padding: 0 1px; }
.toc-empty { padding: 16px; color: var(--h-soft); text-align: center; }

/* телефон: пока открыта боковая панель, плавающие кнопки и «гамбургер» не должны её перекрывать */
body.toc-drawer #toc-toggle, body.toc-drawer #theme-toggle, body.toc-drawer .hud-win.collapsed { visibility: hidden; }

/* панель инструментов редактора скрыта на десктопе */
.code-toolwrap { display: none; }
@media (max-width: 1023px) { .code-toolwrap { display: block; } }

/* подписи на кнопках «соседнего окна» и подсветка строки с ошибкой */
.CodeMirror .cm-errline { background: rgba(229, 72, 77, .28) !important; }
.CodeMirror .cm-errgutter { background: rgba(229, 72, 77, .65) !important; }

/* телефон: когда одна шторка открыта, свёрнутое второе окно — компактный оверлей (аватар Паймон / «Код») в свободной области сверху справа,
   как на десктопе; пока открыта экранная клавиатура, оверлей скрыт */
@media (max-width: 1023px) {
    body[data-sheet="code"] .hud-win.pai.collapsed,
    body[data-sheet="pai"] .code-win.collapsed {
        bottom: auto !important; top: calc(14px + env(safe-area-inset-top, 0px)) !important; z-index: 1250;
    }
    body.kb-open .hud-win.collapsed { visibility: hidden; }
}

/* полоска подсказок автодополнения на телефоне (над панелью инструментов) */
.code-sugg { display: none; }
@media (max-width: 1023px) {
    .code-sugg:not([hidden]) { display: flex; gap: 6px; padding: 7px 10px 0; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
    .code-sugg::-webkit-scrollbar { display: none; }
    .code-sugg .sg { flex: 0 0 auto; height: 36px; padding: 0 14px; border-radius: 999px; cursor: pointer; font: 600 15px Consolas, Monaco, monospace;
        color: var(--h-text); background: var(--h-btn); border: 1px solid var(--h-edge); border-left-width: 4px; }
    .code-sugg .sg:active { background: var(--h-btn-h); }
    .sg-var { border-left-color: #e5c07b !important; } .sg-mth, .sg-fn { border-left-color: #61afef !important; } .sg-cls { border-left-color: #98c379 !important; }
    .sg-kw { border-left-color: #c678dd !important; } .sg-mod, .sg-builtin { border-left-color: #56b6c2 !important; }
}

/* «Поделиться» и страница просмотра ссылки */
.code-sharebox { display: flex; gap: 8px; margin: 0 10px 8px; }
.code-sharebox[hidden] { display: none; }
.code-sharebox .sh-url { flex: 1; min-width: 0; padding: 6px 10px; font: 13px Consolas, Monaco, monospace; color: var(--h-text);
    background: var(--h-field); border: 1px solid var(--h-edge); border-radius: 8px; outline: none; }
.code-sharebox .sh-copy { flex: 0 0 auto; padding: 0 12px; border: 1px solid var(--h-edge); border-radius: 8px; background: var(--h-btn); color: var(--h-text); cursor: pointer; font: 600 12.5px "Segoe UI", Arial, sans-serif; }
.code-sharebox .sh-copy:hover { background: var(--h-btn-h); }
.sh-out { margin: 10px 0 0; padding: 10px 12px; white-space: pre-wrap; font: 13px/1.5 Consolas, Monaco, monospace; color: #cfe3c4; background: #1d2026; border-radius: 10px; }
.sh-out .e { color: #ff9c9c; }
.sh-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.sh-hint { color: var(--h-soft); font-size: 13px; flex: 1 1 260px; }
[hidden] { display: none !important; }

/* «Сообщить об ошибке» / «Пожаловаться»: кнопка в конце страницы и диалог */
.page-foot { clear: both; margin-top: 30px; padding-top: 14px; border-top: 1px dashed var(--h-line, rgba(0, 0, 0, .15)); text-align: center; }
.rep-open { display: inline-flex; align-items: center; gap: 7px; padding: 6px 14px; border: 1px solid transparent; border-radius: 999px; background: none; cursor: pointer;
    color: var(--h-soft); font: 13px "Segoe UI", Arial, sans-serif; }
.rep-open:hover { color: var(--h-gold); border-color: var(--h-edge); background: var(--h-btn); }
.rep-open .ic { width: 15px; height: 15px; }
.rep-dlg { width: min(460px, 92vw); padding: 0; border: 1px solid var(--h-edge); border-radius: 16px; background: var(--h-panel-solid); color: var(--h-text);
    box-shadow: var(--h-shadow); font: 14px/1.45 "Segoe UI", Arial, sans-serif; }
.rep-dlg::backdrop { background: rgba(0, 0, 0, .55); }
.rep-form { display: flex; flex-direction: column; gap: 12px; padding: 18px 20px 16px; }
.rep-form h3 { margin: 0; color: var(--h-gold); font-size: 18px; }
.rep-form label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
.rep-form select, .rep-form textarea { padding: 9px 11px; border: 1px solid var(--h-line); border-radius: 10px; background: var(--h-field); color: var(--h-text); font: 15px "Segoe UI", Arial, sans-serif; }
.rep-form textarea { resize: vertical; min-height: 84px; }
.rep-form label.rep-attach { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.rep-form label[hidden] { display: none; }
.rep-note { margin: 0; color: var(--h-soft); font-size: 12.5px; }
.rep-status { margin: 0; min-height: 1.3em; color: var(--h-gold); font-weight: 600; font-size: 13px; }
.rep-btns { display: flex; justify-content: flex-end; gap: 10px; }
.rep-btns button { padding: 8px 18px; border-radius: 999px; border: 1px solid var(--h-edge); cursor: pointer; font: 600 14px "Segoe UI", Arial, sans-serif; background: var(--h-btn); color: var(--h-text); }
.rep-btns .rep-send { background: linear-gradient(180deg, #ffe9ae, #c7b183); color: #2a2412; border-color: transparent; }
.rep-btns button:disabled { opacity: .55; cursor: progress; }
