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

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: radial-gradient(circle at top, #1b2735 0, #090a0f 55%);
  color: #f9fafb;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.decor-icon {
  position: absolute;
  width: 90px;
  height: 90px;
  opacity: 0.18;
  filter: drop-shadow(0 10px 22px rgba(0, 0, 0, 0.7));
}

.decor-icon svg {
  width: 100%;
  height: 100%;
}

.decor-surface {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.app-header,
.sidebar {
  position: relative;
  overflow: hidden;
}

.decor-bolt {
  top: -20px;
  left: 50%;
  color: rgba(250, 204, 21, 1);
  transform: translateX(-50%) rotate(12deg);
}

.decor-bat-sidebar {
  bottom: -16px;
  left: -18px;
  width: 110px;
  height: 110px;
  opacity: 0.22;
}

.decor-cap-shield {
  top: -6px;
  right: 16px;
  width: 80px;
  height: 80px;
  opacity: 0.2;
}

.decor-bat {
  bottom: -22px;
  left: -10px;
  color: rgba(148, 163, 184, 1);
  transform: rotate(-10deg);
  opacity: 0.14;
}

.decor-dd {
  top: 18px;
  right: -14px;
  color: rgba(248, 113, 113, 1);
  transform: rotate(10deg);
  opacity: 0.13;
}

.decor-bow {
  top: 120px;
  left: 14px;
  width: 82px;
  height: 82px;
  color: rgba(196, 181, 253, 1);
  transform: rotate(-14deg);
  opacity: 0.12;
}

.app-header {
  padding: 1.25rem 2rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: linear-gradient(120deg, rgba(59, 130, 246, 0.2), rgba(236, 72, 153, 0.2));
  backdrop-filter: blur(10px);
}

.app-header h1 {
  margin: 0;
  font-size: 1.8rem;
}

.app-header p {
  margin: 0.25rem 0 0;
  opacity: 0.85;
}

.app-main {
  flex: 1;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 1.5rem;
  padding: 1.5rem 2rem 2rem;
}

.sidebar {
  background: rgba(15, 23, 42, 0.95);
  border-radius: 1rem;
  padding: 1rem;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar h2 {
  margin: 0;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9ca3af;
}

.character-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.character-btn {
  flex: 1 1 45%;
  padding: 0.4rem 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.5);
  background: radial-gradient(circle at top left, rgba(59, 130, 246, 0.35), rgba(15, 23, 42, 0.95));
  color: #e5e7eb;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.character-btn:hover {
  border-color: #60a5fa;
  transform: translateY(-1px);
}

.character-btn.active {
  border-color: #f97316;
  box-shadow: 0 0 0 1px rgba(249, 115, 22, 0.5);
}

.palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid rgba(15, 23, 42, 0.6);
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.1s ease;
}

.swatch:hover {
  transform: translateY(-1px) scale(1.03);
  box-shadow: 0 0 0 2px rgba(249, 250, 251, 0.25);
}

.swatch.selected {
  border-color: #fbbf24;
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.65);
}

.controls {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
}

.control-group span {
  color: #9ca3af;
}

input[type='range'] {
  width: 100%;
}

.btn {
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}

.btn.secondary {
  background: #111827;
  color: #e5e7eb;
  border: 1px solid rgba(55, 65, 81, 0.9);
}

.btn.secondary:hover {
  background: #020617;
}

.btn.tertiary {
  background: transparent;
  border: 1px solid rgba(55, 65, 81, 0.9);
  color: #e5e7eb;
  padding-inline: 0.8rem;
}

.btn.tertiary.active {
  background: rgba(59, 130, 246, 0.25);
  border-color: #60a5fa;
}

.tool-toggle {
  display: inline-flex;
  gap: 0.4rem;
}

.btn.tertiary.small {
  padding-inline: 0.55rem;
  font-size: 0.8rem;
}

.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.zoom-label {
  font-size: 0.8rem;
  color: #e5e7eb;
  min-width: 3ch;
  text-align: center;
}

.canvas-panel {
  background: radial-gradient(circle at top left, rgba(59, 130, 246, 0.12), rgba(15, 23, 42, 0.97));
  border-radius: 1rem;
  padding: 1rem;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
}

.canvas-wrapper {
  position: relative;
  flex: 1;
  border-radius: 0.75rem;
  overflow: hidden;
  background: repeating-conic-gradient(
      from 45deg,
      #111827 0deg 90deg,
      #020617 90deg 180deg
    );
  background-size: 30px 30px;
  border: 1px solid rgba(15, 23, 42, 0.95);
}

.canvas-inner {
  position: relative;
  width: 100%;
  height: 100%;
}

canvas {
  display: block;
  max-width: 100%;
}

#paint-layer,
#lineart-layer {
  position: absolute;
  inset: 0;
}

.canvas-footer {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: #9ca3af;
}

.gallery {
  margin-top: 1.25rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(31, 41, 55, 0.9);
}

.gallery-header {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-bottom: 0.75rem;
}

.gallery-header h2 {
  margin: 0;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9ca3af;
}

.gallery-header p {
  margin: 0;
  font-size: 0.8rem;
  color: #6b7280;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
}

.gallery-item {
  position: relative;
  border-radius: 0.5rem;
  overflow: hidden;
  background: #020617;
  border: 1px solid rgba(31, 41, 55, 0.9);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.gallery-item-meta {
  position: absolute;
  inset: auto 0 0 0;
  padding: 0.35rem 0.45rem;
  background: linear-gradient(to top, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0));
  font-size: 0.7rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #e5e7eb;
}

.gallery-item-meta span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-delete-btn {
  margin-left: 0.4rem;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  border: none;
  font-size: 0.65rem;
  cursor: pointer;
  background: rgba(127, 29, 29, 0.9);
  color: #fee2e2;
  opacity: 0.85;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.gallery-delete-btn:hover {
  opacity: 1;
  transform: translateY(-1px);
}

.lightbox {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
}

.lightbox.open {
  display: flex;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(8px);
}

.lightbox-content {
  position: relative;
  max-width: min(900px, 90vw);
  max-height: min(650px, 90vh);
  border-radius: 1rem;
  overflow: hidden;
  background: #020617;
  border: 1px solid rgba(148, 163, 184, 0.7);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
}

.lightbox-image {
  display: block;
  width: 100%;
  height: auto;
  max-height: 560px;
  object-fit: contain;
  background: #020617;
}

.lightbox-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.9rem 0.7rem;
  font-size: 0.85rem;
  color: #e5e7eb;
}

.lightbox-meta span:last-child {
  color: #9ca3af;
  font-size: 0.8rem;
}

.lightbox-close {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  border: none;
  border-radius: 999px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.7);
}

.lightbox-close:hover {
  background: rgba(30, 64, 175, 0.9);
}

@media (max-width: 900px) {
  .app-main {
    grid-template-columns: 1fr;
  }

  .sidebar {
    order: 2;
  }

  .canvas-panel {
    order: 1;
  }
}

