/* Layout: the whole framework as a block diagram (function bands > category blocks > subcategory tiles).
   Selecting a tile draws its relationships across the diagram and opens the detail panel on the right. */
:root {
  --bg: #f2f4f8; --surface: #ffffff; --sunken: #e8ecf2; --ink: #152033; --muted: #56637a;
  --line: #d3dae5; --accent: #2c49c9; --accent-soft: #e3e8fb;
  --up: #b45309; --up-soft: #fbead3; --down: #2c49c9; --down-soft: #e3e8fb;
  --t1: #c9382c; --t2: #c98a12; --t3: #2b78c2; --t4: #23895a; --t0: #8793a6;
  --chip-ink: #17202e;
  --display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --body: "Inter", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0f141c; --surface: #18202c; --sunken: #121923; --ink: #e5eaf2; --muted: #98a4b6;
  --line: #2b3647; --accent: #93a6ff; --accent-soft: #232d52;
  --up: #f0a55a; --up-soft: #3a2a17; --down: #93a6ff; --down-soft: #232d52;
  --t1: #f0776c; --t2: #e6b04a; --t3: #6cb0f0; --t4: #5fc795; --t0: #6f7b8e;
  color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #0f141c; --surface: #18202c; --sunken: #121923; --ink: #e5eaf2; --muted: #98a4b6;
  --line: #2b3647; --accent: #93a6ff; --accent-soft: #232d52;
  --up: #f0a55a; --up-soft: #3a2a17; --down: #93a6ff; --down-soft: #232d52;
  --t1: #f0776c; --t2: #e6b04a; --t3: #6cb0f0; --t4: #5fc795; --t0: #6f7b8e;
  color-scheme: dark }

* { box-sizing: border-box }
[hidden] { display: none !important }
html { -webkit-text-size-adjust: 100% }
img { max-width: 100% }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 14px; line-height: 1.45 }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: left }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px }
h1, h2, h3 { font-family: var(--display); margin: 0; text-wrap: balance }

.app { max-width: 1560px; margin: 0 auto; padding-block: 18px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 14px }

/* ---- header and toolbar */
.top { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: baseline; justify-content: space-between }
.top h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.01em }
.top p { margin: 0; color: var(--muted); font-size: 13px }
.notice { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
  background: var(--accent-soft); border-radius: 6px; padding: 8px 12px; font-size: 13px }
.notice button, .linkbtn { color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px }
.bar { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center }
#search { flex: 1 1 220px; max-width: 340px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 6px; overflow: hidden }
.seg button { padding: 5px 11px; font-size: 12.5px; border-right: 1px solid var(--line); background: var(--surface) }
.seg button:last-child { border-right: 0 }
.seg button:hover { background: var(--sunken) }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); font-weight: 600 }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12px; color: var(--muted); margin: 0; padding: 0; list-style: none }
.legend li { display: flex; align-items: center; gap: 6px }
.key { width: 14px; height: 14px; border-radius: 3px; border: 2px solid; flex: none }
.key.up { border-color: var(--up); background: var(--up-soft) } .key.down { border-color: var(--down); background: var(--down-soft) }
.legend svg { flex: none } .legend path { stroke: var(--muted); fill: none; stroke-width: 1.5 }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 370px; gap: 18px; align-items: start }

/* ---- block diagram */
.diagram { position: relative; display: flex; flex-direction: column; gap: 10px; min-width: 0 }
#links { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; z-index: 3 }
#links path { fill: none; stroke-width: 1.6; stroke-linecap: round }
#links .up { stroke: var(--up) } #links .down { stroke: var(--down) }
#links polygon.up { fill: var(--up) } #links polygon.down { fill: var(--down) }
#links .S { stroke-dasharray: 6 4 } #links .F { stroke-dasharray: 1.5 4.5 }
#links .far { opacity: .45 }
.band { display: grid; grid-template-columns: 34px minmax(0, 1fr); border: 1px solid var(--line); border-radius: 8px; background: var(--surface); overflow: hidden }
.band-label { display: flex; align-items: center; justify-content: center; color: var(--chip-ink); font-family: var(--display); font-weight: 600; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; writing-mode: vertical-rl; transform: rotate(180deg); padding: 8px 0 }
.cats { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; min-width: 0 }
.catbox { flex: 1 1 auto; min-width: 150px; border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px 8px; display: flex; flex-direction: column; gap: 6px; background: var(--bg) }
.cat-title { display: flex; gap: 6px; align-items: baseline; font-size: 12px; font-weight: 600; line-height: 1.25 }
.cat-title .cid { font-family: var(--mono); color: var(--muted); flex: none }
.tiles { display: flex; flex-wrap: wrap; gap: 5px }
.tile { display: inline-flex; align-items: center; gap: 5px; border: 1.5px solid var(--line); border-radius: 5px; background: var(--surface); padding: 4px 6px 4px 5px; font-family: var(--mono); font-size: 11.5px; font-weight: 600; white-space: nowrap; position: relative }
.tile:hover { border-color: var(--ink) }
.tile i { width: 8px; height: 8px; border-radius: 2px; background: var(--c, transparent); border: 1px solid var(--c, var(--t0)); flex: none }
.tile[data-t="1"] { --c: var(--t1) } .tile[data-t="2"] { --c: var(--t2) } .tile[data-t="3"] { --c: var(--t3) } .tile[data-t="4"] { --c: var(--t4) }
.diagram.has-sel .tile, .diagram.has-find .tile { opacity: .32 }
.diagram .tile.sel, .diagram .tile.up, .diagram .tile.down, .diagram .tile.hit { opacity: 1 }
.tile.up { border-color: var(--up); background: var(--up-soft) }
.tile.down { border-color: var(--down); background: var(--down-soft) }
.tile.up.down { background: linear-gradient(90deg, var(--up-soft) 50%, var(--down-soft) 50%); border-color: var(--up) var(--down) var(--down) var(--up) }
.tile.far { border-style: dashed }
.tile.sel { background: var(--ink); color: var(--surface); border-color: var(--ink); z-index: 4 }
.tile.hit { border-color: var(--ink) }

