/* ===== photogrid.css ===== */
.gr-grid { display: grid; gap: 16px; }
@media (min-width: 860px) { .gr-grid { grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); align-items: start; gap: 24px; } }
.gr-preview { position: sticky; top: calc(var(--h-head) + env(safe-area-inset-top, 0px) + 8px); z-index: 5; background: var(--bg); padding-bottom: 4px; }
@media (min-width: 860px) { .gr-preview { top: calc(var(--h-head) + env(safe-area-inset-top, 0px) + 20px); } }
.gr-stage {
  min-height: 160px; display: grid; place-items: center; padding: 12px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 16px; background-color: #8a949b;
  background-image: linear-gradient(45deg, #7d878e 25%, transparent 25%, transparent 75%, #7d878e 75%), linear-gradient(45deg, #7d878e 25%, transparent 25%, transparent 75%, #7d878e 75%);
  background-size: 16px 16px; background-position: 0 0, 8px 8px;
}
.gr-stage canvas { display: block; max-width: 100%; }
.gr-empty { margin: 0; padding: 12px; text-align: center; font-size: 14px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.gr-meta { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 8px 4px 0; font-size: 13px; color: var(--fg2); min-height: 20px; }
.gr-meta p { margin: 0; }
@media (max-width: 859px) {
  .gr-stage { max-height: 34vh; max-height: 34dvh; }
  .gr-stage canvas { max-height: calc(34dvh - 26px); max-height: calc(34vh - 26px); width: auto; height: auto; }
}

.gr-thumbs { display: flex; gap: 8px; overflow-x: auto; padding: 8px 2px 2px; }
.gr-thumbs:empty { display: none; }
.gr-th { position: relative; flex: none; width: 56px; height: 56px; border: 2px solid var(--line); border-radius: 10px; overflow: hidden; padding: 0; background: var(--card); cursor: pointer; }
.gr-th canvas { display: block; width: 100%; height: 100%; }
.gr-th[aria-selected="true"] { border-color: var(--accent); }
.gr-th .x { position: absolute; top: 0; inset-inline-start: 0; width: 22px; height: 22px; border-radius: 0 0 10px 0; background: rgba(0,0,0,.65); color: #fff; font-size: 14px; line-height: 22px; text-align: center; }

.gr-controls .field:last-child { margin-bottom: 0; }
.gr-controls fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 12px 12px 4px; margin: 0 0 16px; min-width: 0; }
.gr-controls legend { padding: 0 8px; font-size: 14px; font-weight: 600; color: var(--accent); }
.gr-controls select, .gr-controls input[type="text"] { width: 100%; min-height: 44px; background: var(--card); color: var(--fg); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font: inherit; font-size: 16px; }
.gr-controls .lbl { font-size: 14px; font-weight: 500; color: var(--fg2); }
.gr-row { display: grid; gap: 0 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 420px) { .gr-row { grid-template-columns: 1fr 1fr; } }
.gr-hint { margin: 6px 2px 10px; font-size: 12px; color: var(--fg3); line-height: 1.8; }
.gr-drop, .gr-logo-btn { display: grid; place-items: center; gap: 4px; text-align: center; cursor: pointer; min-height: 96px; padding: 16px; border: 2px dashed var(--line); border-radius: 14px; color: var(--fg2); font-size: 14px; }
.gr-logo-btn { min-height: 56px; padding: 8px 12px; }
.gr-drop strong { color: var(--fg); font-size: 15px; } .gr-drop small { color: var(--fg3); font-size: 12px; }
.gr-drop.over, .gr-drop:focus-visible, .gr-logo-btn:focus-visible { border-color: var(--accent); outline: none; background: var(--badge-bg); }
.gr-file { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg label { flex: 1 1 0; min-width: 72px; text-align: center; cursor: pointer; min-height: 44px; display: grid; place-items: center; padding: 6px 12px; border: 1px solid var(--line); border-radius: 9999px; font-size: 14px; font-weight: 500; color: var(--fg2); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--badge-bg); color: var(--accent); border-color: var(--accent); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 15px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.gr-pos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; direction: ltr; }
.gr-pos label { cursor: pointer; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; display: grid; place-items: center; }
.gr-pos label::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--fg3); }
.gr-pos input { position: absolute; opacity: 0; pointer-events: none; }
.gr-pos label:has(input:checked) { background: var(--badge-bg); border-color: var(--accent); }
.gr-pos label:has(input:checked)::after { background: var(--accent); width: 14px; height: 14px; }
.gr-pos label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.gr-tile { margin-bottom: 12px; }

.gr-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.gr-actions .btn { flex: 1 1 140px; min-height: 44px; }
.gr-actions .btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.gr-result { margin-top: 12px; text-align: center; }
.gr-result .btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; }
.gr-result p { margin: 8px 0 0; font-size: 13px; color: var(--fg2); }
.gr-stage canvas { background: #fff; }
.gr-result { margin-top: 12px; text-align: center; }
.gr-result img { max-width: 100%; border: 1px solid var(--line); border-radius: 12px; }
.gr-result p { margin: 8px 0 0; font-size: 13px; color: var(--fg2); }
.gr-opts[hidden] { display: none; }
.gr-controls .seg { margin-bottom: 12px; }
[hidden] { display: none !important; }
