:root {
  color-scheme: light dark;
  font-family: "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  --bg: #f9fafb;
  --bg-gradient: linear-gradient(180deg, #eef2ff 0%, #f9fafb 100%);
  --panel: rgba(255, 255, 255, 0.86);
  --surface: #ffffff;
  --text: #111827;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --border: #d1d5db;
  --muted: #6b7280;
  --shadow-soft: 0 20px 45px -25px rgba(37, 99, 235, 0.35);
  --shadow-panel: 0 20px 40px -40px rgba(15, 23, 42, 0.45);
  --checker-light: rgba(226, 232, 240, 0.9);
  --checker-dark: rgba(203, 213, 225, 0.8);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --bg-gradient: linear-gradient(180deg, #0f172a 0%, #020617 100%);
    --panel: rgba(15, 23, 42, 0.78);
    --surface: rgba(15, 23, 42, 0.92);
    --text: #e2e8f0;
    --accent: #60a5fa;
    --accent-strong: #38bdf8;
    --border: #1f2937;
    --muted: #94a3b8;
    --shadow-soft: 0 20px 45px -30px rgba(56, 189, 248, 0.25);
    --shadow-panel: 0 28px 60px -48px rgba(2, 6, 23, 0.85);
    --checker-light: rgba(148, 163, 184, 0.4);
    --checker-dark: rgba(30, 41, 59, 0.7);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-gradient);
  background-color: var(--bg);
  color: var(--text);
  transition: background 0.3s ease, color 0.3s ease;
}

.container {
  width: min(1180px, 96vw);
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 4rem) 0 clamp(3rem, 6vw, 4.5rem);
  display: flex;
  flex-direction: column;
  gap: clamp(1.5rem, 4vw, 2.5rem);
}

.hero {
  background: var(--panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  padding: 2rem;
  border-radius: 1.2rem;
  box-shadow: var(--shadow-soft);
}

.hero h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.8rem, 2.8vw, 2.8rem);
}

.hero p {
  margin: 0;
  line-height: 1.7;
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: clamp(1.5rem, 3vw, 2.5rem);
  align-items: start;
}

.workspace__column {
  display: flex;
  flex-direction: column;
  gap: clamp(1.25rem, 3vw, 1.75rem);
}

.workspace-preview {
  position: sticky;
  top: clamp(1rem, 4vw, 2rem);
  align-self: start;
  height: fit-content;
}

.workspace-section {
  scroll-margin-top: clamp(4rem, 10vw, 6rem);
}

@media (max-width: 1024px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .workspace-preview {
    position: static;
  }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: clamp(1.25rem, 2vw, 1.75rem);
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel h2 {
  margin: 0;
  font-size: 1.4rem;
}

.input-area {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.file-input {
  position: relative;
  overflow: hidden;
  border: 1px dashed var(--border);
  border-radius: 0.8rem;
  padding: 1rem 1.5rem;
  text-align: center;
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  background: var(--surface);
  transition: border 0.2s ease, transform 0.2s ease, background 0.2s ease,
    color 0.2s ease;
}

.file-input:hover,
.file-input:focus-within {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: rgba(37, 99, 235, 0.08);
  transform: translateY(-1px);
}

.file-input input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 0.8rem;
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  transition: border 0.2s ease, color 0.2s ease, background 0.2s ease,
    transform 0.2s ease;
}

.drop-zone.is-dragover {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent);
  transform: translateY(-1px);
}

.textarea-label {
  font-weight: 600;
}

textarea {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
  font-size: 0.95rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  padding: 1rem;
  min-height: 220px;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
  transition: border 0.2s ease, box-shadow 0.2s ease, background 0.2s ease,
    color 0.2s ease;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  align-items: end;
}

.control-collapsible {
  grid-column: 1 / -1;
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  background: var(--surface);
  overflow: hidden;
}

.control-collapsible > summary {
  list-style: none;
  cursor: pointer;
  font-weight: 700;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  transition: background 0.2s ease;
}

.control-collapsible > summary:hover {
  background: rgba(37, 99, 235, 0.08);
}

.control-collapsible > summary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.control-collapsible > summary::-webkit-details-marker {
  display: none;
}

.control-collapsible > summary::after {
  content: "\25BC";
  font-size: 0.85rem;
  color: var(--muted);
  transition: transform 0.2s ease;
  transform-origin: center;
}

.control-collapsible[open] > summary::after {
  transform: rotate(-180deg);
}

.control-collapsible[open] > summary {
  border-bottom: 1px solid var(--border);
}

.control-collapsible__content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  padding: 1rem;
}

