/*
 * Constructor — diagonal mode («Косое плетение», phase 2.0, 2026-11-26). Design:
 * design/diagonal-2026-11/SPEC.md and its mockups. Builds on constructor.css (tokens, studio shell,
 * sheets, result); only what diagonal weave adds lives here. Phone first; desktop from 1000px, as v2.
 */

:root {
    --ok: #2E7D74;
    --ok-tint: #E3F1EE;
    --ok-ink: #1F5D56;
    --warn: #8A5A00;
    --warn-tint: #FFF4D6;
    --warn-ring: #D9A300;
}

.cn-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cn-inline-link { border: 0; background: none; padding: 0; font: inherit; color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: none; }
.cn-inline-link:hover { text-decoration: underline; }

/* ================================================================ the weave switch (SPEC §3.1, D8) */
.cn-weave { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 4px; padding: 4px; background: var(--tint-2); border-radius: 14px; }
.cn-weave button {
    min-height: var(--tap); border: 0; border-radius: 11px; background: transparent; color: var(--muted);
    font: inherit; font-size: 15px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; padding: 0 8px;
}
.cn-weave button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(38, 32, 28, 0.12); }
.cn-weave .cn-weave-i { display: none; width: 18px; height: 18px; }
.cn-weave button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
/* a 320 px phone has no room for «плетение» twice: «Прямое / Косое», as in the «Схема» sheet */
@media (max-width: 359px) { .cn-weave-long { display: none; } }
@media (hover: hover) { .cn-weave button[aria-pressed="false"]:hover { color: var(--ink); } }

/* the entry card's eyebrow is the switch now */
.cn-entry .cn-eyebrow { display: block; margin-bottom: 18px; }
.cn-entry.is-received .cn-eyebrow { display: none; }
.cn-dtop-weave, .cn-size-weave .cn-weave-i { display: none; }
.cn-size-weave { margin-top: 4px; }

