/* 画像を軽くする — style
   方向性：計量所のタグ。重さの読み取り表示を主役に、色は水色×淡い黄色で爽やかに。 */
:root {
  --paper: #ffffff;
  --paper-2: #e4eef5;
  --card: #ffffff;
  --ink: #23404f;          /* やわらかい紺 */
  --ink-2: #4d6a7a;
  --ink-3: #8aa2b0;
  --line: #d3e2ea;
  --panel: #e3f1f9;        /* 設定パネル：薄い水色 */
  --panel-2: #ffffff;
  --panel-line: #bfd9e8;
  --panel-text: #23404f;
  --panel-mute: #6b8899;
  --sky: #2b9bd6;          /* 数字・強調 */
  --sky-soft: #cfe8f6;
  --accent: #ffd84d;       /* 淡い黄色：選択中・ハイライト */
  --accent-soft: #fff3bf;
  --before: #c9d8e1;       /* 元の重さ */
  --warn: #c98a12;
  --danger: #d25a5a;
  --radius: 6px;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-num: "Barlow Condensed", "Arial Narrow", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--ink);
  background: #fff;
  min-height: 100vh;
  padding-bottom: 110px;
}
h1, h2 { margin: 0; font-weight: 700; }
button, input, select { font: inherit; color: inherit; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num { font-family: var(--font-num); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }

/* ---------- header ---------- */
.top { padding: 26px clamp(16px, 4vw, 56px) 6px; }
.eyebrow { margin: 0 0 10px; font-size: 11px; letter-spacing: .18em; color: var(--ink-3); text-transform: uppercase; }
.eyebrow span { margin: 0 6px; color: var(--line); }
.top-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 40px; }
.top h1 { font-size: clamp(28px, 4vw, 40px); letter-spacing: -.01em; line-height: 1.1; }
.top h1 em { font-style: normal; color: var(--sky); }
.top-note { margin: 0 0 6px; color: var(--ink-2); font-size: 13px; max-width: 52ch; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 22px;
  padding: 16px clamp(16px, 4vw, 56px) 32px;
  align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

/* ---------- settings panel（計器盤） ---------- */
.panel {
  background: var(--panel);
  color: var(--panel-text);
  border-radius: var(--radius);
  padding: 4px 18px 12px;
  position: sticky; top: 12px;
  border: 1px solid var(--panel-line);
}
@media (max-width: 900px) { .panel { position: static; } }
.field { padding: 16px 0 16px; border-bottom: 1px solid var(--panel-line); }
.field:last-of-type { border-bottom: 0; }
.field-title {
  font-size: 11px; font-weight: 700; letter-spacing: .16em; color: var(--panel-mute);
  margin-bottom: 10px; text-transform: uppercase;
}
.field-head { display: flex; justify-content: space-between; align-items: baseline; }
.field-head output { font-family: var(--font-num); font-weight: 700; font-size: 30px; line-height: 1; color: var(--sky); }
.hint { margin: 8px 0 0; font-size: 12px; color: var(--panel-mute); line-height: 1.5; }

/* 選択肢：計器のボタン */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.seg label { position: relative; }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg span {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 46px; padding: 4px 6px;
  border: 1px solid var(--panel-line); border-radius: var(--radius); background: var(--panel-2);
  font-weight: 600; font-size: 13.5px; line-height: 1.2; text-align: center; color: var(--panel-text);
  transition: background .12s, border-color .12s, color .12s;
}
.seg small { font-weight: 400; font-size: 10.5px; color: var(--panel-mute); margin-top: 2px; }
.seg input:checked + span { background: var(--accent); border-color: #e9c235; color: var(--ink); }
.seg input:checked + span small { color: #7a6414; }
.seg input:focus-visible + span { outline: 2px solid var(--sky); outline-offset: 2px; }
.seg label:nth-child(5) { grid-column: span 2; }
.seg.two { grid-template-columns: 1fr 1fr; }
.seg.two label:nth-child(n) { grid-column: auto; }
.seg.two span { min-height: 40px; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; margin: 10px 0 0; height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--sky) 0 var(--fill, 70%), #cfdde6 var(--fill, 70%) 100%); cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 2px solid var(--sky);
  box-shadow: 0 1px 3px rgba(35,64,79,.25);
}
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 2px solid var(--sky); }
.range-scale { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--panel-mute); letter-spacing: .08em; }

