/* ===== Google Fonts ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ===== CSS Custom Properties ===== */
:root {
  /* Colors - Dark Theme */
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-tertiary: #1a2235;
  --bg-card: rgba(26, 34, 53, 0.7);
  --bg-glass: rgba(17, 24, 39, 0.6);
  --bg-glass-hover: rgba(17, 24, 39, 0.8);

  /* Accent Gradient */
  --accent-start: #6366f1;
  --accent-mid: #8b5cf6;
  --accent-end: #a78bfa;
  --accent-gradient: linear-gradient(135deg, var(--accent-start), var(--accent-mid), var(--accent-end));
  --accent-glow: 0 0 20px rgba(99, 102, 241, 0.3);

  /* Text */
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-accent: #a78bfa;

  /* Borders */
  --border-subtle: rgba(148, 163, 184, 0.1);
  --border-default: rgba(148, 163, 184, 0.15);
  --border-hover: rgba(148, 163, 184, 0.25);
  --border-accent: rgba(99, 102, 241, 0.5);

  /* Status */
  --success: #34d399;
  --warning: #fbbf24;
  --error: #f87171;
  --info: #60a5fa;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.6);

  /* Transitions */
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;

  /* Layout */
  --header-height: 64px;
  --sidebar-width: 380px;
  --toolbar-height: 48px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
  line-height: 1.5;
}

/* ===== Custom Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ===== App Layout ===== */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
}

/* ===== Header ===== */
.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-lg);
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 100;
  flex-shrink: 0;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.app-logo .logo-icon {
  width: 36px;
  height: 36px;
  background: var(--accent-gradient);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: var(--accent-glow);
}

.app-logo h1 {
  font-size: 1.15rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.app-logo .badge {
  font-size: 0.6rem;
  font-weight: 600;
  padding: 2px 8px;
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-end);
  border-radius: var(--radius-full);
  border: 1px solid rgba(99, 102, 241, 0.25);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-smooth);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0);
  transition: background var(--duration-fast) var(--ease-smooth);
}

.btn:hover::after {
  background: rgba(255, 255, 255, 0.05);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: var(--accent-glow);
}

.btn-primary:hover {
  box-shadow: 0 0 30px rgba(99, 102, 241, 0.4);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0) scale(0.97);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  color: var(--text-primary);
  background: rgba(148, 163, 184, 0.08);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

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

/* ===== Main Content Area ===== */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ===== Upload Screen ===== */
.upload-screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  background: var(--bg-primary);
  transition: opacity var(--duration-slow) var(--ease-smooth),
              visibility var(--duration-slow) var(--ease-smooth);
}

.upload-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.upload-zone {
  width: 560px;
  max-width: 90vw;
  padding: var(--space-2xl);
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-xl);
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  text-align: center;
  transition: all var(--duration-normal) var(--ease-smooth);
  cursor: pointer;
  position: relative;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent-start);
  background: rgba(99, 102, 241, 0.05);
  box-shadow: var(--accent-glow), var(--shadow-lg);
  transform: translateY(-4px);
}

.upload-zone.drag-over {
  border-style: solid;
  animation: pulse-border 1.5s ease-in-out infinite;
}

@keyframes pulse-border {
  0%, 100% { border-color: var(--accent-start); }
  50% { border-color: var(--accent-end); }
}

.upload-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto var(--space-lg);
  background: var(--accent-gradient);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--accent-glow);
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.upload-icon svg {
  width: 36px;
  height: 36px;
  color: white;
}

.upload-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: var(--space-sm);
  color: var(--text-primary);
}

.upload-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-lg);
}

.upload-formats {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
  margin-top: var(--space-md);
}

.format-tag {
  padding: var(--space-xs) var(--space-md);
  background: rgba(99, 102, 241, 0.1);
  color: var(--text-accent);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid rgba(99, 102, 241, 0.2);
}

.upload-or {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: var(--space-md) 0;
}

#fileInput {
  display: none;
}