/* ---- detail panel */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0;
  position: sticky; top: calc(env(safe-area-inset-top, 0px) + 12px); max-height: calc(100vh - 24px); overflow-y: auto }
.panel h2 { font-size: 16px; font-weight: 600; line-height: 1.3 }
.panel h2 .hid { display: block; font-family: var(--mono); color: var(--accent); font-size: 15px; margin-bottom: 2px }
.panel h3 { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-family: var(--body) }
.panel p { margin: 0; font-size: 13px }
.panel .hint { color: var(--muted) }
.crumb { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12.5px }
.fnchip { display: inline-block; border-radius: 3px; padding: 1px 7px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--chip-ink) }
.ctl { display: flex; flex-direction: column; gap: 5px }
.ctl .seg { align-self: flex-start } .ctl .seg button { padding: 4px 11px }
.verdict { padding: 9px 11px; border-radius: 6px; background: var(--sunken) }
.idlink { font-family: var(--mono); font-weight: 600; color: var(--accent); text-decoration: underline; text-underline-offset: 3px }
.sect { display: flex; flex-direction: column; gap: 4px }
.sect h3 { display: flex; align-items: center; gap: 6px }
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column }
.row { width: 100%; display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 2px 8px; padding: 7px 4px; border-top: 1px solid var(--line); font-size: 12.5px }
.row:hover { background: var(--sunken) }
.row .head { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline }
.row .sid { font-family: var(--mono); font-weight: 600 }
.row .art { font-weight: 600 }
.row .stx { grid-column: 2; color: var(--muted) }
.rel { font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted) }
.tag { font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; border-radius: 3px; padding: 1px 6px; white-space: nowrap; background: var(--sunken); color: var(--muted) }
.tag.block { background: color-mix(in srgb, var(--t1) 20%, var(--surface)); color: var(--ink) }
.tag.weak { background: color-mix(in srgb, var(--t2) 22%, var(--surface)); color: var(--ink) }
.tier { --c: var(--t0); display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border: 1px solid var(--c); border-radius: 4px; font-size: 11px; font-weight: 600;
  background: color-mix(in srgb, var(--c) 16%, var(--surface)); font-variant-numeric: tabular-nums }
.tier[data-t="1"] { --c: var(--t1) } .tier[data-t="2"] { --c: var(--t2) } .tier[data-t="3"] { --c: var(--t3) } .tier[data-t="4"] { --c: var(--t4) }
.tier[data-t="0"] { border-style: dashed; color: var(--muted); background: none }
.none { color: var(--muted); font-size: 13px; padding: 6px 4px; border-top: 1px solid var(--line) }
.more > summary { cursor: pointer; color: var(--muted); font-size: 12.5px; padding: 6px 4px; border-top: 1px solid var(--line) }
.tierkey { display: flex; flex-wrap: wrap; gap: 4px 12px; list-style: none; margin: 0; padding: 0; font-size: 12.5px }
.tierkey li { display: flex; align-items: center; gap: 6px }
footer { color: var(--muted); font-size: 12px; max-width: 90ch }

@media (max-width: 1080px) {
  .layout { grid-template-columns: minmax(0, 1fr) }
  .panel { position: static; max-height: none }
}
@media (max-width: 520px) { .band { grid-template-columns: 26px minmax(0, 1fr) } .cats { padding: 6px; gap: 6px } .catbox { min-width: 100% } }
@media (prefers-reduced-motion: no-preference) { .tile { transition: opacity .15s, background-color .15s, border-color .15s } }

/* ---- assessment bar */
.assess { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; font-size: 13px }
.assess label { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted) }
.assess select, .assess input, .login input { padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit }
.btn { padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); font-size: 13px; font-weight: 500 }
.btn:hover { background: var(--sunken) }
.btn.primary { background: var(--ink); color: var(--surface); border-color: var(--ink) }
.btn.danger { color: var(--t1) }
#newForm { display: flex; flex-wrap: wrap; gap: 8px; align-items: center }
.error { background: color-mix(in srgb, var(--t1) 16%, var(--surface)); border: 1px solid var(--t1); border-radius: 6px; padding: 8px 12px; font-size: 13px }

/* ---- sign-in */
.login-wrap { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: color-mix(in srgb, var(--bg) 88%, transparent) }
.login { width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 24px; display: flex; flex-direction: column; gap: 12px }
.login h2 { font-size: 18px }
.login p { margin: 0; color: var(--muted); font-size: 13px }
.login .msg { color: var(--t1) }
