:root {
  --bg-app: #f3f3f3;
  --bg-surface: #ffffff;
  --bg-subtle: #f9f9f9;
  --bg-hover: #e9e9e9;
  --bg-active: #dfdfdf;
  --border-color: #d1d1d1;
  --border-light: #e5e5e5;
  --accent-color: #0067b8;
  --accent-hover: #005da6;
  --accent-light: #e0f2fe;
  --text-main: #1f1f1f;
  --text-muted: #616161;
  --text-inverse: #ffffff;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.16);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --font-family: 'Segoe UI Variable', 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  --asset-panel-width: 340px;
}

[data-theme="dark"] {
  --bg-app: #202020;
  --bg-surface: #2b2b2b;
  --bg-subtle: #333333;
  --bg-hover: #3d3d3d;
  --bg-active: #484848;
  --border-color: #444444;
  --border-light: #3a3a3a;
  --accent-color: #60cdff;
  --accent-hover: #7ae7ff;
  --accent-light: #16364d;
  --text-main: #ffffff;
  --text-muted: #a0a0a0;
  --text-inverse: #000000;
  --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 24px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ==========================================================================
   Header & Title Bar
   ========================================================================== */
.paint-titlebar {
  height: 38px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 13px;
  z-index: 10;
}

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

.app-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-title {
  font-weight: 600;
  letter-spacing: -0.2px;
}

.file-name-badge {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-subtle);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

.titlebar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  background: transparent;
  border: none;
  outline: none;
  cursor: pointer;
  color: var(--text-main);
  width: 32px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--bg-hover);
}

.icon-btn:active {
  background: var(--bg-active);
}

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

.icon-btn.primary:hover {
  background: var(--accent-hover);
}

/* ==========================================================================
   Ribbon Toolbar
   ========================================================================== */
.paint-ribbon {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: stretch;
  padding: 6px 12px;
  gap: 12px;
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
  z-index: 9;
}

.ribbon-group {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 0 8px;
  border-right: 1px solid var(--border-light);
  min-width: max-content;
}

.ribbon-group:last-child {
  border-right: none;
  margin-left: auto;
}

.ribbon-group-title {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}

.ribbon-content {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 100%;
}

/* Tool Buttons */
.tool-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-main);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 500;
  transition: all 0.15s ease;
  min-width: 48px;
}

.tool-btn i, .tool-btn svg {
  font-size: 18px;
  width: 20px;
  height: 20px;
}

.tool-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

.tool-btn.active {
  background: var(--accent-light);
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.btn-clear-canvas {
  color: #e11d48;
  cursor: pointer;
}

.btn-clear-canvas:hover {
  background: #ffe4e6 !important;
  border-color: #f43f5e !important;
  color: #be123c !important;
  transform: translateY(-1px);
}

.btn-clear-canvas:active {
  transform: translateY(1px);
}

[data-theme="dark"] .btn-clear-canvas:hover {
  background: #4c111a !important;
  border-color: #fb7185 !important;
  color: #fca5a5 !important;
}

.icon-btn.danger-hover:hover {
  background: #ffe4e6 !important;
  color: #be123c !important;
}

[data-theme="dark"] .icon-btn.danger-hover:hover {
  background: #4c111a !important;
  color: #fca5a5 !important;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.tool-btn-sm {
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-main);
  cursor: pointer;
  font-size: 14px;
}

.tool-btn-sm:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

.tool-btn-sm.active {
  background: var(--accent-light);
  border-color: var(--accent-color);
  color: var(--accent-color);
}

/* Shapes Grid */
.shapes-grid {
  display: grid;
  grid-template-columns: repeat(4, 30px);
  grid-template-rows: repeat(2, 30px);
  gap: 3px;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

/* Size Dropdown / Control */
.stroke-size-selector {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.size-preview-dot-wrapper {
  width: 22px;
  height: 22px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.size-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-color);
  background: var(--accent-light);
  padding: 1px 4px;
  border-radius: 4px;
  min-width: 28px;
  text-align: center;
}

.size-preset-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 2px 4px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  min-width: 18px;
  line-height: 1.2;
}