.control-collapsible__content > .checkbox {
  grid-column: 1 / -1;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.control-group--full {
  grid-column: 1 / -1;
}

.control-group__label {
  font-weight: 700;
  font-size: 0.95rem;
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  border: 1px dashed var(--border);
  border-radius: 0.75rem;
  padding: 0.75rem;
  background: var(--surface);
  max-height: 240px;
  overflow-y: auto;
}

.checkbox-list__empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.control-group.is-disabled .checkbox-list {
  opacity: 0.55;
  pointer-events: none;
}

.control-group.range-group {
  align-self: stretch;
}

.control-group input[type="range"] {
  width: 100%;
  appearance: none;
  height: 6px;
  border-radius: 9999px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-strong) 100%);
  outline: none;
  cursor: pointer;
}

.control-group input[type="range"]:disabled {
  background: linear-gradient(90deg, var(--border) 0%, var(--border) 100%);
  cursor: not-allowed;
}

.control-group input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.15);
  transition: transform 0.15s ease;
}

.control-group input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.15);
  transition: transform 0.15s ease;
}

.control-group input[type="range"]:focus-visible::-webkit-slider-thumb,
.control-group input[type="range"]:focus-visible::-moz-range-thumb {
  transform: scale(1.1);
}

.control-group input[type="range"]:disabled::-webkit-slider-thumb,
.control-group input[type="range"]:disabled::-moz-range-thumb {
  border-color: var(--border);
}

.control-group .range-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  text-align: right;
}

.control-group.is-disabled {
  opacity: 0.55;
}

.control-group.is-disabled input,
.control-group.is-disabled .range-value {
  pointer-events: none;
}

.control-group input[type="number"],
.control-group select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 0.65rem;
  border: 1px solid var(--border);
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  transition: border 0.2s ease, box-shadow 0.2s ease, background 0.2s ease,
    color 0.2s ease;
}

.control-group input[type="number"]:focus,
.control-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.control-group input[type="color"] {
  width: 64px;
  height: 40px;
  padding: 0;
  border-radius: 0.65rem;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: border 0.2s ease;
}

.control-group input[type="color"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  background: var(--surface);
  cursor: pointer;
  transition: border 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.checkbox.checkbox--small {
  padding: 0.45rem 0.6rem;
  font-size: 0.92rem;
  align-items: flex-start;
}

.checkbox.checkbox--small input[type='checkbox'] {
  margin-top: 0.15rem;
}

.checkbox.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.checkbox.is-disabled:hover {
  border-color: var(--border);
}

.checkbox.is-disabled input {
  pointer-events: none;
}

.checkbox:hover {
  border-color: var(--accent);
}

.checkbox input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

.checkbox:focus-within {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.color-option {
  align-items: center;
}

.color-option__swatch {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 0.45rem;
  border: 1px solid var(--border);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
  flex-shrink: 0;
}

.color-option__content {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.color-option__label {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
}

.color-option__count {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.primary {
  padding: 0.85rem 1.6rem;
  border-radius: 0.8rem;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease,
    background-color 0.2s ease;
}

.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 30px -18px rgba(37, 99, 235, 0.55);
  background: var(--accent-strong);
}

.primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

#resizeButton {
  grid-column: 1 / -1;
  justify-self: stretch;
}

@media (min-width: 768px) {
  #resizeButton {
    max-width: 280px;
    justify-self: start;
  }
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

#message {
  min-height: 1.5rem;
  color: var(--muted);
  transition: color 0.2s ease;
}

#message.error {
  color: #f87171;
}

.preview {
  min-height: clamp(260px, 45vh, 520px);
  border: 1px dashed var(--border);
  border-radius: 0.8rem;
  padding: clamp(1rem, 2vw, 1.5rem);
  background:
    conic-gradient(var(--checker-light) 0 25%, transparent 0 50%) 0 0 / 24px 24px,
    conic-gradient(var(--checker-dark) 0 25%, transparent 0 50%) 12px 12px / 24px 24px,
    var(--surface);
  display: flex;
  justify-content: center;
  align-items: center;
  transition: border 0.2s ease, background 0.2s ease;
}

.preview svg {
  width: 100%;
  height: auto;
  max-height: 70vh;
}

.downloads {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.button {
  padding: 0.65rem 1.2rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: border 0.2s ease, color 0.2s ease, transform 0.2s ease,
    background 0.2s ease, box-shadow 0.2s ease;
}

.button[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

.button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
  transform: translateY(-1px);
  box-shadow: 0 10px 25px -20px rgba(37, 99, 235, 0.5);
}

.button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

@media (max-width: 640px) {
  .controls {
    grid-template-columns: 1fr;
  }

  .primary {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
