/* TIN/GFX Viewer styles */
:root {
  --font-ui: "Segoe UI", Tahoma, Geneva, sans-serif;
  --font-mono: Consolas, "Courier New", monospace;

  --bg:        #dfe8f3;
  --bg-blur:   #b8cbe0;
  --surface:   #eef4fb;
  --surface-2: #dbe6f2;
  --panel:     #f3f7fc;
  --border:    #a8b9cc;
  --border-2:  #c4d2e2;
  --text:      #14202e;
  --text-dim:  #5a6a7a;
  --text-faint:#8b9aab;
  --accent:    #3c8ddc;
  --accent-2:  #2c6fb3;
  --accent-fg: #ffffff;
  --ok:        #2f9b4a;
  --err:       #c93a3a;
  --warn:      #b8860b;
  --sel:       #cfe2f5;
  --shadow:    0 4px 14px rgba(20,40,70,.18), 0 1px 3px rgba(20,40,70,.14);
  --title-grad: linear-gradient(180deg, #f4f8fd 0%, #d4e3f2 50%, #bcd2e8 51%, #cbdcf0 100%);
  --btn-grad:   linear-gradient(180deg, #f6fafe 0%, #e0ebf7 50%, #d2e2f2 51%, #e6f0fa 100%);
  --btn-grad-h: linear-gradient(180deg, #fbfdff 0%, #e8f1fa 50%, #d8e7f5 51%, #edf4fc 100%);
  --btn-grad-p: linear-gradient(180deg, #b9d8f4 0%, #a3c8ee 50%, #95beeb 51%, #aacdf1 100%);
  --input-bg:   #ffffff;
}

html[data-theme="dark"] {
  --bg:        #0f1418;
  --bg-blur:   #18242c;
  --surface:   #172029;
  --surface-2: #1d2833;
  --panel:     #131a21;
  --border:    #2a3844;
  --border-2:  #38495a;
  --text:      #d8e4ee;
  --text-dim:  #8fa2b4;
  --text-faint:#5a6b7c;
  --accent:    #4fc3f7;
  --accent-2:  #29a3d9;
  --accent-fg: #08141c;
  --ok:        #4fd48a;
  --err:       #ff6b6b;
  --warn:      #ffc14d;
  --sel:       #1d3a52;
  --shadow:    0 4px 16px rgba(0,0,0,.55), 0 1px 3px rgba(0,0,0,.4);
  --title-grad: linear-gradient(180deg, #22323f 0%, #1a2630 48%, #14202a 52%, #1d2d3a 100%);
  --btn-grad:   linear-gradient(180deg, #2b3d4c 0%, #21303d 48%, #1b2833 52%, #243644 100%);
  --btn-grad-h: linear-gradient(180deg, #364b5c 0%, #293c4b 48%, #223441 52%, #2e4253 100%);
  --btn-grad-p: linear-gradient(180deg, #1a4d6b 0%, #154158 48%, #123a4f 52%, #1a5374 100%);
  --input-bg:   #0c1217;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 12.5px/1.45 var(--font-ui);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background .15s, color .15s;
}

header {
  padding: 10px 18px;
  background: var(--title-grad);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  position: relative;
  z-index: 2;
}
html[data-theme="dark"] header {
  box-shadow: 0 1px 4px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.04);
}
header h1 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  letter-spacing: .2px;
  text-shadow: 0 1px 0 rgba(255,255,255,.5);
}
html[data-theme="dark"] header h1 {
  text-shadow: 0 1px 0 rgba(0,0,0,.6);
}
header .sub {
  color: var(--text-dim);
  font-size: 11.5px;
}
header .sub code {
  background: var(--input-bg);
  border: 1px solid var(--border-2);
  border-radius: 3px;
  padding: 0 4px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text);
}

button, .drop {
  background: var(--btn-grad);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 12px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.6), 0 1px 2px rgba(0,0,0,.06);
  transition: background .1s, border-color .1s, box-shadow .1s;
}
html[data-theme="dark"] button,
html[data-theme="dark"] .drop {
  box-shadow: inset 0 1px 0 rgba(255,255,255,.07), 0 1px 2px rgba(0,0,0,.5);
}
button:hover, .drop:hover {
  background: var(--btn-grad-h);
  border-color: var(--accent);
}
button:active, .drop:active {
  background: var(--btn-grad-p);
  border-color: var(--accent-2);
  box-shadow: inset 0 2px 4px rgba(0,0,0,.2);
}
button:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.drop.loaded {
  border-color: var(--ok);
  color: var(--ok);
}
input[type=file] { display: none; }

#toolbar {
  padding: 8px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  position: relative;
  z-index: 1;
}
#toolbar label {
  display: flex;
  gap: 6px;
  align-items: center;
  cursor: pointer;
  color: var(--text);
}
#toolbar input[type=checkbox] {
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  box-shadow: inset 0 1px 1px rgba(0,0,0,.1);
}
#toolbar input[type=checkbox]:hover { border-color: var(--accent); }
#toolbar input[type=checkbox]:checked {
  background: var(--accent);
  border-color: var(--accent-2);
}
#toolbar input[type=checkbox]:checked::after {
  content: "\2713";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-fg);
  font-size: 10px;
  font-weight: bold;
  line-height: 1;
  top: -1px;
}
#status {
  flex: 1;
  text-align: right;
  color: var(--text-faint);
  font-size: 11px;
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#toolbar .sep {
  width: 1px;
  height: 18px;
  background: var(--border-2);
  margin: 0 2px;
}
#selCount {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 0 4px;
}

