:root {
  color-scheme: dark;
  --bg: #0d0f12;
  --panel: rgba(21, 24, 29, 0.88);
  --panel-strong: #171b21;
  --line: rgba(255, 255, 255, 0.829);
  --text: #eceff4;
  --muted: #9aa3ad;
  --accent: #d7dce2;
  --accent-strong: #ffffff;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Hiragino Sans", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.08), transparent 24%),
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.05), transparent 18%),
    linear-gradient(180deg, #171a1f 0%, var(--bg) 100%);
  min-height: 100vh;
}

button,
input {
  font: inherit;
}

.page-shell {
  width: min(1320px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.hero {
  display: block;
  margin-bottom: 24px;
}

.hero-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 3vw, 3rem);
  line-height: 1.05;
  font-weight: 750;
}

.tool-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.tool-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: color 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.tool-link:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.26);
  background: rgba(255, 255, 255, 0.06);
}

.hero-card,
.panel {
  backdrop-filter: blur(12px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.workspace {
  display: grid;
  grid-template-columns: 410px 1fr;
  gap: 24px;
  align-items: start;
}

.panel {
  padding: 22px;
}

.panel-title-row,
.control-header,
.actions-footer,
.input-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

@media (min-width: 1081px) {
  .controls {
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    padding-right: 14px;
    scrollbar-gutter: stable;
  }
}

.hint {
  margin: -4px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.control-group {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
}

.control-group h3,
.preview-card h3,
.panel h2 {
  margin: 0;
}

.slider-row {
  display: grid;
  grid-template-columns: 84px 1fr 56px;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.slider-row.compact {
  grid-template-columns: 72px 1fr 44px;
}

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

output {
  text-align: right;
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
}

.file-button,
button {
  border: 0;
  border-radius: 999px;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease, opacity 160ms ease;
}

.file-button,
button:not(.ghost-button):not(.mini-button) {
  background: linear-gradient(135deg, #f0f3f6 0%, #b7c0ca 100%);
  color: #0f1216;
  font-weight: 700;
}

.ghost-button,
.mini-button {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: var(--text);
}

.mini-button {
  padding: 8px 12px;
  font-size: 0.92rem;
}

.toggle-button {
  min-width: 84px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 700;
}

.toggle-button[aria-pressed="true"] {
  background: linear-gradient(135deg, #eef2f6 0%, #c8d0d9 100%);
  color: #0f1216;
}

.file-button input {
  display: none;
}

button:hover,
.file-button:hover {
  transform: translateY(-1px);
}

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

.curve-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

#curveCanvas {
  width: min(100%, 256px);
  background:
    linear-gradient(to right, rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(135deg, #20252c 0%, #161a20 100%);
  background-size: 32px 32px, 32px 32px, cover;
  border: 1px solid var(--line);
  border-radius: 16px;
}

.curve-sliders {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

#imageMeta {
  color: var(--muted);
}

.preview-card {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
}

.single-preview {
  min-height: 0;
}

.preview-toggle {
  display: inline-flex;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  align-self: flex-start;
}

.preview-toggle-button {
  background: rgba(255, 255, 255, 0.04);
  color: #7f8a96;
  font-weight: 700;
  padding: 10px 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.preview-toggle-button[aria-pressed="true"] {
  background: linear-gradient(135deg, #f4f7fa 0%, #cbd3dc 100%);
  color: #0c0f13;
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow: 0 3px 8px rgba(255, 255, 255, 0.22);
}

.preview-toggle-button[aria-pressed="false"] {
  opacity: 0.5;
}

.fit-toggle-button[aria-pressed="false"] {
  opacity: 0.5;
}

.preview-fit-toggle {
  display: inline-flex;
  gap: 8px;
  align-self: flex-start;
}

.fit-toggle-button {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 700;
}

.fit-toggle-button[aria-pressed="true"] {
  background: #edf2f7;
  color: #0c1015;
  border-color: rgba(255, 255, 255, 0.82);
  box-shadow: 0 8px 20px rgba(255, 255, 255, 0.16);
}

.canvas-frame {
  margin-top: 12px;
  min-height: min(78vh, 920px);
  border-radius: 18px;
  border: 1px dashed rgba(255, 255, 255, 0.3);
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.025) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.025) 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

canvas {
  display: block;
}

.is-hidden {
  display: none !important;
}

.canvas-frame.fit-width canvas {
  width: 100%;
  height: auto;
  max-width: none;
  max-height: none;
}

.canvas-frame.fit-height canvas {
  width: auto;
  height: min(76vh, 900px);
  max-width: none;
  max-height: none;
}

.canvas-frame.fit-height {
  overflow-x: auto;
}

.empty-state {
  width: min(320px, 80%);
  margin: 0;
  text-align: center;
  color: var(--muted);
  line-height: 1.8;
}

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

  .hero-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .tool-links {
    justify-content: flex-start;
  }

  .controls {
    position: static;
    max-height: none;
    overflow: visible;
    padding-right: 22px;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 20px, 1320px);
    padding-top: 18px;
  }

  .panel,
  .hero-card {
    padding: 16px;
    border-radius: 20px;
  }

  .slider-row,
  .slider-row.compact {
    grid-template-columns: 1fr;
  }

  .panel-title-row,
  .control-header,
  .input-actions,
  .actions-footer,
  .preview-fit-toggle {
    flex-direction: column;
    align-items: stretch;
  }

  .canvas-frame {
    min-height: 240px;
  }
}
