:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e8eaed;
  --text-dim: #9aa1ac;
  --accent: #3fb6f0;
  --top-text-scale: 1;
  --headline-scale: 1;
  --top-text-line-height-scale: 1;
  --headline-line-height-scale: 1;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ===================== Lock screen ===================== */
.lock-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, #1b2130, #0b0d12 70%);
}

.lock-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 28px;
  width: 320px;
  text-align: center;
}

.lock-card h1 { font-size: 20px; margin: 0 0 6px; }
.lock-card p { color: var(--text-dim); margin: 0 0 18px; font-size: 14px; }

.lock-card input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
}

.lock-card button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #06202e;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
}

.lock-error { color: #ff6b6b; margin-top: 12px; font-size: 13px; }

/* ===================== App shell ===================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.app-header h1 { font-size: 17px; margin: 0; }

.workspace {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 0;
  min-height: calc(100vh - 57px);
}

@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
}

/* ===================== Editor panel ===================== */
.editor-panel {
  padding: 22px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
}

.field-group { margin-bottom: 22px; }

.field-group > label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

select, .headline-input, #topTextInput {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  padding: 10px 12px;
}

select { cursor: pointer; }

#topTextInput { margin-top: 8px; font-family: inherit; }

.size-control {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.size-control label {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

.size-control input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.size-value {
  font-size: 12px;
  color: var(--text-dim);
  width: 42px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.dropzone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 10px;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--panel-2);
  overflow: hidden;
  text-align: center;
  padding: 12px;
}

.dropzone.drag-over { border-color: var(--accent); background: #16232b; }

.dropzone-empty p { color: var(--text-dim); font-size: 13px; margin: 0; }

.dropzone-img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 6px;
}

.btn {
  border: none;
  border-radius: 7px;
  padding: 8px 14px;
  background: var(--accent);
  color: #06202e;
  font-weight: 700;
  cursor: pointer;
  font-size: 13px;
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  font-weight: 600;
}

.btn-small { padding: 6px 10px; font-size: 12px; }

#removeImageBtn { margin-top: 10px; }

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.toolbar-label { font-size: 12px; color: var(--text-dim); margin-right: 2px; }

.case-toolbar { margin-bottom: 10px; }

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
}
.swatch:hover { border-color: var(--text); }

#customColor {
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

.headline-input {
  min-height: 110px;
  line-height: 1.4;
  outline: none;
}

.headline-input:empty::before {
  content: attr(data-placeholder);
  color: var(--text-dim);
}

.hint {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-top: 26px;
}

/* ===================== Preview panel ===================== */
.preview-panel {
  padding: 22px;
  overflow-y: auto;
}

.preview-panel h2 {
  font-size: 15px;
  color: var(--text-dim);
  margin: 0 0 16px;
  font-weight: 600;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 22px;
}

.template-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.template-card h3 {
  font-size: 13px;
  margin: 0 0 10px;
  color: var(--text-dim);
  font-weight: 600;
}

.template-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  background: #23262e;
  container-type: inline-size;
}

.template-frame.has-image {
  cursor: grab;
  touch-action: none;
}

.template-frame.has-image.dragging {
  cursor: grabbing;
}

.template-frame .bg-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transform-origin: center center;
  pointer-events: none;
}

.frame-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin: 8px 0 0;
}

.image-controls {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.image-controls .btn {
  flex: 1;
}

.template-frame .bg-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  padding: 20px;
}

.template-frame .overlay { position: absolute; inset: 0; pointer-events: none; }

.template-frame .kicker {
  position: absolute;
  font-weight: 700;
  text-transform: uppercase;
  line-height: calc(1.2 * var(--top-text-line-height-scale));
  z-index: 3;
}

.template-frame .headline {
  position: absolute;
  font-weight: 900;
  z-index: 3;
  word-wrap: break-word;
}

.template-frame .headline .hl-default { color: inherit; }

.action-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.download-btn, .copy-btn {
  flex: 1;
}

.copy-btn.copied {
  background: #2ecc71;
}

/* ---------- Template: bold-bar ---------- */
.tpl-bold-bar .overlay {
  background: linear-gradient(to top, rgba(0,0,0,0.92) 0%, rgba(0,0,0,0.55) 40%, rgba(0,0,0,0) 65%);
}
.tpl-bold-bar .content {
  position: absolute; left: 6%; right: 6%; bottom: 6%; z-index: 3;
  display: flex; flex-direction: column; gap: 1.6cqw;
}
.tpl-bold-bar .kicker {
  position: static; color: #fff; font-size: calc(4.2cqw * var(--top-text-scale)); letter-spacing: 0.08em;
}
.tpl-bold-bar .rule {
  position: static; width: 100%; height: 2px; background: rgba(255,255,255,0.85);
}
.tpl-bold-bar .headline {
  position: static; color: #fff; font-size: calc(7.8cqw * var(--headline-scale)); line-height: calc(1.05 * var(--headline-line-height-scale));
}

/* ---------- Template: corner-tag ---------- */
.tpl-corner-tag .overlay {
  background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.35) 45%, rgba(0,0,0,0) 62%);
}
.tpl-corner-tag .kicker {
  left: 6%; top: 6%; background: #dc2626; color: #fff; font-size: calc(3.6cqw * var(--top-text-scale));
  padding: 2.5% 4%; letter-spacing: 0.05em;
}
.tpl-corner-tag .headline {
  left: 6%; right: 6%; bottom: 7%; color: #fff; font-size: calc(7.4cqw * var(--headline-scale)); line-height: calc(1.08 * var(--headline-line-height-scale));
}

