/* ============================================================
   style.css — ScreenshotEditor
   ============================================================ */

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0a0a10;
  --bg2:       #111118;
  --bg3:       #18181f;
  --border:    rgba(255,255,255,0.08);
  --primary:   #7c3aed;
  --primary-h: #6d28d9;
  --text:      #f0f0f5;
  --muted:     #8b8b9e;
  --radius:    14px;
  --toolbar-h: 52px;
  font-size: 15px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; border: none; outline: none; background: none; font-family: inherit; }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(10,10,16,.92);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1400px; margin: 0 auto;
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; height: 56px;
}
.logo {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: .9rem; color: var(--text);
}
.logo svg { color: var(--primary); }
.header-nav { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.btn-ghost {
  padding: 7px 16px; border-radius: 10px; font-size: .83rem; font-weight: 500;
  color: var(--muted); transition: background .15s, color .15s;
}
.btn-ghost:hover { background: rgba(255,255,255,.07); color: var(--text); }

.btn-primary {
  padding: 7px 18px; border-radius: 10px; font-size: .83rem; font-weight: 600;
  background: var(--primary); color: #fff; transition: background .15s, transform .1s, opacity .15s;
  box-shadow: 0 4px 18px rgba(124,58,237,.35);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-h); transform: translateY(-1px); }
.btn-primary:disabled { opacity: .45; cursor: default; }

/* ---------- Landing ---------- */
.landing {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 40px; padding: 60px 24px;
}
.landing-hero { text-align: center; }
.hero-badge {
  display: inline-block; padding: 6px 18px; border-radius: 999px;
  background: rgba(124,58,237,.15); color: var(--primary);
  font-size: .78rem; font-weight: 700; letter-spacing: .08em;
  border: 1px solid rgba(124,58,237,.3); margin-bottom: 22px;
}
.landing-hero h1 {
  font-size: clamp(2rem, 5vw, 3.2rem); font-weight: 900; line-height: 1.15;
  margin-bottom: 16px; color: #fff;
}
.gradient-text { color: var(--primary); }
.hero-sub { color: var(--muted); font-size: 1rem; max-width: 480px; margin: 0 auto; }

.upload-zone {
  width: 100%; max-width: 580px;
  border: 2px dashed rgba(255,255,255,.15);
  border-radius: 22px; padding: 56px 32px;
  text-align: center; background: rgba(255,255,255,.02);
  cursor: pointer; transition: border-color .2s, background .2s;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary); background: rgba(124,58,237,.06);
}
.upload-icon { margin-bottom: 18px; color: var(--muted); }
.upload-title { font-weight: 600; font-size: 1rem; color: var(--text); margin-bottom: 6px; }
.upload-sub   { font-size: .82rem; color: var(--muted); }

/* ---------- Editor layout ---------- */
.editor {
  display: flex; flex: 1; height: calc(100vh - 56px);
  position: relative;
}
.hidden { display: none !important; }

/* Sidebar */
.sidebar {
  width: 272px; min-width: 220px; background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: relative; z-index: 20; flex-shrink: 0;
}
.sidebar-header { padding: 14px 12px 10px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 {
  font-size: .82rem; font-weight: 700; display: flex; align-items: center; gap: 7px;
  color: var(--text); margin-bottom: 12px;
}
.layer-count {
  margin-left: auto; background: rgba(255,255,255,.07);
  padding: 1px 8px; border-radius: 999px; font-size: .72rem; font-weight: 500;
  color: var(--muted);
}
.btn-extract {
  width: 100%; padding: 10px 12px; border-radius: 12px; font-size: .82rem;
  font-weight: 600; color: #fff; background: var(--primary);
  display: flex; align-items: center; justify-content: center; gap: 7px;
  transition: background .15s, transform .1s;
  box-shadow: 0 4px 18px rgba(124,58,237,.3);
}
.btn-extract:hover { background: var(--primary-h); transform: translateY(-1px); }
.btn-extract:disabled { opacity: .45; cursor: default; }
.btn-add-layer {
  width: 100%; margin-top: 8px; padding: 8px 12px; border-radius: 12px;
  font-size: .8rem; font-weight: 500; color: var(--muted);
  border: 1px solid var(--border); transition: background .15s, color .15s;
}
.btn-add-layer:hover { background: rgba(255,255,255,.05); color: var(--text); }

.sidebar-hint {
  padding: 8px 14px; font-size: .72rem; color: rgba(167,139,250,.65);
  background: rgba(124,58,237,.08); border-bottom: 1px solid var(--border);
  line-height: 1.5;
}
.layer-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; }

.layer-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 12px; border: 1px solid transparent;
  cursor: pointer; transition: background .12s, border-color .12s;
  position: relative;
}
.layer-item:hover   { background: rgba(255,255,255,.04); border-color: rgba(255,255,255,.08); }
.layer-item.active  { background: rgba(124,58,237,.1); border-color: rgba(124,58,237,.3); }
.layer-index { font-size: .7rem; font-family: monospace; color: var(--muted); width: 16px; shrink: 0; }
.layer-dot   { width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(255,255,255,.2); flex-shrink: 0; }
.layer-info  { flex: 1; min-width: 0; }
.layer-text  { font-size: .79rem; color: #e8e8f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer-meta  { font-size: .68rem; color: var(--muted); margin-top: 1px; }
.layer-actions { display: none; gap: 2px; }
.layer-item:hover .layer-actions { display: flex; }
.layer-actions button {
  width: 24px; height: 24px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); transition: background .12s, color .12s;
}
.layer-actions button:hover { background: rgba(255,255,255,.1); color: var(--text); }
.layer-actions .del:hover   { background: rgba(239,68,68,.1); color: #f87171; }

.layer-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; opacity: .4; padding: 32px;
}
.layer-empty svg { color: var(--muted); }
.layer-empty p   { font-size: .82rem; color: var(--muted); text-align: center; }

