/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f13;
  --surface: #17171f;
  --surface2: #1e1e2a;
  --surface3: #26263a;
  --border: rgba(255, 255, 255, .07);
  --accent: #6366f1;
  --accent2: #8b5cf6;
  --accent-glow: rgba(99, 102, 241, .35);
  --green: #34d399;
  --red: #f87171;
  --yellow: #fbbf24;
  --text: #e8e8f0;
  --text2: #9090a8;
  --text3: #5a5a70;
  --radius: 10px;
  --radius-sm: 6px;
  --trans: .15s ease;
  --font: 'Inter', system-ui, sans-serif;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--surface3);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* ===== UTILITIES ===== */
.hidden {
  display: none !important;
}

.flex {
  display: flex;
}

.gap-2 {
  gap: 8px;
}

/* ===== BUTTONS ===== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  border: none;
  cursor: pointer;
  transition: opacity var(--trans), transform var(--trans), box-shadow var(--trans);
  box-shadow: 0 2px 12px var(--accent-glow);
}

.btn-primary:hover {
  opacity: .9;
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary svg {
  width: 16px;
  height: 16px;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--trans);
}

.btn-ghost:hover {
  background: var(--surface2);
  color: var(--text);
}

.btn-ghost svg {
  width: 15px;
  height: 15px;
}

.btn-accent {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  background: rgba(99, 102, 241, .15);
  color: #a5b4fc;
  font-size: 13px;
  border: 1px solid rgba(99, 102, 241, .3);
  cursor: pointer;
  transition: all var(--trans);
}

.btn-accent:hover {
  background: rgba(99, 102, 241, .27);
  color: #fff;
}

.btn-accent svg {
  width: 15px;
  height: 15px;
}

.btn-full {
  width: 100%;
  justify-content: center;
  margin-top: 6px;
}

.btn-mini {
  padding: 5px 9px;
  border-radius: 5px;
  background: var(--surface3);
  color: var(--text2);
  font-size: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--trans);
}

.btn-mini:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-mini.danger:hover {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text2);
  border: none;
  cursor: pointer;
  transition: all var(--trans);
}

.icon-btn:hover {
  background: var(--surface2);
  color: var(--text);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

/* ===== SPLASH ===== */
.splash {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  overflow-y: auto;
}

.splash-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 60% at 30% 20%, rgba(99, 102, 241, .18) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 80%, rgba(139, 92, 246, .12) 0%, transparent 60%),
    var(--bg);
}

.splash-content {
  position: relative;
  z-index: 1;
  max-width: 720px;
  width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 40px 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.logo em {
  color: #a5b4fc;
  font-style: normal;
}

.logo-icon {
  width: 44px;
  height: 44px;
}

.logo-icon svg {
  width: 100%;
  height: 100%;
}

.splash-content h1 {
  font-size: clamp(28px, 5vw, 42px);
  font-weight: 700;
  text-align: center;
  background: linear-gradient(135deg, #e8e8f0, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.splash-content>p {
  text-align: center;
  font-size: 16px;
  color: var(--text2);
  max-width: 480px;
  line-height: 1.6;
}

/* Dropzone */
.dropzone {
  width: 100%;
  border: 2px dashed rgba(99, 102, 241, .4);
  border-radius: 16px;
  padding: 40px 20px;
  background: rgba(99, 102, 241, .05);
  transition: border-color .2s, background .2s;
  cursor: pointer;
}

.dropzone.drag-over {
  border-color: var(--accent);
  background: rgba(99, 102, 241, .12);
}

.dropzone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.drop-icon {
  width: 64px;
  height: 64px;
}

.drop-icon svg {
  width: 100%;
  height: 100%;
}

.drop-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.drop-sub {
  font-size: 13px;
  color: var(--text3);
}

.drop-formats {
  font-size: 11px;
  color: var(--text3);
  letter-spacing: .05em;
}

/* Feature grid */
.features-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: 100%;
}

.feat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 10px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--text2);
  transition: all var(--trans);
}

.feat:hover {
  border-color: rgba(99, 102, 241, .4);
  color: var(--text);
}

.feat-icon {
  font-size: 20px;
}

/* ===== EDITOR LAYOUT ===== */
.editor {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* TopBar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 10px;
}

.topbar-left,
.topbar-center,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-center {
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.logo-sm {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
}

.logo-sm em {
  color: #a5b4fc;
  font-style: normal;
}

.logo-sm svg {
  width: 28px;
  height: 28px;
}

.sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

.zoom-label {
  font-size: 12px;
  color: var(--text2);
  min-width: 38px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Editor body */
.editor-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Left toolbar */
.toolbar-left {
  width: 52px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 2px;
  overflow-y: auto;
  flex-shrink: 0;
}

.tool-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  width: 100%;
}

.tool-group:last-child {
  border-bottom: none;
}

.tool-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--trans);
  position: relative;
}

.tool-btn svg {
  width: 18px;
  height: 18px;
}

.tool-btn:hover {
  background: var(--surface2);
  color: var(--text);
}

.tool-btn.active {
  background: rgba(99, 102, 241, .2);
  color: #a5b4fc;
  box-shadow: inset 0 0 0 1px rgba(99, 102, 241, .4);
}

