:root {
  color-scheme: dark;
  --ink: #f8fbff;
  --muted: rgba(248, 251, 255, 0.68);
  --line: rgba(255, 255, 255, 0.22);
  --glass: rgba(255, 255, 255, 0.13);
  --glass-strong: rgba(255, 255, 255, 0.19);
  --shadow: rgba(15, 23, 42, 0.26);
  --aqua: #69d7ff;
  --rose: #ff83b7;
  --mint: #7ff0b5;
  --amber: #ffd36a;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 14%, rgba(105, 215, 255, 0.34), transparent 28%),
    radial-gradient(circle at 88% 10%, rgba(255, 131, 183, 0.30), transparent 24%),
    radial-gradient(circle at 80% 86%, rgba(127, 240, 181, 0.24), transparent 26%),
    linear-gradient(135deg, #111827 0%, #243447 42%, #3a2f49 100%);
  overflow-x: hidden;
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, black, transparent 86%);
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.hero,
.workspace,
.result-header,
.actions,
.control-grid,
.preview-caption {
  display: flex;
  gap: 16px;
}

.hero {
  min-height: 18vh;
  align-items: end;
  justify-content: space-between;
  padding: 20px 0 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2.7rem, 7vw, 6.4rem);
  line-height: 0.92;
}

h2 {
  font-size: 1.8rem;
}

.status {
  min-width: 132px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.10);
  box-shadow: 0 18px 40px var(--shadow);
  backdrop-filter: blur(24px) saturate(150%);
  text-align: center;
  color: var(--muted);
}

.notice {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(105, 215, 255, 0.32);
  border-radius: 16px;
  background: rgba(105, 215, 255, 0.10);
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
}

.notice[data-tone="success"] {
  border-color: rgba(127, 240, 181, 0.34);
  background: rgba(127, 240, 181, 0.12);
}

.notice[data-tone="error"] {
  border-color: rgba(255, 131, 183, 0.45);
  background: rgba(255, 131, 183, 0.14);
}

.workspace {
  align-items: stretch;
  display: grid;
  grid-template-columns: 380px 1fr;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(145deg, var(--glass-strong), rgba(255, 255, 255, 0.07));
  box-shadow: 0 24px 80px var(--shadow), inset 0 1px rgba(255, 255, 255, 0.26);
  backdrop-filter: blur(28px) saturate(160%);
}

.controls {
  display: flex;
  flex-direction: column;
  padding: 18px;
}

.dropzone {
  position: relative;
  display: grid;
  min-height: 210px;
  place-items: center;
  align-content: center;
  gap: 8px;
  border: 1px dashed rgba(255, 255, 255, 0.42);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.dropzone:hover,
.dropzone.dragging {
  transform: translateY(-1px);
  border-color: var(--aqua);
  background: rgba(105, 215, 255, 0.12);
}

.dropzone.locked {
  pointer-events: none;
}

.dropzone input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.drop-icon {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 2rem;
  line-height: 1;
}

.drop-title {
  max-width: 100%;
  padding: 0 18px;
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drop-meta,
.file-facts,
.field span,
.field output,
.preview-caption,
.secondary,
.stat-label {
  color: var(--muted);
}

.file-facts {
  min-height: 32px;
  margin-top: 10px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: rgba(8, 17, 31, 0.18);
  font-size: 0.86rem;
  font-weight: 700;
}

.tabs-nav {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(20px);
  width: fit-content;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  min-height: auto;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.tab-btn:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
}

.tab-btn.active {
  border-color: rgba(105, 215, 255, 0.4);
  color: var(--ink);
  background: linear-gradient(135deg, rgba(105, 215, 255, 0.2), rgba(127, 240, 181, 0.2));
  box-shadow: 0 4px 20px rgba(105, 215, 255, 0.15);
}

.control-grid {
  flex-direction: column;
  margin: 18px 0;
}

.field {
  display: grid;
  grid-template-columns: 74px 1fr 48px;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
}

.field[hidden] {
  display: none;
}

.muted-field {
  opacity: 0.55;
}

.field select,
.field input {
  width: 100%;
}

select {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  color: var(--ink);
  background: rgba(20, 31, 46, 0.78);
}

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

input[type="number"],
input[type="text"],
textarea {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  color: var(--ink);
  background: rgba(20, 31, 46, 0.78);
}

textarea {
  min-height: 82px;
  padding: 9px 10px;
  resize: vertical;
  font: inherit;
}

.text-field {
  align-items: start;
}

button,
.secondary {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 16px;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #08111f;
  background: linear-gradient(135deg, var(--aqua), var(--mint) 58%, var(--amber));
  box-shadow: 0 18px 42px rgba(105, 215, 255, 0.22);
}

.primary:disabled,
.secondary:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.11);
  backdrop-filter: blur(20px);
}

