/* ============================================================
   YALP GLB Optimizer — brand dark theme
   Brand: teal #58B898 · lime #E8F880
   ============================================================ */
:root {
  --teal: #58b898;
  --teal-bright: #74d3af;
  --teal-dim: #3f8d74;
  --lime: #e8f880;
  --lime-dim: #c3d45f;

  --bg-0: #0c110f;
  --bg-1: #101714;
  --bg-2: #16211c;
  --bg-3: #1c2a23;
  --bg-hover: #223228;
  --border: #27362e;
  --border-bright: #34493d;

  --text: #e8f0ea;
  --text-dim: #93a89c;
  --text-faint: #61756a;

  --danger: #e8776b;
  --warn: #e8c766;
  --ok: var(--teal-bright);

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  --grad: linear-gradient(120deg, var(--teal) 0%, var(--lime) 130%);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1100px 600px at 12% -8%, rgba(88, 184, 152, .10), transparent 60%),
    radial-gradient(900px 500px at 105% 110%, rgba(232, 248, 128, .06), transparent 55%),
    var(--bg-0);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
button { font-family: inherit; cursor: pointer; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--teal-dim); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- App layout ---------- */
.app { display: grid; grid-template-rows: auto 1fr; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-1), rgba(16, 23, 20, .6));
  backdrop-filter: blur(6px);
  z-index: 20;
}
.topbar .logo { height: 34px; width: auto; display: block; }
.topbar .brand { display: flex; flex-direction: column; line-height: 1.15; }
.topbar .brand .title { font-size: 16px; font-weight: 700; letter-spacing: .2px; }
.topbar .brand .title b { color: var(--lime); }
.topbar .brand .sub { font-size: 11.5px; color: var(--text-dim); }
.topbar .spacer { flex: 1; }
.topbar .top-actions { display: flex; gap: 10px; align-items: center; }

/* ---------- Three-column workspace ---------- */
.workspace {
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  min-height: 0;
}
.panel { min-height: 0; display: flex; flex-direction: column; }
.panel.left { border-right: 1px solid var(--border); background: var(--bg-1); }
.panel.right { border-left: 1px solid var(--border); background: var(--bg-1); }
.panel .panel-scroll { overflow-y: auto; padding: 16px; flex: 1 1 auto; min-height: 0; }
.panel-footer {
  flex: none; padding: 12px 16px 14px;
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(16,23,20,.6), var(--bg-1));
  display: flex; flex-direction: column; gap: 8px;
}
.panel-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.4px;
  color: var(--text-faint); margin: 2px 0 12px;
}

/* ---------- Center / viewer ---------- */
.center { position: relative; display: flex; flex-direction: column; min-width: 0; background: var(--bg-0); }
.viewer-toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--bg-1); z-index: 6;
}
.viewer-stage { position: relative; flex: 1; min-height: 0; display: grid; }
.viewer-stage.mode-split { grid-template-columns: 1fr 1fr; }
.viewer-stage.mode-single { grid-template-columns: 1fr; }
.viewer-pane { position: relative; overflow: hidden; }
.viewer-stage.mode-split .viewer-pane + .viewer-pane { border-left: 2px solid var(--border-bright); }
.viewer-pane.hidden { display: none; }
.viewer-pane canvas { display: block; width: 100%; height: 100%; }
.pane-tag {
  position: absolute; top: 12px; left: 12px; z-index: 3;
  font-size: 10.5px; letter-spacing: 1px; text-transform: uppercase; font-weight: 700;
  padding: 4px 10px; border-radius: 20px;
  background: rgba(12, 17, 15, .72); border: 1px solid var(--border-bright);
  color: var(--text-dim); backdrop-filter: blur(4px);
}
.pane-tag.after { color: var(--lime); border-color: var(--lime-dim); }
.pane-tag.before { color: var(--teal-bright); border-color: var(--teal-dim); }
.pane-stat {
  position: absolute; bottom: 12px; left: 12px; z-index: 3;
  font-family: var(--mono); font-size: 11px; color: var(--text-dim);
  background: rgba(12, 17, 15, .72); border: 1px solid var(--border);
  padding: 5px 9px; border-radius: 8px; backdrop-filter: blur(4px);
  white-space: pre; pointer-events: none;
}
.pane-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: 13px; text-align: center; padding: 20px; pointer-events: none;
}

/* animation bar */
.anim-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 14px; border-top: 1px solid var(--border); background: var(--bg-1);
}
.anim-bar.disabled { opacity: .4; pointer-events: none; }
.anim-bar .scrub { flex: 1; }
.anim-bar select { min-width: 130px; }
.anim-bar .time { font-family: var(--mono); font-size: 11px; color: var(--text-dim); min-width: 84px; text-align: right; }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 1.5px dashed var(--border-bright); border-radius: var(--radius);
  padding: 26px 16px; text-align: center; color: var(--text-dim);
  background: var(--bg-2); transition: .15s; cursor: pointer;
}
.dropzone:hover, .dropzone.drag { border-color: var(--teal); background: var(--bg-hover); color: var(--text); }
.dropzone .dz-icon { font-size: 26px; margin-bottom: 8px; }
.dropzone b { color: var(--teal-bright); }
.dropzone .hint { font-size: 11px; color: var(--text-faint); margin-top: 6px; }