/* ===== Editor Screen ===== */
.editor-screen {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

.editor-screen.active {
  display: flex;
}

/* ===== Toolbar ===== */
.editor-toolbar {
  height: var(--toolbar-height);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0 var(--space-md);
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex-shrink: 0;
}

/* ===== Font Controls Group (Toolbar) ===== */
.font-toolbar-group {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.toolbar-select.font-family-select {
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-smooth);
  max-width: 160px;
}

.toolbar-select.font-family-select:hover,
.toolbar-select.font-family-select:focus {
  border-color: var(--accent-start);
  background: var(--bg-secondary);
}

.font-size-stepper {
  display: inline-flex;
  align-items: center;
  height: 32px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 0 2px;
  gap: 1px;
}

.btn-stepper {
  width: 26px !important;
  height: 26px !important;
  padding: 0 !important;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.btn-stepper:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.font-size-input {
  width: 32px;
  height: 26px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
  outline: none;
  padding: 0;
  -moz-appearance: textfield;
}

.font-size-input::-webkit-outer-spin-button,
.font-size-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.font-size-unit {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-right: 2px;
  user-select: none;
}

.btn-format-toggle {
  width: 32px !important;
  height: 32px !important;
  padding: 0 !important;
}

.btn-format-toggle.active {
  background: rgba(99, 102, 241, 0.25) !important;
  color: var(--accent-start) !important;
  border: 1px solid rgba(99, 102, 241, 0.4) !important;
}

.format-letter-icon {
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
}

.format-letter-icon.italic {
  font-style: italic;
  font-family: Georgia, serif;
}

/* Ink Shade / Character Darkness & Lightness Controls */
.ink-shade-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 0 4px;
  height: 32px;
}

.btn-shade {
  width: 26px !important;
  height: 26px !important;
  padding: 0 !important;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.btn-shade:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.ink-shade-value {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-start);
  min-width: 38px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.color-picker-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-left: 3px;
  cursor: pointer;
  border-radius: 4px;
  border: 1px solid var(--border-default);
  overflow: hidden;
  background: #000000;
  transition: border-color var(--duration-fast);
}

.color-picker-label:hover {
  border-color: var(--accent-start);
}

.color-picker-input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.color-picker-swatch {
  width: 100%;
  height: 100%;
  border-radius: 3px;
  background-color: #000000;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border-default);
  margin: 0 var(--space-sm);
}

.toolbar-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-right: var(--space-xs);
}

.page-indicator {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
  min-width: 60px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.zoom-value {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
  min-width: 44px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ===== Canvas Viewport ===== */
.editor-body {
  display: flex;
  flex: 1;
  min-height: 0;
  min-width: 0;
  width: 100%;
  overflow: hidden;
  position: relative;
}

.canvas-viewport {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: var(--space-md);
  background:
    radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(139, 92, 246, 0.03) 0%, transparent 50%),
    var(--bg-primary);
  position: relative;
  -webkit-overflow-scrolling: touch;
  text-align: center;
}

.canvas-container {
  position: relative;
  display: inline-block;
  box-shadow: var(--shadow-xl);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin: 0 auto;
  vertical-align: top;
}

.canvas-container canvas {
  display: block;
}

/* ===== Text Overlay ===== */
.text-overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

.text-overlay .word-box {
  position: absolute;
  pointer-events: all;
  cursor: text;
  border: 1px solid transparent;
  border-radius: 2px;
  outline: none;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  transition: border-color var(--duration-fast) var(--ease-smooth),
              box-shadow var(--duration-fast) var(--ease-smooth);
}

.text-overlay .word-box:hover {
  border-color: rgba(99, 102, 241, 0.5);
}

.text-overlay .word-box:focus,
.text-overlay .word-box.editing {
  border-color: var(--accent-start) !important;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.35);
  z-index: 30 !important;
}

.text-overlay .word-box.modified {
  border-color: rgba(99, 102, 241, 0.4);
}

.text-overlay .word-box.modified:hover {
  border-color: var(--accent-start);
}

.text-overlay .word-box.highlighted {
  box-shadow: 0 0 0 2px var(--warning);
}

/* ===== Floating Word Quick Toolbar ===== */
.floating-word-toolbar {
  position: absolute;
  z-index: 120;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px 6px;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  box-shadow: 0 10px 28px -4px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(99, 102, 241, 0.35);
  pointer-events: all;
  user-select: none;
  animation: floatFadeIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
  transform-origin: bottom center;
}

@keyframes floatFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.floating-font-select {
  height: 24px;
  padding: 0 6px;
  border-radius: 4px;
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #f1f5f9;
  font-size: 0.72rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  max-width: 110px;
}

.floating-font-select:hover,
.floating-font-select:focus {
  border-color: var(--accent-start);
  background: rgba(51, 65, 85, 0.95);
}

.floating-divider {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.16);
  margin: 0 2px;
}

