:root {
  --bg: #0c1020;
  --bg-soft: #121935;
  --text: #edf1ff;
  --muted: #9ea8c7;
  --line: rgba(255, 255, 255, 0.12);
  --card: rgba(255, 255, 255, 0.08);
  --accent: #6d5efc;
  --accent-2: #00d4ff;
  --ok: #1ecb8b;
  --shadow: 0 18px 40px rgba(6, 10, 30, 0.35);
}

body.light {
  --bg: #eef2ff;
  --bg-soft: #f7f8ff;
  --text: #101322;
  --muted: #4f5978;
  --line: rgba(16, 19, 34, 0.14);
  --card: rgba(255, 255, 255, 0.78);
  --accent: #5f47ff;
  --accent-2: #0093ff;
  --shadow: 0 18px 40px rgba(42, 53, 107, 0.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden], .hidden { display: none !important; }
html, body { min-height: 100%; }
body {
  font-family: Inter, Segoe UI, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top right, rgba(109, 94, 252, 0.22), transparent 40%), var(--bg);
  padding: 16px 16px 92px;
}

.topbar, .layout { width: min(1200px, 100%); margin: 0 auto; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-dot {
  width: 14px; height: 14px; border-radius: 999px;
  background: linear-gradient(130deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 0 7px rgba(109, 94, 252, 0.2);
}
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.layout { display: grid; gap: 14px; grid-template-columns: 390px 1fr; }
.hero, .left-panel, .right-panel, .history-panel { border-radius: 22px; }
.hero { grid-column: 1 / -1; padding: 18px 20px; }
.left-panel, .right-panel, .history-panel { padding: 16px; }
.history-panel { grid-column: 1 / -1; }

.glass {
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.eyebrow { color: var(--accent-2); font-weight: 700; margin-bottom: 8px; }
h1 { font-size: clamp(1.6rem, 3.8vw, 2.7rem); margin-bottom: 8px; }
h2 { font-size: 1.15rem; }
.sub { color: var(--muted); max-width: 860px; line-height: 1.45; }

.upload {
  display: grid; gap: 6px; place-items: center;
  border: 1.5px dashed var(--line);
  border-radius: 16px; padding: 26px 14px; cursor: pointer;
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease;
}
.upload-icon { font-size: 1.8rem; }
.upload small { color: var(--muted); }
.upload:hover, .upload:focus-visible, .upload.drag {
  border-color: rgba(0, 212, 255, 0.8);
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(0, 212, 255, 0.15);
  outline: none;
}

input[type=file] { display: none; }
.url-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 12px; }
input[type=url], select {
  width: 100%; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.2); color: var(--text); padding: 10px 12px;
}
body.light input[type=url], body.light select { background: #fff; }

.warning {
  margin-top: 10px; border: 1px solid rgba(255, 190, 60, 0.35);
  background: rgba(255, 190, 60, 0.1); padding: 10px 12px; border-radius: 12px;
}

.preview {
  margin-top: 12px; border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; background: rgba(0, 0, 0, 0.4);
}
.preview img { width: 100%; max-height: 260px; object-fit: contain; display: block; }

.control-grid { margin-top: 12px; display: grid; gap: 12px; }
.control span { display: block; margin-bottom: 8px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }

button {
  border: 1px solid transparent; border-radius: 12px;
  padding: 11px 12px; cursor: pointer; font-weight: 700;
  transition: .2s ease; color: var(--text);
}
button:hover { transform: translateY(-1px); }
button:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.primary-btn {
  color: #fff; border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.ghost-btn { border-color: var(--line); background: rgba(0, 0, 0, 0.17); }
body.light .ghost-btn { background: rgba(255, 255, 255, 0.92); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stats article {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px;
  text-align: center; background: rgba(0, 0, 0, 0.16);
}
.stats b { display: block; font-size: 1.05rem; margin-bottom: 4px; }
.stats small { color: var(--muted); }

.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  border-radius: 999px; padding: 7px 12px; border: 1px solid var(--line);
  background: transparent; color: var(--muted);
}
.tab.active {
  color: #fff;
  background: linear-gradient(130deg, rgba(109, 94, 252, 0.95), rgba(0, 212, 255, 0.85));
}

.palette-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px;
}
.empty {
  border: 1px dashed var(--line);
  border-radius: 14px; padding: 30px 16px;
  color: var(--muted); text-align: center;
}
.color-card {
  border-radius: 14px; overflow: hidden; border: 1px solid var(--line);
  background: rgba(5, 9, 28, 0.7); cursor: pointer;
  transition: transform .22s ease, box-shadow .22s ease;
}
.color-card:hover, .color-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 0 0 1px rgba(0, 212, 255, 0.45), 0 12px 24px rgba(0, 212, 255, 0.18);
  outline: none;
}
.swatch { height: 84px; position: relative; }
.lock-btn {
  position: absolute; right: 8px; top: 8px; border-radius: 999px; padding: 3px 8px;
  border: 1px solid rgba(255, 255, 255, 0.35); color: #fff; background: rgba(0, 0, 0, 0.26);
}
.lock-btn.locked { background: rgba(30, 203, 139, 0.25); border-color: rgba(30, 203, 139, 0.75); }

.meta { padding: 9px; font-size: .84rem; line-height: 1.45; }
.hex { font-weight: 800; margin-bottom: 4px; letter-spacing: .03em; }
.muted { color: var(--muted); }
.good { color: var(--ok); }

.skeleton-card {
  border: 1px solid var(--line); border-radius: 14px; min-height: 180px;
  background: linear-gradient(100deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04));
  background-size: 250% 100%;
  animation: shimmer 1.1s linear infinite;
}
@keyframes shimmer { to { background-position: -250% 0; } }

