:root {
  --bg: #0e0f13;
  --bg-2: #14161c;
  --card: #181b22;
  --card-2: #1f232c;
  --line: #2a2f3a;
  --text: #eef1f6;
  --muted: #9aa3b2;
  --accent: #5b6cff;
  --accent-2: #9b5bff;
  --danger: #ff5b6c;
  --ok: #34d399;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

html[data-theme="light"] {
  --bg: #f2f4f9;
  --bg-2: #e9ecf3;
  --card: #ffffff;
  --card-2: #f4f6fb;
  --line: #e2e6ef;
  --text: #1a1d26;
  --muted: #5c6677;
  --shadow: 0 10px 30px rgba(20, 30, 60, .10);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(91, 108, 255, .14), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(155, 91, 255, .12), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  max-width: 1180px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { border-radius: 9px; box-shadow: var(--shadow); }
.brand-text h1 { font-size: 1.18rem; margin: 0; letter-spacing: -.02em; }
.brand-text p { margin: 2px 0 0; font-size: .82rem; color: var(--muted); }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- Layout ---------- */
.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 40px);
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, .9fr);
  gap: 20px;
  align-items: start;
}
.card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Stage / Vorschau ---------- */
.stage { padding: 22px; display: grid; gap: 22px; }
.preview-wrap { display: grid; gap: 8px; place-items: center; }
.checker {
  position: relative;
  width: min(360px, 70vw);
  aspect-ratio: 1;
  border-radius: var(--radius);
  background-color: var(--card-2);
  background-image:
    conic-gradient(from 0deg, rgba(255, 255, 255, .045) 0 25%, transparent 0 50%, rgba(255, 255, 255, .045) 0 75%, transparent 0);
  background-size: 28px 28px;
  display: grid;
  place-items: center;
  overflow: hidden;
}
#mainCanvas {
  width: 88%;
  height: 88%;
  image-rendering: auto;
  filter: drop-shadow(0 12px 22px rgba(0, 0, 0, .35));
  touch-action: none;
  cursor: grab;
}
#mainCanvas:active { cursor: grabbing; }
#mainCanvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 8px; }
.preview-hint {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: .9rem;
  pointer-events: none;
}
.drag-tip { margin: 0; font-size: .78rem; color: var(--muted); }

/* Phone-Mock */
.phone { display: grid; justify-items: center; gap: 8px; }
.phone-screen {
  width: 200px;
  border-radius: 26px;
  padding: 18px 16px;
  background: linear-gradient(160deg, #2a2050, #123b4d 60%, #0d2b3a);
  border: 1px solid rgba(255, 255, 255, .08);
  box-shadow: inset 0 0 0 4px rgba(0, 0, 0, .25), var(--shadow);
}
.phone-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 10px; }
.cell { display: grid; justify-items: center; gap: 5px; }
.cell .ic {
  width: 34px; height: 34px; border-radius: 11px;
  background: rgba(255, 255, 255, .22);
}
.cell.live canvas { width: 34px; height: 34px; display: block; }
.cell .lbl { width: 30px; height: 4px; border-radius: 3px; background: rgba(255, 255, 255, .25); }
.phone-label { font-size: .76rem; color: var(--muted); }

/* ---------- Panel ---------- */
.panel { padding: 8px 18px 18px; display: grid; }
.group { padding: 16px 0; border-bottom: 1px solid var(--line); display: grid; gap: 12px; }
.group:last-child { border-bottom: 0; }
.group-title { font-size: .82rem; font-weight: 600; color: var(--muted); letter-spacing: .01em; }

.dropzone {
  display: grid; justify-items: center; gap: 4px;
  padding: 22px 14px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s var(--ease), background .15s var(--ease), color .15s var(--ease);
  text-align: center;
}
.dropzone strong { color: var(--text); }
.dropzone small { font-size: .76rem; }
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); color: var(--text); background: rgba(91, 108, 255, .06); outline: none; }
.dropzone.drag { border-color: var(--accent); background: rgba(91, 108, 255, .1); color: var(--text); }

