:root {
  --ink: #14202b;
  --ink-soft: #3a4a58;
  --paper: #eef3f6;
  --line: rgba(20, 32, 43, 0.14);
  --accent: #c0392b;
  --accent-deep: #8e241b;
  --indigo: #243b55;
  --focus: #2f6f8f;
  --page-pad: 1.1rem;
  --font-display: "Cormorant Garamond", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Hiragino Kaku Gothic ProN", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  margin: 0;
  max-width: 100%;
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  max-width: 100%;
  overflow-x: clip;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

img,
video,
canvas,
svg {
  max-width: 100%;
  height: auto;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 70% 55% at 0% 0%, rgba(47, 111, 143, 0.16), transparent 55%),
    radial-gradient(ellipse 55% 45% at 100% 10%, rgba(36, 59, 85, 0.12), transparent 50%),
    linear-gradient(165deg, #f4f7fa 0%, #e4ecf2 48%, #d9e4ec 100%);
  pointer-events: none;
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.25;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
}

.site-header,
.workspace,
.site-footer {
  width: 100%;
  max-width: 1100px;
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--page-pad);
  padding-right: var(--page-pad);
}

.site-header {
  padding-top: 1.5rem;
  padding-bottom: 0.85rem;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.2;
  color: var(--indigo);
  overflow-wrap: anywhere;
}

.tagline {
  margin: 0.45rem 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 400;
}

/* Mobile-first: always a single vertical column */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
  padding-bottom: 2.5rem;
}

.panel {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.panel-title {
  margin: 0 0 0.55rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--indigo);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.65rem;
}

.panel-head .panel-title {
  margin: 0;
}

.mode-toggle {
  display: flex;
  width: 100%;
  border-bottom: 1px solid var(--line);
}

.mode-btn {
  appearance: none;
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  min-height: 42px;
  padding: 0.5rem 0.6rem;
  text-align: center;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  -webkit-tap-highlight-color: transparent;
}

.mode-btn.is-active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.dropzone {
  display: block;
  position: relative;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px dashed var(--line);
  background: rgba(255, 255, 255, 0.42);
  cursor: pointer;
  overflow: hidden;
}

.dropzone:hover,
.dropzone.is-dragging {
  border-color: var(--focus);
  background: rgba(255, 255, 255, 0.62);
}

.dropzone-idle {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  text-align: center;
  padding: 1rem;
}

.dropzone-action {
  color: var(--indigo);
  font-weight: 700;
}

.dropzone-hint {
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  display: block;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  width: 100%;
}

.preset-item {
  appearance: none;
  border: 1px solid transparent;
  padding: 0.2rem;
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.preset-item.is-selected {
  border-color: var(--accent);
}

.preset-item img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #c5d0d8;
}

.preset-item .preset-name {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.68rem;
  color: var(--ink-soft);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.preset-item .preset-score {
  display: block;
  margin-top: 0.1rem;
  font-size: 0.62rem;
  color: #7a8894;
  line-height: 1.3;
}

.panel-controls {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
  width: 100%;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.engine-field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
}

.engine-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  gap: 0.45rem;
  border-bottom: 0;
}

.engine-toggle .mode-btn {
  border: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 0;
  padding: 0.45rem 0.6rem;
}

.engine-toggle .mode-btn.is-active {
  border-color: var(--accent);
  color: var(--accent-deep);
  background: rgba(192, 57, 43, 0.08);
}

.size-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "label value"
    "slider slider";
  gap: 0.35rem 0.75rem;
  width: 100%;
  min-width: 0;
}

.size-field .field-label {
  grid-area: label;
  font-size: 0.85rem;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.size-field .field-value {
  grid-area: value;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  color: var(--ink);
  text-align: right;
}

.size-field input[type="range"] {
  grid-area: slider;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 2rem;
  margin: 0;
}

#max-dim {
  accent-color: var(--indigo);
}

#style-strength {
  accent-color: var(--accent);
}

.check-field {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  min-height: 42px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.check-field input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.check-field .field-label {
  margin: 0;
}

.engine-note {
  margin: 0;
  width: 100%;
  max-width: 100%;
  font-size: 0.78rem;
  color: var(--ink-soft);
  background: rgba(47, 111, 143, 0.08);
  border-left: 2px solid var(--focus);
  padding: 0.55rem 0.75rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.engine-note .note-long {
  display: none;
}

.engine-note .note-short {
  display: inline;
}

.convert-btn {
  appearance: none;
  width: 100%;
  min-height: 48px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.9rem 1.2rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.convert-btn:hover:not(:disabled) {
  background: var(--accent-deep);
}

.convert-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.status {
  margin: 0;
  min-height: 1.25rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.status.is-error {
  color: var(--accent-deep);
}

.panel-result {
  width: 100%;
  max-width: 100%;
}

.result-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
}

.result-head .panel-title {
  margin: 0;
}

.download-btn {
  color: var(--indigo);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  border-bottom: 1px solid currentColor;
  padding-bottom: 0.1rem;
}

.download-btn:hover {
  color: var(--accent);
}

/* Result image: never wider than the screen; scroll the page instead */
.result-image {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid var(--line);
}

.site-footer {
  padding-top: 0;
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  color: var(--ink-soft);
  font-size: 0.68rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

/* ---- Desktop / tablet landscape: two columns only when wide enough ---- */
@media (min-width: 900px) {
  :root {
    --page-pad: clamp(1.25rem, 4vw, 2rem);
  }

  .site-header {
    padding-top: clamp(2.5rem, 6vw, 4.5rem);
    padding-bottom: 1.25rem;
  }

  .brand {
    font-size: clamp(2.2rem, 6vw, 4.4rem);
    letter-spacing: 0.04em;
  }

  .tagline {
    margin-top: 0.75rem;
    max-width: 28rem;
    font-size: 1rem;
  }

  .workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.5rem 1.75rem;
    padding-bottom: 4rem;
  }

  .panel-controls,
  .panel-result {
    grid-column: 1 / -1;
  }

  .panel-title {
    font-size: 1.35rem;
    margin-bottom: 0.75rem;
  }

  .panel-head {
    flex-wrap: nowrap;
    justify-content: space-between;
  }

  .mode-toggle {
    width: auto;
  }

  .mode-btn {
    flex: none;
    text-align: left;
    min-height: 0;
    padding: 0.4rem 0.7rem;
    font-size: 0.85rem;
  }

  .dropzone,
  .dropzone-compact {
    aspect-ratio: 4 / 3;
  }

  .preset-grid {
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
    gap: 0.65rem;
  }

  .preset-item .preset-name {
    font-size: 0.72rem;
  }

  .panel-controls {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem 1.5rem;
  }

  .engine-field {
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    flex: 1 1 320px;
    width: auto;
  }

  .engine-toggle {
    display: flex;
    width: auto;
    gap: 0.4rem;
  }

  .size-field {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "label slider value";
    align-items: center;
    gap: 0.65rem 0.75rem;
    flex: 1 1 240px;
    width: auto;
  }

  .convert-btn {
    width: auto;
    min-width: 12rem;
  }

  .check-field {
    width: auto;
    flex: 0 0 auto;
  }

  .engine-note {
    flex: 1 1 100%;
    font-size: 0.8rem;
  }

  .engine-note .note-long {
    display: inline;
  }

  .engine-note .note-short {
    display: none;
  }

  .result-image {
    max-height: 70vh;
  }

  .site-footer {
    padding-bottom: 2.5rem;
    font-size: 0.75rem;
  }
}

@media (min-width: 480px) and (max-width: 899px) {
  .preset-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