.file-chip {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.file-chip .fc-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .fc-size { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }
.file-chip .fc-x { margin-left: auto; color: var(--text-faint); background: none; border: none; font-size: 16px; }
.file-chip .fc-x:hover { color: var(--danger); }

/* ---------- Settings ---------- */
.section {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 10px; background: var(--bg-2); overflow: hidden;
}
.section > summary {
  list-style: none; cursor: pointer; padding: 11px 13px;
  display: flex; align-items: center; gap: 9px; user-select: none;
  font-weight: 600; font-size: 13px;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary .chev { margin-left: auto; color: var(--text-faint); transition: transform .15s; }
.section[open] > summary .chev { transform: rotate(90deg); }
.section > summary .sdot { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 8px var(--teal); }
.section > summary .sdot.off { background: var(--text-faint); box-shadow: none; }
.section-body { padding: 4px 13px 14px; border-top: 1px solid var(--border); }

.field { margin: 12px 0; }
.field:first-child { margin-top: 10px; }
.field > label.lbl { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; }
.field > label.lbl .val { font-family: var(--mono); color: var(--teal-bright); font-size: 11.5px; }
.help { font-size: 11px; color: var(--text-faint); margin-top: 4px; }

/* toggle row */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; }
.toggle-row .tr-label { font-size: 13px; }
.toggle-row .tr-sub { font-size: 11px; color: var(--text-faint); }

.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 22px; background: var(--bg-3);
  border: 1px solid var(--border-bright); transition: .18s;
}
.switch .track::before {
  content: ""; position: absolute; height: 15px; width: 15px; left: 3px; top: 2.5px;
  background: var(--text-dim); border-radius: 50%; transition: .18s;
}
.switch input:checked + .track { background: var(--grad); border-color: transparent; }
.switch input:checked + .track::before { transform: translateX(15px); background: #0c110f; }

/* range */
input[type="range"] { -webkit-appearance: none; width: 100%; height: 4px; border-radius: 3px; background: var(--bg-3); outline: none; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--teal-bright); cursor: pointer; border: 2px solid var(--bg-0); box-shadow: 0 0 0 1px var(--teal-dim);
}
input[type="range"]:disabled { opacity: .4; }

/* select + segmented */
select, input[type="number"] {
  width: 100%; padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--bg-3); border: 1px solid var(--border-bright); color: var(--text); font-size: 13px;
}
select:focus, input:focus { border-color: var(--teal); outline: none; }
.segment { display: flex; background: var(--bg-3); border: 1px solid var(--border-bright); border-radius: var(--radius-sm); padding: 3px; gap: 3px; }
.segment button {
  flex: 1; padding: 7px 6px; border: none; background: transparent; color: var(--text-dim);
  border-radius: 6px; font-size: 12.5px; font-weight: 600; transition: .12s;
}
.segment button.active { background: var(--grad); color: #0c110f; }
.segment button:not(.active):hover { color: var(--text); background: var(--bg-hover); }

/* pill toggle buttons (viewer toolbar) */
.pill {
  padding: 6px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;
  background: var(--bg-2); border: 1px solid var(--border-bright); color: var(--text-dim);
}
.pill.active { background: var(--grad); color: #0c110f; border-color: transparent; }
.pill:not(.active):hover { color: var(--text); background: var(--bg-hover); }
.toolbar-group { display: flex; gap: 6px; align-items: center; }
.toolbar-group .glabel { font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-faint); margin-right: 2px; }
.tb-sep { width: 1px; height: 20px; background: var(--border); }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px;
  background: var(--bg-2); border: 1px solid var(--border-bright); color: var(--text-dim); font-size: 15px;
}
.icon-btn:hover { color: var(--text); background: var(--bg-hover); }
.icon-btn.play { width: 40px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius-sm); font-weight: 600; font-size: 13.5px;
  border: 1px solid var(--border-bright); background: var(--bg-2); color: var(--text); transition: .13s;
}
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--grad); color: #0c110f; border: none; box-shadow: 0 4px 18px rgba(88,184,152,.25); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 7px 12px; font-size: 12.5px; }