main {
  flex: 1;
  display: grid;
  grid-template-columns: 380px 1fr;
  min-height: 0;
}

#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: auto;
}
#sidebar .sec {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-2);
}
#sidebar .sec h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-dim);
  margin: 0 0 8px;
}
.kv {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 3px 8px;
  font-size: 11.5px;
  font-family: var(--font-mono);
}
.kv .k { color: var(--text-dim); }
.kv .v { color: var(--text); word-break: break-all; }
.arr {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.7;
}
.arr b { color: var(--text); font-weight: 600; }

#entryList {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 3px;
  max-height: 320px;
  overflow: auto;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.06);
  user-select: none;
}
html[data-theme="dark"] #entryList {
  box-shadow: inset 0 1px 3px rgba(0,0,0,.6);
}
.entry {
  display: grid;
  grid-template-columns: 34px 1fr 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 3px 6px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 11.5px;
  font-family: var(--font-mono);
}
.entry:hover { background: var(--sel); }
.entry.sel {
  background: var(--accent);
  color: var(--accent-fg);
}
.entry .idx   { color: var(--text-faint); }
.entry.sel .idx { color: rgba(0,0,0,.5); }
.entry .type  { color: var(--accent); font-weight: 600; }
.entry.sel .type { color: var(--accent-fg); }
.entry .sz    { color: var(--text-dim); font-size: 10.5px; }
.entry.sel .sz { color: rgba(0,0,0,.7); }
.entry .off   { color: var(--text-faint); font-size: 10.5px; }
.entry.sel .off { color: rgba(0,0,0,.55); }
.entry.nodata { opacity: .5; }

#viewport {
  overflow: auto;
  padding: 16px;
  background:
    radial-gradient(ellipse at top, var(--bg-blur) 0%, var(--bg) 65%),
    var(--bg);
}
html[data-theme="dark"] #viewport {
  background:
    radial-gradient(ellipse at top, #1a2a36 0%, #0f1418 60%),
    var(--bg);
}
#stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-content: flex-start;
  min-height: 100%;
  box-shadow: var(--shadow);
}
html[data-theme="dark"] #stage {
  background: linear-gradient(180deg, #172029 0%, #131b22 100%);
  border-color: var(--border-2);
}

.tex {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 4px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  cursor: pointer;
  user-select: none;
  transition: border-color .1s, box-shadow .1s;
}
html[data-theme="dark"] .tex {
  background: linear-gradient(180deg, #1d2833 0%, #172029 100%);
  box-shadow: 0 2px 6px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.03);
}
.tex:hover { border-color: var(--accent); }
.tex.sel {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent), 0 1px 3px rgba(0,0,0,.1);
}
html[data-theme="dark"] .tex.sel {
  box-shadow: 0 0 0 2px var(--accent), 0 2px 6px rgba(0,0,0,.4);
}
.tex canvas {
  background: repeating-conic-gradient(
    var(--surface) 0 25%, var(--surface-2) 0 50%) 0 0 / 14px 14px;
  border-radius: 2px;
  border: 1px solid var(--border-2);
  image-rendering: pixelated;
  display: block;
}
.tex .cap {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
  padding: 2px 0;
}
.tex .cap b { color: var(--text); font-weight: 600; }

.empty {
  color: var(--text-faint);
  padding: 60px 20px;
  text-align: center;
  font-size: 12.5px;
  white-space: pre-wrap;
  font-family: var(--font-mono);
}
.warn { color: var(--warn); }
.err  { color: var(--err); }
.ok   { color: var(--ok); }
.muted { color: var(--text-faint); }
.note {
  font-size: 10.5px;
  color: var(--text-dim);
  line-height: 1.7;
  margin-top: 6px;
}
.note code {
  background: var(--input-bg);
  border: 1px solid var(--border-2);
  border-radius: 2px;
  padding: 0 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text);
}

.theme-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.theme-btn svg { width: 14px; height: 14px; }

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-2);
  border: 3px solid transparent;
  background-clip: padding-box;
}
html[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #2d3d4b; }
html[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #3a4d5e; }

