:root {
  --bg-1: #eef2fb;
  --bg-2: #f1f6fc;
  --panel: #ffffff;
  --border: #dde4f0;
  --border-strong: #c5cee0;
  --text: #1e2837;
  --muted: #6b7585;
  --brand: #2f74d0;
  --brand-2: #4f8ee0;
  --brand-dark: #1f5bab;
  --tint: #e8f0fc;
  --danger: #e11d48;
  --ok: #1f5bab;
  --shadow-sm: 0 1px 2px rgba(30,40,60,.06);
  --shadow-md: 0 6px 16px rgba(30,40,60,.09);
  --shadow-lg: 0 20px 44px rgba(30,50,90,.16);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background:
    radial-gradient(1200px 600px at 12% -8%, #d9e6f8 0%, transparent 55%),
    radial-gradient(1000px 560px at 100% 0%, #e0eafa 0%, transparent 50%),
    linear-gradient(180deg, #e6edf8, #eef2fb);
  background-attachment: fixed;
  color: var(--text);
  font-size: 14px;
  line-height: 1.65;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: url("assets/car-bg.jpg") center center / cover no-repeat fixed;
  filter: grayscale(1);
  opacity: .10;
}
header, .toolbar, main { position: relative; z-index: 1; }

/* ===== Header ===== */
header.app-header {
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 13px 22px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 40;
}
.brand { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; }
.brand-mark {
  font-size: 20px; line-height: 1; width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--tint); border: 1px solid #bcd3f3;
}
.brand-text { font-size: 17px; font-weight: 800; color: var(--brand-dark); letter-spacing: .3px; }
.brand-logo { height: 30px; width: auto; display: block; }
.privacy-badge {
  font-size: 12px; color: var(--ok); background: var(--tint); border: 1px solid #bcd3f3;
  padding: 4px 11px; white-space: nowrap; font-weight: 600;
}
.app-header .spacer { flex: 1; }
.app-header .counter {
  font-size: 13px; color: var(--brand-dark); font-weight: 700;
  background: var(--tint); border: 1px solid #bcd3f3; padding: 4px 11px; white-space: nowrap;
}

/* ===== Toolbar ===== */
.toolbar {
  position: sticky; top: 57px; z-index: 30;
  background: rgba(255,255,255,.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 11px 22px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
}
.toolbar .group {
  display: flex; gap: 7px; align-items: center;
  padding: 4px 13px 4px 8px; border-right: 1px solid var(--border); flex-wrap: wrap;
}
.toolbar .group:last-child { border-right: none; }
.toolbar .group.grow { flex: 1 1 220px; }
.toolbar .group-label { font-size: 11px; color: var(--muted); margin-right: 2px; font-weight: 700; }
.chk { font-size: 13px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.chk input { width: 16px; height: 16px; accent-color: var(--brand); }
.chk.enlarge { font-size: 12px; color: var(--muted); }

.unit { font-size: 12px; color: var(--muted); }
.qhint { font-size: 11px; color: var(--muted); white-space: nowrap; }
.qval { font-size: 13px; font-weight: 700; color: var(--brand-dark); min-width: 26px; text-align: right; }

.sel, .inp {
  font: inherit; font-size: 13px; padding: 7px 9px;
  border: 1px solid var(--border-strong); background: #fff; color: var(--text);
}
.sel:focus, .inp:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 2px rgba(47,116,208,.18); }
.sel.auto { width: auto; }
.inp.num { width: 86px; }

.presets { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border-strong); background: #fff; color: var(--muted);
  padding: 5px 10px; transition: background .12s, color .12s, border-color .12s;
}
.chip:hover { background: var(--tint); color: var(--brand-dark); border-color: var(--brand); }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.range { width: 100%; min-width: 120px; accent-color: var(--brand); cursor: pointer; }

/* ===== Buttons ===== */
button.btn {
  font: inherit; font-size: 13px; font-weight: 600;
  border: 1px solid var(--border-strong); background: #fff; color: var(--text);
  padding: 8px 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s, transform .06s;
  white-space: nowrap;
}
button.btn:hover:not(:disabled) { background: var(--tint); border-color: var(--brand); color: var(--brand-dark); }
button.btn:active:not(:disabled) { transform: translateY(1px); }
button.btn:disabled { opacity: .45; cursor: not-allowed; }
button.btn.primary {
  background: var(--brand); border-color: var(--brand); color: #fff;
  box-shadow: 0 1px 3px rgba(47,116,208,.25);
}
button.btn.primary:hover:not(:disabled) { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
button.btn.big {
  padding: 17px 40px; font-size: 16px; font-weight: 700; letter-spacing: .3px;
  transition: transform .22s cubic-bezier(.2,.7,.2,1), box-shadow .22s ease, background .18s ease;
}
button.btn.big.primary { box-shadow: 0 8px 24px rgba(47,116,208,.4); }
button.btn.big.primary:hover:not(:disabled) {
  transform: translateY(-3px); box-shadow: 0 16px 34px rgba(47,116,208,.5); background: var(--brand);
}
button.btn.danger { color: var(--danger); border-color: #f0c4ce; }
button.btn.danger:hover:not(:disabled) { background: #fff1f3; border-color: var(--danger); color: var(--danger); }

/* ===== Main ===== */
main { padding: 30px 22px 44px; flex: 1 1 auto; }

/* ===== Hero (empty state) ===== */
.hero { max-width: 920px; margin: 26px auto 0; display: flex; flex-direction: column; align-items: center; gap: 22px; }
.hero-card {
  width: 100%; background: transparent; border: 2px dashed rgba(47,116,208,.5);
  padding: 56px 28px 50px; text-align: center; transition: border-color .18s, background .18s;
}
.hero.drag .hero-card { border-color: var(--brand); background: rgba(47,116,208,.06); }
.hero-icon {
  width: 80px; height: 80px; margin: 0 auto 22px;
  display: flex; align-items: center; justify-content: center; color: var(--brand); background: var(--tint);
}
.hero h2 { font-size: 28px; margin: 0 0 12px; font-weight: 800; letter-spacing: .4px; color: var(--text); }
.hero-sub { color: #3f4654; margin: 0 0 26px; font-size: 15px; line-height: 1.7; }
.hero-sub strong { color: var(--brand); font-weight: 700; }
.picker-btn { margin-bottom: 6px; }
.hero-privacy { color: var(--ok); font-size: 12.5px; margin: 20px 0 0; font-weight: 600; }

.steps { display: flex; align-items: stretch; gap: 10px; flex-wrap: wrap; justify-content: center; width: 100%; }
.step { flex: 1; min-width: 190px; background: #fff; border: 1px solid var(--border); padding: 18px 20px; display: flex; align-items: center; gap: 15px; }
.step .num { flex: none; width: 30px; height: 30px; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; }
.step div { display: flex; flex-direction: column; line-height: 1.45; }
.step b { font-size: 14px; }
.step div span { color: var(--muted); font-size: 12px; }
.step-arrow { display: flex; align-items: center; color: #b9c4dc; font-size: 18px; font-weight: 700; }

.features { width: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(205px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); }
.feat { background: #fff; padding: 18px 20px; display: flex; align-items: center; gap: 15px; transition: background .12s; }
.feat:hover { background: #f6f9fe; }
.feat .ico { flex: none; width: 40px; height: 40px; background: var(--tint); color: var(--brand); display: flex; align-items: center; justify-content: center; font-size: 19px; }
.feat .txt { display: flex; flex-direction: column; gap: 2px; line-height: 1.4; }
.feat .txt b { font-size: 14px; font-weight: 700; }
.feat .txt small { color: var(--muted); font-size: 11.5px; }

/* ===== List ===== */
.list-wrap { max-width: 1100px; margin: 0 auto; }
.list-bar {
  display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap;
  padding: 2px 2px 14px;
}
.list-sum { font-weight: 700; font-size: 15px; color: var(--text); }
.list-sum b { color: var(--brand-dark); }
.list-hint { font-size: 12px; color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card {
  background: #fff; border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; overflow: hidden;
}
.card-thumb {
  position: relative; height: 170px; background:
    repeating-conic-gradient(#eef1f6 0% 25%, #fff 0% 50%) 50% / 18px 18px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.card-thumb img { max-width: 100%; max-height: 100%; display: block; object-fit: contain; }
.card-thumb .badge {
  position: absolute; top: 8px; right: 8px;
  font-size: 11px; font-weight: 700; color: #fff; background: rgba(31,91,171,.92);
  padding: 3px 8px; letter-spacing: .3px;
}
.card-del {
  position: absolute; top: 8px; left: 8px; width: 26px; height: 26px;
  border: none; background: rgba(20,28,45,.55); color: #fff; cursor: pointer;
  font-size: 15px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.card-del:hover { background: var(--danger); }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 9px; }
.card-name { font-size: 13px; font-weight: 700; word-break: break-all; line-height: 1.4; }
.card-stats { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.card-stats .row { display: flex; align-items: center; gap: 8px; }
.card-stats .arrow { color: var(--brand); font-weight: 700; }
.card-stats .out { color: var(--text); font-weight: 600; }
.card-stats .save {
  font-weight: 700; padding: 1px 7px; font-size: 11px;
  background: var(--tint); color: var(--brand-dark); border: 1px solid #bcd3f3;
}
.card-stats .save.up { background: #fff1f3; color: var(--danger); border-color: #f0c4ce; }
.card-foot { display: flex; gap: 8px; margin-top: 2px; }
.card-foot .btn { flex: 1; justify-content: center; }
.card.busy .card-thumb::after {
  content: "処理中…"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.7); font-size: 12px; font-weight: 700; color: var(--brand-dark);
}

/* ===== Editor (切り抜き・透過) ===== */
.editor-back {
  position: fixed; inset: 0; background: rgba(20,26,42,.55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 80; padding: 18px;
}
.editor {
  background: #fff; border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 1080px; max-height: 94vh; display: flex; flex-direction: column;
}
.editor-head {
  display: flex; align-items: center; gap: 10px; padding: 13px 18px;
  border-bottom: 1px solid var(--border);
}
.ed-title { font-size: 15px; font-weight: 800; color: var(--brand-dark); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 50%; }
.ed-spacer { flex: 1; }
.editor-main { display: flex; gap: 0; min-height: 0; flex: 1; }
.ed-stage {
  position: relative; flex: 1; min-width: 0; background:
    repeating-conic-gradient(#e7ebf2 0% 25%, #fff 0% 50%) 50% / 22px 22px;
  display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 18px;
}
.ed-stage.pick { cursor: crosshair; }
#edCanvas { display: block; box-shadow: 0 2px 14px rgba(20,30,50,.18); touch-action: none; }
.ed-crop {
  position: absolute; box-sizing: border-box; border: 1px solid #fff;
  box-shadow: 0 0 0 1px rgba(20,30,50,.6), 0 0 0 9999px rgba(20,26,42,.5);
  cursor: move;
}
.ed-stage.pick .ed-crop { pointer-events: none; box-shadow: 0 0 0 1px rgba(20,30,50,.6); }
.ed-crop::before, .ed-crop::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to right, transparent calc(33.33% - .5px), rgba(255,255,255,.45) 33.33%, transparent calc(33.33% + .5px),
    transparent calc(66.66% - .5px), rgba(255,255,255,.45) 66.66%, transparent calc(66.66% + .5px));
}
.ed-crop::after { background: linear-gradient(to bottom, transparent calc(33.33% - .5px), rgba(255,255,255,.45) 33.33%, transparent calc(33.33% + .5px),
    transparent calc(66.66% - .5px), rgba(255,255,255,.45) 66.66%, transparent calc(66.66% + .5px)); }
.ed-h { position: absolute; width: 13px; height: 13px; background: #fff; border: 1px solid var(--brand); box-sizing: border-box; z-index: 2; }
.ed-h[data-d="nw"] { left: -7px; top: -7px; cursor: nwse-resize; }
.ed-h[data-d="ne"] { right: -7px; top: -7px; cursor: nesw-resize; }
.ed-h[data-d="sw"] { left: -7px; bottom: -7px; cursor: nesw-resize; }
.ed-h[data-d="se"] { right: -7px; bottom: -7px; cursor: nwse-resize; }
.ed-h[data-d="n"] { left: 50%; top: -7px; transform: translateX(-50%); cursor: ns-resize; }
.ed-h[data-d="s"] { left: 50%; bottom: -7px; transform: translateX(-50%); cursor: ns-resize; }
.ed-h[data-d="w"] { left: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.ed-h[data-d="e"] { right: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

.ed-panel { width: 320px; flex: none; border-left: 1px solid var(--border); padding: 16px 18px; overflow: auto; display: flex; flex-direction: column; gap: 18px; }
.ed-sec { display: flex; flex-direction: column; gap: 10px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.ed-sec:last-child { border-bottom: none; padding-bottom: 0; }
.ed-sec-t { font-size: 14px; font-weight: 800; color: var(--text); }
.ed-help { font-size: 11.5px; color: var(--muted); margin: -4px 0 0; line-height: 1.5; }
.ed-ratios { display: flex; gap: 5px; flex-wrap: wrap; }
.ed-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ed-row.tol { gap: 8px; }
.ed-lbl { font-size: 12px; color: var(--muted); font-weight: 700; }
.ed-dims { font-size: 12px; color: var(--brand-dark); font-weight: 700; }
.ed-swatch { width: 30px; height: 30px; border: 1px solid var(--border-strong); background:
  repeating-conic-gradient(#e7ebf2 0% 25%, #fff 0% 50%) 50% / 10px 10px; flex: none; }
.ed-note { font-size: 11px; color: var(--muted); margin: 0; line-height: 1.5; background: var(--tint); border: 1px solid #bcd3f3; padding: 7px 9px; }
.ed-note b { color: var(--brand-dark); }
.ed-keyon { font-weight: 700; }

@media (max-width: 760px) {
  .editor-main { flex-direction: column; }
  .ed-panel { width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .ed-stage { min-height: 240px; }
}

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: #1e2837; color: #fff; padding: 12px 22px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-lg); z-index: 90; max-width: 90vw;
}
.toast.warn { background: #b45309; }

.hidden { display: none !important; }

/* ===== topnav ===== */
.topnav { display: flex; align-items: center; gap: 4px; margin-left: 14px; }
.topnav-btn {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 13.5px; font-weight: 600; color: var(--muted);
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  padding: 7px 13px; cursor: pointer; text-decoration: none; line-height: 1;
  transition: background .12s, color .12s;
}
.topnav-btn:hover { background: rgba(47,116,208,.10); color: var(--brand-dark); }
.topnav-btn.active { background: var(--brand); color: #fff; }
.topnav-btn.link { color: var(--muted); border-color: var(--border); }
.topnav-btn.link:hover { color: var(--brand-dark); border-color: var(--brand); }

@media (max-width: 640px) {
  .hero h2 { font-size: 22px; }
}
