:root {
  color-scheme: dark;
  --bg: #06101a;
  --panel: #0d2435;
  --panel2: #12324a;
  --line: #2b5775;
  --soft: rgba(145, 190, 218, 0.22);
  --text: #e9f6fb;
  --muted: #9ab4c6;
  --cyan: #5ed4ff;
  --amber: #f0b34f;
  --green: #82d992;
  --red: #ff8585;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button { color: inherit; }
input, select {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #071522;
  color: var(--text);
  padding: 8px 10px;
}
label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #081827;
}
.topbar h1 { margin: 0; font-size: 22px; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.topbar input[type="file"] { display: none; }

.layout {
  display: grid;
  grid-template-columns: minmax(330px, 430px) minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}
.sidebar, .content { display: grid; align-content: start; gap: 12px; min-width: 0; }
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
  min-width: 0;
}
.panelTitle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--soft);
}
.panelTitle h2 { margin: 0; font-size: 15px; }
.muted { color: var(--muted); font-size: 12px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel2);
  cursor: pointer;
  padding: 7px 10px;
  white-space: nowrap;
}
.button:hover { border-color: var(--cyan); }
.button.primary { border-color: #2f8dbb; background: #12618b; }
.button.small { min-height: 28px; padding: 4px 8px; }
.button.square { width: 34px; padding: 0; font-size: 20px; }
.toolbar, .actions { display: flex; align-items: center; gap: 8px; }
.actions { justify-content: space-between; padding: 8px 12px; border-top: 1px solid var(--soft); }

.message {
  margin: 8px 12px;
  padding: 9px 10px;
  border: 1px solid rgba(240, 179, 79, .45);
  border-radius: 6px;
  background: rgba(240, 179, 79, .11);
  color: #ffe0a6;
}
.message.error { border-color: rgba(255, 133, 133, .45); background: rgba(255, 133, 133, .12); color: #ffd6d6; }
.hidden { display: none; }
.empty { color: var(--muted); padding: 14px 12px; }

.fileList { max-height: 260px; overflow: auto; }
.fileRow {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--soft);
  background: transparent;
  padding: 9px 12px;
  text-align: left;
}
.fileRow.active, .fileRow:hover, tr.active { background: rgba(94, 212, 255, .08); }
.badge { border-radius: 4px; padding: 3px 6px; font-size: 11px; color: #06101a; background: var(--cyan); }
.badge.ols { background: var(--amber); }
.fileName { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.searchGrid { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 8px; padding: 10px 12px; }
.tableScroller { overflow: auto; }
.smallTable { max-height: 330px; }
table { width: 100%; border-collapse: collapse; min-width: 520px; }
th, td { border-bottom: 1px solid var(--soft); padding: 8px 10px; text-align: left; vertical-align: top; }
th { position: sticky; top: 0; z-index: 2; background: #081827; color: var(--muted); font-size: 12px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: rgba(94, 212, 255, .07); }

.details { padding: 10px 12px; }
.selectedGrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.selectedGrid div, .formulaResult {
  border: 1px solid var(--soft);
  border-radius: 6px;
  background: rgba(6, 16, 26, .55);
  padding: 8px;
}
.mono { font-family: "Cascadia Mono", Consolas, monospace; }
.valueGrid { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; margin-top: 10px; }
.bits { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.bit { border: 1px solid var(--soft); border-radius: 6px; padding: 7px; text-align: center; }
.bit.on { border-color: rgba(130, 217, 146, .7); color: var(--green); }
.converter { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 10px 12px; border-top: 1px solid var(--soft); }
.wide, .formulaResult { grid-column: 1 / -1; }
.formulaResult { color: var(--green); font-weight: 700; }
.formulaResult.bad { color: var(--red); }

.addressInput { width: 138px; font-family: "Cascadia Mono", Consolas, monospace; }
.hexScroller { max-height: 540px; }
.hexTable { min-width: 1120px; font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.hexTable th, .hexTable td { padding: 3px 4px; text-align: center; }
.addr { position: sticky; left: 0; z-index: 1; min-width: 112px; background: #081827; color: var(--cyan); text-align: left !important; }
th.addr { z-index: 3; }
.byteBtn {
  width: 32px;
  height: 24px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}
.byteBtn:hover, .byteBtn.active { border-color: var(--amber); background: rgba(240, 179, 79, .18); }
.dec { color: #98d8a6; }
.ascii { min-width: 140px; color: var(--amber); text-align: left !important; white-space: pre; }

.manualForm {
  display: grid;
  grid-template-columns: minmax(160px, 1.2fr) minmax(118px, .8fr) 58px 58px 120px 82px 82px 76px auto;
  align-items: end;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--soft);
}
.mapSplit { display: grid; grid-template-columns: minmax(360px, .9fr) minmax(320px, 1.1fr); min-height: 320px; }
.mapTable { max-height: 420px; border-right: 1px solid var(--soft); }
.mapPreview { min-width: 0; padding: 12px; }
.mapGrid { min-width: 0; width: auto; font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.mapGrid td { min-width: 58px; border: 1px solid rgba(145, 190, 218, .18); padding: 6px; text-align: right; background: rgba(6, 16, 26, .55); }

.compareControls { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto 110px; gap: 8px; align-items: end; padding: 10px 12px; border-bottom: 1px solid var(--soft); }
.check { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.check input { width: 16px; }
.compareTable { max-height: 420px; }
.diff { background: rgba(240, 179, 79, .06); }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .topbar { align-items: stretch; flex-direction: column; }
  .manualForm, .mapSplit, .compareControls, .converter, .searchGrid { grid-template-columns: 1fr; }
}