.floating-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: #cbd5e1;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.75rem;
  transition: all var(--duration-fast) var(--ease-smooth);
}

.floating-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.floating-btn.active {
  background: rgba(99, 102, 241, 0.35);
  color: #818cf8;
}

.floating-size-badge {
  font-size: 0.72rem;
  font-weight: 600;
  color: #f8fafc;
  min-width: 32px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding: 0 2px;
}

.floating-shade-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: #38bdf8;
  min-width: 36px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding: 0 2px;
}

/* ===== Side Panel ===== */
.side-panel {
  width: var(--sidebar-width);
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--duration-normal) var(--ease-smooth),
              opacity var(--duration-normal) var(--ease-smooth);
}

.side-panel.collapsed {
  width: 0;
  opacity: 0;
  overflow: hidden;
  border-left: none;
}

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.side-panel-header h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.side-panel-header .word-count {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-muted);
}

.side-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
}

.text-editor {
  width: 100%;
  min-height: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.88rem;
  line-height: 1.8;
  resize: none;
  outline: none;
}

.text-editor::placeholder {
  color: var(--text-muted);
}

/* Line-by-line editor */
.line-editor {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.text-line {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  transition: background var(--duration-fast) var(--ease-smooth);
  cursor: text;
}

.text-line:hover {
  background: rgba(148, 163, 184, 0.05);
}

.text-line.active {
  background: rgba(99, 102, 241, 0.08);
}

.text-line .line-number {
  font-size: 0.7rem;
  color: var(--text-muted);
  min-width: 24px;
  text-align: right;
  padding-top: 3px;
  font-variant-numeric: tabular-nums;
  user-select: none;
  flex-shrink: 0;
}

.text-line .line-content {
  flex: 1;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-primary);
  outline: none;
  border: none;
  background: transparent;
  padding: 2px 4px;
  border-radius: 3px;
  white-space: pre-wrap;
  word-break: break-word;
}

.text-line .line-content:focus {
  background: rgba(99, 102, 241, 0.06);
  box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.2);
}

.text-line .line-content.modified {
  color: var(--success);
}

/* ===== Loading Overlay ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(10, 14, 26, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-normal) var(--ease-smooth),
              visibility var(--duration-normal) var(--ease-smooth);
}

.loading-overlay.active {
  opacity: 1;
  visibility: visible;
}

.loading-card {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  text-align: center;
  min-width: 380px;
  box-shadow: var(--shadow-xl);
}

.loading-spinner {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-lg);
  position: relative;
}

.loading-spinner::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 3px solid var(--border-default);
  border-top-color: var(--accent-start);
  border-right-color: var(--accent-mid);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.loading-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: var(--space-sm);
}

.loading-status {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-lg);
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: var(--radius-full);
  width: 0%;
  transition: width var(--duration-normal) var(--ease-smooth);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

.progress-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: var(--space-sm);
  font-variant-numeric: tabular-nums;
}

/* ===== Toast Notifications ===== */
.toast-container {
  position: fixed;
  top: calc(var(--header-height) + var(--space-md));
  right: var(--space-md);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  color: var(--text-primary);
  animation: toast-in var(--duration-normal) var(--ease-bounce);
  min-width: 260px;
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error { border-left: 3px solid var(--error); }
.toast.toast-info { border-left: 3px solid var(--info); }
.toast.toast-warning { border-left: 3px solid var(--warning); }

.toast .toast-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.toast.leaving {
  animation: toast-out var(--duration-normal) var(--ease-smooth) forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(100%) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(100%) scale(0.8);
  }
}

/* ===== Empty state in editor ===== */
.editor-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: var(--space-xl);
}

.editor-empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-md);
  opacity: 0.3;
}

/* ===== Filename display ===== */
.file-info {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  color: var(--text-secondary);
  max-width: 250px;
  overflow: hidden;
}

.file-info .file-icon {
  flex-shrink: 0;
}

.file-info .file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Responsive Design ===== */

/* Tablet & Smaller Laptops (<= 1024px) */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 320px;
  }

  .app-header {
    padding: 0 var(--space-md);
  }
}