/* 上限サイズ */
.target { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-top: 10px; }
.target .inline-input { margin-top: 0; flex: 1 1 200px; }
.target .inline-input > span:first-child { white-space: nowrap; }
.target .inline-input input { min-width: 90px; }
.quick { display: flex; gap: 4px; flex: 0 0 auto; }
.quick button {
  padding: 6px 9px; border: 1px solid var(--panel-line); border-radius: var(--radius); background: var(--panel-2);
  color: var(--panel-text); font-family: var(--font-num); font-weight: 600; font-size: 14px; cursor: pointer; line-height: 1.2;
}
.quick button:hover { border-color: var(--sky); }
.quick button.on { background: var(--accent); border-color: #e9c235; color: var(--ink); }

/* 画像の大きさ：用途で選ぶ */
.sizes { display: flex; flex-direction: column; gap: 4px; }
.sizes label { position: relative; }
.sizes input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.sizes span {
  display: grid; grid-template-columns: 84px minmax(0, 1fr); align-items: center; gap: 10px;
  padding: 6px 10px; border: 1px solid var(--panel-line); border-radius: var(--radius); background: var(--panel-2);
  transition: background .12s, border-color .12s;
}
.sizes b { font-family: var(--font-num); font-weight: 700; font-size: 20px; line-height: 1; white-space: nowrap; color: var(--sky); }
.sizes b i { font-style: normal; font-size: 11px; font-weight: 600; color: var(--panel-mute); margin-left: 3px; letter-spacing: .05em; }
.sizes small { font-size: 11.5px; line-height: 1.4; color: var(--panel-mute); }
.sizes label:last-child b { font-family: var(--font-body); font-size: 13px; letter-spacing: 0; }
.sizes input:checked + span { background: var(--accent); border-color: #e9c235; }
.sizes input:checked + span b { color: var(--ink); }
.sizes input:checked + span b i, .sizes input:checked + span small { color: #7a6414; }
.sizes input:focus-visible + span { outline: 2px solid var(--sky); outline-offset: 2px; }

.inline-input { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 12.5px; color: var(--panel-mute); }
.inline-input input, .inline-input select {
  flex: 1; min-width: 0; padding: 7px 9px; border: 1px solid var(--panel-line); border-radius: var(--radius);
  background: var(--panel-2); color: var(--ink); font-family: var(--font-mono); font-size: 13px;
}
.inline-input input::placeholder { color: #a3b6c2; }
.inline-input .unit { color: var(--panel-mute); }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; cursor: pointer; margin-top: 10px; color: var(--panel-text); }
.check input { margin: 4px 0 0; accent-color: var(--sky); }

/* 保存されるファイル名：荷札のプレビュー */
.name-preview {
  margin-top: 12px; padding: 10px 12px; border-radius: var(--radius);
  background: var(--card); color: var(--ink); border: 1px solid var(--panel-line);
  position: relative;
}
.name-preview::before {
  content: ""; position: absolute; right: 10px; top: 9px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--panel); box-shadow: 0 0 0 2px var(--panel-line);
}
.name-preview .lbl { display: block; font-size: 10.5px; letter-spacing: .14em; color: var(--ink-3); margin-bottom: 4px; text-transform: uppercase; }
.name-preview code { display: flex; flex-wrap: wrap; align-items: center; font-family: var(--font-mono); font-size: 13.5px; font-weight: 500; word-break: break-all; }
.name-preview .from { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--sky); }
.name-preview .arrow { display: inline-block; width: 16px; height: 1px; background: var(--ink-3); margin: 0 8px; position: relative; }
.name-preview .arrow::after { content: ""; position: absolute; right: -1px; top: -3px; width: 5px; height: 5px; border-top: 1px solid var(--ink-3); border-right: 1px solid var(--ink-3); transform: rotate(45deg); }
.name-preview mark { background: var(--accent); color: var(--ink); border-radius: 2px; padding: 0 3px; }

.panel-foot { margin: 10px 0 0; font-size: 11px; color: var(--panel-mute); }

/* ---------- drop zone ---------- */
.drop {
  border: 1.5px dashed var(--ink-3); border-radius: var(--radius);
  background: #f7fbfd; cursor: pointer;
  padding: 48px 24px; text-align: center;
  transition: border-color .12s, background .12s;
}
.drop:hover, .drop:focus-visible { border-color: var(--ink); }
.drop.over { border-color: var(--sky); border-style: solid; background: var(--sky-soft); }
.drop.compact { padding: 16px 24px; }
.drop.compact .drop-icon, .drop.compact .drop-sub, .drop.compact .drop-safe { display: none; }
.drop.compact .drop-title { font-size: 14px; }
.drop-icon { width: 64px; height: 36px; margin: 0 auto 16px; position: relative; }
.drop-icon::before, .drop-icon::after { content: ""; position: absolute; left: 0; height: 12px; border-radius: 2px; }
.drop-icon::before { top: 0; width: 100%; background: var(--before); }
.drop-icon::after { top: 22px; width: 22%; background: var(--sky); }
.drop-title { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.drop-sub { margin: 6px 0 0; font-size: 12px; color: var(--ink-3); }
.drop-safe {
  display: inline-flex; align-items: center; gap: 7px; margin: 16px 0 0;
  font-size: 11.5px; font-weight: 600; letter-spacing: .04em; color: var(--ink);
  padding: 4px 11px 4px 9px; background: var(--accent-soft); border: 1px solid #f0d97a; border-radius: 999px;
}
.drop-safe::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--sky); }