/* ---------- Right: results ---------- */
.result-card {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.savings { text-align: center; margin-bottom: 6px; }
.savings .big { font-size: 40px; font-weight: 800; background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; line-height: 1; }
.savings .cap { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--text-faint); margin-top: 4px; }
.sizes-row { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; font-family: var(--mono); font-size: 13px; }
.sizes-row .before { color: var(--text-dim); text-decoration: line-through; text-decoration-color: var(--border-bright); }
.sizes-row .arrow { color: var(--teal); }
.sizes-row .after { color: var(--lime); font-weight: 700; }
.bar { height: 8px; border-radius: 6px; background: var(--bg-3); overflow: hidden; margin-top: 14px; position: relative; }
.bar > i { display: block; height: 100%; background: var(--grad); border-radius: 6px; transition: width .5s ease; }

/* breakdown */
.bd-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 8px; }
.bd-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--text-dim); margin-bottom: 10px; }
.bd-legend span { display: inline-flex; align-items: center; gap: 5px; }
.bd-legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.stack {
  display: flex; height: 22px; border-radius: 6px; overflow: hidden; background: var(--bg-3);
  border: 1px solid var(--border); margin-bottom: 12px;
}
.stack > i { height: 100%; transition: width .4s; }

.bd-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.bd-table th { text-align: left; color: var(--text-faint); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; padding: 4px 6px; border-bottom: 1px solid var(--border); }
.bd-table td { padding: 7px 6px; border-bottom: 1px solid var(--bg-2); }
.bd-table td.num { font-family: var(--mono); text-align: right; color: var(--text-dim); }
.bd-table td.num.after { color: var(--lime); }
.bd-table .cat { display: inline-flex; align-items: center; gap: 7px; }
.bd-table .cat i { width: 9px; height: 9px; border-radius: 2px; }
.bd-table tr.detail td { color: var(--text-faint); font-size: 11.5px; padding-left: 22px; }
.bd-table .delta.down { color: var(--teal-bright); }
.bd-table .delta.up { color: var(--warn); }

.empty-note { color: var(--text-faint); font-size: 12.5px; text-align: center; padding: 30px 10px; }

/* per-texture list */
.tex-list { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.tex-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; }
.tex-row .tx-thumb {
  width: 36px; height: 36px; flex: none; border-radius: 6px; overflow: hidden;
  border: 1px solid var(--border-bright); display: grid; place-items: center;
  background-color: #14201b;
  background-image:
    linear-gradient(45deg, #26332c 25%, transparent 25%, transparent 75%, #26332c 75%),
    linear-gradient(45deg, #26332c 25%, transparent 25%, transparent 75%, #26332c 75%);
  background-size: 10px 10px; background-position: 0 0, 5px 5px;
}
.tex-row .tx-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tex-row .tx-thumb.ph { color: var(--text-faint); font-size: 13px; background: var(--bg-2); }
.tex-row .tx-info { min-width: 0; flex: 1; }
.tex-row .tx-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tex-row .tx-meta { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); }
.tex-row select { width: auto; min-width: 92px; padding: 5px 7px; font-size: 12px; flex: none; }
.tex-row select.changed { border-color: var(--lime-dim); color: var(--lime); }

/* log */
.logbox {
  font-family: var(--mono); font-size: 11px; color: var(--text-dim);
  background: var(--bg-0); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px; max-height: 150px; overflow-y: auto; white-space: pre-wrap;
}
.logbox .l-ok { color: var(--teal-bright); }
.logbox .l-warn { color: var(--warn); }
.logbox .l-err { color: var(--danger); }
.logbox .l-dim { color: var(--text-faint); }

/* ---------- Overlay / progress ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: center; justify-content: center; flex-direction: column; gap: 18px;
  background: rgba(8, 12, 10, .78); backdrop-filter: blur(4px);
}
.overlay.show { display: flex; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 3px solid var(--border-bright); border-top-color: var(--lime); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.overlay .ov-text { color: var(--text); font-weight: 600; }
.overlay .ov-sub { color: var(--text-dim); font-size: 12px; margin-top: -8px; font-family: var(--mono); }

/* toast */
.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 11px 16px; border-radius: 10px; background: var(--bg-3); border: 1px solid var(--border-bright);
  color: var(--text); font-size: 13px; box-shadow: var(--shadow); animation: rise .2s ease;
}
.toast.err { border-color: var(--danger); }
.toast.ok { border-color: var(--teal); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* fly-navigation hint */
.fly-hint {
  position: absolute; right: 14px; bottom: 66px; z-index: 4;
  font-size: 11px; color: var(--text-faint);
  background: rgba(12, 17, 15, .72); border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 8px; backdrop-filter: blur(4px);
  pointer-events: none; transition: .2s; opacity: .75;
}
.fly-hint b { color: var(--teal-bright); font-weight: 700; }
.viewer-stage.flying { cursor: none; }
.center:has(.viewer-stage.flying) .fly-hint { opacity: 1; border-color: var(--teal-dim); color: var(--text-dim); }

.hide { display: none !important; }
.badge-pro { font-size: 9px; background: var(--lime); color: #0c110f; padding: 1px 5px; border-radius: 4px; font-weight: 800; letter-spacing: .3px; vertical-align: middle; }
