/* `hidden` must win over the display rules below (an invisible overlay would block every click). */
[hidden] { display: none !important; }
:root {
  --bg: #f6f5fb; --card: #fff; --text: #22212b; --muted: #6b6878; --line: #e3e0ee;
  --primary: #5b4bd1; --on-primary: #fff; --secondary: #ece8ff; --danger: #c43d5b; --warn: #b26a00;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #16161d; --card: #1f1f28; --text: #ece9f6; --muted: #a29fb3; --line: #33323f;
    --primary: #b9a8ff; --on-primary: #241a5c; --secondary: #2f2a52; --danger: #ff8aa4; --warn: #ffc266; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.6 system-ui, "Hiragino Sans", "Noto Sans JP", sans-serif; }
.top { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.top h1 { font-size: 18px; margin: 0; }
.top h1 span { color: var(--muted); font-weight: 500; }
.top-actions { display: flex; flex-wrap: wrap; gap: 6px; }
main { max-width: 900px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h2 { font-size: 16px; margin: 0 0 10px; }
.card h2 small { color: var(--muted); font-weight: 500; font-size: 13px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
textarea { resize: vertical; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-bottom: 10px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.options { margin-top: 8px; gap: 14px; }
button, .button { font: inherit; font-size: 14px; border: 1px solid transparent; border-radius: 999px; padding: 8px 16px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; flex-direction: row; color: var(--text); }
.primary { background: var(--primary); color: var(--on-primary); }
.secondary { background: var(--secondary); color: var(--text); }
.ghost { background: transparent; border-color: var(--line); }
.danger { color: var(--danger); background: transparent; border-color: var(--line); }
.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0; }
.footer { margin: 8px 4px 40px; }
.msg { padding: 8px 12px; border-radius: 10px; background: var(--secondary); font-size: 13px; }
.msg.error { color: var(--danger); }

.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 16px; text-align: center; outline: none; }
.dropzone .row { justify-content: center; }
.dropzone.over, .dropzone:focus { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 7%, transparent); }
.dropzone p { margin: 6px 0; }

.checker { background-color: #fff; background-image:
  linear-gradient(45deg, #ddd 25%, transparent 25%), linear-gradient(-45deg, #ddd 25%, transparent 25%),
  linear-gradient(45deg, transparent 75%, #ddd 75%), linear-gradient(-45deg, transparent 75%, #ddd 75%);
  background-size: 14px 14px; background-position: 0 0, 0 7px, 7px -7px, -7px 0; }
.images { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-top: 12px; }
.img-tile { position: relative; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); aspect-ratio: 1; }
.img-tile img { width: 100%; height: 100%; object-fit: contain; display: block; }
.img-tile .bar { position: absolute; inset: auto 0 0 0; display: flex; justify-content: space-between; align-items: center; padding: 3px 4px;
  background: rgba(0,0,0,.55); color: #fff; font-size: 11px; }
.img-tile .bar button { color: #fff; padding: 1px 7px; font-size: 11px; line-height: 1.5; white-space: nowrap; background: transparent; border-color: rgba(255,255,255,.4); }

.entry { display: grid; grid-template-columns: 96px 1fr; gap: 12px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.entry .thumb { width: 96px; height: 96px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); cursor: pointer; }
.entry .thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.entry .body { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.entry .head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.entry .chance { font-weight: 700; font-size: 18px; }
.entry .rare-badge { color: #e0a000; font-weight: 700; font-size: 12px; }
.entry textarea { width: 100%; }
.entry .count { font-size: 12px; color: var(--muted); }
.entry .count.warn { color: var(--warn); }
.entry .controls { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.entry .controls label { flex-direction: row; align-items: center; gap: 6px; }
.entry .controls input[type=range] { width: 120px; padding: 0; }
.days, .slots { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 3px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; font-size: 12px; color: var(--text); cursor: pointer; user-select: none; }
.chip input { display: none; }
.chip:has(input:checked) { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.entry .actions { display: flex; gap: 6px; flex-wrap: wrap; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details.more > div { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; margin-top: 6px; }
.picker button { padding: 0; border-radius: 8px; overflow: hidden; aspect-ratio: 1; border: 2px solid var(--line); }
.picker button.sel { border-color: var(--primary); }
.picker img { width: 100%; height: 100%; object-fit: contain; }
@media (max-width: 560px) { .entry { grid-template-columns: 72px 1fr; } .entry .thumb { width: 72px; height: 72px; } }

.preview { position: fixed; inset: 0; z-index: 20; background: rgba(10,10,20,.55); display: flex; align-items: center; justify-content: center; }
.phone { width: min(360px, 92vw); height: min(720px, 86vh); border-radius: 32px; background: linear-gradient(160deg, #7f8fd6, #e6a1c7); position: relative; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.pv-stage { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; }
.pv-hint { position: absolute; bottom: 8px; width: 100%; text-align: center; color: rgba(255,255,255,.85); }
.pv-sticker { max-width: 70%; max-height: 60%; object-fit: contain; filter: drop-shadow(0 6px 10px rgba(0,0,0,.25)); }
.bubble { background: #fff; color: #222; border: 2px solid #222; border-radius: 18px; padding: 8px 14px; font-weight: 700; max-width: 80%; text-align: center;
  margin-bottom: 12px; position: relative; white-space: pre-line; }
.bubble .clock { font-size: 1.6em; line-height: 1.2; }
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -10px; transform: translateX(-50%); border: 9px solid transparent; border-top-color: #222; border-bottom: 0; }
.rare { color: #ffd54f; font-weight: 900; font-size: 20px; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
@keyframes pop { 0% { transform: scale(0); } 60% { transform: scale(1.15); } 80% { transform: scale(.95); } 100% { transform: scale(1); } }
@keyframes fade { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: scale(1); } }
@keyframes drop { 0% { transform: translateY(-120vh); } 60% { transform: translateY(20px); } 80% { transform: translateY(-8px); } 100% { transform: translateY(0); } }
@keyframes spin { from { transform: rotate(-360deg) scale(0); } to { transform: rotate(0) scale(1); } }
@keyframes slide { 0% { transform: translateX(-120vw); } 70% { transform: translateX(16px); } 100% { transform: translateX(0); } }
@keyframes float { from { transform: translateY(-5px); } to { transform: translateY(5px); } }
.fx-POP, .fx-CONFETTI { animation: pop .5s ease-out both; }
.fx-FADE { animation: fade .45s ease-out both; }
.fx-DROP { animation: drop .7s ease-out both; }
.fx-SPIN { animation: spin .55s ease-out both; }
.fx-SLIDE { animation: slide .55s ease-out both; }
.confetti { position: absolute; width: 10px; height: 6px; top: 50%; left: 50%; animation: burst 1.6s ease-out forwards; }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30; background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; }

/* ---------------------------------------------------------------- layout
   Phones / narrow windows: one column (set, images, combinations, 出し方), preview via 試す.
   PC (>= 1100px): three columns -- left settings, centre combinations, right live preview. */
.layout { display: flex; flex-direction: column; }
.col-left, .col-main { display: contents; }
#sec-set { order: 1; } #sec-images { order: 2; } #sec-entries { order: 3; } #sec-settings { order: 4; }
.col-preview { display: none; }
.mt { margin-top: 16px !important; }

@media (min-width: 1100px) {
  main { max-width: 1680px; padding: 16px 20px; }
  .layout { display: grid; grid-template-columns: minmax(320px, 380px) minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
  .col-left, .col-main { display: block; }
  .col-preview { display: block; position: sticky; top: 64px; }
  .col-preview .card { margin-bottom: 0; }
  #btn-try { display: none; }
  /* Narrow left column: stack the form grids. */
  .col-left .grid2 { grid-template-columns: 1fr 1fr; }
  .col-left .images { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  /* Centre: combinations two-up when there's room. */
  #entries { display: grid; grid-template-columns: repeat(auto-fill, minmax(460px, 1fr)); gap: 10px; }
  #entries .entry { margin-bottom: 0; }
  #entries > .hint { grid-column: 1 / -1; }
  .entry.focused { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 30%, transparent); }
}

.phone.live { width: 100%; height: 520px; border-radius: 26px; box-shadow: none; }
.phone.live .pv-sticker { max-height: 62%; }
.live-actions { margin: 10px 0 4px; }
.now-list { display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow: auto; }
.now-row { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center; font-size: 12.5px; cursor: pointer; border-radius: 8px; padding: 2px 4px; }
.now-row:hover { background: var(--secondary); }
.now-row img { width: 34px; height: 34px; object-fit: contain; border-radius: 6px; }
.now-row .bar { height: 6px; border-radius: 3px; background: var(--primary); margin-top: 3px; }
.now-row .pct { font-weight: 700; }

/* ---------------------------------------------------------------- 対象を切り抜く (js/cutout.js) */
.cut { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; }
.cut-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.cut-area { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 12px;
  background-color: #fff; background-image: linear-gradient(45deg, #e6e6e6 25%, transparent 25%), linear-gradient(-45deg, #e6e6e6 25%, transparent 25%),
  linear-gradient(45deg, transparent 75%, #e6e6e6 75%), linear-gradient(-45deg, transparent 75%, #e6e6e6 75%);
  background-size: 18px 18px; background-position: 0 0, 0 9px, 9px -9px, -9px 0; }
.cut-area canvas { max-width: 100%; max-height: 100%; touch-action: none; cursor: crosshair; box-shadow: 0 2px 12px rgba(0,0,0,.2); }
.cut-cursor { position: absolute; border: 2px solid #fff; outline: 1px solid #000; border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; }
.cut-tools { padding: 10px 16px 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.cut-tools .row { gap: 8px 12px; }
.cut-tools .inline { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.cut-tools input[type=range] { width: 130px; padding: 0; }
.cut-hint { margin: 0; }
.cut-area { overflow: hidden; }
.cut-area.result canvas { cursor: grab; box-shadow: none; }
.cut-zoom { position: absolute; right: 12px; bottom: 12px; display: flex; align-items: center; gap: 4px; background: var(--card);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.cut-zoom span { min-width: 44px; text-align: center; font-size: 12px; }
.viewer { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; }
.viewer-area img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: grab; user-select: none; touch-action: none; }
.viewer-area.plain { background-image: none !important; }
.img-tile img { cursor: zoom-in; }