/* Segmented control */
.seg { display: flex; flex-wrap: wrap; gap: 6px; background: var(--bg-2); padding: 5px; border-radius: 12px; border: 1px solid var(--line); }
.seg-btn {
  flex: 1 1 auto;
  min-width: 60px;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-active { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(91, 108, 255, .35); }

/* Background controls */
.bg-controls { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.color-field {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 10px 6px 6px; font-size: .82rem; color: var(--muted);
}
.color-field input[type="color"] {
  width: 30px; height: 30px; border: 0; padding: 0; border-radius: 7px; background: none; cursor: pointer;
}
.color-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-field input[type="color"]::-webkit-color-swatch { border: 1px solid var(--line); border-radius: 7px; }

.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.preset {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .15);
  cursor: pointer; transition: transform .12s var(--ease); padding: 0;
}
.preset:hover { transform: scale(1.1); }

.slider-field { display: grid; gap: 6px; font-size: .82rem; color: var(--muted); }
.slider-field b { color: var(--text); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.text-field { display: grid; gap: 6px; font-size: .82rem; color: var(--muted); }
.text-field input, .text-field select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--text); font-size: .9rem; font-family: inherit;
}
.text-field input:focus, .text-field select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.export-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 2px; }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit; font-size: .88rem; font-weight: 600;
  border-radius: 11px; border: 1px solid transparent; cursor: pointer;
  padding: 11px 16px; transition: transform .08s var(--ease), background .15s var(--ease), opacity .15s var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: 8px 12px; font-size: .82rem; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 6px 18px rgba(91, 108, 255, .35); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn-secondary { background: var(--card-2); color: var(--text); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--accent); }
.btn-icon { background: transparent; border-color: var(--line); color: var(--text); padding: 9px 11px; line-height: 1; }
.btn-icon:hover { border-color: var(--accent); }

/* ---------- Tray ---------- */
.tray { max-width: 1180px; margin: 20px auto 0; width: calc(100% - 2 * clamp(16px, 4vw, 40px)); padding: 18px; }
.tray-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.tray-head h2 { margin: 0; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.tray-actions { display: flex; gap: 8px; }
.badge { background: var(--accent); color: #fff; font-size: .74rem; border-radius: 999px; padding: 2px 9px; }
.set-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 12px; }
.empty-note { grid-column: 1 / -1; color: var(--muted); font-size: .88rem; margin: 6px 0; text-align: center; }
.set-item {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; gap: 8px; justify-items: center;
}
.set-item .thumb {
  width: 72px; height: 72px; border-radius: 14px;
  background-color: var(--card-2);
  background-image: conic-gradient(from 0deg, rgba(255, 255, 255, .05) 0 25%, transparent 0 50%, rgba(255, 255, 255, .05) 0 75%, transparent 0);
  background-size: 12px 12px;
  object-fit: contain;
}
.set-item .name { font-size: .78rem; color: var(--text); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-item .item-actions { display: flex; gap: 6px; }
.icon-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 8px;
  width: 30px; height: 28px; cursor: pointer; font-size: .85rem; display: grid; place-items: center;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-btn.del:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- Footer ---------- */
.app-footer { text-align: center; color: var(--muted); font-size: .78rem; padding: 26px 16px 34px; }

/* ---------- Dialog ---------- */
.dialog {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0;
  background: var(--card); color: var(--text); max-width: 520px; width: calc(100% - 32px); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 1.05rem; }
.dialog-body { padding: 18px 20px 22px; }
.steps { margin: 0 0 14px; padding-left: 20px; display: grid; gap: 10px; font-size: .9rem; line-height: 1.5; }
.steps b { color: var(--text); }
.note { font-size: .82rem; color: var(--muted); background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 0; line-height: 1.5; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 999px;
  font-size: .86rem; font-weight: 600; box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity .2s var(--ease), transform .2s var(--ease); z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .stage { order: -1; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
