*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242836;
  --border: #2e3345;
  --text: #e8eaf0;
  --muted: #8b92a8;
  --accent: #6c8cff;
  --accent-hover: #8aa4ff;
  --danger: #ff6b6b;
  --radius: 10px;
  --sidebar-w: 320px;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  direction: ltr;
}

.header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.layout {
  display: flex;
  min-height: calc(100vh - 80px);
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 1rem;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--surface);
}

.panel {
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.panel:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.field span {
  color: var(--muted);
  font-size: 0.8125rem;
}

input[type="text"],
select {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  direction: ltr;
  unicode-bidi: isolate;
}

.text-field {
  display: block;
  margin-bottom: 0.75rem;
  text-align: left;
  writing-mode: horizontal-tb;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  cursor: pointer;
}

.check input {
  accent-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) {
  background: #2d3347;
  border-color: #3d4560;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8125rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.file-btn {
  display: inline-block;
  padding: 0.55rem 0.9rem;
  margin-bottom: 0.5rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  font-size: 0.875rem;
  cursor: pointer;
  text-align: center;
}

.file-btn:hover {
  border-color: var(--accent);
  background: rgba(108, 140, 255, 0.08);
}

.file-btn-sm {
  display: block;
  padding: 0.4rem 0.65rem;
  font-size: 0.8125rem;
  margin-bottom: 0.75rem;
}

.hint {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.8125rem;
}

.hint.error {
  color: var(--danger);
}

.hint.success {
  color: #6ee7a0;
}

.hidden {
  display: none !important;
}

.canvas-wrap.has-image {
  min-width: 120px;
  min-height: 120px;
}

.workspace {
  flex: 1;
  padding: 1rem;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.canvas-wrap {
  position: relative;
  max-width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  background: repeating-conic-gradient(#2a2d3a 0% 25%, #232630 0% 50%) 50% / 16px 16px;
}

#mainCanvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.text-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 2;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  pointer-events: none;
}

@media (max-width: 900px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}
