:root {
  --bg-app: #080a0f;
  --bg-panel: #0e121a;
  --bg-card: rgba(255, 255, 255, 0.025);
  --bg-card-hover: rgba(255, 255, 255, 0.05);
  --bg-canvas: #050608;

  --border-subtle: rgba(255, 255, 255, 0.07);
  --border-card: rgba(255, 255, 255, 0.1);
  --border-focus: rgba(99, 140, 255, 0.55);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-primary: #3b82f6;
  --accent-primary-hover: #60a5fa;
  --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  --accent-glow: rgba(59, 130, 246, 0.28);

  --accent-restore: #10b981;
  --accent-restore-glow: rgba(16, 185, 129, 0.25);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 9999px;

  --shadow-hud: 0 12px 32px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.08);
  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-modal: 0 24px 64px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.1);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* App Shell Layout */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Workspace Grid (Full viewport height now that top header is removed) */
.workspace {
  display: grid;
  grid-template-columns: 1fr 340px;
  width: 100%;
  height: 100%;
  min-height: 0;
  position: relative;
  transition: grid-template-columns 240ms cubic-bezier(0.16, 1, 0.3, 1);
}

.app-shell.panel-collapsed .workspace {
  grid-template-columns: 1fr;
}

/* Viewport Area */
.viewport {
  position: relative;
  background: radial-gradient(circle at center, #111520 0%, var(--bg-canvas) 100%);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
}

#paintCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: none;
  touch-action: none;
}

.viewport.is-pan-ready #paintCanvas {
  cursor: grab;
}

.viewport.is-panning #paintCanvas {
  cursor: grabbing;
}

.viewport.is-pan-ready .brush-cursor,
.viewport.is-panning .brush-cursor {
  opacity: 0 !important;
}

/* Floating Expand Panel Toggle (visible when panel is collapsed) */
.floating-panel-toggle {
  position: absolute;
  top: 18px;
  right: 18px;
  display: none;
  align-items: center;
  gap: 8px;
  background: rgba(14, 18, 27, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-hud);
  color: var(--text-primary);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 8px 16px;
  cursor: pointer;
  z-index: 15;
  transition: all 160ms ease;
}

.floating-panel-toggle svg {
  width: 16px;
  height: 16px;
  color: var(--accent-primary);
}

.floating-panel-toggle:hover {
  background: rgba(25, 32, 48, 0.96);
  border-color: var(--border-focus);
  transform: translateY(-1px);
}

.app-shell.panel-collapsed .floating-panel-toggle {
  display: flex;
}

/* Brush Cursor with Dual-Ring Visibility */
.brush-cursor {
  position: absolute;
  left: 0;
  top: 0;
  width: 160px;
  height: 160px;
  border-radius: var(--radius-pill);
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease, border-color 160ms ease;
  box-shadow:
    0 0 0 1.5px rgba(255, 255, 255, 0.88),
    0 0 0 3px rgba(0, 0, 0, 0.65),
    inset 0 0 0 1px rgba(0, 0, 0, 0.5);
}

.brush-cursor.is-restore {
  box-shadow:
    0 0 0 2px var(--accent-restore),
    0 0 0 3.5px rgba(0, 0, 0, 0.7),
    inset 0 0 0 1px rgba(16, 185, 129, 0.4);
}

.viewport.is-hovering .brush-cursor {
  opacity: 1;
}

/* Floating Viewport HUD (Center-Bottom) */
.viewport-hud {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(14, 18, 27, 0.86);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-hud);
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 10;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.hud-separator {
  width: 1px;
  height: 18px;
  background: var(--border-subtle);
  margin: 0 4px;
}

.hud-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 120ms ease;
}

.hud-btn svg {
  width: 15px;
  height: 15px;
}

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

.hud-btn:active {
  background: rgba(255, 255, 255, 0.14);
}

.hud-text-btn {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.zoom-readout {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 44px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding: 0 4px;
}

/* Drop Overlay */
.drop-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  background: rgba(8, 10, 15, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 160ms ease;
  z-index: 15;
}

.viewport.is-dragover .drop-overlay {
  opacity: 1;
}

.drop-overlay-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  text-align: center;
  padding: 28px 36px;
  border-radius: var(--radius-lg);
  border: 1.5px dashed var(--accent-primary);
  background: rgba(18, 23, 34, 0.96);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  transform: scale(0.96);
  transition: transform 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

.viewport.is-dragover .drop-overlay-inner {
  transform: scale(1);
}

.drop-icon {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-pill);
  background: var(--accent-glow);
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.drop-icon svg {
  width: 24px;
  height: 24px;
}

.drop-overlay-inner strong {
  font-size: 1.1rem;
  font-weight: 600;
}

.drop-overlay-inner span {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Control Panel (Sidebar) */
.control-panel {
  background: var(--bg-panel);
  border-left: 1px solid var(--border-subtle);
  padding: 16px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  overflow-x: hidden;
  height: 100%;
}

.app-shell.panel-collapsed .control-panel {
  display: none;
}

.control-panel::-webkit-scrollbar {
  width: 6px;
}
.control-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-pill);
}