.size-preset-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-color);
}

.size-preset-btn.active {
  background: var(--accent-color);
  color: #ffffff;
  border-color: var(--accent-color);
}

/* Colors Section */
.color-slots-container {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 8px;
}

.color-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}

.color-box {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-color);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
  transition: transform 0.1s, border-color 0.15s;
}

.color-slot.active .color-box {
  border-color: var(--accent-color);
  transform: scale(1.08);
}

.color-label {
  font-size: 10px;
  color: var(--text-muted);
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(10, 20px);
  grid-template-rows: repeat(2, 20px);
  gap: 3px;
  background: var(--bg-subtle);
  padding: 4px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
}

.palette-swatch {
  width: 20px;
  height: 20px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
}

.palette-swatch:hover {
  transform: scale(1.2);
  z-index: 2;
  box-shadow: var(--shadow-sm);
}

.palette-custom {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#customColorInput {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* Asset Toggle Button */
.asset-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--accent-light);
  color: var(--accent-color);
  border: 1px solid var(--accent-color);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.asset-toggle-btn:hover {
  background: var(--accent-color);
  color: #ffffff;
}

.asset-badge {
  background: #ff5252;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 12px;
}

/* ==========================================================================
   Main Work Area Layout
   ========================================================================== */
.paint-main-workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.canvas-viewport {
  flex: 1;
  background-color: #555555;
  background-image: 
    linear-gradient(45deg, #444444 25%, transparent 25%), 
    linear-gradient(-45deg, #444444 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #444444 75%), 
    linear-gradient(-45deg, transparent 75%, #444444 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0px;
  overflow: auto;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 40px;
  cursor: crosshair;
}

.canvas-container {
  position: relative;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  background: #ffffff;
  display: inline-block;
  line-height: 0;
}

#paintCanvas {
  display: block;
  background: #ffffff;
}

/* Canvas Resize Handles */
.canvas-resize-handle {
  position: absolute;
  width: 9px;
  height: 9px;
  background: #ffffff;
  border: 1px solid #000000;
  z-index: 5;
}

.resize-r {
  right: -5px;
  top: 50%;
  transform: translateY(-50%);
  cursor: e-resize;
}

.resize-b {
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  cursor: s-resize;
}

.resize-br {
  right: -5px;
  bottom: -5px;
  cursor: se-resize;
}

/* Selection / Stamp Overlay */
.selection-box {
  position: absolute;
  border: 1px dashed #0078d4;
  outline: 1px dashed rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 8px rgba(0, 120, 212, 0.35);
  cursor: move;
  z-index: 20;
  pointer-events: all;
  animation: marchingAnts 1s linear infinite;
}

@keyframes marchingAnts {
  0% { border-style: dashed; border-color: #0078d4; }
  50% { border-style: dotted; border-color: #ffffff; }
  100% { border-style: dashed; border-color: #0078d4; }
}

.selection-handle {
  position: absolute;
  width: 9px;
  height: 9px;
  background: #ffffff;
  border: 1.5px solid #0078d4;
  border-radius: 2px;
}

.handle-nw { top: -5px; left: -5px; cursor: nwse-resize; }
.handle-ne { top: -5px; right: -5px; cursor: nesw-resize; }
.handle-se { bottom: -5px; right: -5px; cursor: nwse-resize; }
.handle-sw { bottom: -5px; left: -5px; cursor: nesw-resize; }
.handle-n { top: -5px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.handle-s { bottom: -5px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.handle-w { left: -5px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.handle-e { right: -5px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

.selection-actions-bar {
  position: absolute;
  top: -42px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  z-index: 25;
}

.selection-actions-bar button {
  background: transparent;
  border: none;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-main);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.selection-actions-bar button:hover {
  background: var(--bg-hover);
}

.selection-actions-bar button.apply-btn {
  background: var(--accent-color);
  color: #ffffff;
}

/* Text Tool Overlay Input */
.text-tool-overlay {
  position: absolute;
  border: 1.5px dashed var(--accent-color);
  background: rgba(255, 255, 255, 0.95);
  padding: 4px 6px;
  outline: none;
  font-family: inherit;
  font-size: 18px;
  color: #000000;
  min-width: 100px;
  min-height: 36px;
  z-index: 15;
  box-shadow: var(--shadow-md);
  border-radius: 4px;
}

/* ==========================================================================
   Right Panel: Asset Library (우측 에셋 보관함)
   ========================================================================== */
.paint-asset-panel {
  width: var(--asset-panel-width);
  background: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: width 0.25s cubic-bezier(0.1, 0.9, 0.2, 1), transform 0.25s ease;
  z-index: 12;
  box-shadow: var(--shadow-md);
}

.paint-asset-panel.collapsed {
  width: 0;
  border-left: none;
  overflow: hidden;
}

.asset-panel-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.asset-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
}

.asset-panel-banner {
  padding: 10px 14px;
  background: var(--accent-light);
  color: var(--accent-color);
  font-size: 12px;
  line-height: 1.45;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.asset-panel-controls {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-subtle);
}

.asset-search-input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-main);
  outline: none;
}

.asset-search-input:focus {
  border-color: var(--accent-color);
}

.asset-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Empty State */
.asset-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  gap: 12px;
}

.asset-empty-state i {
  font-size: 42px;
  color: var(--border-color);
}

.asset-empty-state h4 {
  font-size: 14px;
  color: var(--text-main);
}

.asset-empty-state p {
  font-size: 12px;
  line-height: 1.5;
}

/* Asset Card */
.asset-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  position: relative;
}

.asset-card:hover {
  border-color: var(--accent-color);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.asset-card-preview-wrapper {
  width: 100%;
  height: 130px;
  background-color: #2b2b2b;
  background-image: 
    linear-gradient(45deg, #222 25%, transparent 25%), 
    linear-gradient(-45deg, #222 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #222 75%), 
    linear-gradient(-45deg, transparent 75%, #222 75%);
  background-size: 16px 16px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

.asset-card-thumb {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform 0.2s;
}

.asset-card:hover .asset-card-thumb {
  transform: scale(1.03);
}

.asset-card-hover-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.asset-card-preview-wrapper:hover .asset-card-hover-overlay {
  opacity: 1;
}

.asset-card-hover-overlay span {
  background: var(--accent-color);
  color: #fff;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.asset-card-info {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.asset-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  border: 1px solid transparent;
  padding: 2px 4px;
  border-radius: 4px;
  outline: none;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-card-title:focus {
  background: var(--bg-hover);
  border-color: var(--accent-color);
}

.asset-card-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  margin-top: 2px;
}

.asset-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid var(--border-light);
}

.asset-btn {
  flex: 1;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 6px 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background 0.15s, color 0.15s;
}

.asset-btn:hover {
  background: var(--accent-light);
  color: var(--accent-color);
  border-color: var(--accent-color);
}

.asset-btn.danger:hover {
  background: #fee2e2;
  color: #dc2626;
  border-color: #ef4444;
}

/* ==========================================================================
   Bottom Status Bar
   ========================================================================== */
.paint-statusbar {
  height: 28px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  font-size: 12px;
  color: var(--text-muted);
  z-index: 10;
}

.statusbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.statusbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.zoom-slider-container {
  display: flex;
  align-items: center;
  gap: 6px;
}

.zoom-slider {
  width: 90px;
  accent-color: var(--accent-color);
  cursor: pointer;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  background: rgba(30, 30, 30, 0.92);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.25s ease forwards;
  pointer-events: all;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}
