/* てもとフォト: 写真の色を正しく判断できるよう、くすんだ暗いグレーで統一（どの端末でも同じ見た目） */
:root {
  --bg: #121315;
  --stage: #0a0a0b;
  --surface: #1c1d20;
  --surface-2: #26282c;
  --line: #34363b;
  --text: #ececee;
  --muted: #a3a6ad;
  --accent: #f2c14e;
  --accent-ink: #1b1405;
  --select: #6fd0c4;
  --danger: #ff8a7a;
  --radius: 12px;
  --font: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.55; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.vh { position: absolute !important; left: 0; top: 0; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
[hidden] { display: none !important; }

button, .btn {
  min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface-2); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:hover:not(:disabled), .btn:hover { border-color: #55585f; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
button.ghost, .btn.ghost { background: transparent; }
button.small, .btn.small { min-height: 34px; padding: 4px 12px; font-size: .85rem; }
button.big { min-height: 52px; font-size: 1.05rem; padding-inline: 22px; }
button.danger { color: var(--danger); }
button.danger-fill { background: #c2412f; border-color: #c2412f; color: #fff; font-weight: 700; }
button.active { border-color: var(--select); color: var(--select); }
button.icon { width: 40px; padding: 0; font-size: 1.25rem; }
input:not([type=range]):not([type=checkbox]):not([type=color]), textarea {
  width: 100%; min-height: 40px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
}
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: #8b8e95; }
input[type=color] { width: 36px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: none; }

/* ── 写真一覧 ── */
.lib-head { max-width: 1100px; margin: 0 auto; padding: 22px 16px 8px; display: grid; gap: 6px; }
.lib-back { font-size: .85rem; text-decoration: none; color: var(--muted); }
.lib-head h1 { margin: 0; font-size: clamp(1.6rem, 5vw, 2.2rem); display: flex; align-items: center; gap: 10px; letter-spacing: .02em; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: url("icon.svg") center / cover; }
.lib-lead { margin: 0; color: var(--muted); max-width: 60ch; }
.lib-main { max-width: 1100px; margin: 0 auto; padding: 8px 16px 48px; display: grid; gap: 18px; }
.drop {
  display: grid; justify-items: center; gap: 4px; padding: 28px 16px; border: 2px dashed var(--line); border-radius: 18px;
  background: var(--surface); cursor: pointer; text-align: center; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over, .drop:focus-within { border-color: var(--accent); background: #22201a; }
.drop-icon { font-size: 2rem; line-height: 1; color: var(--accent); }
.lib-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lib-bar h2 { margin: 0; font-size: 1.05rem; }
.lib-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.lib-actions:empty { display: none; }
.lib-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.lib-item { display: grid; gap: 6px; min-width: 0; }
.lib-open { position: relative; padding: 0; border-radius: var(--radius); overflow: hidden; aspect-ratio: 1; background: var(--surface); border: 1px solid var(--line); }
.lib-open img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lib-noimg { font-size: 2rem; color: var(--muted); }
.lib-badge { position: absolute; left: 6px; bottom: 6px; padding: 1px 8px; border-radius: 999px; background: rgb(0 0 0 / 65%); font-size: .72rem; }
.lib-meta { display: flex; gap: 6px; align-items: center; min-width: 0; }
.lib-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .88rem; }
.lib-check { width: 18px; height: 18px; accent-color: var(--accent); }
.lib-empty, .privacy { padding: 16px 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.lib-empty h2, .privacy h2 { margin: 0 0 6px; font-size: 1rem; }
.privacy p { margin: 4px 0; color: var(--muted); max-width: 70ch; }
.feature-list { margin: 0; padding-left: 1.2em; display: grid; gap: 4px; columns: 2 260px; }
.loading, .fatal { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 12px; padding: 16px; text-align: center; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 編集画面 ── */
.editor { height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.ed-head {
  display: flex; align-items: center; gap: 8px; padding: calc(6px + env(safe-area-inset-top, 0px)) 10px 6px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.ed-head .back { border: none; background: none; padding-inline: 6px; }
.ed-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: .95rem; }
.ed-tools { display: flex; gap: 6px; align-items: center; }
.menu { position: relative; }
.menu summary { list-style: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-size: 1.2rem; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: 46px; z-index: 30; display: grid; gap: 4px; padding: 8px; min-width: 230px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 40px rgb(0 0 0 / 50%); }
.menu-list button { justify-content: flex-start; border-radius: 8px; }

.stage { position: relative; overflow: hidden; background: var(--stage); display: grid; place-items: center; touch-action: none; user-select: none; -webkit-user-select: none; }
.stage[data-tool="crop"], .stage[data-tool="hide"], .stage[data-tool="draw"] { cursor: crosshair; }
.stage[data-tool="heal"], .stage[data-tool="local"] { cursor: none; }
.view-wrap { position: relative; transform-origin: center; line-height: 0; }
.view { display: block; box-shadow: 0 4px 30px rgb(0 0 0 / 45%); }
.handles { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.handles .shade { fill: rgb(0 0 0 / 55%); }
.handles .crop-box { fill: none; stroke: #fff; }
.handles .thirds { stroke: rgb(255 255 255 / 45%); }
.handles .hd { fill: #fff; stroke: var(--stage); stroke-width: 2; }
.handles .hd-sq { fill: #fff; }
.handles .guide { fill: none; stroke: #fff; stroke-opacity: .85; }
.handles .dashed { stroke-dasharray: 6 6; }
.handles .heal-path { fill: none; stroke: rgb(111 208 196 / 45%); stroke-linecap: round; stroke-linejoin: round; }
.handles .sel-rect { fill: rgb(242 193 78 / 15%); stroke: var(--accent); }
.handles .sel-box { fill: none; stroke: var(--select); stroke-dasharray: 8 6; }
.handles .cursor { fill: none; stroke: #fff; mix-blend-mode: difference; }
.orig-badge { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); padding: 3px 12px; border-radius: 999px; background: rgb(0 0 0 / 70%); font-size: .8rem; }

.dock { display: grid; grid-template-rows: minmax(0, 1fr) auto; background: var(--bg); border-top: 1px solid var(--line); max-height: 46dvh; }
.panel { overflow-y: auto; overscroll-behavior: contain; }
.panel-inner { padding: 12px 14px 14px; display: grid; gap: 12px; max-width: 760px; margin: 0 auto; }
.tabs { display: flex; gap: 2px; overflow-x: auto; padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; min-width: 64px; min-height: 52px; padding: 4px 6px; border: none; border-radius: 10px; background: transparent; display: grid; justify-items: center; gap: 0; font-size: .72rem; color: var(--muted); }
.tab-icon { font-size: 1.15rem; line-height: 1.3; }
.tabs button[aria-selected="true"] { color: var(--accent); background: var(--surface); }

@media (min-width: 900px) {
  .editor { grid-template-columns: minmax(0, 1fr) 380px; grid-template-rows: auto minmax(0, 1fr); }
  .ed-head { grid-column: 1 / -1; }
  .dock { max-height: none; border-top: none; border-left: 1px solid var(--line); grid-template-rows: auto minmax(0, 1fr); }
  .tabs { order: -1; flex-wrap: wrap; border-top: none; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
  .tabs button { min-width: 0; flex: 1 0 22%; white-space: nowrap; font-size: .68rem; }
}

/* スライダー */
.sl { display: grid; gap: 2px; }
.sl-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: .86rem; }
.sl-head label { cursor: pointer; }
.sl-val { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 3.5em; text-align: right; }
.sl-val.changed { color: var(--accent); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: var(--line); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--line); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -8px; border-radius: 50%; background: #f4f4f5; border: 2px solid var(--stage); box-shadow: 0 1px 4px rgb(0 0 0 / 60%); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #f4f4f5; border: 2px solid var(--stage); }
input[type=range].track-hue::-webkit-slider-runnable-track { height: 8px; background: linear-gradient(90deg, #f33, #fd3, #3f6, #3df, #36f, #d3f, #f33); }
input[type=range].track-hue::-moz-range-track { height: 8px; background: linear-gradient(90deg, #f33, #fd3, #3f6, #3df, #36f, #d3f, #f33); }
input[type=range].track-hue::-webkit-slider-thumb { margin-top: -6px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chips button { min-height: 34px; padding: 4px 12px; font-size: .85rem; }
.chips button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.chips.bands button { width: 40px; padding: 0; }
.dot { width: 18px; height: 18px; border-radius: 50%; display: inline-block; }
.chips.bands button[aria-pressed="true"] { background: var(--surface-2); border: 2px solid var(--text); color: var(--text); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { margin: 0; font-size: .84rem; color: var(--muted); }
.sub-head { display: grid; gap: 0; margin: 4px 0 -4px; }
.sub-head b { font-size: .9rem; }
.histo { width: 100%; height: 64px; display: block; border-radius: 8px; background: var(--surface); }
.field { display: grid; gap: 4px; }
.field label { font-size: .86rem; }
.local-opts { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.tg { display: inline-flex; gap: 6px; align-items: center; font-size: .88rem; cursor: pointer; min-height: 34px; }
.tg input { width: 18px; height: 18px; accent-color: var(--accent); }
.color-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cp-label { font-size: .86rem; width: 100%; }
.swatch { width: 28px; height: 28px; min-height: 0; padding: 0; border-radius: 50%; border: 2px solid var(--line); }
.swatch[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--bg) inset; }

.looks { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x proximity; }
.look { flex: none; display: grid; gap: 4px; justify-items: center; padding: 4px; min-height: 0; border-radius: 10px; border: 2px solid transparent; background: none; scroll-snap-align: start; font-size: .72rem; width: 92px; }
.look canvas { width: 80px; height: 80px; border-radius: 8px; display: block; background: var(--surface); }
.look span { max-width: 84px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.look[aria-pressed="true"] { border-color: var(--accent); }
.presets { display: grid; gap: 8px; }
.preset { display: inline-flex; }
.preset > button:first-child { border-radius: 999px 0 0 999px; }
.preset .x { border-radius: 0 999px 999px 0; border-left: none; width: 32px; padding: 0; }
.preset-save { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.preset-save input { flex: 1 1 160px; width: auto; }

.curve-box { position: relative; width: min(100%, 300px, 34dvh); aspect-ratio: 1; margin: 0 auto; }
.curve-box .curve-bg { border-radius: 6px; background: var(--surface); position: absolute; inset: 3%; width: 94%; height: 94%; opacity: .5; }
.curve { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.curve .grid { stroke: var(--line); stroke-width: .004; }
.curve .diag { stroke: #4a4d53; stroke-width: .004; stroke-dasharray: .02 .02; }
.curve .line { fill: none; stroke-width: .012; }
.curve .pt { fill: var(--bg); stroke: #fff; stroke-width: .008; }
.grade-zone { display: grid; gap: 4px; padding: 10px 12px; border-radius: 10px; background: var(--surface); }

.stickers { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; }
.stickers button { min-height: 44px; padding: 0; font-size: 1.5rem; border-radius: 10px; background: var(--surface); }

.info { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; font-size: .88rem; }
.info dt { color: var(--muted); }
.info dd { margin: 0; overflow-wrap: anywhere; }
.gps-warn { display: grid; gap: 4px; padding: 10px 12px; border-radius: 10px; background: #3a2a16; border: 1px solid #6b4a1c; font-size: .86rem; }
.ok-note { margin: 0; font-size: .84rem; color: #9ee6c1; }
.keys ul { margin: 6px 0 0; padding-left: 1.1em; font-size: .85rem; display: grid; gap: 2px; }
kbd { font-family: ui-monospace, monospace; font-size: .8rem; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); background: var(--surface-2); }

.dlg { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); padding: 18px; width: min(92vw, 460px); display: grid; gap: 12px; }
.dlg[open] { display: grid; }
.dlg::backdrop { background: rgb(0 0 0 / 60%); }
.dlg h2 { margin: 0; font-size: 1.1rem; }
.dlg p { margin: 0; }
.dlg-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* トースト（shared/lib.js の toast を使う） */
.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); display: grid; justify-items: center; gap: 6px; z-index: 100; pointer-events: none; padding: 0 16px; }
.toast { background: #f4f4f5; color: #121315; padding: 9px 16px; border-radius: 999px; font-size: .88rem; box-shadow: 0 6px 24px rgb(0 0 0 / 45%); max-width: 100%; }
.nojs { padding: 16px; }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

@media (max-width: 420px) { .ed-title { display: none; } .ed-head { justify-content: space-between; } }
/* 長押し（比較ボタンなど）で iPhone の選択メニューが出ないように */
.ed-head button, .tabs button, .stage { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.lib-badge.raw { left: auto; right: 6px; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
/* グリッド */
.grid-layouts { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.grid-layout { flex: none; display: grid; gap: 4px; justify-items: center; padding: 6px; min-height: 0; border-radius: 10px; border: 2px solid transparent; background: none; font-size: .72rem; width: 86px; }
.grid-layout canvas { width: 56px; height: 56px; border-radius: 6px; }
.grid-layout span { max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid-layout[aria-pressed="true"] { border-color: var(--accent); }
.stage[data-tool="grid"] { cursor: grab; }
