:root{
  --bg:#0b0b0c;
  --panel:#101012;
  --border:#242428;

  --text:#f2f2f2;
  --muted:#a3a3a3;

  --btn:#ffffff;
  --btnText:#0b0b0c;

  --btnGhost:#151518;

  --radius:14px;
  --radiusSm:10px;
  --pill:999px;

  --font: system-ui,-apple-system,BlinkMacSystemFont,"SF Pro Text","Inter","Segoe UI",sans-serif;
}

*{box-sizing:border-box}
html,body{height:100%;margin:0}
body{background:var(--bg);color:var(--text);font-family:var(--font)}

.app{min-height:100vh;display:flex;flex-direction:column}

/* Header */
.header{
  height:58px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 16px;
  background:var(--panel);
  border-bottom:1px solid var(--border);
  position:sticky;top:0;z-index:20;
}
.title{font-size:14px;font-weight:700;letter-spacing:.02em}
.subtitle{font-size:12px;color:var(--muted)}
.badge{
  padding:6px 10px;
  border-radius:var(--pill);
  border:1px solid var(--border);
  background:#0b0b0c;
  font-size:12px;
  color:var(--muted);
}

/* Layout */
.layout{
  width:100%;
  max-width:1150px;
  margin:0 auto;
  padding:14px;
  display:grid;
  grid-template-columns:320px minmax(0,1fr);
  gap:12px;
}
@media (max-width:980px){
  .layout{grid-template-columns:minmax(0,1fr)}
}

/* Panels */
.panel{
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:12px;
}
.panel-title{
  font-size:13px;
  font-weight:700;
  margin-bottom:10px;
  color:var(--text);
}

/* Sidebar */
.sidebar{display:flex;flex-direction:column;gap:12px}
.help{font-size:12px;line-height:1.4;color:var(--muted)}

/* Area table */
.area-table{display:flex;flex-direction:column;gap:10px}
.area-head{
  display:grid;
  grid-template-columns:1fr 68px 68px;
  gap:10px;
  font-size:11px;
  color:var(--muted);
  padding-bottom:8px;
  border-bottom:1px solid var(--border);
}
.area-row{
  display:grid;
  grid-template-columns:1fr 68px 68px;
  gap:10px;
  align-items:center;
}
.area-name{font-size:13px;color:var(--text)}

/* Switch (monochrome) */
.switch{display:inline-flex;justify-content:center}
.switch input{display:none}
.switch span{
  width:44px;height:24px;border-radius:var(--pill);
  border:1px solid var(--border);
  background:#0b0b0c;
  position:relative;
  display:inline-block;
}
.switch span::after{
  content:"";
  width:18px;height:18px;border-radius:999px;
  background:#d4d4d4;
  position:absolute;top:50%;left:3px;
  transform:translateY(-50%);
  transition:all .15s ease;
}
.switch input:checked + span{
  background:#ffffff;
}
.switch input:checked + span::after{
  left:22px;
  background:#0b0b0c;
}

/* Slider row */
.row{
  display:flex;
  align-items:center;
  gap:10px;
}
#pixel-size-range{width:100%}
.mono{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  color:var(--muted);
  font-size:12px;
  min-width:28px;
  text-align:right;
}

/* Main */
.main{display:flex;flex-direction:column;gap:12px}

/* Dropzone */
.dropzone{
  border:1px dashed var(--border);
  border-radius:var(--radius);
  padding:12px;
  background:#0b0b0c;
  outline:none;
}
.dropzone:focus{border-style:solid}
.dropzone.dragover{
  border-style:solid;
}
.dropzone-top{
  display:flex;
  gap:8px;
  align-items:center;
  justify-content:flex-start;
}
.dropzone-text{margin:12px 0 6px}
.dropzone-primary{font-size:13px;font-weight:600}
.dropzone-secondary{font-size:12px;color:var(--muted)}
.meta{
  margin-top:8px;
  font-size:12px;
  color:var(--muted);
  word-break:break-word;
}

/* Buttons (monochrome) */
.btn{
  border:1px solid var(--border);
  background:var(--btn);
  color:var(--btnText);
  border-radius:var(--pill);
  padding:7px 12px;
  font-size:13px;
  font-weight:700;
  cursor:pointer;
  text-decoration:none;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}
.btn:hover{filter:brightness(.92)}
.btn:disabled{opacity:.5;cursor:not-allowed}

.btn.ghost{
  background:var(--btnGhost);
  color:var(--text);
}
.btn.ghost:hover{filter:brightness(1.1)}

.btn.primary{
  background:#ffffff;
  color:#0b0b0c;
}

/* Preview */
.preview{
  margin-top:10px;
  border:1px solid var(--border);
  border-radius:var(--radius);
  background:#0b0b0c;
  padding:10px;
  min-height:220px;

  /* center content and let media size itself */
  display:flex;
  align-items:center;
  justify-content:center;
}

.preview.empty{padding:18px}
.empty-text{font-size:12px;color:var(--muted)}

/* ✅ FIX: do NOT force width:100%; keep correct aspect ratio and scale down if needed */
.preview img,
.preview video{
  display:block;
  border-radius:var(--radiusSm);
  border:1px solid var(--border);
  background:#0b0b0c;

  /* preserve real proportions */
  width:auto;
  height:auto;

  /* fit inside preview box */
  max-width:100%;
  max-height:520px;

  /* never crop */
  object-fit:contain;
}

/* videos often default to a tiny box; allow them to expand while still keeping aspect ratio */
.preview video{
  width:min(100%, 900px);
  height:auto;
}

/* Actions */
.actions{
  margin-top:10px;
  display:flex;
  gap:8px;
  justify-content:flex-end;
}

/* show "locked" state subtly */
body.locked .panel-title { opacity: 0.9; }
body.locked .area-table,
body.locked #pixel-size-range {
  opacity: 0.55;
}
body.locked .area-table *:disabled,
body.locked #pixel-size-range:disabled {
  cursor: not-allowed;
}

.dash{
  color: var(--muted);
  font-size: 12px;
  display:flex;
  align-items:center;
  justify-content:center;
}

.switch input:disabled + span{
  opacity: 0.35;
  cursor: not-allowed;
}
.switch input:disabled + span::after{
  opacity: 0.7;
}

.subdivider{
  height:1px;
  background: rgba(255,255,255,0.08);
  margin: 12px 0;
}

/* Footer */
.footer{
  width:100%;
  padding: 6px 14px 18px;
}
.footer-inner{
  width:100%;
  max-width:1150px;
  margin:0 auto;
  display:flex;
  justify-content:center;
}

/* Footer centering override (robust) */
.footer{ text-align:center; }
.footer-inner{ display:block; text-align:center; }
.footer-inner .btn{ margin:0 auto; }
