/* Design Tokens */
:root {
  /* Light Theme */
  --bg-primary: #f5f2eb;
  --bg-secondary: #edeae1;
  --bg-tertiary: #e4e0d5;
  --text-primary: #1f1f21;
  --text-secondary: #5e5d59;
  --text-tertiary: #8f8e87;
  --accent: #bc3b29;
  --accent-hover: #a03020;
  --border: #d2cfc7;
  --grid-line: rgba(0, 0, 0, 0.03);
  --active-shadow: 0 0 12px rgba(188, 59, 41, 0.15);
  --font-mono: 'JetBrains Mono', monospace;
  --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  --border-radius: 4px;

  /* Typography Scale */
  --fs-h1: 1.5rem;
  --fs-h2: 1.25rem;
  --fs-body: 0.8rem;
  --fs-sm: 0.7rem;

  /* Letter Spacing */
  --ls-track: 0.2em;
  --ls-base: -0.1em;
}

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

button, input, select, textarea {
  font-family: inherit;
}

body {
  font-family: var(--font-mono);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--fs-body);
  letter-spacing: var(--ls-base);
  line-height: 1.5;
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 40px;
  border-bottom: 1px solid var(--border);
  background-color: var(--bg-primary);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: var(--fs-h1);
  font-weight: 600;
  letter-spacing: 0.15em;
  line-height: 1.1;
}

.brand-text .subtitle {
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
  letter-spacing: 0.25em;
  margin-top: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 15px;
}

.status-badge {
  font-size: var(--fs-sm);
  letter-spacing: var(--ls-track);
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  color: var(--text-secondary);
}

.offline-only {
  display: none;
}

body.offline .offline-only {
  display: inline-block;
  border-color: var(--accent);
  color: var(--accent);
}

/* Main Workspace */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 360px;
  min-height: calc(100vh - 140px);
}

/* Left preview pane */
.preview-pane {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
  background-color: var(--bg-secondary);
  position: relative;
  background-image: 
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 30px 30px;
  background-position: center;
  overflow: hidden;
}

.canvas-wrapper {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  border: 1px solid var(--border);
  background-color: var(--bg-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 320px;
  min-height: 320px;
  aspect-ratio: 1;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
  transition: border-color 0.2s ease;
}

.canvas-wrapper.drag-over {
  border-color: var(--accent);
  box-shadow: var(--active-shadow);
}

#output-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: none;
}

/* Empty State / Drag and Drop */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
}

.empty-state-icon {
  color: var(--text-tertiary);
  margin-bottom: 16px;
}

.empty-state h2 {
  font-size: var(--fs-h2);
  font-weight: 500;
  letter-spacing: var(--ls-base);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: var(--fs-body);
  color: var(--text-secondary);
  margin-bottom: 24px;
  max-width: 240px;
}

.file-hidden {
  display: none;
}

/* Controls Panel */
.control-pane {
  background-color: var(--bg-primary);
  border-left: 1px solid var(--border);
  padding: 30px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  overflow-y: auto;
  max-height: calc(100vh - 140px);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.group-title {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: var(--ls-track);
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.control-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.slider-header label {
  font-size: var(--fs-body);
  font-weight: 400;
  color: var(--text-secondary);
}

.slider-value {
  font-size: var(--fs-body);
  color: var(--accent);
}

/* Custom inputs range sliders */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 2px;
  background: var(--border);
  outline: none;
  transition: background 0.3s;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.3);
  background: var(--accent-hover);
}

/* Segmented Control */
.segmented-control {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  overflow: hidden;
}

.segment-option {
  flex: 1;
  text-align: center;
  position: relative;
  cursor: pointer;
}

.segment-option input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.segment-option span {
  display: block;
  padding: 10px 0;
  font-size: var(--fs-body);
  color: var(--text-secondary);
  background-color: var(--bg-secondary);
  transition: var(--transition);
  border-right: 1px solid var(--border);
}

.segment-option:last-child span {
  border-right: none;
}

.segment-option input:checked + span {
  background-color: var(--bg-tertiary);
  color: var(--accent);
  font-weight: 500;
}

/* Sub-setting Panels */
.sub-setting-panel {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: slideDown 0.25s cubic-bezier(0.25, 0.8, 0.25, 1);
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

.sub-label {
  font-size: var(--fs-body);
  font-weight: 400;
  color: var(--text-secondary);
}

/* Input Fields */
#unicode-chars {
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: var(--fs-body);
  outline: none;
  border-radius: var(--border-radius);
  transition: var(--transition);
}

#unicode-chars:focus {
  border-color: var(--accent);
  box-shadow: var(--active-shadow);
}

.helper-text {
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
}



.sub-setting-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-picker-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: var(--border-radius);
}

input[type="color"] {
  -webkit-appearance: none;
  border: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  background: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: 1px solid var(--border);
  border-radius: 50%;
}

.hex-value {
  font-size: var(--fs-body);
  color: var(--text-secondary);
}

/* Preset dots */
.palette-preset-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preset-colors {
  display: flex;
  gap: 8px;
}

.color-preset {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s;
  padding: 0;
}

.color-preset:hover {
  transform: scale(1.2);
}

.color-preset.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 3px var(--accent);
}

/* Metadata bar */
.image-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--border-radius);
}

