:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1e222e;
  --line: #2a2f3d;
  --text: #e7e9ee;
  --muted: #8b91a3;
  --accent: #5b8cff;
  --accent-2: #7c5bff;
  --danger: #ff6b6b;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---------------- Sidebar ---------------- */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 18px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08) inset;
  flex: 0 0 auto;
}
.brand h1 { font-size: 16px; margin: 0; letter-spacing: -0.01em; }
.tag { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.panel {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  color: var(--text);
}
.row { display: flex; gap: 10px; }
.row .field { flex: 1; margin-bottom: 0; }

.hint { margin: 6px 0 0; color: var(--muted); font-size: 11.5px; line-height: 1.4; }

input[type="number"], select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}
input[type="number"]:focus, select:focus { border-color: var(--accent); }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  margin: 2px 0 0;
}
output { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 600; }

.check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--muted); }
.check input { accent-color: var(--accent); }

/* Buttons */
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .05s ease, background .15s ease, border-color .15s ease;
  flex: 1;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
  width: 100%;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; }

/* File button */
.filebtn {
  display: block;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  transition: border-color .15s, color .15s;
}
.filebtn:hover { border-color: var(--accent); color: var(--text); }
.filebtn-primary { border-style: solid; color: var(--text); margin-bottom: 10px; }

/* Logo list */
.logo-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.logo-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
}
.logo-thumb {
  width: 34px; height: 34px; flex: 0 0 auto;
  border-radius: 6px;
  background-image:
    linear-gradient(45deg, #2a2f3d 25%, transparent 25%),
    linear-gradient(-45deg, #2a2f3d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2f3d 75%),
    linear-gradient(-45deg, transparent 75%, #2a2f3d 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
  object-fit: contain;
}
.logo-name { flex: 1; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo-scale { width: 62px; }
.logo-scale input { width: 46px; text-align: right; }
.logo-scale-wrap { display: flex; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); }
.logo-del {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 4px;
}
.logo-del:hover { color: var(--danger); }

/* Tier list */
.tier-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.tier-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 7px;
}
.tier-color {
  width: 22px; height: 22px; flex: 0 0 auto;
  padding: 0; border: 1px solid var(--line); border-radius: 5px;
  background: transparent; cursor: pointer;
}
.tier-color::-webkit-color-swatch-wrapper { padding: 2px; }
.tier-color::-webkit-color-swatch { border: none; border-radius: 3px; }
.tier-name {
  flex: 1; min-width: 0;
  background: transparent; border: none; color: var(--text);
  font-size: 12.5px; font-weight: 600; padding: 2px 0; outline: none;
}
.tier-name:focus { border-bottom: 1px solid var(--accent); }
.tier-pct { display: flex; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); }
.tier-pct input {
  width: 52px; text-align: right;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 6px; color: var(--text); font-size: 12px; padding: 3px 5px; outline: none;
}
.tier-pct input:focus { border-color: var(--accent); }
.logo-del:disabled { opacity: 0.25; cursor: default; }
.logo-del:disabled:hover { color: var(--muted); }
.btn-block { width: 100%; }

.logo-tier {
  flex: 0 0 auto;
  max-width: 116px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 6px;
  padding: 4px 5px;
  font-size: 11.5px;
  outline: none;
}
.logo-tier:focus { border-color: var(--accent); }

/* ---------------- Stage ---------------- */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 30% 20%, #1b2030 0%, var(--bg) 60%);
  overflow: auto;
}
.stage-inner {
  background:
    linear-gradient(45deg, #14171f 25%, transparent 25%),
    linear-gradient(-45deg, #14171f 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #14171f 75%),
    linear-gradient(-45deg, transparent 75%, #14171f 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 100%;
  max-height: 100%;
}
#canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 120px);
  border-radius: 8px;
  cursor: grab;
  touch-action: none;
}
#canvas.dragging { cursor: grabbing; }
.stage-hint {
  position: absolute;
  bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  background: rgba(15,17,23,0.7);
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
}

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 45vh; }
}