/* ---------- Template: bottom-card ---------- */
.tpl-bottom-card .overlay {
  position: absolute; left: 0; right: 0; bottom: 0; top: 62%;
  background: #111318;
}
.tpl-bottom-card .kicker {
  left: 6%; top: 58%; background: #ff5b57; color: #fff; font-size: calc(3.4cqw * var(--top-text-scale));
  padding: 2.2% 4.5%; border-radius: 50px; letter-spacing: 0.04em;
}
.tpl-bottom-card .headline {
  left: 6%; right: 6%; top: 68%; color: #fff; font-size: calc(6.8cqw * var(--headline-scale)); line-height: calc(1.12 * var(--headline-line-height-scale));
}

/* ---------- Template: center-focus ---------- */
.tpl-center-focus .overlay {
  background: rgba(0,0,0,0.35);
}
.tpl-center-focus .textbox {
  position: absolute; left: 8%; right: 8%; top: 50%; transform: translateY(-50%);
  background: rgba(10,10,14,0.6); border-radius: 10px; padding: 6% 6%; z-index: 3;
}
.tpl-center-focus .kicker {
  position: static; color: #f5c518; font-size: calc(3.8cqw * var(--top-text-scale)); letter-spacing: 0.12em; margin-bottom: 4%;
}
.tpl-center-focus .headline {
  position: static; color: #fff; font-size: calc(7cqw * var(--headline-scale)); line-height: calc(1.15 * var(--headline-line-height-scale)); text-align: center;
}

/* ---------- Template: side-strip ---------- */
.tpl-side-strip .overlay {
  background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.2) 55%, rgba(0,0,0,0) 70%);
}
.tpl-side-strip .strip {
  position: absolute; left: 0; top: 0; bottom: 0; width: 2.5%; background: #10b981; z-index: 3;
}
.tpl-side-strip .content {
  position: absolute; left: 8%; right: 6%; bottom: 6%; z-index: 3;
  display: flex; flex-direction: column; gap: 1.6cqw;
}
.tpl-side-strip .kicker {
  position: static; color: #10b981; font-size: calc(3.8cqw * var(--top-text-scale)); letter-spacing: 0.1em;
}
.tpl-side-strip .headline {
  position: static; color: #fff; font-size: calc(7.4cqw * var(--headline-scale)); line-height: calc(1.1 * var(--headline-line-height-scale));
}

/* ===================== Solid color background controls ===================== */
.color-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
}
.color-swatch:hover { border-color: var(--text-dim); }
.color-swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(63, 182, 240, 0.35); }

.color-custom {
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  margin-left: auto;
}

/* ---------- Template: solid color cards ---------- */
.solid-kicker {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 30%;
  text-align: center;
  color: #fff;
  font-family: "Baloo 2", Arial, sans-serif;
  font-weight: 700;
  font-size: calc(4.2cqw * var(--top-text-scale));
  line-height: calc(1.2 * var(--top-text-line-height-scale));
  -webkit-text-stroke: calc(0.5cqw * var(--top-text-scale)) #000;
  paint-order: stroke fill;
  z-index: 3;
}

.solid-headline {
  position: absolute;
  left: 7%;
  right: 7%;
  top: 53%;
  transform: translateY(-50%);
  text-align: center;
  color: #fff;
  font-family: "Baloo 2", Arial, sans-serif;
  font-weight: 800;
  font-size: calc(10cqw * var(--headline-scale));
  line-height: calc(1.05 * var(--headline-line-height-scale));
  -webkit-text-stroke: calc(0.9cqw * var(--headline-scale)) #000;
  paint-order: stroke fill;
  z-index: 3;
}

/* ---------- Template: sticky note ---------- */
.tpl-sticky-note .overlay {
  background: rgba(0,0,0,0.15);
}

.tpl-sticky-note .sticky-note {
  position: absolute;
  left: 12%;
  right: 12%;
  top: 50%;
  transform: translateY(-50%) rotate(-3deg);
  background: #fff59d;
  box-shadow: 0 1.4cqw 2.4cqw rgba(0,0,0,0.35);
  padding: 7% 8%;
  z-index: 3;
}

.tpl-sticky-note .sticky-tape {
  position: absolute;
  top: -4%;
  left: 50%;
  transform: translateX(-50%) rotate(-2deg);
  width: 28%;
  height: 9%;
  background: rgba(255,255,255,0.6);
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.tpl-sticky-note .sticky-kicker {
  position: static;
  font-family: "Caveat", cursive;
  font-weight: 600;
  font-size: calc(5.5cqw * var(--top-text-scale));
  line-height: calc(1.2 * var(--top-text-line-height-scale));
  color: #4b4632;
  text-align: center;
  margin-bottom: 3%;
}

.tpl-sticky-note .sticky-headline {
  position: static;
  font-family: "Caveat", cursive;
  font-weight: 700;
  font-size: calc(8.4cqw * var(--headline-scale));
  line-height: calc(1.08 * var(--headline-line-height-scale));
  color: #1a1a1a;
  text-align: center;
}
