/* TSI EDIT — synthwave terminal theme */

:root {
  --bg:        #0a0612;
  --bg-panel:  #140a26;
  --bg-panel2: #1b1033;
  --bg-deep:   #06030d;
  --magenta:   #ff2e97;
  --cyan:      #05d9e8;
  --violet:    #b14aed;
  --amber:     #ffd166;
  --lime:      #7CFFB2;
  --text:      #e8e0ff;
  --text-dim:  #8b7fb0;
  --grid:      rgba(177, 74, 237, 0.10);
  --scan:      rgba(0, 0, 0, 0.28);

  /* ROM section accents */
  --sec-vector: var(--cyan);
  --sec-phone:  var(--magenta);
  --sec-audio:  var(--violet);

  --mono: 'VT323', 'IBM Plex Mono', monospace;
  --pixel: 'Press Start 2P', monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 27px;
  letter-spacing: .3px;
}

/* atmospheric background: perspective grid + radial glow */
body {
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(255,46,151,.18), transparent 60%),
    radial-gradient(ellipse 70% 50% at 90% 110%, rgba(5,217,232,.14), transparent 60%),
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 40px 40px,
    var(--bg);
}

/* CRT scanline overlay */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom, transparent 0, transparent 2px, var(--scan) 3px, transparent 4px);
  mix-blend-mode: multiply;
  z-index: 9999;
}

a { color: var(--cyan); }

/* ---------------------------------------------------------------- header */
header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 22px;
  border-bottom: 2px solid var(--magenta);
  background: linear-gradient(180deg, var(--bg-panel) 0%, transparent 100%);
  box-shadow: 0 0 24px rgba(255,46,151,.25);
  flex-wrap: wrap;
}

.logo {
  font-family: var(--pixel);
  font-size: 26px;
  color: var(--magenta);
  text-shadow: 0 0 8px var(--magenta), 3px 3px 0 var(--violet);
  white-space: nowrap;
}
.logo .v { color: var(--cyan); text-shadow: 0 0 8px var(--cyan); }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar label { margin-left: 6px; }
.toolbar label:first-child { margin-left: 0; }
/* keep the action buttons together (they wrap as one unit, not individually) */
.btn-group { display: inline-flex; align-items: center; gap: 8px; }
/* keep a toolbar label and its control glued together so they wrap as a pair */
.tb-group { display: inline-flex; align-items: center; gap: 8px; }
.tb-group label { margin-left: 0; }
.toolbar label { color: var(--cyan); text-transform: uppercase; font-size: 24px; letter-spacing: 1px; }
.toolbar label.file-btn { color: var(--cyan); }