/* Tablets & Mobile Devices (<= 768px) */
@media (max-width: 768px) {
  :root {
    --header-height: 56px;
    --toolbar-height: 44px;
    --sidebar-width: 85vw;
  }

  .app-header {
    padding: 0 var(--space-sm);
  }

  .app-logo h1 {
    font-size: 1rem;
  }

  .app-logo .logo-icon {
    width: 30px;
    height: 30px;
    font-size: 15px;
  }

  .file-info {
    max-width: 130px;
    padding: 2px 8px;
    font-size: 0.72rem;
  }

  .btn-save-text {
    display: none;
  }

  .btn-save-text-mobile {
    display: inline !important;
  }

  /* Upload Screen on Mobile */
  .upload-zone {
    width: 100%;
    max-width: 92vw;
    padding: var(--space-xl) var(--space-md);
    border-radius: var(--radius-lg);
  }

  .upload-icon {
    width: 60px;
    height: 60px;
    margin-bottom: var(--space-md);
  }

  .upload-icon svg {
    width: 28px;
    height: 28px;
  }

  .upload-title {
    font-size: 1.15rem;
  }

  .upload-subtitle {
    font-size: 0.82rem;
  }

  .upload-formats {
    flex-wrap: wrap;
    gap: 6px;
  }

  .format-tag {
    padding: 3px 8px;
    font-size: 0.7rem;
  }

  /* Toolbar on Mobile (Smooth Horizontal Scroll) */
  .editor-toolbar {
    padding: 0 var(--space-xs);
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .editor-toolbar::-webkit-scrollbar {
    display: none;
  }

  .toolbar-group {
    flex-shrink: 0;
  }

  .toolbar-divider {
    margin: 0 4px;
  }

  /* Canvas Viewport */
  .canvas-viewport {
    padding: 8px;
  }

  /* Side Panel as Drawer */
  .side-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 150;
    width: var(--sidebar-width);
    max-width: 380px;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.7);
    transform: translateX(0);
    opacity: 1;
    transition: transform var(--duration-normal) var(--ease-smooth);
  }

  .side-panel.collapsed {
    transform: translateX(100%);
    width: var(--sidebar-width);
    opacity: 1;
    display: flex;
    overflow: visible;
  }

  .side-panel-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 14, 26, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 140;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--duration-normal) var(--ease-smooth),
                visibility var(--duration-normal) var(--ease-smooth);
  }

  .side-panel-backdrop.active {
    opacity: 1;
    visibility: visible;
  }

  /* Loading Overlay on Mobile */
  .loading-card {
    min-width: 0;
    width: 90vw;
    max-width: 360px;
    padding: var(--space-xl) var(--space-md);
  }

  /* Toast on Mobile */
  .toast-container {
    top: calc(var(--header-height) + 8px);
    left: 12px;
    right: 12px;
    max-width: calc(100vw - 24px);
  }

  .toast {
    min-width: 0;
    width: 100%;
  }
}

/* Extra Small Phones (<= 480px) */
@media (max-width: 480px) {
  .app-logo .badge {
    display: none;
  }

  .file-info {
    max-width: 90px;
  }

  .btn {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .toolbar-label {
    display: none;
  }

  .upload-zone {
    padding: var(--space-lg) var(--space-sm);
  }
}

/* ===== Selection ===== */
::selection {
  background: rgba(99, 102, 241, 0.3);
  color: white;
}

/* ===== Focus visible ===== */
:focus-visible {
  outline: 2px solid var(--accent-start);
  outline-offset: 2px;
}

/* ===== Tooltip ===== */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) scale(0.8);
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.7rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all var(--duration-fast) var(--ease-smooth);
  pointer-events: none;
  border: 1px solid var(--border-default);
  z-index: 100;
}

[data-tooltip]:hover::before {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) scale(1);
}

/* ===== Keyboard shortcuts hint ===== */
.shortcut-hint {
  font-size: 0.65rem;
  padding: 1px 5px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: 3px;
  color: var(--text-muted);
  font-family: monospace;
}

/* ===== App Nav Tabs ===== */
.app-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-primary);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--duration-fast) var(--ease-smooth);
}

.nav-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.nav-tab.active {
  color: #fff;
  background: var(--accent-gradient);
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* Vertical Word Boxes & Margin Text */
.text-overlay .word-box.vertical-word-box {
  transform-origin: 0 0 !important;
  transform: rotate(-90deg) !important;
}

.text-overlay .word-box.vertical-word-box:focus,
.text-overlay .word-box.vertical-word-box.editing {
  z-index: 45 !important;
}

/* Add Text Tool */
#btnAddText.active {
  background: var(--accent-gradient);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 2px 8px var(--accent-glow);
}