.gradient-preview {
  height: 56px; border-radius: 12px; border: 1px solid var(--line); margin-top: 10px;
}

.history-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.history-item {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px;
  display: grid; gap: 8px; background: rgba(0, 0, 0, 0.15);
}
.history-colors { display: flex; gap: 4px; }
.history-colors span { flex: 1; height: 24px; border-radius: 7px; border: 1px solid rgba(255, 255, 255, 0.2); }
.history-row { display: flex; gap: 6px; }

.toast {
  position: fixed; right: 14px; bottom: 14px;
  border: 1px solid rgba(30, 203, 139, 0.35);
  background: #091024; color: #fff;
  padding: 10px 14px; border-radius: 10px;
  opacity: 0; transform: translateY(8px); transition: .2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

.mobile-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 80;
  display: none; grid-template-columns: repeat(3, 1fr); gap: 1px;
  background: rgba(0, 0, 0, 0.24); border-top: 1px solid var(--line);
}
.mobile-bar button {
  border: 0; border-radius: 0; background: var(--bg-soft); color: var(--text); padding: 14px 8px;
}

.popup-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  display: none; align-items: center; justify-content: center; z-index: 130;
}
.popup-overlay.active { display: flex; }
.popup-box {
  width: min(680px, calc(100% - 24px)); max-height: calc(100vh - 28px); overflow: auto;
  border-radius: 16px; padding: 16px; border: 1px solid var(--line);
  background: var(--bg-soft);
}
.popup-close { float: right; }
textarea {
  width: 100%; min-height: 140px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25); color: var(--text); margin: 10px 0; padding: 10px;
}

.legal-popup-overlay {
  position: fixed; inset: 0; z-index: 150; background: rgba(0, 0, 0, 0.6);
  display: grid; place-items: center; padding: 14px;
}
.legal-popup-box {
  width: min(520px, 100%); border-radius: 16px; border: 1px solid var(--line);
  background: var(--bg-soft); padding: 16px;
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  body { padding-bottom: 74px; }
  .mobile-bar { display: grid; }
  .actions { grid-template-columns: 1fr; }
}
