:root {
  color-scheme: light;
  --bg: #f2f0eb;
  --panel: #ffffff;
  --ink: #18211e;
  --muted: #67736e;
  --line: #d5ddd8;
  --accent: #247a5b;
  --accent-dark: #15533d;
  --soft: #edf4f0;
  --shadow: 0 18px 54px rgba(24, 33, 30, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, #eef8f2 0%, #f7fbf6 100%);
}

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

.topbar {
  display: grid;
  justify-items: center;
  gap: 14px;
  margin-bottom: 20px;
  text-align: center;
}

.brand {
  display: grid;
  justify-items: center;
  gap: 12px;
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(135deg, #2aa978, #1f7556);
  box-shadow: inset 0 -10px 0 rgba(0, 0, 0, 0.1), 0 12px 30px rgba(36, 122, 91, 0.2);
}

.brand-icon span {
  width: 32px;
  height: 26px;
  border: 3px solid #fff;
  border-radius: 5px;
  background: linear-gradient(135deg, transparent 55%, rgba(255, 255, 255, 0.8) 56%);
}

h1 {
  margin: 0 0 6px;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Times New Roman", serif;
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0;
  color: #121f19;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75);
}

p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.65);
  font-size: 13px;
}

.status-pill.ready {
  color: var(--accent-dark);
  border-color: rgba(36, 122, 91, 0.35);
  background: rgba(36, 122, 91, 0.08);
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
  gap: 18px;
}

.drop-panel,
.settings-panel,
.progress-panel {
  background: #f1fbf4;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.drop-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
  padding: 18px;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 2px dashed #aab8b1;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.drop-zone:hover,
.drop-zone.dragging {
  border-color: var(--accent);
  background: rgba(36, 122, 91, 0.06);
}

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

.drop-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 12px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 34px;
  line-height: 1;
}

.drop-zone strong {
  font-size: 22px;
  overflow-wrap: anywhere;
}

.drop-zone span:last-child {
  margin-top: 8px;
  color: var(--muted);
}

.preview-box {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 290px;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(45deg, #eff2f0 25%, transparent 25%),
    linear-gradient(-45deg, #eff2f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eff2f0 75%),
    linear-gradient(-45deg, transparent 75%, #eff2f0 75%);
  background-color: #fff;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

#previewImage {
  display: none;
  max-width: 100%;
  max-height: 360px;
  object-fit: contain;
}

#previewImage.visible {
  display: block;
}

#previewEmpty {
  color: var(--muted);
  font-weight: 700;
}

.settings-panel {
  padding: 18px;
}

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

.field {
  display: grid;
  gap: 8px;
}

.field select + input {
  min-height: 40px;
}

.field input:read-only {
  opacity: 1;
  background: #ffffff;
}

.dimension-field:has(select:disabled) {
  opacity: 1;
}

.dimension-field select,
.dimension-field input {
  background: #ffffff;
}

.dimension-field select:disabled,
.dimension-field input:disabled {
  color: #7d8984;
  background: #ffffff;
  border-color: #d7e1dc;
  opacity: 0.86;
}

.wide,
.save-field {
  grid-column: 1 / -1;
}

.compact-field {
  max-width: 180px;
}

label {
  font-weight: 800;
}

select,
input,
button {
  min-height: 46px;
  border-radius: 8px;
  font: inherit;
}

select,
input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfcfb;
  color: var(--ink);
  padding: 0 12px;
}

input[type="color"] {
  padding: 4px;
}

.range-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  gap: 10px;
  align-items: center;
}

input[type="range"] {
  padding: 0;
}

output {
  text-align: right;
  font-weight: 800;
  color: var(--accent-dark);
}

.check-row {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-start;
  grid-column: 1 / -1;
  min-height: 54px;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  font-size: 14px;
}

.check-row input {
  width: 14px;
  min-height: 14px;
  accent-color: var(--accent);
}

.check-row span {
  display: flex;
  gap: 10px;
  align-items: baseline;
  min-width: 0;
}

.check-row small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
}

.save-field {
  margin-top: 14px;
}

.path-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  gap: 8px;
}

.browse-button {
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  width: 100%;
  min-height: 48px;
  margin-top: 18px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

.primary-button:disabled {
  background: #aebbb5;
  cursor: not-allowed;
}

.progress-panel {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: 18px;
}

.progress-panel > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

#progressText,
#outputMeta {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.progress-track {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #dbe4df;
}

.tool-footer {
  display: grid;
  justify-items: center;
  margin-top: 18px;
  padding: 6px 0 0;
}

.tool-footer nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.tool-footer a {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border: 1px solid rgba(21, 83, 61, 0.18);
  border-radius: 999px;
  color: var(--accent-dark);
  background: rgba(255, 255, 255, 0.62);
  text-decoration: none;
  font-size: 13px;
  font-weight: 800;
}

.tool-footer a:hover,
.tool-footer a:focus-visible {
  border-color: rgba(21, 83, 61, 0.34);
  background: rgba(255, 255, 255, 0.9);
  outline: none;
}

#progressBar {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

.tool-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 18px;
}

.tool-info > div {
  padding: 18px;
  border: 1px solid rgba(21, 83, 61, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
  box-shadow: 0 12px 34px rgba(21, 83, 61, 0.08);
}

.tool-info h2 {
  margin: 0 0 8px;
  font-size: 17px;
  line-height: 1.4;
}

.tool-info p {
  font-size: 14px;
  line-height: 1.8;
}

.download-link {
  display: grid;
  place-items: center;
  min-height: 46px;
  border-radius: 8px;
  background: #18211e;
  color: #fff;
  text-decoration: none;
  font-weight: 900;
}

.download-link.disabled {
  pointer-events: none;
  background: #aebbb5;
  color: #eef2ef;
  cursor: not-allowed;
}

.form-save-link {
  margin-top: 12px;
}

.hidden {
  display: none;
}

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

  .topbar {
    justify-items: center;
  }

  .brand {
    justify-items: center;
  }

  .brand-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
  }

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

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

  .compact-field {
    max-width: 180px;
  }

  .check-row span {
    display: grid;
    gap: 2px;
  }

  .check-row small {
    white-space: normal;
  }

  .drop-zone {
    min-height: 190px;
  }

  .preview-box {
    min-height: 220px;
  }

  .path-row {
    grid-template-columns: 1fr;
  }

  .tool-info {
    grid-template-columns: 1fr;
  }

  .tool-footer a {
    font-size: 12px;
    padding: 5px 10px;
  }
}