.full-width {
  width: 100%;
  margin-top: 10px;
}

.pattern-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.button-icon {
  font-size: 0.72rem;
}

.preview {
  min-height: 540px;
  padding: 16px;
}

.preview-toolbar {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 10px;
}

.view-tabs {
  display: flex;
  gap: 6px;
  padding: 5px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.08);
}

.view-tabs button {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 11px;
  color: var(--muted);
  background: transparent;
  font-size: 0.86rem;
}

.view-tabs button.active {
  border-color: rgba(105, 215, 255, 0.48);
  color: var(--ink);
  background: rgba(105, 215, 255, 0.15);
}

.preview-frame {
  position: relative;
  display: grid;
  min-height: 480px;
  place-items: center;
  overflow: hidden;
  border-radius: 22px;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.12) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.12) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.12) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.12) 75%);
  background-color: rgba(8, 17, 31, 0.26);
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  background-size: 22px 22px;
}

.preview-frame img {
  display: none;
  max-width: 100%;
  max-height: 480px;
  object-fit: contain;
}

.preview-frame img.visible {
  display: block;
}

.busy {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  background: rgba(8, 17, 31, 0.58);
  backdrop-filter: blur(12px);
}

.busy span {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.26);
  border-top-color: var(--aqua);
  border-radius: 999px;
  animation: spin 760ms linear infinite;
}

.busy strong {
  font-size: 1rem;
}

.busy small {
  color: var(--muted);
  font-weight: 700;
}

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

.empty {
  color: var(--muted);
}

.preview-caption {
  justify-content: space-between;
  padding: 12px 4px 0;
}

.results {
  margin-top: 18px;
}

.result-header {
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.layer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}



.layer-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 18px 44px var(--shadow);
  backdrop-filter: blur(24px) saturate(150%);
  color: var(--ink);
  text-align: left;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.layer-card:hover,
.layer-card.active {
  transform: translateY(-1px);
  border-color: rgba(105, 215, 255, 0.58);
  background: rgba(105, 215, 255, 0.12);
}

.layer-thumb {
  display: grid;
  height: 166px;
  place-items: center;
  background: rgba(8, 17, 31, 0.26);
}

.layer-thumb img {
  max-width: 100%;
  max-height: 166px;
  object-fit: contain;
}

.layer-info {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  padding: 12px;
}

.swatch {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.48);
  border-radius: 12px;
}

.layer-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.layer-pixels {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.88rem;
}

.edge-results {
  padding-bottom: 4px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  min-height: 96px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 18px 44px var(--shadow);
  backdrop-filter: blur(24px) saturate(150%);
}

.stat-label,
.stat-value {
  display: block;
}

.stat-label {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

.stat-value {
  margin-top: 10px;
  overflow-wrap: anywhere;
  font-size: 1.1rem;
  font-weight: 900;
}

.stat-value.good {
  color: var(--mint);
}

@media (max-width: 860px) {
  .hero {
    align-items: start;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .preview,
  .preview-frame {
    min-height: 360px;
  }

  .preview-toolbar {
    justify-content: start;
  }

  .preview-frame img {
    max-height: 360px;
  }

  .result-header {
    align-items: start;
    flex-direction: column;
  }

  .actions {
    justify-content: start;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .mode-control {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .shell {
    width: min(100vw - 20px, 1180px);
    padding-top: 16px;
  }

  .panel {
    border-radius: 22px;
  }

  .field {
    grid-template-columns: 1fr;
  }

  .secondary,
  .view-tabs {
    width: 100%;
  }

  .pattern-tools {
    grid-template-columns: 1fr;
  }

  .view-tabs button {
    flex: 1;
    padding: 0 8px;
  }
}