select, input[type="text"], input[type="number"], button, .file-btn {
  font-family: var(--mono);
  font-size: 24px;
  background: var(--bg-deep);
  color: var(--text);
  border: 1px solid var(--violet);
  padding: 5px 12px;
  outline: none;
  border-radius: 2px;
}
select:focus, input:focus { border-color: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
select { -webkit-appearance: none; appearance: none; padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 50%, var(--cyan) 50%), linear-gradient(135deg, var(--cyan) 50%, transparent 50%);
  background-position: right 11px center, right 6px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
select option { background: var(--bg-panel); color: var(--text); font-family: var(--mono); }

button, .file-btn {
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-color: var(--cyan);
  color: var(--cyan);
  transition: all .12s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
  height: 38px;
  white-space: nowrap;
}
select { height: 38px; }
button:hover, .file-btn:hover {
  background: var(--cyan);
  color: var(--bg);
  box-shadow: 0 0 14px var(--cyan);
}
button.primary { border-color: var(--magenta); color: var(--magenta); }
button.primary:hover { background: var(--magenta); color: var(--bg); box-shadow: 0 0 14px var(--magenta); }
button:disabled { opacity: .35; cursor: not-allowed; box-shadow: none; background: var(--bg-deep); color: var(--text-dim); }

.spacer { flex: 1; }


/* themed slide toggle (focus mode) */
.toggle-wrap { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
.toggle-label { font-family: var(--mono); font-size: 20px; color: var(--text-dim); letter-spacing: 1px; }
.switch { position: relative; display: inline-block; width: 46px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; cursor: pointer; background: var(--bg-deep); border: 1px solid var(--violet); border-radius: 22px; transition: .2s; }
.slider:before { content: ""; position: absolute; height: 14px; width: 14px; left: 3px; top: 3px; background: var(--text-dim); border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { border-color: var(--cyan); box-shadow: 0 0 10px var(--cyan); }
.switch input:checked + .slider:before { transform: translateX(23px); background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }

.phone-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 7px; vertical-align: middle; box-shadow: 0 0 6px currentColor; }

/* themed custom dropdown (replaces native <select> look) */
.dd { position: relative; display: inline-block; }
.dd-native { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dd-btn {
  font-family: var(--mono); font-size: 24px; height: 38px;
  background: var(--bg-deep); color: var(--text);
  border: 1px solid var(--violet); border-radius: 2px;
  padding: 0 30px 0 12px; min-width: 118px;
  display: inline-flex; align-items: center; cursor: pointer; position: relative;
}
.dd-btn:hover { border-color: var(--cyan); }
.dd.open .dd-btn { border-color: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.dd-val { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-arrow {
  position: absolute; right: 11px; top: 50%; transform: translateY(-50%);
  width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-top: 6px solid var(--cyan); transition: transform .15s;
}
.dd.open .dd-arrow { transform: translateY(-50%) rotate(180deg); }
.dd-list {
  position: absolute; top: calc(100% + 4px); left: 0; min-width: 100%;
  max-height: 280px; overflow-y: auto; display: none; z-index: 50;
  background: var(--bg-panel); border: 1px solid var(--cyan); border-radius: 3px;
  box-shadow: 0 8px 26px rgba(0,0,0,.65), 0 0 14px rgba(5,217,232,.3);
}
.dd.open .dd-list { display: block; }
.dd-item { padding: 6px 14px; font-size: 23px; color: var(--text); cursor: pointer; white-space: nowrap; }
.dd-item:hover { background: rgba(5,217,232,.15); color: var(--cyan); }
.dd-item.sel { background: rgba(255,46,151,.18); color: var(--magenta); text-shadow: 0 0 6px var(--magenta); }

.incomplete-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 26px;
  line-height: 1.4;
  color: var(--bg);
  background: var(--amber);
  border: 1px solid var(--amber);
  border-radius: 2px;
  padding: 8px 14px;
  margin: 0 0 8px;
}
.incomplete-banner b { color: var(--magenta); }
.incomplete-banner .warn-icon { flex: none; font-size: 56px; line-height: 1; }
.incomplete-banner[hidden] { display: none; }

/* ---------------------------------------------------------------- layout */
main {
  display: grid;
  grid-template-columns: minmax(166px, 200px) max-content 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 14px;
  padding: 14px;
  height: calc(100vh - 70px);
  min-height: 0;
}
.panel {
  background: linear-gradient(160deg, var(--bg-panel) 0%, var(--bg-deep) 100%);
  border: 1px solid var(--violet);
  border-radius: 4px;
  box-shadow: inset 0 0 30px rgba(177,74,237,.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel > h2 {
  margin: 0;
  padding: 11px 16px;
  font-family: var(--pixel);
  font-size: 19px;
  line-height: 1.3;
  letter-spacing: 1px;
  color: var(--violet);
  border-bottom: 1px solid rgba(177,74,237,.4);
  text-transform: uppercase;
  background: rgba(177,74,237,.08);
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 0 8px rgba(177,74,237,.5);
}
/* the title span (e.g. "WAVEFORM: HELP") shrinks and ellipsizes so the
   right-side header buttons (▶ play, + phone, focus toggle) stay visible
   instead of being pushed past the panel's clipped edge on narrow screens */
.panel > h2 > [id$="-title"] {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.panel > h2 > .hdr-btns,
.panel > h2 > .toggle-wrap { flex: 0 0 auto; }

.panel .body { overflow: auto; padding: 10px 14px; flex: 1; min-height: 0; }

#word-panel { grid-row: 1 / span 2; }
#word-panel .body { padding: 8px 6px; }
#hex-panel  { grid-column: 2; grid-row: 1 / span 2; max-width: 100%; }
#wave-panel { grid-column: 3; grid-row: 1; }
#chunk-panel{ grid-column: 3; grid-row: 2; }

/* ---------------------------------------------------------------- word list */
.word { padding: 0 6px; line-height: 1.25; cursor: pointer; border-left: 3px solid transparent; display: flex; gap: 6px; align-items: baseline; }
.word:hover { background: rgba(5,217,232,.08); }
.word.sel { background: rgba(255,46,151,.16); border-left-color: var(--magenta); }
.word .id { color: var(--text-dim); font-size: 18px; min-width: 24px; text-align: right; }
.word .nm { color: var(--text); }
.word.sel .nm { color: var(--magenta); text-shadow: 0 0 6px var(--magenta); }

/* ---------------------------------------------------------------- hex view */
#hex-body { position: relative; padding: 0; scrollbar-gutter: stable; }

/* themed scrollbars so the gutter doesn't overlap content */
.body::-webkit-scrollbar, #hex-body::-webkit-scrollbar { width: 10px; height: 10px; }
.body::-webkit-scrollbar-track, #hex-body::-webkit-scrollbar-track { background: var(--bg-deep); }
.body::-webkit-scrollbar-thumb, #hex-body::-webkit-scrollbar-thumb { background: var(--violet); border-radius: 6px; border: 2px solid var(--bg-deep); }
.body::-webkit-scrollbar-thumb:hover, #hex-body::-webkit-scrollbar-thumb:hover { background: var(--magenta); }
.hex-head {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  gap: 14px;
  /* size to the content (the 16 byte columns) so the header scrolls in sync
     with the rows below and its labels never wrap on narrow screens */
  width: max-content;
  min-width: 100%;
  white-space: nowrap;
  padding: 6px 14px 5px;
  font-size: 21px;
  background: linear-gradient(180deg, var(--bg-deep), var(--bg-panel));
  border-bottom: 1px solid var(--violet);
  box-shadow: 0 4px 10px rgba(0,0,0,.5);
}
.hex-head .addr { color: var(--cyan); }
.hex-head .hexbytes b { display: inline-block; width: 1.6em; text-align: center; color: var(--amber); font-weight: normal; }
#hex-wrap { position: relative; padding: 22px 28px 16px 14px; display: inline-block; min-width: 100%; }
#hex-overlay { position: absolute; top: 0; left: 0; pointer-events: none; overflow: visible; }

#hex { font-size: 21px; line-height: 1.5; white-space: pre; }
.hexrow { display: flex; gap: 14px; }
.hexrow .addr { color: var(--text-dim); }
.hexrow.ellipsis { color: var(--text-dim); opacity: .55; font-style: italic; padding: 2px 0; }
.hexbytes b { display: inline-block; width: 1.6em; text-align: center; color: var(--text); font-weight: normal; }
.sec-vector { color: var(--sec-vector) !important; }
.sec-phone  { color: var(--sec-phone)  !important; }
.sec-audio  { color: var(--sec-audio)  !important; }
.hl { background: var(--magenta); color: var(--bg) !important; border-radius: 2px; box-shadow: 0 0 8px var(--magenta); }
.hl-vec  { background: var(--cyan);   color: var(--bg) !important; box-shadow: 0 0 8px var(--cyan); }
.hl-phone{ background: var(--magenta);color: var(--bg) !important; box-shadow: 0 0 8px var(--magenta); }
.hl-audio{ background: var(--violet); color: var(--bg) !important; box-shadow: 0 0 8px var(--violet); }

.legend { display: flex; gap: 16px; padding: 7px 14px; font-size: 19px; border-bottom: 1px solid rgba(177,74,237,.3); }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; display: inline-block; border-radius: 2px; }

/* ---------------------------------------------------------------- waveform */
.wave-wrap { flex: 1; position: relative; min-height: 0; overflow: hidden; }
#wave { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }

/* ---------------------------------------------------------------- chunks */
.chunk {
  border: 1px solid var(--magenta);
  border-radius: 3px;
  padding: 6px 10px;
  margin-bottom: 8px;
  background: rgba(255,46,151,.06);
}
.chunk h3 { margin: 0 0 5px; font-size: 23px; color: var(--magenta); font-family: var(--mono); letter-spacing: 1px; display: flex; align-items: center; }
.chunk .flags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 18px; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--violet); color: var(--text-dim); }

.pd-ovf { margin-left: auto; font-size: 14px; color: var(--bg); background: var(--magenta); padding: 0 7px; border-radius: 9px; }
.phone-diagram { width: 100%; max-width: 430px; height: auto; display: block; margin-top: 2px; }
.phone-diagram text { font-family: var(--mono); }
.pd-hex { font-size: 15px; fill: #cfc6ef; letter-spacing: .5px; }
.pd-dec { font-size: 13px; fill: var(--text-dim); }
.pd-bit { font-size: 16px; text-anchor: middle; font-weight: bold; }
.pd-bidx { font-size: 11px; fill: #6f6597; text-anchor: middle; }
.pd-lab { font-size: 13px; text-anchor: middle; font-weight: bold; letter-spacing: .3px; }
.tag.on { color: var(--bg); background: var(--lime); border-color: var(--lime); }
.tag.mir.on { background: var(--cyan); border-color: var(--cyan); }
.tag.sil.on { background: var(--amber); border-color: var(--amber); }
.tag.ovf.on { background: var(--magenta); border-color: var(--magenta); color: var(--bg); animation: pulse 1s infinite; }

.chunk.ovf { border-color: var(--magenta); box-shadow: 0 0 12px rgba(255,46,151,.5); }
.ovf-banner {
  border: 1px solid var(--magenta);
  background: rgba(255,46,151,.14);
  color: var(--magenta);
  padding: 6px 10px;
  border-radius: 3px;
  margin-bottom: 8px;
  font-weight: bold;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

/* ---------------------------------------------------------------- panel header button */
.hdr-btns { margin-left: auto; display: inline-flex; gap: 6px; flex: 0 0 auto; }
.hdr-btn {
  font-family: var(--mono);
  font-size: 21px;
  height: 32px;
  padding: 0 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.hdr-btn.danger { border-color: var(--magenta); color: var(--magenta); }
.hdr-btn.danger:hover { background: var(--magenta); color: var(--bg); box-shadow: 0 0 14px var(--magenta); }
.hdr-btn .hdr-ico {
  width: 1.15em; height: 1.15em; flex: 0 0 auto; margin-right: 7px;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
/* icon-only header buttons in the word list, where horizontal space is tight:
   shrink the pixel title and the buttons so all three fit on one row */
.hdr-btn.hdr-icon { padding: 0 5px; height: 28px; }
.hdr-btn.hdr-icon .hdr-ico { margin-right: 0; width: 1em; height: 1em; }
#word-panel > h2 { font-size: 14px; padding: 11px 10px; gap: 5px; }
#word-panel .hdr-btns { gap: 3px; }
#word-panel .hdr-btn.hdr-icon { font-size: 18px; }

/* ---------------------------------------------------------------- word props modal */
.wp-modal { width: min(680px, 94vw); }
.wp-grid { display: flex; gap: 22px; flex-wrap: wrap; margin-bottom: 16px; }
.wp-grid label { display: flex; flex-direction: column; gap: 5px; color: var(--cyan); text-transform: uppercase; font-size: 18px; letter-spacing: 1px; }
.wp-grid #wp-name { width: 320px; max-width: 60vw; }
.wp-grid #wp-pos { width: 110px; }

.wp-info {
  border: 1px solid var(--violet);
  border-radius: 4px;
  background: rgba(177,74,237,.06);
  padding: 10px 14px;
  margin-bottom: 16px;
}
.wp-row { display: flex; gap: 12px; align-items: baseline; padding: 2px 0; font-size: 19px; }
.wp-row .wp-k { color: var(--text-dim); min-width: 96px; font-size: 16px; letter-spacing: 1px; }
.wp-row .wp-v { color: var(--text); }
.wp-seqrow { align-items: flex-start; }
.wp-seq { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.wp-pb { color: var(--amber); }
.wp-pb.wp-fl { color: var(--magenta); }
.wp-sep { color: var(--text-dim); opacity: .5; margin: 0 2px; }

.wp-preview { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.wp-col {
  flex: 1; min-width: 160px;
  border: 1px solid rgba(177,74,237,.4);
  border-radius: 4px;
  background: var(--bg-deep);
  padding: 6px 8px;
}
.wp-coltitle { font-size: 15px; color: var(--cyan); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 5px; }
.wp-arrow { color: var(--magenta); font-size: 26px; flex: 0 0 auto; text-shadow: 0 0 8px var(--magenta); }
.wp-mw { display: flex; gap: 8px; align-items: baseline; padding: 1px 4px; border-left: 3px solid transparent; }
.wp-mw .wp-mi { color: var(--text-dim); font-size: 16px; min-width: 26px; text-align: right; }
.wp-mw .wp-mn { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wp-mw.cur { background: rgba(255,46,151,.16); border-left-color: var(--magenta); }
.wp-mw.cur .wp-mn { color: var(--magenta); text-shadow: 0 0 6px var(--magenta); }
.wp-ell { color: var(--text-dim); opacity: .5; text-align: center; line-height: 1; }
.wp-same { color: var(--text-dim); font-size: 16px; padding: 8px 4px; }
.wp-note { color: var(--text-dim); font-size: 18px; }
.wp-mw-ph { opacity: .35; }
.wp-mw-ph .wp-mi, .wp-mw-ph .wp-mn { color: var(--text-dim); }
.wp-col-wide { flex: 1 1 100%; }
.wp-pos-btns { margin-left: auto; display: inline-flex; gap: 4px; align-self: center; flex: 0 0 auto; }
.wp-mw .wp-pos-btns .cp-obtn { background: var(--bg); color: var(--cyan); border-color: var(--bg); }
.wp-mw .wp-pos-btns .cp-obtn:hover:not(:disabled) { background: var(--bg-deep); color: #fff; box-shadow: none; }
.wp-mw .wp-pos-btns .cp-obtn:disabled { opacity: .45; }

/* copy a word from another rom (button in the add-word overlay) */
.wp-copy-btn { align-self: flex-end; font-size: 18px; height: 36px; }
.wp-copy-btn[hidden] { display: none; }
#wp-status.ok { color: var(--cyan); }

/* ---------------------------------------------------------------- copy picker */
.modal.cp-modal { width: min(820px, 95vw); }
.cp-pickers { display: flex; gap: 22px; flex-wrap: wrap; margin-bottom: 14px; }
.cp-pickers label { display: flex; align-items: center; gap: 8px; color: var(--cyan); text-transform: uppercase; font-size: 18px; letter-spacing: 1px; }
.cp-wave-wrap {
  position: relative; height: 170px;
  border: 1px solid var(--violet); border-radius: 4px;
  background: var(--bg-deep); overflow: hidden;
  box-shadow: inset 0 0 24px rgba(177,74,237,.10);
}
#cp-wave { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cp-phonepick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.cp-pbtn { font-size: 18px; height: 30px; padding: 0 12px; }
.cp-pbtn.sel { color: var(--bg); font-weight: bold; }
.cp-status { min-height: 22px; margin-top: 8px; font-size: 18px; color: var(--text-dim); }
.cp-status.ok { color: var(--cyan); }

/* add-phone: source-kind toggle + clickable insert-position list */
.cp-mode:not([hidden]) { display: flex; gap: 22px; margin-bottom: 14px; }
.cp-radio { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 18px; cursor: pointer; }
.cp-radio input[type="radio"] { width: 18px; height: 18px; accent-color: var(--cyan); cursor: pointer; }
#cp-src[hidden] { display: none; }
.cp-pos-wrap { margin-top: 14px; }
.cp-pos-head { font-size: 16px; color: var(--cyan); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px; }
.cp-pos {
  border: 1px solid rgba(177,74,237,.4); border-radius: 4px;
  background: var(--bg-deep); padding: 4px; max-height: 230px; overflow-y: auto;
}
.cp-prow { display: flex; align-items: center; gap: 8px; padding: 6px 8px; font-size: 18px; color: var(--text); }
.cp-prow .cp-pdot { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 auto; }
.cp-prow .cp-pf { color: var(--text-dim); font-size: 16px; }
.cp-prow.cp-new {
  background: var(--cyan); color: var(--bg); border-radius: 3px;
  font-weight: bold; letter-spacing: 1px; margin: 2px 0;
}
.cp-new-btns { margin-left: auto; display: inline-flex; gap: 4px; }
.cp-obtn { font-size: 14px; height: 26px; padding: 0 9px; line-height: 1; }
.cp-prow.cp-new .cp-obtn { background: var(--bg); color: var(--cyan); border-color: var(--bg); }
.cp-prow.cp-new .cp-obtn:hover:not(:disabled) { background: var(--bg-deep); color: #fff; box-shadow: none; }
.cp-prow.cp-new .cp-obtn:disabled { opacity: .45; }

/* ---------------------------------------------------------------- upload modal */
.modal.up-modal { width: min(500px, 94vw); }
.up-intro { color: var(--text-dim); font-size: 21px; line-height: 1.3; margin: 0 0 4px; }
.up-intro b { color: var(--cyan); }
.up-bullets { padding-left: 1.4em; margin: 0 0 8px; }
.up-slot {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--violet); border-radius: 4px;
  background: rgba(177,74,237,.06);
  padding: 7px 14px; margin-bottom: 6px;
}
.up-slot.disabled { opacity: .4; }
.up-role {
  display: flex; flex-direction: column; gap: 2px;
  color: var(--cyan); font-size: 22px; letter-spacing: 1px;
  min-width: 76px; flex: 0 0 auto;
}
.up-role .up-hint { color: var(--text-dim); font-size: 16px; letter-spacing: 1px; }
.up-pick { font-size: 18px; height: 34px; flex: 0 0 auto; }
.up-file {
  color: var(--text); font-family: var(--mono); font-size: 21px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 auto;
}
#name-input { flex: 1 1 auto; font-size: 21px; }
.up-summary { min-height: 24px; font-size: 19px; color: var(--text-dim); margin-top: 4px; }
.up-summary.ok { color: var(--cyan); }
.up-summary.err { color: var(--magenta); font-weight: bold; }
.up-note { color: var(--text-dim); font-size: 21px; line-height: 1.3; margin: 0 0 4px; }
.up-note code { color: var(--cyan); font-family: var(--mono); }
.up-example { color: var(--cyan); font-family: var(--mono); font-size: 18px; line-height: 1.5; margin: 0 0 8px; padding: 4px 12px; background: rgba(255,255,255,.04); border-left: 2px solid var(--cyan); white-space: pre; }

/* download modal option groups */
.dl-group {
  border: 1px solid var(--violet); border-radius: 4px;
  background: rgba(177,74,237,.06);
  padding: 10px 14px; margin-bottom: 12px;
}
.dl-legend {
  display: block; color: var(--cyan); font-size: 18px;
  letter-spacing: 1px; margin-bottom: 8px;
}
.dl-legend b { color: var(--cyan); }
.dl-opt {
  display: flex; align-items: center; gap: 10px;
  font-size: 21px; color: var(--text); padding: 5px 0; cursor: pointer;
}
.dl-opt input { width: 18px; height: 18px; accent-color: var(--cyan); cursor: pointer; }
.dl-opt b { color: var(--cyan); }

/* ---------------------------------------------------------------- editor modal */
.overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(6,3,13,.82);
  display: none; align-items: center; justify-content: center;
  backdrop-filter: blur(3px);
}
.overlay.open { display: flex; }
.modal {
  position: relative;
  width: min(920px, 94vw); max-height: 90vh; overflow: auto;
  background: var(--bg-panel);
  border: 2px solid var(--magenta);
  border-radius: 6px;
  box-shadow: 0 0 40px rgba(255,46,151,.4);
  padding: 0;
}
.modal header {
  border-bottom: 2px solid var(--magenta); box-shadow: none;
  /* opaque (panel + magenta tint) so scrolled content can't show through */
  background: linear-gradient(rgba(255,46,151,.08), rgba(255,46,151,.08)), var(--bg-panel);
  /* keep the title + ✕ pinned to the top while a tall modal body scrolls */
  position: sticky; top: 0; z-index: 4;
  /* reserve room on the right so header contents never slide under the ✕ */
  padding-right: 58px;
}

/* corner close (✕) button — tucked into the top-right corner of every modal
   header, sitting clear of the header's bottom border line. The `.modal`
   prefix keeps it winning over the mobile `.modal header button` sizing rule. */
.modal .modal-x {
  position: absolute; top: 6px; right: 6px; z-index: 1;
  width: 30px; height: 30px; padding: 0;
  font-size: 20px; letter-spacing: 0;
}
.modal .mbody { padding: 16px 20px; }
.modal h2 { font-family: var(--pixel); font-size: 13px; color: var(--magenta); margin: 0; }

/* ---------------------------------------------------------------- phone editor */
.modal.phone-modal { width: min(1180px, 96vw); }
.pe-body { display: flex; gap: 18px; align-items: stretch; }
.pe-main { flex: 1 1 auto; min-width: 0; }
.pe-side { flex: 0 0 290px; display: flex; flex-direction: column; min-width: 0; }

/* in-modal waveform of the active phone (single forward pass) */
.pe-wave-wrap {
  position: relative; height: 180px;
  border: 1px solid var(--violet); border-radius: 4px;
  background: var(--bg-deep); overflow: hidden;
  box-shadow: inset 0 0 24px rgba(177,74,237,.10);
}
#editor-wave { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }

/* row under the graph: readout on the left, phone/word toggle at bottom-right */
.pe-wave-foot { display: flex; align-items: center; gap: 6px 14px; flex-wrap: wrap; margin-top: 8px; }
.pe-wave-toggle { flex: 0 0 auto; }   /* margin-left:auto (from .toggle-wrap) pins it right */
.pe-wave-toggle .toggle-label { font-size: 18px; }

.pe-readout { font-size: 20px; color: var(--text-dim); flex: 1 1 auto; min-width: 0; }
.pe-readout .pe-rv { color: var(--cyan); }
.pe-readout .pe-rsep { color: var(--text-dim); opacity: .5; margin: 0 7px; }

.pe-phone-status { min-height: 22px; margin-top: 4px; font-size: 18px; line-height: 1.3; }
.pe-phone-status .pe-warn { color: var(--amber); margin-right: 14px; }

/* flag controls row */
.pe-flags { display: flex; gap: 14px 18px; align-items: center; flex-wrap: wrap; margin: 12px 0 4px; }
.pe-flag { color: var(--text-dim); font-size: 18px; display: flex; gap: 6px; align-items: center; text-transform: uppercase; }
.pe-flag input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--cyan); cursor: pointer; }
.pe-flag.pe-sel select { font-size: 20px; padding: 2px 22px 2px 8px; height: 34px; }
.pe-flag-note { color: var(--magenta); font-size: 14px; opacity: .8; }

.pe-deltas-head {
  display: flex; align-items: baseline; gap: 12px;
  margin: 14px 0 6px; font-size: 18px; color: var(--cyan); letter-spacing: 1px;
}
.pe-deltas-hint { margin-left: auto; font-size: 15px; color: var(--text-dim); letter-spacing: 0; }
.pe-empty { color: var(--text-dim); font-size: 18px; font-style: italic; }

/* phone order / switcher list */
.pe-side-head { font-size: 18px; color: var(--cyan); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px; }
.pe-order {
  flex: 1 1 auto; overflow-y: auto; min-height: 0;
  border: 1px solid rgba(177,74,237,.4); border-radius: 4px;
  background: var(--bg-deep); padding: 4px;
}
.pe-prow {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px;
  border-left: 3px solid transparent; border-radius: 2px; cursor: pointer;
}
.pe-prow:hover { background: rgba(5,217,232,.08); }
.pe-prow.cur { background: rgba(255,46,151,.16); border-left-color: var(--magenta); }
.pe-prow.has-last { outline: 1px dashed var(--amber); outline-offset: -1px; }
.pe-pi { display: flex; align-items: center; gap: 6px; font-size: 20px; color: var(--text); min-width: 56px; }
.pe-prow.cur .pe-pi { color: var(--magenta); }
.pe-pdot { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 auto; }
.pe-pf { flex: 1 1 auto; font-size: 16px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pe-pbtns { display: inline-flex; gap: 3px; flex: 0 0 auto; }
.pe-obtn { font-size: 16px; height: 30px; padding: 0 9px; line-height: 1; }
.pe-obtn.danger { border-color: var(--magenta); color: var(--magenta); }
.pe-obtn.danger:hover { background: var(--magenta); color: var(--bg); box-shadow: 0 0 10px var(--magenta); }
.pe-hint { color: var(--text-dim); font-size: 20px; line-height: 1.35; margin: 8px 0 0; }

/* per-phone edit button on the PHONES pane cards */
.chunk h3 .ch-right { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; }
.chunk h3 .ch-right .pd-ovf { margin-left: 0; }
.pe-edit { font-size: 20px; height: 34px; padding: 0 14px; letter-spacing: .5px; }

.warn-inline { color: var(--amber); font-weight: bold; }

/* 2-bit delta grid */
.deltas { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.byte-group { display: flex; flex-direction: column; align-items: stretch; gap: 2px; padding: 3px; border: 1px solid rgba(177,74,237,.3); border-radius: 2px; }
.dcell-row { display: flex; gap: 1px; }
/* editable hex nibbles above each byte: one digit centred over its 2 delta cells */
.pe-nib-row { display: flex; gap: 1px; }
.pe-hex-in {
  font-family: var(--mono); font-size: 18px; height: 22px; width: 41px;
  text-align: center; text-transform: uppercase; letter-spacing: 1px;
  background: var(--bg-deep); color: var(--amber);
  border: 1px solid var(--violet); border-radius: 2px; padding: 0;
}
.pe-hex-in:focus { border-color: var(--cyan); box-shadow: 0 0 6px var(--cyan); color: var(--text); }
.pe-base .pe-base-in { width: 34px; }
.pe-base .pe-base-addr { color: var(--cyan); letter-spacing: 1px; }
/* bytes past the read window (length/repeat read fewer) are shown but de-emphasised */
.byte-group.pe-unused { opacity: .35; }
.byte-group.pe-unused .pe-hex-in { color: var(--text-dim); }
.dcell {
  width: 20px; height: 26px; line-height: 26px; text-align: center; cursor: pointer;
  font-size: 15px; border-radius: 1px; user-select: none; color: var(--bg); font-weight: bold;
}
.dcell.d0 { background: #2a1a4a; color: var(--text-dim); }
.dcell.d1 { background: var(--cyan); }
.dcell.d2 { background: var(--violet); }
.dcell.d3 { background: var(--magenta); }
.dcell:hover { outline: 1px solid var(--amber); }

.modal-foot { display: flex; gap: 12px; align-items: center; padding: 14px 20px; border-top: 1px solid var(--violet); }
.err { color: var(--magenta); font-weight: bold; }

.empty { color: var(--text-dim); padding: 20px; text-align: center; }

/* ---------------------------------------------------------------- compact summary */
.ck-headline {
  font-family: var(--pixel); font-size: 15px; line-height: 1.5;
  color: var(--lime); margin: 10px 0 14px; text-shadow: 0 0 10px rgba(124,255,178,.4);
}
.ck-headline.nochange { color: var(--text-dim); text-shadow: none; }
.ck-headline.bad { color: var(--amber); text-shadow: none; }
.ck-stats { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.ck-stat { display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
  border-bottom: 1px dashed rgba(177,74,237,.25); padding: 5px 0; }
.ck-stat .k { color: var(--text-dim); white-space: nowrap; }
.ck-stat .v { color: var(--cyan); font-weight: bold; white-space: nowrap; }
.ck-stat .v.good { color: var(--lime); }

/* ---------------------------------------------------------------- compacting (in-modal loading state) */
.ck-loading { text-align: center; padding: 14px 0 6px; }
.busy-title {
  font-family: var(--pixel); font-size: 14px; color: var(--cyan);
  animation: pulse 1.1s ease-in-out infinite;
}
.busy-msg { color: var(--text-dim); margin-top: 12px; }
/* indeterminate progress bar — only revealed once an op runs long (>5s) */
.busy-bar {
  position: relative; height: 14px; margin-top: 18px;
  background: var(--bg-deep);
  border: 1px solid var(--violet); border-radius: 7px; overflow: hidden;
}
.busy-bar > span {
  position: absolute; top: 0; bottom: 0; width: 40%;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  animation: busySlide 1.2s linear infinite;
}
@keyframes busySlide {
  0%   { left: -40%; }
  100% { left: 100%; }
}

/* ---------------------------------------------------------------- responsive */
@media (max-width: 860px) {
  body { font-size: 24px; }

  header { flex-direction: column; align-items: center; gap: 10px; padding: 12px 14px; }
  .logo { text-align: center; width: 100%; }
  .toolbar { width: 100%; justify-content: center; gap: 6px 8px; }
  .toolbar label { margin-left: 2px; }
  /* the action buttons stay on one row, centered and compact */
  .btn-group { gap: 6px; flex-wrap: nowrap; justify-content: center; }
  .btn-group button { font-size: 18px; height: 35px; padding: 0 9px; letter-spacing: .5px; }
  .spacer { display: none; }

  /* reset + info share a row; both match the play-all button height */
  #reset-btn { height: 35px; }
  #info-btn { height: 35px; width: 35px; }

  /* single column, stacked: waveform → words (short) → phones → hex */
  main {
    display: flex;
    flex-direction: column;
    height: auto;
    gap: 12px;
  }
  .panel { min-height: 0; }
  #wave-panel  { order: 1; height: 380px; }
  #word-panel  { order: 2; max-height: 240px; }
  #chunk-panel { order: 3; }
  #hex-panel   { order: 4; max-width: 100%; }
  #hex-panel .body { max-height: 60vh; }

  /* word list: bigger text in multiple columns filling the width */
  #words {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
    gap: 2px 10px;
    align-content: start;
  }
  .word { padding: 1px 8px; font-size: 24px; }
  .word .id { font-size: 20px; min-width: 26px; }

  /* modal headers stay as a row (the generic header rule goes column on mobile) */
  .modal header { flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .modal header h2 { width: 100%; }
  .modal header button { font-size: 20px; height: 34px; padding: 0 10px; }

  /* phone editor: stack waveform/controls above the phone-order list */
  .pe-body { flex-direction: column; }
  .pe-side { flex: 1 1 auto; }
  .pe-order { max-height: 200px; }

  html, body { height: auto; }
}

/* very narrow phones (e.g. Firefox mobile portrait): let the action buttons
   wrap onto multiple rows rather than overflow the viewport */
@media (max-width: 480px) {
  .btn-group { flex-wrap: wrap; }
  .toolbar { gap: 6px; }
  /* modal action rows (footers / header button clusters) wrap cleanly too */
  .modal-foot { flex-wrap: wrap; }
}

/* ---------------------------------------------------------------- info modal */
.modal.info-modal { width: min(600px, 94vw); }
.info-body { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.info-chip { width: 68%; margin: 0 auto; }
.info-chip svg { width: 100%; height: auto; display: block; }
.info-text { width: 100%; }
.info-text h3 {
  font-family: var(--pixel); font-size: 13px; color: var(--cyan);
  margin: 16px 0 8px; letter-spacing: 0.5px;
}
.info-text h3:first-child { margin-top: 0; }
.info-text p { font-size: 24px; color: var(--text); line-height: 1.15; margin: 0 0 10px; }
.info-text em { color: var(--amber); font-style: normal; }
.info-text strong { color: var(--magenta); font-style: normal; }
.info-text ul { padding-left: 20px; margin: 6px 0 0; }
.info-text li { font-size: 23px; color: var(--text); line-height: 1.15; margin-bottom: 4px; }

/* ---------------------------------------------------------------- reset button */
#reset-btn {
  border-color: var(--amber);
  color: var(--amber);
  flex-shrink: 0;
}
#reset-btn:hover {
  background: var(--amber);
  color: var(--bg);
  box-shadow: 0 0 12px rgba(255,209,102,.5);
}

/* reset confirmation modal */
.reset-body { padding: 18px 20px 10px; }
.reset-warn-row {
  display: flex;
  align-items: flex-start;
  gap: 18px;
}
.reset-warn-icon {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  fill: none;
  stroke: var(--amber);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 8px rgba(255,209,102,.5));
}
.reset-msg {
  font-size: 21px;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0;
}
.reset-msg strong { color: var(--magenta); }
button.primary.danger {
  border-color: var(--magenta);
  color: var(--magenta);
}
button.primary.danger:hover {
  background: var(--magenta);
  color: var(--bg);
  box-shadow: 0 0 14px var(--magenta);
}

/* reset + info button row (keeps them together in the header flex layout) */
.header-end { display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* info / help button in header */
#info-btn {
  font-family: var(--pixel); font-size: 14px;
  background: transparent;
  border: 1.5px solid var(--violet); color: var(--violet);
  border-radius: 50%; width: 28px; height: 28px;
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 0 0 0 2px; line-height: 1; letter-spacing: 0;
  transition: border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
#info-btn:hover {
  border-color: var(--magenta); color: var(--magenta);
  box-shadow: 0 0 8px rgba(255,46,151,.4);
}
@media (max-width: 860px) {
  #info-btn { height: 35px; width: 35px; }
}
