:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f0f5ff;
  --panel-strong: #fbfdff;
  --text: #172033;
  --muted: #66758f;
  --line: #d8e0ec;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #e8f0ff;
  --danger: #d92d20;
  --shadow: 0 18px 45px rgba(40, 55, 80, 0.12);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 2.6rem;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

.header-note {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.6;
}

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.settings-panel,
.upload-panel,
.results-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.settings-panel {
  position: sticky;
  top: 20px;
  padding: 20px;
}

.main-column {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.upload-panel,
.results-panel {
  padding: 20px;
}

.upload-box {
  position: relative;
  background: var(--panel-soft);
  border-radius: 8px;
}

.upload-box.drag-over {
  background: var(--accent-soft);
  outline: 2px solid var(--accent);
  outline-offset: -8px;
}

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

.upload-content {
  display: grid;
  min-height: 220px;
  place-items: center;
  align-content: center;
  gap: 10px;
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
}

.upload-icon {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  font-size: 1.8rem;
  line-height: 1;
}

.upload-content p {
  margin-bottom: 4px;
  color: var(--muted);
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 18px;
}

.button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.mini {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.86rem;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.primary,
.convert {
  background: var(--accent);
  color: #ffffff;
}

.primary:hover,
.convert:hover {
  background: var(--accent-dark);
}

.secondary {
  background: var(--panel-soft);
  border-color: var(--line);
  color: var(--text);
}

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

.ghost {
  min-height: 34px;
  background: transparent;
  color: var(--muted);
}

.ghost:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.convert {
  width: 100%;
  margin-top: 12px;
}

.field-group {
  display: grid;
  gap: 10px;
  margin: 0 0 18px;
  padding: 0;
  border: 0;
}

legend,
.input-label {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 8px;
  color: var(--text);
  font-weight: 700;
}

.radio-row,
.option-row {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 34px;
  color: var(--muted);
}

.radio-row input,
.option-row input,
.check-chip input {
  accent-color: var(--accent);
}

.radio-row:has(input:disabled),
.text-input:disabled {
  opacity: 0.45;
}

.text-input,
.select-input {
  width: 100%;
  height: 44px;
  margin-bottom: 18px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--text);
}

.select-input {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 18px, calc(100% - 12px) 18px;
  background-repeat: no-repeat;
  background-size: 6px 6px;
}

.text-input::placeholder {
  color: var(--muted);
}

.text-input:focus,
.select-input:focus,
.range-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.text-input:disabled,
.select-input:disabled {
  opacity: 0.45;
}

.range-input {
  width: 100%;
  accent-color: var(--accent);
}

.input-unit {
  color: var(--muted);
  font-weight: 600;
}

.hint,
.status-text {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.hint {
  margin: 8px 0 18px;
}

.crop-group {
  gap: 8px;
}

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

.compact-label {
  display: grid;
  gap: 6px;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 700;
}

.compact-input {
  margin-bottom: 0;
}

.crop-group .select-input {
  margin-bottom: 0;
}

.status-text {
  min-height: 22px;
  margin: 12px 0 0;
}

.status-text.error {
  color: var(--danger);
}

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

.check-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--text);
  font-weight: 700;
}

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

.file-list {
  display: grid;
  gap: 12px;
}

.file-list.empty {
  min-height: 280px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.file-card {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.thumb {
  width: 92px;
  height: 92px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--panel-soft);
}

.file-body {
  min-width: 0;
}

.file-topline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.file-name {
  overflow: hidden;
  margin: 0;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta,
.result-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.file-body > .mini {
  width: fit-content;
  margin-top: 10px;
}

.remove-button {
  min-width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
}

.remove-button:hover {
  color: var(--danger);
  border-color: #f2b8b5;
}

.result-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 800;
  text-decoration: none;
}

.download-link:hover {
  background: var(--accent-soft);
}

.crop-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(23, 32, 51, 0.58);
}

.crop-modal[hidden] {
  display: none;
}

.crop-dialog {
  width: min(900px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.crop-editor {
  position: relative;
  display: grid;
  min-height: 360px;
  max-height: 58vh;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f172a;
  touch-action: none;
  user-select: none;
}

.crop-editor img {
  display: block;
  max-width: 100%;
  max-height: 58vh;
  pointer-events: none;
}

.crop-selection {
  position: absolute;
  border: 2px solid #ffffff;
  background: rgba(37, 99, 235, 0.22);
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.48);
  pointer-events: none;
}

.crop-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

@media (max-width: 860px) {
  .app-header {
    display: block;
  }

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

  .header-note {
    max-width: none;
    margin-top: 12px;
  }

  .settings-panel {
    position: static;
  }

  h1 {
    font-size: 2.4rem;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding: 20px 0;
  }

  .file-card {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .thumb {
    width: 72px;
    height: 72px;
  }

  .crop-editor {
    min-height: 260px;
  }

  h1 {
    font-size: 2rem;
  }
}