.meta-label {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

/* Buttons */
.btn {
  font-size: var(--fs-body);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--ls-track);
  padding: 10px 20px;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
}

.btn-primary {
  background-color: var(--accent);
  color: #ffffff;
}

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

.btn-outline {
  background-color: transparent;
  border-color: var(--border);
  color: var(--text-primary);
}

.btn-outline:hover:not(:disabled) {
  background-color: var(--bg-secondary);
  border-color: var(--text-secondary);
}

.btn-sm {
  padding: 6px 12px;
  font-size: var(--fs-sm);
}

.btn-xs {
  padding: 4px 8px;
  font-size: var(--fs-sm);
}

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

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 8px;
  cursor: pointer;
  border-radius: var(--border-radius);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.btn-icon-svg {
  stroke-width: 1.5;
}

/* Actions Group */
.actions-group {
  margin-top: auto;
  display: flex;
  gap: 12px;
  border-top: 1px solid var(--border);
  padding-top: 24px;
}

.actions-group .btn {
  flex: 1;
  padding: 14px 0;
}

/* Loading Overlay */
.loading-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(18, 18, 20, 0.8);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 5;
}

[data-theme="light"] .loading-overlay {
  background-color: rgba(245, 242, 235, 0.8);
}

.spinner {
  width: 30px;
  height: 30px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay span {
  font-size: var(--fs-body);
  letter-spacing: var(--ls-track);
  color: var(--text-secondary);
}

/* Footer */
.app-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 40px;
  border-top: 1px solid var(--border);
  background-color: var(--bg-primary);
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
  z-index: 10;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 12px;
}

.divider {
  color: var(--border);
}

.install-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideDown 0.3s ease;
}

/* Responsiveness */
@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  
  .control-pane {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: none;
    overflow-y: visible;
  }
  
  .app-header, .app-footer {
    padding: 15px 20px;
  }
  
  .preview-pane {
    position: sticky;
    top: 0;
    z-index: 5;
    height: 40vh;
    min-height: 0;
    padding: 15px;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    box-sizing: border-box;
  }

  .canvas-wrapper {
    min-width: 0;
    min-height: 0;
    max-width: 100%;
    max-height: 100%;
  }
}

/* Camera overlay stream */
.camera-stream-wrapper {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #000;
  display: flex;
  flex-direction: column;
  z-index: 4;
  border-radius: var(--border-radius);
  overflow: hidden;
}
#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  flex: 1;
  background-color: #000;
}
.camera-controls {
  display: flex;
  justify-content: center;
  gap: 15px;
  padding: 15px;
  background-color: var(--bg-primary);
  border-top: 1px solid var(--border);
}

/* Border input field styling */
#border-title-input {
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: var(--fs-body);
  outline: none;
  border-radius: var(--border-radius);
  transition: var(--transition);
}
#border-title-input:focus {
  border-color: var(--accent);
  box-shadow: var(--active-shadow);
}

/* Wide mode screen fit - prevent scrolling on desktop/tablet */
@media (min-width: 901px) {
  body {
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
  }
  .app-container {
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
  }
  .workspace {
    height: 0;
    min-height: 0;
    flex: 1;
  }
  .preview-pane {
    height: 100%;
    max-height: 100%;
    padding: 20px; /* Maximize vertical height for canvas preview */
    box-sizing: border-box;
    overflow: hidden;
  }
  .canvas-wrapper {
    max-height: 100%;
    max-width: 100%;
  }
  .control-pane {
    height: 100%;
    max-height: 100%;
    overflow-y: auto;
  }
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translate(-50%, 14px);
  background-color: var(--text-primary, #1f1f21);
  color: var(--bg-primary, #f5f2eb);
  border: 1px solid var(--border, #d2cfc7);
  padding: 8px 16px;
  border-radius: var(--border-radius, 4px);
  font-family: var(--font-mono, monospace);
  font-size: var(--fs-sm, 0.7rem);
  letter-spacing: var(--ls-track, 0.2em);
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
  z-index: 9999;
}

.toast.visible {
  opacity: 1 !important;
  transform: translate(-50%, 0) !important;
  pointer-events: auto;
}

.toast-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent);
  flex-shrink: 0;
}

/* Modal Backdrop & Card */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(18, 18, 20, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10000;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  animation: slideUpModal 0.25s cubic-bezier(0.25, 0.8, 0.25, 1);
  overflow: hidden;
}

@keyframes slideUpModal {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background-color: var(--bg-primary);
}

.modal-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-title-group h2 {
  font-size: var(--fs-h2);
  font-weight: 600;
  letter-spacing: 0.15em;
  line-height: 1;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.modal-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-section-title {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: var(--ls-track);
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.modal-text {
  font-size: var(--fs-body);
  color: var(--text-secondary);
  line-height: 1.6;
}

.modal-guide-list {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: var(--fs-body);
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-guide-list strong {
  color: var(--text-primary);
}

.modal-meta-section {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  padding: 14px 16px;
  gap: 8px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--fs-body);
}

.meta-label-dim {
  color: var(--text-tertiary);
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: var(--ls-track);
}

.meta-val {
  color: var(--text-primary);
  font-weight: 500;
}

.modal-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
}

.modal-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}
