:root {
  --fox: #d86a3a;
  --fox-deep: #a63c22;
  --cream: #fff4e4;
  --chest: #ffe8c8;
  --teal: #2a6d73;
  --night: #16343c;
  --gold: #f0c36a;
  --ink: #1a120e;
  --mute: #3d2a22;
  --pad: #1c1210;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font: 16px/1.55 "Hiragino Maru Gothic ProN", "PingFang SC", "Noto Sans SC", sans-serif;
  background:
    linear-gradient(180deg, rgba(255, 248, 236, 0.88) 0%, rgba(255, 244, 228, 0.96) 36%, #fff4e4 70%),
    url("/den.jpg") center top / cover no-repeat fixed,
    #fff4e4;
}
.glow {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 20% 0%, rgba(240, 195, 106, 0.25), transparent 42%);
  z-index: 0;
}
.den-loop {
  position: fixed;
  right: -4%;
  bottom: -6%;
  width: min(42vw, 420px);
  border-radius: 28px;
  opacity: 0.28;
  pointer-events: none;
  z-index: 0;
  mask-image: linear-gradient(180deg, transparent, #000 20%, #000 80%, transparent);
}
.floaters { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.sticker {
  position: absolute;
  width: 88px;
  border-radius: 22px;
  border: 3px solid #fff;
  box-shadow: 0 8px 16px rgba(42, 28, 20, 0.18);
  opacity: 0.88;
  object-fit: cover;
  aspect-ratio: 1;
}
.s1 { top: 12%; left: 2%; transform: rotate(-8deg); }
.s2 { top: 38%; left: 1%; width: 72px; transform: rotate(7deg); }
.s3 { top: 64%; left: 3%; transform: rotate(-4deg); }
.s4 { top: 18%; right: 3%; transform: rotate(10deg); }
.s5 { top: 48%; right: 2%; width: 76px; transform: rotate(-9deg); }
.s6 { bottom: 8%; right: 8%; width: 80px; transform: rotate(6deg); }
@media (max-width: 900px) {
  .floaters, .den-loop { display: none; }
}
.wrap { position: relative; z-index: 1; max-width: 760px; margin: 0 auto; padding: 28px 18px 88px; }
.hero {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 10px;
}
.mascot {
  width: 88px; height: 88px; object-fit: cover;
  border-radius: 50% 50% 46% 54%;
  border: 4px solid #fff;
  box-shadow: 0 8px 0 #e8c9a0, 0 0 0 6px rgba(216, 106, 58, 0.25);
  background: var(--chest);
}
.hero-text {
  background: rgba(255, 252, 246, 0.92);
  border-radius: 18px;
  padding: 10px 14px;
}
.eyebrow { margin: 0; color: #1b5c62; font-size: 13px; letter-spacing: 0.08em; font-weight: 700; }
h1 { margin: 2px 0 4px; font-size: 28px; color: var(--fox-deep); letter-spacing: 0.02em; }
.tag, .empty { color: var(--mute); margin: 0; }
.hint {
  color: var(--ink);
  background: rgba(255, 252, 246, 0.95);
  border: 2px solid #f0d2a8;
  border-radius: 16px;
  padding: 10px 14px;
  margin: 0 0 16px;
  font-weight: 600;
}
.wallets {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #fff;
  color: var(--fox-deep);
  border-radius: 18px;
  padding: 10px 14px;
  font-weight: 700;
  box-shadow: 0 4px 0 #e8c9a0;
  white-space: nowrap;
  font-size: 14px;
}
.wallets .inf { color: var(--teal); }
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 18px;
  padding: 4px;
  background: #efe4d2;
  border-radius: 14px;
}
.tab {
  position: relative;
  margin: 0;
  text-align: center;
  padding: 10px 12px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  font-weight: 700;
  color: #5a4338;
  cursor: pointer;
}
.tab:has(input:checked),
.tab.on {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(26, 18, 14, 0.12);
}
.tab input,
.ratio input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.tab:has(input:focus-visible),
.ratio:has(input:focus-visible) {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}
.tune { margin: 16px 0 6px; border: 0; padding: 0; background: transparent; }
.tune legend { margin-bottom: 8px; }
.seg {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 4px;
  padding: 4px;
  background: #efe4d2;
  border-radius: 14px;
}
.seg .tab { padding: 8px 10px; }
.seg .tab:has(input:disabled) { opacity: 0.4; cursor: not-allowed; }
.aspect { margin: 16px 0 6px; border: 0; padding: 0; background: transparent; }
.aspect legend { margin-bottom: 10px; }
.ratio-board { display: grid; gap: 14px; }
.ratio-kicker {
  margin: 0 0 8px;
  color: #6b5348;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
}
.ratio-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.ratio-group.solo .ratio-row { grid-template-columns: 1fr; max-width: calc(25% - 6px); }
.ratio-auto-stage { position: relative; }
.ratio-auto-stage .ratio-frame:first-child { opacity: 0.38; }
.ratio-auto-stage .ratio-frame:last-child {
  position: absolute;
  opacity: 0.9;
  border-style: dashed;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.later { margin-top: 16px; }
.shot-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 8px 0 10px;
}
.shot {
  position: relative;
  width: 96px;
  background: #fff;
  border: 1px solid #e4d3bb;
  border-radius: 14px;
  overflow: hidden;
}
.shot img {
  display: block;
  width: 100%;
  height: 96px;
  object-fit: cover;
  background: #f4ead8;
  cursor: zoom-in;
}
.shot-n {
  position: absolute;
  top: 6px;
  left: 6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(26, 18, 14, 0.72);
  color: #fff8ee;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.shot-x {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(26, 18, 14, 0.78);
  color: #fff;
  cursor: pointer;
  font: 14px/1 inherit;
}
.shot-tools {
  display: flex;
  gap: 4px;
  padding: 6px;
}
.shot-tools button {
  flex: 1;
  border: 0;
  background: #fff6ea;
  color: var(--fox-deep);
  border-radius: 8px;
  padding: 4px 0;
  font: 11px/1.2 inherit;
  font-weight: 700;
  cursor: pointer;
}
.add-shot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  border: 2px dashed #efc49a;
  border-radius: 14px;
  background: #fffaf2;
  color: var(--fox-deep);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.add-shot:disabled, .add-shot.hidden { display: none; }
.voice-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 4px;
}
.voice-chip {
  border: 1px solid #e4d3bb;
  background: #fff;
  color: #2a1c14;
  border-radius: 999px;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.voice-chip.on {
  border-color: var(--fox);
  background: #fff6ea;
  box-shadow: 0 0 0 2px rgba(216, 106, 58, 0.16);
}
.voice-chip:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.voice-chip small {
  margin-left: 4px;
  color: var(--fox-deep);
  font-variant-numeric: tabular-nums;
}
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(16, 10, 8, 0.78);
  display: grid;
  place-items: center;
  padding: 24px;
  cursor: zoom-out;
}
.lightbox.hidden { display: none; }
.lightbox img {
  max-width: min(92vw, 920px);
  max-height: 82vh;
  object-fit: contain;
  border-radius: 12px;
  background: #1a120e;
}
.lightbox p {
  position: absolute;
  bottom: 18px;
  margin: 0;
  color: #fff8ee;
  font-weight: 600;
}
.ratio {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 12px 8px 10px;
  border: 1px solid #e4d3bb;
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  color: #2a1c14;
}
.ratio-stage {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
}
.ratio-frame {
  display: block;
  width: calc(52px * var(--w) / max(var(--w), var(--h)));
  height: calc(52px * var(--h) / max(var(--w), var(--h)));
  border: 1.5px solid rgba(26, 18, 14, 0.22);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 42%),
    #d8c6ab;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.ratio-name {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.ratio:hover { border-color: #c9a57a; }
.ratio:has(input:checked) {
  border-color: var(--fox);
  background: #fff6ea;
  box-shadow: 0 0 0 3px rgba(216, 106, 58, 0.16);
}
.ratio:has(input:checked) .ratio-frame {
  border-color: transparent;
  background:
    linear-gradient(180deg, rgba(255, 244, 214, 0.7), transparent 50%),
    linear-gradient(180deg, #f0c36a, #d86a3a);
}
.sub { margin: 0 0 8px; font-size: 13px; color: #4a342c; font-weight: 500; }
.mode-only.hidden { display: none; }
.panel, .result {
  background: rgba(255, 252, 246, 0.92);
  border: 3px solid #f0d2a8;
  border-radius: 28px;
  padding: 20px;
  box-shadow: 0 10px 0 rgba(166, 60, 34, 0.08);
}
label, legend { display: block; color: var(--fox-deep); font-size: 14px; margin-bottom: 6px; font-weight: 600; }
textarea, input[type="file"] {
  width: 100%;
  background: #fffaf2;
  color: var(--ink);
  border: 2px dashed #efc49a;
  border-radius: 18px;
  padding: 12px 14px;
  font: inherit;
}
textarea:focus { outline: 3px solid rgba(42, 109, 115, 0.25); border-style: solid; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
fieldset { border: 2px solid #f0d2a8; border-radius: 18px; background: #fff7ea; }
.ref-box { margin: 14px 0; }
.ref-label { margin: 0 0 8px; color: var(--fox-deep); font-weight: 700; font-size: 14px; }
.ref-hint { margin: 8px 0 0; color: var(--mute); font-size: 13px; }
.ref-strip { display: flex; flex-wrap: wrap; gap: 8px; }
.ref-pick {
  width: 86px;
  padding: 0 0 6px;
  border: 3px solid #f0d2a8;
  background: #fffaf2;
  border-radius: 18px;
  cursor: pointer;
  font: inherit;
  color: var(--mute);
  box-shadow: 0 3px 0 #e8c9a0;
}
.ref-pick img {
  width: 100%; height: 72px; object-fit: cover;
  border-radius: 14px 14px 8px 8px; display: block;
}
.ref-pick span { display: block; font-size: 12px; margin-top: 4px; }
.ref-pick.on, .frame-pick.on {
  border-color: var(--fox);
  color: var(--fox-deep);
  background: #ffe8d2;
  box-shadow: 0 3px 0 var(--fox-deep);
}
.frame-pick {
  width: 86px;
  padding: 0 0 6px;
  border: 3px solid #f0d2a8;
  background: #fffaf2;
  border-radius: 18px;
  cursor: pointer;
  font: inherit;
  color: var(--mute);
}
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.presets button, #dl {
  background: #fff7ea;
  color: var(--fox-deep);
  border: 2px solid #f0d2a8;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font: inherit;
}
.presets button.on, .presets button:hover { background: #ffe0c2; }
#go {
  width: 100%;
  border: 0;
  border-radius: 999px;
  padding: 14px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  color: #fff8ee;
  background: linear-gradient(180deg, #ee8a4d, #c24b28);
  box-shadow: 0 6px 0 #8d2c16;
}
#go:disabled { opacity: 0.55; box-shadow: none; }
.status { min-height: 1.4em; color: #4a342c; font-weight: 600; }
.status.err { color: #b4331b; }
.hist-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 36px 0 8px;
}
.hist-head h2 { margin: 0; }
.hist-head button {
  background: #fff7ea;
  color: var(--fox-deep);
  border: 2px solid #f0d2a8;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.grid .slot {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 12px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  background: #f4ead8;
  color: #5a4338;
}
.grid figure.wait { cursor: default; }
.grid figure.fail .slot { color: #b4331b; background: #fde8e0; }
.result { margin-top: 18px; }
.result img, .result video { width: 100%; border-radius: 20px; display: block; }
.hidden { display: none; }
h2 { color: var(--fox-deep); font-size: 20px; margin: 36px 0 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.grid figure {
  position: relative;
  margin: 0;
  background: #fffaf2;
  border: 3px solid #f0d2a8;
  border-radius: 20px;
  overflow: hidden;
  cursor: pointer;
}
.grid figure:hover { border-color: var(--fox); }
.grid img, .grid video { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #1a120e; }
.grid figure.vid::after {
  content: "▶";
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(26, 18, 14, 0.72);
  color: #fff8ee;
  font-size: 11px;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.grid figcaption { padding: 8px 10px; font-size: 12px; color: var(--mute); max-height: 4.6em; overflow: hidden; }
@media (max-width: 640px) {
  .hero { grid-template-columns: 72px 1fr; }
  .credit { grid-column: 1 / -1; justify-self: start; }
  .row { grid-template-columns: 1fr; }
  .ratio-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ratio-group.solo .ratio-row { max-width: calc(50% - 4px); }
}