/* ================================================================ the diagonal tab of the entry card */
.cn-entry.is-diagonal { grid-template-areas: "eyebrow" "unreadable" "bad" "dcard" "my"; }
.cn-entry.is-diagonal > #cn-restore, .cn-entry.is-diagonal > #cn-lede, .cn-entry.is-diagonal > #cn-field,
.cn-entry.is-diagonal > #cn-preview-box, .cn-entry.is-diagonal > .cn-actions { display: none !important; }
.cn-dcard { grid-area: dcard; min-width: 0; }
.cn-dwell { grid-area: well; }
.cn-dlede { margin-bottom: 6px; }
.cn-dnote { font-size: 13.5px; color: var(--muted); margin: 0 0 18px; line-height: 1.45; }
.cn-dlabel { font-size: 15px; font-weight: 600; margin: 0 0 10px; }
.cn-dtiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
/* a 320 px phone: two tiles a row leave «Полоски» no room — one a row, lower */
@media (max-width: 359px) {
    .cn-dtiles { grid-template-columns: 1fr; gap: 8px; }
    .cn-dtile { height: 72px; }
    .cn-dtile-well { height: 56px; }
}
.cn-dtile {
    text-align: left; border: 1.5px solid var(--line); border-radius: 16px; padding: 8px 10px 8px 8px; background: var(--surface);
    display: flex; gap: 12px; align-items: center; height: 96px; overflow: hidden; cursor: pointer; font: inherit; color: var(--ink); min-width: 0;
}
.cn-dtile.is-on { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent); }
.cn-dtile-well { width: 40px; height: 78px; border-radius: 9px; overflow: hidden; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); display: flex; justify-content: center; padding-top: 2px; flex: none; }
.cn-dtile-well canvas { display: block; }
.cn-dtile-tx { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cn-dtile b { font-size: 15.5px; font-weight: 600; display: block; line-height: 1.2; }
.cn-dtile small { font-size: 12.5px; color: var(--muted); }
.cn-dtile-ic { display: flex; gap: 3px; margin-top: 4px; }
.cn-dactions { margin-top: 18px; }
.cn-dcard .cn-restore { margin-bottom: 4px; }
.cn-dthumb canvas { display: block; }

/* ================================================================ the studio */
.cn-dstudio .cn-title { flex: 0 1 auto; overflow: hidden; }
.cn-dstudio .cn-title b, .cn-dstudio .cn-title > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.cn-dstudio .cn-topbar .cn-spacer { flex: 1 0 4px; }
.cn-dstudio .cn-topbar .cn-title { padding: 4px 6px; }
.cn-dstudio .cn-title em { font-style: normal; font-weight: 600; }
.cn-dstudio .cn-title em.is-ok { color: var(--ok); }
.cn-dstudio .cn-title em.is-warn { color: var(--warn); }
.cn-dstage { flex: 1; min-width: 0; position: relative; display: flex; justify-content: center; }
.cn-dscroll { flex: 1 1 auto; min-width: 0; overflow: auto; position: relative; padding-bottom: 24px; overscroll-behavior: contain; scrollbar-width: thin; }
.cn-dsheet { position: relative; }
.cn-dchips { position: sticky; top: 0; z-index: 2; height: 54px; background: linear-gradient(var(--bg) 82%, rgba(251, 246, 240, 0)); }
.cn-dchip {
    position: absolute; top: 10px; border-radius: 999px; display: flex; align-items: center; justify-content: center;
    font-weight: 700; box-shadow: inset 0 0 0 1px rgba(38, 32, 28, 0.2); border: 0; padding: 0; cursor: pointer; font-family: inherit;
}
/* a 44 px target around a 30 px chip */
.cn-dchips .cn-dchip::before { content: ""; position: absolute; inset: -7px; }
.cn-dchip-end { top: 6px; cursor: default; }
.cn-dchip-end.is-off { box-shadow: inset 0 0 0 1px rgba(38, 32, 28, 0.2), 0 0 0 2px var(--bg), 0 0 0 4px var(--warn-ring); }
.cn-dchart { position: relative; line-height: 0; }
.cn-dchart canvas { display: block; touch-action: pan-x pan-y; cursor: pointer; -webkit-touch-callout: none; }
.cn-dchart canvas:focus-visible { outline: none; }
.cn-dends { position: relative; height: 44px; }
.cn-dbelow { position: sticky; left: 0; padding: 4px 12px 0 26px; box-sizing: border-box; }
.cn-drepeat { border-radius: 14px; padding: 10px 12px; font-size: 14px; line-height: 1.4; display: flex; gap: 10px; align-items: flex-start; }
.cn-drepeat .cn-i { width: 20px; height: 20px; margin-top: 1px; }
.cn-drepeat.is-ok { background: var(--ok-tint); color: var(--ok-ink); }
.cn-drepeat.is-warn { background: var(--warn-tint); color: var(--warn); }
.cn-drepeat b { font-weight: 600; }
.cn-drows { display: flex; gap: 10px; margin-top: 12px; }
.cn-drows .cn-btn { flex: 1 1 0; min-width: 0; min-height: var(--tap); height: var(--tap); gap: 6px; font-size: 15px; padding: 0 8px; }
.cn-drows .cn-i { width: 18px; height: 18px; }
.cn-dlimit { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.cn-dfade { position: absolute; top: 0; bottom: 0; right: 0; width: 28px; background: linear-gradient(90deg, rgba(251, 246, 240, 0), var(--bg)); pointer-events: none; }
.cn-dbig { display: none; }

/* phone: «Вид» (SPEC D7) */
.cn-dview { width: 52px; flex: none; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 0; border-left: 1px solid var(--line); }
.cn-dview-cap { font-size: 10.5px; color: var(--muted); font-weight: 600; }
.cn-dview-well { position: relative; border-radius: 6px; overflow: hidden; background: var(--surface); box-shadow: 0 0 0 1px var(--line); touch-action: none; cursor: pointer; line-height: 0; }
.cn-dview-well canvas { display: block; }
.cn-dview-frame { position: absolute; border: 2px solid var(--ink); border-radius: 4px; pointer-events: none; box-sizing: border-box; }
.cn-dfit { background: var(--surface); }

/* phone dock: the four knots, then the tools */
.cn-ddock { padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); gap: 2px; background: var(--bg); }
.cn-dknots { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.cn-dknot {
    display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 2px; border-radius: 14px; min-height: 70px;
    border: 0; background: transparent; cursor: pointer; font: inherit; color: var(--body);
}
.cn-dknot-ic { line-height: 0; }
.cn-dknot-cap { font-size: 11.5px; font-weight: 500; line-height: 1.2; text-align: center; }
.cn-dknot.is-on { background: var(--tint); }
.cn-dknot.is-on .cn-dknot-cap { color: var(--ink); font-weight: 600; }
.cn-ddock .cn-tools { justify-content: flex-start; gap: 2px; }
.cn-ddock .cn-tool { width: 64px; height: 54px; color: var(--body); }
.cn-ddock .cn-tool.is-on .cn-i { color: var(--accent-2); }
/* a phone: the title keeps «повторяется / не повторяется» whole, the weave name goes (it is in the «Схема» sheet) */
@media (max-width: 999px) { .cn-dt-weave { display: none; } }
@media (max-width: 359px) {
    .cn-ddock .cn-tools .cn-iconbtn, .cn-ddock .cn-tools .cn-tools-sep { display: inline-flex; }
    .cn-ddock .cn-tool { width: 54px; }
    .cn-dknot-cap { font-size: 11px; }
}
.cn-dstudio .cn-toast { bottom: calc(150px + env(safe-area-inset-bottom)); }

/* ---- sheets */
.cn-scrim.is-light { background: rgba(38, 32, 28, 0.12); }
.cn-dhint { font-size: 13.5px; color: var(--muted); margin: 10px 0 0; line-height: 1.45; }
.cn-dhint b { color: var(--accent-2); font-weight: 600; }
.cn-dstepper { display: flex; align-items: center; gap: 12px; }
.cn-dstepper .cn-iconbtn { width: 48px; height: 48px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); }
.cn-dstepper .cn-iconbtn:disabled { opacity: 0.4; }
.cn-dstepper output { min-width: 56px; text-align: center; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cn-dunit { color: var(--muted); font-size: 15px; }
.cn-dschips { display: flex; gap: 4px; flex-wrap: wrap; }
.cn-dschip { width: 38px; height: 52px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: transparent; padding: 0; cursor: pointer; font: inherit; }
.cn-dschip i { width: 30px; height: 30px; border-radius: 999px; display: flex; align-items: center; justify-content: center; font-style: normal; font-size: 13px; font-weight: 700; box-shadow: inset 0 0 0 1px rgba(38, 32, 28, 0.2); }
.cn-dschip small { font-size: 10.5px; color: var(--muted); font-weight: 600; }
.cn-dschip.is-on { background: var(--tint); }
.cn-dschip.is-on i { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }
.cn-dschip.is-twin i { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent-2); }
.cn-dpalette { margin-top: 14px; }
.cn-dstrings .cn-label span { text-align: right; }

/* the knot card (SPEC §3.4) */
.cn-dcame { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 14.5px; color: var(--body); background: var(--tint-2); border-radius: 14px; padding: 10px 12px; line-height: 1.6; }
.cn-dcame i { width: 24px; height: 24px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; font-style: normal; font-size: 11.5px; font-weight: 700; box-shadow: inset 0 0 0 1px rgba(38, 32, 28, 0.2); vertical-align: middle; }
.cn-dopts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.cn-dopt { display: flex; gap: 10px; align-items: center; text-align: left; border: 1.5px solid var(--line); border-radius: 14px; padding: 10px; min-height: 64px; background: var(--surface); cursor: pointer; font: inherit; color: var(--ink); }
.cn-dopt b { font-size: 14.5px; font-weight: 600; display: block; line-height: 1.2; }
.cn-dopt small { font-size: 12.5px; color: var(--muted); display: block; line-height: 1.3; margin-top: 2px; }
.cn-dopt.is-on { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent); }
.cn-dopt svg { flex: none; }
.cn-dwhole { width: 100%; margin-top: 6px; }
.cn-dcard-sheet { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.cn-dcard-sheet .cn-sheet-head { margin-bottom: 10px; }

/* «Четыре узла» (SPEC §3.5) */
.cn-dhelp { max-height: 88%; }
.cn-dhelp-intro { font-size: 15.5px; color: var(--body); line-height: 1.5; margin: 0 0 10px; }
.cn-dhelp-intro b { font-weight: 600; }
.cn-dhk { display: grid; grid-template-columns: 76px 1fr; gap: 14px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.cn-dhk:first-child { border-top: 0; }
.cn-dhk-pic { width: 76px; height: 76px; border-radius: 14px; background: var(--tint-2); display: flex; align-items: center; justify-content: center; }
.cn-dhk-pic canvas { display: block; }
.cn-dhk b { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.cn-dhk b em { font-style: normal; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.cn-dhk p { margin: 2px 0 0; font-size: 14.5px; color: var(--body); line-height: 1.4; }
/* «Понятно» stays in reach while the list scrolls */
.cn-dhelp .cn-sheet-actions { position: sticky; bottom: calc(-20px - env(safe-area-inset-bottom)); margin-bottom: calc(-20px - env(safe-area-inset-bottom)); padding: 12px 0 calc(20px + env(safe-area-inset-bottom)); background: var(--surface); margin-top: 12px; }
.cn-dhelp-how { margin: 12px 0 0; padding: 12px 14px; background: var(--tint-2); border-radius: 14px; font-size: 14.5px; line-height: 1.45; color: var(--body); }

/* «Схема» (SPEC §3.7) */
.cn-dscheme .cn-weave { margin: 0; }
.cn-dscheme .cn-tiles { margin-top: 0; }
.cn-dlength-edit { margin-top: 8px; }

/* ---- result (SPEC §3.12) */
.cn-dresult-cards { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.cn-dres-card {
    background: var(--surface); border-radius: 18px; box-shadow: inset 0 0 0 1px var(--line); padding: 14px; display: flex; flex-direction: column; align-items: center;
    border: 0; font: inherit; color: var(--ink); text-align: left; min-width: 0;
}
button.cn-dres-card { cursor: zoom-in; }
/* sharp() writes the CSS size inline; when max-width shrinks a canvas its height must follow, or knots turn into ellipses */
.cn-dres-card canvas { display: block; max-width: 100%; height: auto !important; }
.cn-dres-cap { align-self: stretch; display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.cn-dres-repeat { display: flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 600; margin-top: 6px; align-self: stretch; }
.cn-dres-repeat .cn-i { width: 16px; height: 16px; }
.cn-dres-repeat.is-ok { color: var(--ok); }
.cn-dres-repeat.is-warn { color: var(--warn); }
.cn-dres-strip-box { width: 100%; overflow: hidden; border-radius: 8px; line-height: 0; }
.cn-dlegend { display: flex; flex-direction: column; gap: 0; min-width: 0; }
.cn-dlegend-inline { margin-top: 20px; }
.cn-dlegend h3 { font-size: 15px; font-weight: 600; font-family: var(--text); letter-spacing: 0; margin: 18px 0 8px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; color: var(--ink); }
.cn-dlegend h3:first-child { margin-top: 0; }
.cn-dlegend h3 span { font-weight: 500; color: var(--muted); font-size: 13px; text-align: right; }
.cn-dthr { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.cn-dthr:first-of-type { border-top: 0; }
.cn-dthr > i { width: 24px; height: 24px; border-radius: 999px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; font-style: normal; flex: none; box-shadow: inset 0 0 0 1px rgba(38, 32, 28, 0.2); }
.cn-dthr b { font-size: 15px; font-weight: 600; display: block; color: var(--ink); }
.cn-dthr span span { font-size: 13.5px; color: var(--muted); }
.cn-dthr-len { margin-left: auto; text-align: right; font-weight: 700; font-size: 15px; white-space: nowrap; }
.cn-dlegend .cn-advice { margin-top: 14px; padding-bottom: 10px; }
.cn-dlegend .cn-advice .cn-linkbtn { min-height: 36px; }
.cn-dknotlegend { display: grid; grid-template-columns: 1fr; gap: 8px 12px; }
.cn-dknotlegend > div { display: flex; gap: 8px; align-items: center; font-size: 13.5px; line-height: 1.25; }
.cn-dknotlegend > div.is-unused { opacity: 0.45; }
.cn-dknotlegend small { display: block; color: var(--muted); font-size: 12px; }
.cn-dknotlegend svg { flex: none; }
.cn-dlegend .cn-legend-foot { margin-top: 12px; }
.cn-dresult .cn-result-side > .cn-dlegend { display: none; }

/* ---- print (SPEC §3.13) */
@media print {
    .cn-print .cn-print-strip { display: block; max-width: 180mm; margin: 0 0 4mm; }
    .cn-print .cn-print-seg { margin: 0 0 6mm; }
}

/* ================================================================ desktop */
@media (min-width: 1000px) {
    .cn-weave .cn-weave-i { display: block; }
    .cn-entry .cn-eyebrow { max-width: 420px; }
    .cn-entry.is-diagonal {
        grid-template-columns: minmax(0, 1fr) 330px; column-gap: 36px;
        grid-template-areas: "eyebrow well" "unreadable well" "bad well" "dcard well" ". well" "my my";
        grid-template-rows: auto auto auto auto 1fr auto;
    }
    .cn-dtiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .cn-dtile { flex-direction: column; align-items: flex-start; height: auto; min-height: 96px; padding: 10px; gap: 8px; }
    .cn-dtile-well { width: 100%; height: 44px; padding-top: 0; align-items: center; }
    .cn-dactions { flex-direction: row; align-items: center; flex-wrap: wrap; }
    .cn-dactions .cn-btn-primary { padding: 0 28px; }
    #cn-dempty { background: transparent; border: 0; color: var(--accent); padding: 0 12px; }
    #cn-dempty:hover { background: var(--tint-2); }
    .cn-dwell { background: var(--tint-2); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 10px; align-self: start; }
    .cn-dwell[hidden] { display: none; }
    .cn-dwell-title { font-size: 12.5px; color: var(--muted); font-weight: 600; align-self: flex-start; }
    .cn-dwell-pics { display: flex; gap: 16px; align-items: flex-start; }
    .cn-dwell-pics canvas { display: block; }
    .cn-dwell-strip { border-radius: 6px; box-shadow: 0 0 0 1px var(--line); }
    .cn-dwell-facts { font-size: 13.5px; color: var(--body); text-align: center; }

    /* studio */
    .cn-dtop-weave { display: block; width: 380px; flex: none; }
    .cn-studio:not(.cn-dstudio) .cn-dtop-weave { width: 340px; }
    .cn-size-weave { display: none; }
    .cn-dstudio .cn-topbar .cn-spacer { flex: 1; }
    .cn-dstudio .cn-topbar .cn-dtop-weave + .cn-top-tools { margin-left: auto; }
    .cn-drail { width: 112px; }
    .cn-drail .cn-dknots { grid-template-columns: 1fr; gap: 4px; }
    .cn-drail .cn-dknot { min-height: 76px; }
    .cn-drail .cn-dknot-cap { font-size: 12px; }
    .cn-drail .cn-tool { width: 100%; height: 60px; font-size: 12px; }
    .cn-dview, .cn-ddock { display: none; }
    .cn-dstage { gap: 48px; padding: 0 24px; }
    .cn-dscroll { flex: 0 1 auto; padding: 8px 8px 40px; }
    .cn-dbelow { padding-left: 30px; padding-right: 10px; }
    .cn-dbig { display: flex; flex-direction: column; align-items: center; gap: 8px; padding-top: 16px; flex: none; }
    .cn-dbig > span { font-size: 12.5px; color: var(--muted); font-weight: 600; }
    .cn-dbig-well { background: var(--surface); border-radius: 14px; padding: 10px 8px; box-shadow: inset 0 0 0 1px var(--line); line-height: 0; }
    .cn-dpanel { background: var(--bg); padding: 20px 24px; }
    .cn-dpanel .cn-dschip { width: 32px; }
    .cn-dpanel .cn-dhint { margin-top: 8px; }
    .cn-dstudio .cn-toast { bottom: 40px; left: calc(50% - 114px); }

    /* the knot card is a popover beside the knot, no scrim */
    .cn-studio .cn-sheet.cn-dcard-sheet.is-pop {
        position: fixed; right: auto; bottom: auto; width: 360px; max-height: none; border-radius: 18px;
        box-shadow: var(--shadow-lg), 0 0 0 1px var(--line); border: 0; padding: 14px 16px 16px; z-index: 50;
    }
    .cn-dcard-sheet.is-pop .cn-sheet-head h2 { font-size: 17px; }
    .cn-dhelp.cn-modal { padding: 22px 28px 24px; }

    .cn-dresult-cards { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 20px; align-items: start; }
    /* the chart decides the card's width; a long repeat note wraps under it */
    .cn-dres-chart { width: fit-content; max-width: 100%; }
    .cn-dresult .cn-result-body { overflow: auto; }
    .cn-dresult .cn-result-side > .cn-dlegend { display: flex; padding: 82px 28px 0; overflow: auto; flex: 0 1 auto; }
    .cn-dlegend-inline { display: none; }
    .cn-dknotlegend { grid-template-columns: 1fr 1fr; }
    .cn-dresult .cn-result-side { width: 420px; }
}
