:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #6ee7b7;
  --accent-dim: #34d399;
  --danger: #f87171;
  --radius: 12px;
  --font: "SF Pro Text", "PingFang SC", "Helvetica Neue", system-ui, sans-serif;
}

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

html {
  font-size: 15px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: radial-gradient(ellipse 120% 80% at 50% -20%, #1e3a5f 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

header {
  margin-bottom: 2rem;
}

header h1 {
  font-size: 1.65rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
}

header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.badge {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: rgba(110, 231, 183, 0.12);
  color: var(--accent);
  border: 1px solid rgba(110, 231, 183, 0.25);
}

.layout {
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: 320px 1fr;
    align-items: start;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
}

.panel h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 1rem;
  font-weight: 600;
}

#drop-zone {
  display: block;
  cursor: pointer;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--surface-2);
}

#drop-zone:hover,
#drop-zone.dragover {
  border-color: var(--accent-dim);
  background: rgba(52, 211, 153, 0.06);
}

#drop-zone strong {
  display: block;
  margin-bottom: 0.25rem;
}

#drop-zone span {
  font-size: 0.85rem;
  color: var(--muted);
}

#file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.field {
  margin-top: 1.1rem;
}

.field label {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  margin-bottom: 0.4rem;
}

.field label span {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

select,
input[type="range"] {
  width: 100%;
}

select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font: inherit;
}

input[type="range"] {
  accent-color: var(--accent-dim);
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 1.25rem;
}

button {
  font: inherit;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, transform 0.1s;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: linear-gradient(135deg, var(--accent-dim), #059669);
  color: #042f1e;
  font-weight: 600;
}

button.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

button.danger {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.35);
}

button.danger:not(:disabled):hover {
  border-color: var(--danger);
  color: #fff;
}

button:not(:disabled):active {
  transform: scale(0.98);
}

#meta {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
}

#meta dl {
  margin: 0;
  display: grid;
  gap: 0.35rem;
}

#meta div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

#meta dt {
  color: var(--muted);
}

#meta dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.preview-panel {
  min-height: 420px;
}

.preview-hint {
  margin: -0.35rem 0 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.canvas-wrap.preview-target.has-image {
  cursor: zoom-in;
}

.canvas-wrap.preview-target.has-image:focus-visible {
  outline: 2px solid var(--accent-dim);
  outline-offset: 2px;
}

.canvas-wrap.preview-target canvas {
  pointer-events: none;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.tabs button {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
}

.tabs button.active {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface-2);
}

.canvas-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  background: repeating-conic-gradient(#1c2534 0% 25%, #151c28 0% 50%) 50% / 16px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 0.5rem;
}

.canvas-wrap canvas {
  max-width: 100%;
  height: auto;
  display: block;
  image-rendering: pixelated;
}

#status {
  margin-top: 0.85rem;
  font-size: 0.85rem;
  color: var(--muted);
}

#status[data-type="ok"] {
  color: var(--accent);
}

#status[data-type="error"] {
  color: var(--danger);
}

footer {
  margin-top: 2rem;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.lightbox[hidden] {
  display: none !important;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  margin: 0;
  background: rgba(5, 10, 18, 0.92);
  cursor: zoom-out;
}

.lightbox-panel {
  position: relative;
  z-index: 1;
  width: min(96vw, 1400px);
  max-height: 96vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.lightbox-header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
}

.lightbox-counter {
  color: var(--muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
}

.lightbox-close {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  width: 2rem;
  height: 2rem;
  padding: 0;
  line-height: 1;
  font-size: 1.35rem;
  border-radius: 8px;
}

.lightbox-stage {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 1rem 3.25rem;
  background: repeating-conic-gradient(#1c2534 0% 25%, #151c28 0% 50%) 50% / 16px 16px;
  touch-action: pan-y;
}

.lightbox-stage canvas {
  max-width: 100%;
  max-height: calc(96vh - 8.5rem);
  width: auto;
  height: auto;
  display: block;
  image-rendering: pixelated;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(26, 35, 50, 0.92);
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1;
  padding: 0;
}

.lightbox-nav-prev {
  left: 0.55rem;
}

.lightbox-nav-next {
  right: 0.55rem;
}

.lightbox-dots {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.35rem 1rem 0;
}

.lightbox-dot {
  width: 0.55rem;
  height: 0.55rem;
  padding: 0;
  border-radius: 999px;
  border: none;
  background: var(--border);
}

.lightbox-dot.active {
  background: var(--accent-dim);
}

.lightbox-foot {
  margin: 0;
  padding: 0.5rem 1rem 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

body.lightbox-open {
  overflow: hidden;
}