/* ---------- results ---------- */
.results-head { display: flex; justify-content: space-between; align-items: center; margin: 24px 0 10px; }
.results-head h2 { font-size: 11px; letter-spacing: .16em; color: var(--ink-3); text-transform: uppercase; }
.results-actions { display: flex; gap: 4px; }

.results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) auto;
  gap: 16px; align-items: center;
  background: var(--card); border-radius: var(--radius);
  padding: 12px 16px 12px 12px;
  border: 1px solid var(--line); border-left: 4px solid var(--sky-soft);
}
.row.error { border-left-color: var(--danger); }
.thumb {
  width: 76px; height: 76px; border-radius: 2px; overflow: hidden;
  background: repeating-conic-gradient(#e3e6e3 0 25%, #fff 0 50%) 0 0 / 12px 12px;
  display: grid; place-items: center; cursor: zoom-in; border: 0; padding: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:disabled { cursor: default; }
.thumb .ph { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--sky); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.row-main { min-width: 0; }
.row-name { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.row-name strong { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-name .rename {
  border: 0; background: none; padding: 1px 6px; margin-left: -6px; border-radius: 2px;
  font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); white-space: nowrap; cursor: text;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.row-name .rename:hover { background: var(--paper); color: var(--ink); }
.row-name .rename::after { content: "✎"; margin-left: 5px; font-size: 11px; opacity: .6; }
.row-name .rename[disabled] { cursor: default; }
.row-name .rename[disabled]::after { content: none; }
.row-name .rename-input {
  font-family: var(--font-mono); font-size: 12px; padding: 2px 6px; border: 1px solid var(--sky); border-radius: 2px;
  width: min(100%, 320px); background: var(--card);
}
.row-name .ext { font-size: 12px; color: var(--ink-3); }
.row-dims { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.row-dims .arrow { display: inline-block; width: 12px; height: 1px; background: var(--ink-3); vertical-align: middle; margin: 0 6px; position: relative; }
.row-dims .arrow::after { content: ""; position: absolute; right: -1px; top: -3px; width: 5px; height: 5px; border-top: 1px solid var(--ink-3); border-right: 1px solid var(--ink-3); transform: rotate(45deg); }
.row-dims .badge { display: inline-block; font-size: 10.5px; letter-spacing: .06em; padding: 0 6px; border: 1px solid var(--line); border-radius: 2px; color: var(--ink-2); margin-left: 8px; }
.row-note { font-size: 12px; color: var(--warn); margin-top: 2px; }
.row-error { font-size: 12.5px; color: var(--danger); margin-top: 2px; }

/* 重さの目盛り：上が元、下が最適化後 */
.bars { margin-top: 10px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; }
.bar { height: 6px; border-radius: 1px; background: var(--before); position: relative; }
.bar.before { background: repeating-linear-gradient(90deg, var(--before) 0 6px, transparent 6px 8px); }
.bar.after { background: var(--sky); width: 0; transition: width .6s cubic-bezier(.2,.7,.2,1); }
.bar.after.bigger { background: var(--warn); }
.bar-val { font-family: var(--font-num); font-weight: 600; font-size: 15px; line-height: 1; color: var(--ink-3); white-space: nowrap; }
.bar-val.before { text-decoration: line-through; text-decoration-color: var(--sky); text-decoration-thickness: 1.5px; }
.bar-val.after { color: var(--ink); font-weight: 700; font-size: 18px; }

.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.saved { font-family: var(--font-num); font-size: 38px; font-weight: 700; color: var(--sky); line-height: .9; letter-spacing: -.01em; }
.saved.bigger { color: var(--warn); }
.saved.pending { color: var(--ink-3); font-family: var(--font-body); font-size: 12px; font-weight: 500; line-height: 1.4; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--ink);
  background: transparent; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--ink);
  transition: background .12s, color .12s;
  text-decoration: none;
}
.btn:hover { background: var(--ink); color: #fff; }
a.btn { color: var(--ink); }
.btn.ghost { border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--paper-2); color: var(--ink); }
.btn.primary { background: var(--accent); border-color: #e9c235; color: var(--ink); padding: 12px 22px; font-size: 15px; letter-spacing: .02em; }
.btn.primary:hover { background: #ffcf1f; border-color: #e0b820; color: var(--ink); }
.btn.primary:disabled { opacity: .5; cursor: progress; }
.btn.small { padding: 5px 12px; font-size: 12.5px; }

.loader-note { margin: 12px 0 0; font-size: 12.5px; color: var(--danger); }

@media (max-width: 600px) {
  body { padding-bottom: 180px; }
  .row { grid-template-columns: 56px minmax(0, 1fr); gap: 12px; }
  .thumb { width: 56px; height: 56px; }
  .row-side { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; }
}

/* ---------- total footer（計量表示） ---------- */
.total {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 10px clamp(16px, 4vw, 56px);
  background: var(--panel); color: var(--panel-text);
  border-top: 3px solid var(--accent);
  box-shadow: 0 -6px 20px rgba(35,64,79,.08);
}
.total-stats { display: flex; align-items: baseline; gap: 26px; flex-wrap: wrap; }
.total-count { display: flex; align-items: baseline; gap: 4px; }
.total-count .num { font-size: 26px; line-height: 1; color: var(--ink); }
.total-count .lbl, .total-saved .lbl { font-size: 11.5px; color: var(--panel-mute); letter-spacing: .04em; }
.total-size { display: flex; align-items: baseline; }
.total-size .num { font-size: 22px; line-height: 1; color: var(--ink); }
.total-size .num.before { color: var(--panel-mute); text-decoration: line-through; text-decoration-color: var(--sky); }
.total-size .arrow { display: inline-block; width: 14px; height: 1px; background: var(--panel-mute); margin: 0 10px; position: relative; align-self: center; }
.total-size .arrow::after { content: ""; position: absolute; right: -1px; top: -3px; width: 5px; height: 5px; border-top: 1px solid var(--panel-mute); border-right: 1px solid var(--panel-mute); transform: rotate(45deg); }
.total-saved { display: flex; align-items: baseline; gap: 8px; }
.total-saved .big { font-size: 44px; line-height: .9; color: var(--sky); letter-spacing: -.01em; }

/* ---------- compare dialog ---------- */
.compare {
  width: min(96vw, 1100px); max-width: none; border: 0; border-radius: var(--radius); padding: 0;
  background: var(--card); color: var(--ink);
}
.compare::backdrop { background: rgba(35, 64, 79, .6); }
.compare-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.compare-head strong { display: block; font-size: 14px; }
.compare-head .mono { font-size: 12px; color: var(--ink-2); }
.compare-stage {
  position: relative; overflow: hidden; user-select: none; touch-action: none;
  background: repeating-conic-gradient(#e3e6e3 0 25%, #fff 0 50%) 0 0 / 16px 16px;
  max-height: 72vh;
}
.compare-stage img { display: block; width: 100%; height: auto; max-height: 72vh; object-fit: contain; }
.compare-before { position: absolute; inset: 0; width: 50%; overflow: hidden; }
.compare-before img { width: var(--stage-w, 100%); max-width: none; }
.compare-handle { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; background: var(--sky); }
.compare-handle::after {
  content: ""; position: absolute; top: 50%; left: 50%; width: 30px; height: 30px; border-radius: 50%;
  background: var(--sky); transform: translate(-50%, -50%); box-shadow: 0 1px 6px rgba(0,0,0,.3);
}
.compare-tag { position: absolute; top: 10px; font-size: 10.5px; letter-spacing: .1em; padding: 3px 8px; border-radius: 2px; background: var(--ink); color: #fff; }
.compare-tag.left { left: 10px; }
.compare-tag.right { right: 10px; }
.compare-range { width: 100%; margin: 0; display: block; padding: 10px 16px; accent-color: var(--sky); }

@media (prefers-reduced-motion: reduce) {
  .bar.after { transition: none; }
  .drop { transition: none; }
  .thumb .ph { animation-duration: 2s; }
}
