:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --text: #172033;
  --muted: #68738a;
  --line: #dce1eb;
  --primary: #235ee7;
  --primary-dark: #1847b5;
  --danger: #c43f4b;
  --success: #16855b;
  --shadow: 0 14px 40px rgba(22, 36, 66, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  line-height: 1.6;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.container {
  width: min(1180px, calc(100% - 40px));
  margin-inline: auto;
}

.site-header {
  padding: 54px 0 38px;
  color: #fff;
  background: linear-gradient(135deg, #152a58 0%, #225fe8 100%);
}

.header-inner {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 30px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(2rem, 4vw, 3.3rem); line-height: 1.15; }
h2 { margin-bottom: 0; font-size: 1.35rem; }

.eyebrow, .step-label {
  margin-bottom: 4px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.eyebrow { color: #b9d1ff; }
.step-label { color: var(--primary); }
.lead { margin-bottom: 0; color: #dce8ff; }

.privacy-badge {
  flex: 0 0 auto;
  padding: 10px 14px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px;
  background: rgba(255,255,255,.11);
  font-size: .9rem;
  font-weight: 700;
}

.main-layout {
  display: grid;
  gap: 24px;
  padding: 34px 0 70px;
}

.panel {
  padding: 28px;
  border: 1px solid rgba(28, 43, 73, 0.08);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.section-heading-actions { align-items: flex-end; }
.section-note { margin: 5px 0 0; color: var(--muted); font-size: .9rem; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}

.field { display: grid; gap: 7px; font-size: .9rem; font-weight: 700; }
.field-wide { grid-column: span 1; }

input[type="number"], select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.color-field { max-width: 150px; }
input[type="color"] { width: 100%; min-height: 46px; padding: 4px; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
input[type="color"]:disabled { cursor: not-allowed; opacity: .45; }

input[type="number"] { padding: 0 54px 0 13px; }
select { padding: 0 40px 0 13px; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(35,94,231,.12); }

.input-with-unit { position: relative; }
.input-with-unit span { position: absolute; top: 50%; right: 14px; transform: translateY(-50%); color: var(--muted); font-weight: 600; }
.range-title { display: flex; justify-content: space-between; }
input[type="range"] { width: 100%; accent-color: var(--primary); }
.quality-field { min-width: 0; margin: 0; padding: 0; border: 0; }
.quality-field legend { margin-bottom: 7px; padding: 0; }
.quality-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.quality-options label { position: relative; cursor: pointer; }
.quality-options input { position: absolute; opacity: 0; pointer-events: none; }
.quality-options span { display: grid; place-items: center; min-height: 46px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 10px; background: #fff; line-height: 1.2; }
.quality-options small { color: var(--muted); font-size: .67rem; font-weight: 700; }
.quality-options input:checked + span { border-color: var(--primary); color: #fff; background: var(--primary); }
.quality-options input:checked + span small { color: #dce8ff; }
.quality-options input:focus-visible + span { outline: 3px solid rgba(35,94,231,.2); outline-offset: 2px; }
.quality-options input:disabled + span { cursor: not-allowed; opacity: .45; }
.field-help { color: var(--muted); font-size: .75rem; font-weight: 500; line-height: 1.45; }

.preset-group { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.preset-button, .count-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8faff;
  color: var(--text);
}
.preset-button { padding: 8px 12px; font-size: .84rem; font-weight: 700; }
.preset-button:hover { border-color: var(--primary); color: var(--primary); }
.preset-button.is-active { border-color: var(--primary); color: #fff; background: var(--primary); }
.count-badge { padding: 6px 11px; font-size: .85rem; font-weight: 800; }

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 190px;
  padding: 26px;
  border: 2px dashed #b8c4dc;
  border-radius: 16px;
  background: #f8faff;
  text-align: center;
  transition: .2s ease;
}
.drop-zone:hover, .drop-zone.is-dragover { border-color: var(--primary); background: #eef4ff; }
.drop-zone span:last-child { color: var(--muted); font-size: .9rem; }
.drop-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-bottom: 10px;
  border-radius: 50%;
  color: #fff;
  background: var(--primary);
  font-size: 1.7rem;
  line-height: 1;
}

.error-message { margin: 12px 0 0; color: var(--danger); font-weight: 700; }

.button-group { display: flex; flex-wrap: wrap; gap: 10px; }
.button {
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 800;
  transition: .18s ease;
}
.button:disabled { cursor: not-allowed; opacity: .45; }
.button-primary { color: #fff; background: var(--primary); }
.button-primary:hover:not(:disabled) { background: var(--primary-dark); }
.button-ghost { border-color: var(--line); color: var(--text); background: #fff; }
.button-ghost:hover:not(:disabled) { border-color: #aeb8ca; background: #f7f8fb; }
.button-danger { color: var(--danger); background: #fff2f3; }
.button-small { min-height: 34px; padding: 6px 10px; font-size: .8rem; }

.empty-state {
  padding: 56px 20px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
}
.empty-state p { margin-bottom: 0; }

.image-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.image-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.thumbnail-button {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: #e9edf5;
}
.thumbnail { width: 100%; height: 100%; object-fit: cover; display: block; }
.edit-label {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 5px 9px;
  border-radius: 999px;
  color: #fff;
  background: rgba(11, 18, 34, .75);
  font-size: .75rem;
  font-weight: 800;
}
.image-card-body { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; }
.image-card-copy { min-width: 0; display: grid; gap: 2px; }
.image-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.image-meta, .crop-status { color: var(--muted); font-size: .77rem; }
.crop-status.is-custom { color: var(--success); font-weight: 800; }
.image-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.modal { position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center; padding: 24px; }
.modal.is-open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 13, 26, .72); }
.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(1080px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 24px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 30px 80px rgba(0,0,0,.28);
}
.modal-header, .modal-footer { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.modal-header { margin-bottom: 18px; }
.modal-footer { margin-top: 18px; }
.icon-button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: #eef1f7; font-size: 1.5rem; }
.crop-stage-wrap { overflow: auto; border-radius: 14px; background: #151a25; }
#cropCanvas { display: block; width: 100%; height: auto; touch-action: none; cursor: crosshair; }
.crop-help { margin: 10px 0 0; color: var(--muted); font-size: .85rem; }

.site-footer { padding: 24px 0; border-top: 1px solid var(--line); background: #fff; }
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.footer-inner p { margin: 0; color: var(--muted); font-size: .85rem; }
.footer-inner nav { display: flex; flex-wrap: wrap; gap: 18px; }
.footer-inner a, .legal-page a { color: var(--primary); }
.legal-page { max-width: 860px; }
.legal-page h2 { margin: 32px 0 10px; }
.legal-page h3 { margin: 22px 0 8px; }
.legal-page li + li { margin-top: 6px; }
.notice-box { padding: 16px 18px; border: 1px solid #e5c66a; border-radius: 12px; background: #fff9e8; }
.usage-notice { margin-bottom: 56px; padding: 22px 26px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.usage-notice h2 { margin-bottom: 10px; font-size: 1.1rem; }
.usage-notice ul { margin: 0; padding-left: 1.4em; color: var(--muted); font-size: .9rem; }
.definition-list { display: grid; grid-template-columns: 10em 1fr; margin: 0; }
.definition-list dt, .definition-list dd { padding: 12px; border-bottom: 1px solid var(--line); }
.definition-list dt { font-weight: 800; }
.definition-list dd { margin: 0; }

@media (max-width: 900px) {
  .header-inner, .section-heading-actions { align-items: flex-start; flex-direction: column; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .image-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .container { width: min(100% - 24px, 1180px); }
  .site-header { padding-top: 38px; }
  .privacy-badge { align-self: stretch; text-align: center; }
  .panel { padding: 20px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .form-grid, .image-grid { grid-template-columns: 1fr; }
  .button-group, .button-group .button { width: 100%; }
  .modal { padding: 10px; }
  .modal-dialog { padding: 16px; max-height: calc(100vh - 20px); }
  .modal-footer { align-items: stretch; flex-direction: column; }
  .footer-inner { align-items: flex-start; flex-direction: column; }
  .definition-list { grid-template-columns: 1fr; }
  .definition-list dd { padding-top: 0; }
  .quality-options { grid-template-columns: 1fr; }
}
