:root {
  --bg: #0d0d12;
  --panel: rgba(24, 24, 32, 0.72);
  --panel-solid: #16161e;
  --berry: #e8425a;
  --berry-dim: #b3324a;
  --cream: #faf4e8;
  --muted: #8a8a99;
  --line: rgba(255,255,255,0.08);
  --glow: 0 0 24px rgba(232,66,90,0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--cream);
  font-family: "Bricolage Grotesque", sans-serif;
  overflow: hidden;
}
.mono { font-family: "JetBrains Mono", monospace; }
.tiny { font-size: 11px; }

/* Atmospheric background */
body::before {
  content: "";
  position: fixed; inset: 0;
  background:
    radial-gradient(circle at 15% 20%, rgba(232,66,90,0.14), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(120,80,200,0.12), transparent 50%),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.015) 0 2px, transparent 2px 22px);
  pointer-events: none; z-index: 0;
}

#app {
  position: relative; z-index: 1;
  height: 100vh;
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-rows: 60px 1fr 96px;
  grid-template-areas:
    "top top"
    "stage panel"
    "film panel";
  gap: 0;
}

/* Header */
#topbar {
  grid-area: top;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(13,13,18,0.6);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 26px; filter: drop-shadow(var(--glow)); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 0%,100%{transform:translateY(0) rotate(-4deg);} 50%{transform:translateY(-3px) rotate(4deg);} }
.brand-name { font-weight: 800; font-size: 20px; letter-spacing: -0.5px; }

.mode-toggle {
  position: relative;
  display: flex; background: #1c1c26; border-radius: 999px; padding: 4px;
  border: 1px solid var(--line);
}
.mode-slider {
  position: absolute; top: 4px; left: 4px; bottom: 4px; width: calc(50% - 4px);
  background: var(--berry); border-radius: 999px;
  transition: transform .28s cubic-bezier(.4,1.4,.5,1);
  box-shadow: var(--glow);
}
.mode-btn {
  position: relative; z-index: 1;
  background: none; border: none; color: var(--muted);
  font-family: inherit; font-weight: 700; font-size: 14px;
  padding: 8px 22px; cursor: pointer; transition: color .2s;
}
.mode-btn.active { color: #fff; }

.help-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line); background: #1c1c26; color: var(--cream);
  font-weight: 700; cursor: pointer; font-family: inherit; font-size: 16px;
  transition: transform .15s, background .2s;
}
.help-btn:hover { transform: scale(1.08); background: var(--berry-dim); }

