* { box-sizing: border-box; }
body { margin: 0; font: 13px/1.45 -apple-system, Segoe UI, Roboto, sans-serif; color: #1f324d; background: #f4f6f8; }
header { display: flex; align-items: baseline; gap: 14px; padding: 10px 16px; background: #1f324d; color: #fff; }
header h1 { font-size: 17px; margin: 0; font-weight: 600; }
.universe { font-size: 12px; background: #2e6f95; padding: 2px 8px; border-radius: 10px; }
#sourcewrap { position: relative; }
#source-btn { font-size: 13px; border: 1px solid #3a4a63; background: #2a3b54; color: #fff; cursor: pointer; border-radius: 5px; padding: 5px 11px; }
#source-btn:hover { background: #2e6f95; }
#source-panel { position: absolute; top: 30px; left: 0; z-index: 60; background: #fff; color: #1f324d; border: 1px solid #cdd6dd; border-radius: 7px; box-shadow: 0 8px 28px rgba(0,0,0,.25); padding: 8px 12px; min-width: 230px; }
#source-panel.hidden { display: none; }
#source-panel .srcrow { display: block; font-weight: 600; margin: 6px 0 2px; cursor: pointer; }
#source-panel .srcrow input { margin-right: 6px; }
#source-panel .srcsub { margin: 2px 0 8px 20px; }
#source-panel .srcsub label { font-weight: 400; }
#search { margin-left: 18px; width: 260px; padding: 5px 9px; border: 0; border-radius: 5px; font-size: 13px; }
#layoutctl { margin-left: 12px; display: inline-flex; gap: 2px; }
#layoutctl button { font-size: 14px; line-height: 1; border: 1px solid #3a4a63; background: #2a3b54; color: #cdd6dd; cursor: pointer; border-radius: 4px; padding: 3px 7px; }
#layoutctl button.active { background: #2e6f95; color: #fff; border-color: #2e6f95; }
#layoutctl button[data-mode="bottom"] { transform: rotate(90deg); }
#help-btn { margin-left: 12px; width: 24px; height: 24px; border-radius: 50%; border: 1px solid #3a4a63; background: #2a3b54; color: #fff; cursor: pointer; font-weight: 700; }
#help-btn:hover { background: #2e6f95; }
.count { margin-left: auto; font-size: 12px; opacity: .85; }

#help { position: fixed; inset: 0; background: rgba(20,28,40,.55); display: flex; align-items: center; justify-content: center; z-index: 80; }
#help.hidden { display: none; }
.help-card { background: #fff; border-radius: 10px; width: 88vw; max-width: 760px; max-height: 86vh; overflow: auto; padding: 20px 26px; position: relative; }
.help-card h2 { margin: 0 0 6px; color: #1f324d; }
.help-card h3 { margin: 16px 0 4px; color: #2e6f95; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid #eef2f5; padding-bottom: 3px; }
.help-intro { color: #5b6670; font-size: 13px; margin: 0 0 6px; }
.help-card dl { margin: 0; }
.help-card dt { font-weight: 700; color: #1f324d; margin-top: 7px; }
.help-card dd { margin: 1px 0 0; color: #34404d; font-size: 13px; line-height: 1.5; }
.help-card code { background: #eef2f5; padding: 0 4px; border-radius: 3px; }
#help-close { position: absolute; top: 8px; right: 12px; font-size: 22px; border: 0; background: none; cursor: pointer; color: #5b6670; }

#layout { display: flex; height: calc(100vh - 41px); width: 100%; }
/* docked preview reflows the page so the table stays fully visible */
body.deepopen-right #layout { width: calc(100% - 46vw); }
body.deepopen-bottom #layout { height: calc(100vh - 41px - 48vh); }
#config { width: 290px; overflow-y: auto; padding: 10px 12px; background: #fff; border-right: 1px solid #dde3e8; }
#config h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: #5b6670; margin: 4px 0 10px; }
fieldset { border: 1px solid #e3e8ec; border-radius: 6px; margin: 0 0 10px; padding: 6px 9px 9px; }
legend { font-size: 11px; font-weight: 600; color: #2e6f95; text-transform: uppercase; letter-spacing: .03em; cursor: pointer; user-select: none; }
legend::before { content: "\25be "; font-size: 9px; }
fieldset.collapsed legend::before { content: "\25b8 "; }
fieldset.collapsed > *:not(legend) { display: none; }
#config h2 { cursor: pointer; user-select: none; }
#config h2::before { content: "\25be "; font-size: 10px; }
#config.allcollapsed h2::before { content: "\25b8 "; }
#config.allcollapsed fieldset, #config.allcollapsed button { display: none; }
.row { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
.row label { width: 74px; color: #5b6670; }
.row input[type=number] { width: 70px; }
.row input[type=range] { flex: 1; }
.row span { width: 34px; text-align: right; font-variant-numeric: tabular-nums; color: #1f324d; }
.chk { display: block; margin: 4px 0; cursor: pointer; }
select { width: 100%; margin: 4px 0; padding: 3px; }
.letters { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.letters label { background: #eef2f5; border-radius: 4px; padding: 2px 7px; cursor: pointer; }
.letters input { margin-right: 3px; }
#motif_filter { max-height: 150px; overflow-y: auto; margin-top: 4px; border-top: 1px solid #eee; padding-top: 4px; }
#motif_filter label { display: block; font-size: 12px; cursor: pointer; }
#reset { width: 100%; padding: 6px; background: #2e6f95; color: #fff; border: 0; border-radius: 5px; cursor: pointer; }

#results { flex: 1; overflow: auto; }
table { border-collapse: collapse; width: 100%; background: #fff; }
th, td { padding: 4px 8px; text-align: left; border-bottom: 1px solid #eef2f5; white-space: nowrap; }
th { position: sticky; top: 0; background: #f0f3f6; cursor: pointer; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: #5b6670; }
th.sorted::after { content: " \25be"; }
th.asc::after { content: " \25b4"; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #eaf3f8; }
.bar { display: inline-block; height: 9px; border-radius: 2px; vertical-align: middle; }
.pill { font-size: 10px; padding: 1px 5px; border-radius: 8px; color: #fff; }
.motif-chip { font-size: 10px; padding: 0 4px; border-radius: 3px; color: #fff; margin-right: 2px; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

#deep.hidden { display: none !important; }
/* modal (default) */
#deep.mode-modal { position: fixed; inset: 0; background: rgba(20,28,40,.55); display: flex; align-items: center; justify-content: center; z-index: 50; }
#deep.mode-modal .deep-card { width: 92vw; max-width: 1150px; height: 88vh; border-radius: 8px; }
/* dock right */
#deep.mode-right { position: fixed; top: 41px; right: 0; bottom: 0; width: 46vw; z-index: 50; }
#deep.mode-right .deep-card { width: 100%; height: 100%; border-radius: 0; box-shadow: -4px 0 24px rgba(0,0,0,.25); }
/* dock bottom */
#deep.mode-bottom { position: fixed; left: 0; right: 0; bottom: 0; height: 48vh; z-index: 50; }
#deep.mode-bottom .deep-card { width: 100%; height: 100%; border-radius: 0; box-shadow: 0 -4px 24px rgba(0,0,0,.25); }
#deep.mode-right .deep-body, #deep.mode-bottom .deep-body { grid-template-columns: 1fr; }
#deep.mode-right #viewer3d, #deep.mode-bottom #viewer3d { grid-row: auto; height: 300px; }
.deep-card { background: #fff; padding: 14px 18px; position: relative; overflow: auto; }
.deep-tools { position: absolute; top: 8px; right: 10px; display: flex; gap: 2px; z-index: 2; }
.deep-tools button { font-size: 16px; line-height: 1; border: 1px solid #dde3e8; background: #f4f6f8; cursor: pointer; color: #5b6670; border-radius: 4px; padding: 3px 7px; }
.deep-tools button:hover { background: #eaf3f8; }
.deep-tools button[data-mode="bottom"] { transform: rotate(90deg); }
#deep-close { font-size: 18px; }
#deep-export { font-size: 12px; padding: 4px 10px; font-weight: 600; color: #2e6f95; }
#deep-export:hover { background: #2e6f95; color: #fff; border-color: #2e6f95; }
#deep-title { margin: 0 0 8px; font-size: 16px; }
.deep-body { display: grid; grid-template-columns: 1.1fr 1fr; grid-template-rows: auto auto; gap: 12px; }
#viewer3d { position: relative; width: 100%; height: 420px; background: #0d1117; border-radius: 6px; grid-row: span 2; }
#tracks { width: 100%; overflow-x: auto; }
#props { font-size: 12px; }
#props table { width: 100%; }
#props td { white-space: normal; }
.muted { color: #8a96a0; }

#gate { position: fixed; inset: 0; background: #1f324d; display: flex; align-items: center; justify-content: center; z-index: 100; }
#gate.hidden { display: none; }
.gate-card { background: #fff; padding: 30px 34px; border-radius: 10px; width: 320px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.gate-card h2 { margin: 0 0 2px; font-size: 18px; color: #1f324d; }
.gate-sub { margin: 0 0 14px; color: #5b6670; font-size: 13px; }
.gate-card input { width: 100%; padding: 9px; border: 1px solid #cdd6dd; border-radius: 5px; font-size: 14px; }
.gate-card button { width: 100%; padding: 9px; margin-top: 10px; background: #2e6f95; color: #fff; border: 0; border-radius: 5px; cursor: pointer; font-size: 14px; }
.gate-err { color: #c0504d; min-height: 1em; margin: 10px 0 0; font-size: 12px; }