.sidebar-footer { padding: 10px; border-top: 1px solid var(--border); }
.btn-clear {
  width: 100%; padding: 8px; border-radius: 10px; font-size: .78rem;
  color: var(--muted); border: 1px solid var(--border);
  transition: background .12s, color .12s;
}
.btn-clear:hover { background: rgba(255,255,255,.04); color: var(--text); }

/* Canvas area */
.canvas-area {
  flex: 1; overflow: auto; display: flex;
  align-items: center; justify-content: center;
  background: repeating-conic-gradient(rgba(255,255,255,.03) 0% 25%, transparent 0% 50%) 0 0 / 24px 24px;
  padding: 24px;
}
.canvas-wrapper {
  position: relative; display: inline-block;
  max-width: 100%; max-height: calc(100vh - 56px - 48px);
  box-shadow: 0 8px 60px rgba(0,0,0,.7);
  border-radius: 6px; overflow: hidden; line-height: 0;
}
#canvas-image {
  display: block; max-width: 100%;
  max-height: calc(100vh - 56px - 48px);
  object-fit: contain;
  user-select: none; pointer-events: none;
}
#overlay-container { position: absolute; inset: 0; pointer-events: none; }

/* Text overlays */
.text-overlay {
  position: absolute; pointer-events: auto; cursor: move;
  user-select: none; box-sizing: border-box;
}
.text-overlay .overlay-bg {
  position: absolute; inset: 0; pointer-events: none;
  border-radius: 2px;
}
.text-overlay .overlay-ring {
  position: absolute; inset: 0; pointer-events: none;
  border-radius: 2px; transition: box-shadow .12s;
}
.text-overlay:hover .overlay-ring     { box-shadow: 0 0 0 1px rgba(255,255,255,.3); }
.text-overlay.selected .overlay-ring  { box-shadow: 0 0 0 2px var(--primary), 0 0 0 4px rgba(124,58,237,.25); }

.overlay-text {
  position: relative; z-index: 2;
  width: 100%; height: 100%;
  word-break: break-word; white-space: pre-wrap;
  line-height: 1.2; padding: 2px 4px;
  outline: none;
}
.overlay-text[contenteditable="true"] { cursor: text; user-select: text; }

/* Resize handles */
.resize-handle {
  position: absolute; width: 12px; height: 12px;
  background: #fff; border: 2px solid var(--primary);
  border-radius: 50%; z-index: 10; pointer-events: auto;
  box-shadow: 0 2px 6px rgba(0,0,0,.4); transition: transform .1s;
}
.resize-handle:hover { transform: scale(1.3); }
.resize-handle.tl { top: -6px; left: -6px; cursor: nwse-resize; }
.resize-handle.tr { top: -6px; right: -6px; cursor: nesw-resize; }
.resize-handle.bl { bottom: -6px; left: -6px; cursor: nesw-resize; }
.resize-handle.br { bottom: -6px; right: -6px; cursor: nwse-resize; }

/* Floating toolbar */
.floating-toolbar {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; align-items: center; gap: 4px;
  padding: 7px 10px; border-radius: 18px;
  background: rgba(18,18,30,.96); backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,.1); box-shadow: 0 8px 40px rgba(0,0,0,.6);
}
.toolbar-group { display: flex; align-items: center; gap: 2px; }
.toolbar-sep { width: 1px; height: 22px; background: rgba(255,255,255,.1); margin: 0 4px; }

.tb-btn {
  width: 30px; height: 30px; border-radius: 9px; font-size: .82rem;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); transition: background .12s, color .12s;
}
.tb-btn:hover   { background: rgba(255,255,255,.1); color: var(--text); }
.tb-btn.active  { background: var(--primary); color: #fff; }
.tb-btn.tb-delete:hover { background: rgba(239,68,68,.15); color: #f87171; }

.tb-size-input {
  width: 42px; text-align: center; font-size: .78rem; font-weight: 500;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px; color: var(--text); padding: 4px 2px;
  -moz-appearance: textfield;
}
.tb-size-input::-webkit-inner-spin-button { display: none; }
.tb-size-input:focus { outline: none; border-color: var(--primary); }

.tb-color-wrap { display: flex; align-items: center; gap: 5px; padding: 0 6px; }
.tb-color-label { font-size: .7rem; color: var(--muted); line-height: 1; }
.tb-color-swatch {
  width: 20px; height: 20px; border-radius: 5px;
  border: 1px solid rgba(255,255,255,.2); overflow: hidden;
  position: relative; cursor: pointer;
}
.tb-color-swatch input[type="color"] {
  position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer;
}

/* Spinner */
.spinner-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.65); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.spinner-box {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 20px; padding: 40px 48px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.spinner-ring {
  width: 48px; height: 48px; border-radius: 50%;
  border: 3px solid rgba(124,58,237,.2);
  border-top-color: var(--primary); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-box p     { font-weight: 600; font-size: .95rem; }
.spinner-box small { color: var(--muted); font-size: .78rem; }

/* Footer */
.app-footer {
  border-top: 1px solid var(--border);
  padding: 16px 24px; text-align: center;
  font-size: .78rem; color: var(--muted);
}

/* Ad placeholders (invisible by default) */
.ad-placeholder { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sidebar { width: 220px; }
  .landing-hero h1 { font-size: 1.9rem; }
}
@media (max-width: 560px) {
  .editor { flex-direction: column; }
  .sidebar { width: 100%; height: auto; max-height: 220px; border-right: none; border-bottom: 1px solid var(--border); }
  .canvas-area { padding: 12px; }
  .floating-toolbar { width: calc(100% - 32px); justify-content: center; }
}