/* Panel Header: App Branding + Help + Toggle */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

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

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 0 14px var(--accent-glow);
}

.brand-logo svg {
  width: 17px;
  height: 17px;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-text h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #ffffff 30%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge-tag {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.2;
}

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

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 120ms ease;
}

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

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

.icon-btn:active {
  background: rgba(255, 255, 255, 0.12);
}

/* Control Group Cards */
.control-group {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-card);
}

.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.group-title svg {
  width: 13px;
  height: 13px;
  color: var(--accent-primary);
}

/* Image Meta Badge */
.image-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.28);
  padding: 7px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-meta svg {
  width: 14px;
  height: 14px;
  color: var(--accent-primary);
  flex-shrink: 0;
}

.image-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.84rem;
  font-weight: 600;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 160ms cubic-bezier(0.16, 1, 0.3, 1);
  text-decoration: none;
  white-space: nowrap;
}

.btn svg {
  width: 15px;
  height: 15px;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 2px 10px var(--accent-glow);
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 18px var(--accent-glow);
  transform: translateY(-1px);
}

.btn:disabled, .tool-btn:disabled, .hud-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: none;
}

.tool-btn-labeled {
  height: 34px;
  font-size: 0.8rem;
}

/* Segmented Control */
.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-subtle);
  padding: 3px;
  border-radius: var(--radius-md);
  gap: 4px;
}

.segmented-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 140ms ease;
}

.segmented-btn svg {
  width: 15px;
  height: 15px;
}

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

.segmented-btn.is-active {
  background: rgba(59, 130, 246, 0.18);
  color: #ffffff;
  border: 1px solid rgba(59, 130, 246, 0.45);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.2);
}

#modeRestoreBtn.is-active {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.45);
  box-shadow: 0 0 12px var(--accent-restore-glow);
}

.shortcut-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
}

/* Control Fields & Sliders */
.control-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.field-label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.value-badge {
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.range-container {
  display: flex;
  align-items: center;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-pill);
  outline: none;
  cursor: pointer;
  transition: background 150ms ease;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: var(--radius-pill);
  background: #ffffff;
  border: 2px solid var(--accent-primary);
  box-shadow: 0 0 8px var(--accent-glow);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 0 12px var(--accent-glow);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-pill);
  background: #ffffff;
  border: 2px solid var(--accent-primary);
  box-shadow: 0 0 8px var(--accent-glow);
  cursor: pointer;
}

/* Preset Chips */
.preset-chips {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.chip-btn {
  flex: 1;
  height: 24px;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 120ms ease;
}

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

.chip-btn.is-active {
  background: rgba(59, 130, 246, 0.18);
  border-color: rgba(59, 130, 246, 0.4);
  color: #ffffff;
}

/* Button Rows & Tool Buttons */
.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 140ms ease;
}

.tool-btn svg {
  width: 14px;
  height: 14px;
  color: var(--text-secondary);
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
}

.btn-subtle {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
  font-size: 0.78rem;
  height: 30px;
}

.btn-subtle:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.2);
}

/* Status Box */
.status-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;
  min-height: 40px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: #10b981;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
  flex-shrink: 0;
}

.status-box.is-loading .status-indicator {
  background: #f59e0b;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
  animation: pulse-dot 1.2s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-bottom-width: 2px;
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Help Modal Dialog */
.help-modal {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  background: transparent;
  color: var(--text-primary);
  max-width: 520px;
  width: 90vw;
  box-shadow: var(--shadow-modal);
  overflow: hidden;
}

.help-modal::backdrop {
  background: rgba(5, 7, 12, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.modal-card {
  background: #121723;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.02);
}

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

.modal-logo {
  width: 36px;
  height: 36px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.modal-subtitle {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.modal-close-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 120ms ease;
}

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

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-height: 70vh;
  overflow-y: auto;
}

.help-section h3 {
  margin: 0 0 8px;
  font-size: 0.88rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent-primary-hover);
}

.help-section p {
  margin: 0 0 10px;
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.help-feature-list {
  margin: 0;
  padding-left: 20px;
  font-size: 0.84rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.help-feature-list strong {
  color: var(--text-primary);
}

.shortcuts-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
}

.shortcut-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  justify-content: flex-end;
}

/* Responsive Handling */
@media (max-width: 840px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 55vh auto;
  }

  .control-panel {
    border-left: none;
    border-top: 1px solid var(--border-subtle);
    height: auto;
  }
}