.tool-btn.danger:hover {
  background: rgba(248, 113, 113, .15);
  color: var(--red);
}

/* Canvas Area */
.canvas-area {
  flex: 1;
  overflow: scroll;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  background: #111118;
  background-image: radial-gradient(circle, rgba(255, 255, 255, .04) 1px, transparent 1px);
  background-size: 28px 28px;
  position: relative;
}

.canvas-wrap {
  margin: 20px auto;
  box-shadow: 0 8px 48px rgba(0, 0, 0, .6), 0 2px 8px rgba(0, 0, 0, .4);
  position: relative;
  line-height: 0;
}


.canvas-wrap canvas {
  display: block;
}

.ocr-overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

/* Loading overlay */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 19, .75);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 50;
  border-radius: 4px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(99, 102, 241, .2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-overlay p {
  color: var(--text2);
  font-size: 14px;
}

/* Right Panel */
.panel-right {
  width: 240px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.panel-section {
  border-bottom: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-header {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text3);
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel-hint {
  font-size: 11px;
  color: var(--text3);
  line-height: 1.5;
}

/* Props */
.prop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.prop-row label {
  font-size: 12px;
  color: var(--text2);
  min-width: 46px;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.color-swatch-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.color-swatch-wrap input[type="color"] {
  width: 18px;
  height: 18px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 3px;
  padding: 0;
}

.color-swatch-wrap span {
  font-size: 11px;
  color: var(--text2);
  font-family: 'JetBrains Mono', monospace;
}

.num-input-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
}

.num-input {
  width: 46px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  text-align: right;
  outline: none;
}

.unit {
  font-size: 11px;
  color: var(--text3);
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.slider {
  flex: 1;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--surface3);
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: pointer;
}

.slider-row span {
  font-size: 11px;
  color: var(--text2);
  min-width: 30px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.select-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}

.select-input:focus {
  border-color: var(--accent);
}

.style-btns {
  display: flex;
  gap: 4px;
}

.style-btn {
  width: 28px;
  height: 28px;
  border-radius: 5px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--trans);
}

.style-btn svg {
  width: 14px;
  height: 14px;
}

.style-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.style-btn.active {
  background: rgba(99, 102, 241, .2);
  border-color: var(--accent);
  color: #a5b4fc;
}

.transparent-btn {
  font-size: 14px;
  width: 28px;
  height: 28px;
  text-align: center;
  padding: 0;
}

/* Sampled color */
.sampled-color {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}

.sampled-swatch {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: transparent;
}

.sampled-color span {
  font-size: 12px;
  color: var(--text2);
  font-family: 'JetBrains Mono', monospace;
}

/* OCR List */
.ocr-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 250px;
  overflow-y: auto;
}

.ocr-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 12px;
  color: var(--text2);
  transition: all var(--trans);
}

.ocr-item:hover {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(99, 102, 241, .08);
}

.ocr-item.selected {
  border-color: var(--accent);
  background: rgba(99, 102, 241, .12);
  color: #a5b4fc;
}

.ocr-item-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  color: var(--text);
}

.ocr-item.ocr-low-conf {
  opacity: 0.7;
}

.ocr-item.ocr-low-conf .ocr-item-text {
  font-style: italic;
  color: var(--text3);
}

.ocr-item-actions {
  display: flex;
  gap: 6px;
}

.ocr-item-actions button {
  flex: 1;
  padding: 6px 4px;
  font-size: 11px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  margin-left: 4px;
}

/* Layers */
.layers-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 160px;
  overflow-y: auto;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 11px;
  color: var(--text2);
  transition: all var(--trans);
}

.layer-item:hover {
  border-color: var(--accent);
  color: var(--text);
}

.layer-item.selected {
  border-color: var(--accent);
  background: rgba(99, 102, 241, .1);
  color: #a5b4fc;
}

.layer-icon {
  font-size: 13px;
}

.layer-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-vis {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: .5;
  cursor: pointer;
}

.layers-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding-top: 4px;
}

/* OCR Tooltip */
.ocr-tooltip {
  position: fixed;
  z-index: 200;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
  padding: 12px 14px;
  min-width: 200px;
  animation: fadeIn .15s ease;
}

.ocr-tooltip-text {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 10px;
  word-break: break-word;
}

.ocr-tooltip-actions {
  display: flex;
  gap: 6px;
}

.ocr-tooltip-actions button {
  flex: 1;
  padding: 7px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface3);
  color: var(--text2);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--trans);
}

.ocr-tooltip-actions button:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}

.modal-header {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.modal-box p {
  font-size: 13px;
  color: var(--text2);
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 8px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

/* Crop rubber-band */
#cropRect {
  position: absolute;
  border: 2px dashed var(--accent);
  background: rgba(99, 102, 241, .1);
  pointer-events: none;
  z-index: 10;
}

/* Responsive */
@media (max-width: 900px) {
  .panel-right {
    width: 200px;
  }

  .features-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .topbar-center .btn-accent span {
    display: none;
  }

  .panel-right {
    display: none;
  }

  .logo-sm span {
    display: none;
  }
}