:root {
  color-scheme: light dark;
  --bg: #0b0b0d;
  --card: #17171a;
  --card-2: #202024;
  --text: #f6f6f7;
  --muted: #b5b5bb;
  --line: #303037;
  --accent: #ffffff;
  --button-text: #111111;
  --shadow: rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  padding: env(safe-area-inset-top) 14px calc(20px + env(safe-area-inset-bottom));
}

.app-shell {
  width: min(720px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 4px 10px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 25px;
  line-height: 1.16;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

.topbar p,
.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  margin-top: 7px;
}

.version {
  flex: none;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  margin: 12px 0;
  box-shadow: 0 12px 28px var(--shadow);
}

.primary-card {
  background: linear-gradient(180deg, var(--card-2), var(--card));
}

.main-button,
.secondary-button,
.link-button {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.main-button {
  background: var(--accent);
  color: var(--button-text);
}

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

.main-button:disabled,
.secondary-button:disabled {
  opacity: 0.48;
}

.link-button {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.field span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  color: var(--text);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 15px;
}

.advanced {
  margin-top: 12px;
}

.advanced summary {
  color: var(--muted);
  cursor: pointer;
  padding: 8px 0 0;
}

.crop-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.sliders {
  display: grid;
  gap: 12px;
  margin: 14px 0;
}

.sliders label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

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

.status-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
}

.progress-wrap {
  height: 8px;
  border-radius: 999px;
  background: var(--card-2);
  overflow: hidden;
  margin: 12px 0 0;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.12s ease;
}

.file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  max-height: 112px;
  overflow: auto;
}

.file-pill {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-wrap {
  width: 100%;
  max-height: 70vh;
  overflow: auto;
  background: #000;
  border-radius: 14px;
  border: 1px solid var(--line);
  display: flex;
  justify-content: center;
}

#previewCanvas {
  width: 100%;
  height: auto;
  display: block;
}

.result-actions {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.result-item {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
}

.result-item img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 9px;
  background: #fff;
}

.result-item p {
  color: var(--muted);
  font-size: 11px;
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 620px) {
  .settings-grid {
    grid-template-columns: 1fr 1fr;
  }

  .result-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f4f5;
    --card: #ffffff;
    --card-2: #f2f2f4;
    --text: #111113;
    --muted: #616169;
    --line: #d9d9df;
    --accent: #111111;
    --button-text: #ffffff;
    --shadow: rgba(0, 0, 0, 0.08);
  }
}