/* Stage */
#stage {
  grid-area: stage;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 22px; overflow: hidden;
}
#canvas-wrap {
  position: relative;
  max-width: 100%; max-height: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 16px; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 0 1px var(--line);
  background-color: #1a1a22;
  background-image:
    linear-gradient(45deg, #202028 25%, transparent 25%),
    linear-gradient(-45deg, #202028 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #202028 75%),
    linear-gradient(-45deg, transparent 75%, #202028 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}
#canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

.empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 30px; pointer-events: none;
}
.empty-state .suggestion { pointer-events: auto; }
.empty-emoji { font-size: 64px; margin-bottom: 14px; animation: bob 4s ease-in-out infinite; }
.empty-title { font-size: 22px; font-weight: 700; color: var(--cream); }
.suggestion {
  margin-top: 14px; color: var(--berry); font-size: 15px; font-weight: 600;
  cursor: pointer; max-width: 340px; transition: opacity .3s;
}
.suggestion:hover { text-decoration: underline; }

.loading-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(13,13,18,0.55); backdrop-filter: blur(3px); z-index: 5;
}
.shimmer {
  width: 60px; height: 60px; border-radius: 50%;
  border: 4px solid rgba(232,66,90,0.2);
  border-top-color: var(--berry);
  animation: spin 0.9s linear infinite; margin-bottom: 18px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-weight: 600; color: var(--cream); }

.brush-cursor {
  position: fixed; pointer-events: none; z-index: 50;
  border: 2px solid var(--berry); border-radius: 50%;
  transform: translate(-50%, -50%);
  background: rgba(232,66,90,0.15);
  box-shadow: 0 0 8px rgba(232,66,90,0.5);
}

/* Toolbar */
.toolbar {
  position: absolute; left: 34px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 10px; align-items: center;
  background: var(--panel); backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 16px; padding: 12px 10px;
  z-index: 10;
}
.tool-btn {
  width: 42px; height: 42px; border-radius: 11px;
  border: 1px solid var(--line); background: #1c1c26; color: #fff;
  font-size: 18px; cursor: pointer; transition: all .15s;
}
.tool-btn:hover { transform: scale(1.08); }
.tool-btn.active { background: var(--berry); box-shadow: var(--glow); }
.tool-btn.danger:hover { background: var(--berry-dim); }
.tool-divider { width: 26px; height: 1px; background: var(--line); }
.tool-slider-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tool-hint { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.tool-slider-wrap input { width: 60px; }
.mask-thumb-wrap { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
#mask-thumb { display: block; }

/* Panel */
#panel {
  grid-area: panel;
  background: var(--panel-solid);
  border-left: 1px solid var(--line);
  padding: 20px 18px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
}
.panel-label {
  display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); margin-bottom: 8px; font-weight: 700;
}
.panel-label .opt { text-transform: none; letter-spacing: 0; color: #5a5a68; }
.prompt-box {
  width: 100%; resize: vertical; min-height: 74px;
  background: #101018; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; color: var(--cream); font-family: inherit; font-size: 14px;
  transition: border-color .2s;
}
.prompt-box:focus { outline: none; border-color: var(--berry); box-shadow: var(--glow); }

.drop-zone {
  border: 2px dashed var(--line); border-radius: 12px;
  padding: 18px 14px; text-align: center; color: var(--muted);
  font-size: 13px; cursor: pointer; transition: all .2s; position: relative;
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--berry); color: var(--cream); background: rgba(232,66,90,0.06); }
.ref-preview { max-width: 100%; max-height: 130px; border-radius: 8px; display: block; margin: 0 auto; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: #101018; color: var(--muted); font-family: inherit; font-size: 12px;
  font-weight: 600; cursor: pointer; transition: all .15s;
}
.chip:hover { color: var(--cream); }
.chip.active { background: var(--berry); border-color: var(--berry); color: #fff; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 5px;
  background: #2a2a36; border-radius: 999px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--berry); cursor: pointer; box-shadow: var(--glow);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border: none; border-radius: 50%;
  background: var(--berry); cursor: pointer;
}

.action-btn {
  width: 100%; padding: 14px; border: none; border-radius: 12px;
  background: var(--berry); color: #fff; font-family: inherit;
  font-weight: 800; font-size: 16px; cursor: pointer;
  transition: transform .12s, filter .2s, opacity .2s;
  box-shadow: var(--glow);
}
.action-btn:hover:not(.disabled) { transform: translateY(-2px); filter: brightness(1.1); }
.action-btn:active:not(.disabled) { transform: translateY(0); }
.action-btn.disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.action-hint { font-size: 12px; color: var(--muted); text-align: center; min-height: 15px; margin-top: -8px; }
.secondary-btn {
  width: 100%; padding: 11px; border: 1px solid var(--line); border-radius: 12px;
  background: #101018; color: var(--cream); font-family: inherit; font-weight: 600;
  font-size: 14px; cursor: pointer; transition: all .15s;
}
.secondary-btn:hover { border-color: var(--berry); }
.error-msg {
  background: rgba(232,66,90,0.15); border: 1px solid var(--berry-dim);
  color: #ffb3c0; padding: 10px; border-radius: 10px; font-size: 13px; text-align: center;
}

/* Filmstrip */
#filmstrip-bar {
  grid-area: film;
  border-top: 1px solid var(--line);
  background: rgba(13,13,18,0.6); backdrop-filter: blur(10px);
  padding: 12px 16px; overflow: hidden;
}
.filmstrip { display: flex; gap: 10px; height: 100%; overflow-x: auto; align-items: center; }
.filmstrip-empty { color: var(--muted); font-size: 13px; font-style: italic; }
.film-item {
  position: relative; height: 68px; width: 68px; flex: 0 0 auto;
  border-radius: 10px; overflow: hidden; border: 1px solid var(--line);
  cursor: pointer; transition: transform .15s, border-color .2s;
}
.film-item:hover { transform: translateY(-3px); border-color: var(--berry); }
.film-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.film-dl {
  position: absolute; bottom: 3px; right: 3px; border: none;
  background: rgba(0,0,0,0.6); border-radius: 6px; font-size: 11px;
  cursor: pointer; opacity: 0; transition: opacity .2s; padding: 2px 4px;
}
.film-item:hover .film-dl { opacity: 1; }

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
}
.modal-card {
  background: var(--panel-solid); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px; max-width: 420px; width: 90%;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-card h2 { font-size: 24px; }
.modal-card p { font-size: 14px; color: #c5c5d0; line-height: 1.5; }
.modal-card p strong { color: var(--berry); }
.modal-card .action-btn { margin-top: 8px; }

.credit {
  position: fixed; bottom: 6px; right: 344px; z-index: 40;
  font-size: 11px;
}
.credit a { color: var(--muted); text-decoration: none; }
.credit a:hover { color: var(--berry); }

.hidden { display: none !important; }

/* Mobile */
@media (max-width: 820px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 54px 1fr auto auto;
    grid-template-areas:
      "top"
      "stage"
      "film"
      "panel";
  }
  #panel {
    border-left: none; border-top: 1px solid var(--line);
    max-height: 46vh;
  }
  .mode-btn { padding: 7px 16px; font-size: 13px; }
  .toolbar {
    left: 50%; top: auto; bottom: 12px; transform: translateX(-50%);
    flex-direction: row; padding: 8px 10px;
  }
  .toolbar .tool-slider-wrap { flex-direction: row; gap: 6px; }
  .tool-slider-wrap input { width: 70px; }
  .mask-thumb-wrap { display: none; }
  #filmstrip-bar { padding: 8px 12px; }
  .film-item { height: 54px; width: 54px; }
  .credit { right: 12px; bottom: 2px; }
  .brand-name { font-size: 17px; }
}
</parameter>