:root {
  color-scheme: dark;
  --bg: #0d1130;
  --bg-glow: #243070;
  --panel: #151a40;
  --field: #1c2250;
  --line: #2d3573;
  --text: #eef0ff;
  --muted: #a3a9d8;
  --accent: #a8c6ff;
  --accent-2: #86a8ff;
  --accent-ink: #0d1130;
  --radius: 14px;
  --holo: linear-gradient(110deg, #cfe0ff, #f6d2ff 40%, #fff1c6 60%, #c6e9ff);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1100px 520px at 12% -8%, var(--bg-glow) 0%, transparent 62%),
    radial-gradient(900px 480px at 100% 10%, #2a2366 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  padding-inline: max(16px, env(safe-area-inset-left, 0px));
  padding-block: calc(env(safe-area-inset-top, 0px) + 20px) calc(env(safe-area-inset-bottom, 0px) + 48px);
  min-height: 100vh;
}
img { max-width: 100%; }
.wrap { max-width: 1380px; margin: 0 auto; display: grid; gap: 22px; }

.top { display: grid; gap: 6px; }
.brand { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand img { height: 30px; width: auto; }
.script {
  font-family: "Great Vibes", cursive;
  font-size: 30px;
  line-height: 1;
  background: var(--holo);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.lead { margin: 0; color: var(--muted); font-size: 14px; max-width: 66ch; }

.studio { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
.stage { display: grid; gap: 12px; position: sticky; top: calc(env(safe-area-inset-top, 0px) + 16px); perspective: 1800px; }

.frame {
  transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  transition: transform .35s ease-out;
  transform-style: preserve-3d;
}
.flip {
  position: relative;
  width: min(100%, calc((100vh - 230px) * var(--arn, 1.6)));
  margin-inline: auto;
  transform-style: preserve-3d;
  transition: transform .9s cubic-bezier(.2, .8, .2, 1.15);
  aspect-ratio: var(--ar, 1.6);
}
.flip.flipped { transform: rotateY(180deg); }
.face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .65), 0 0 0 1px rgba(255, 255, 255, .06);
  background: #1a2156;
}
.face.back { transform: rotateY(180deg); }
.face canvas { display: block; width: 100%; height: 100%; }
#card { touch-action: none; }
#card.grab { cursor: grab; }
#card.grabbing { cursor: grabbing; }
#card.resize { cursor: nwse-resize; }
.foil {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 22%, rgba(255, 140, 210, .55) 36%, rgba(140, 230, 255, .55) 48%, rgba(255, 245, 160, .5) 58%, rgba(190, 150, 255, .5) 66%, transparent 80%);
  background-size: 300% 300%;
  background-position: var(--mx, 50%) var(--my, 50%);
  mix-blend-mode: color-dodge;
  opacity: 0;
  transition: opacity .35s;
}
.frame.live .foil { opacity: .2; }

.bar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; }
.bar > div { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.publish { display: grid; gap: 6px; justify-items: start; padding-top: 6px; }

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, transform .15s, box-shadow .2s;
}
.btn:hover { border-color: var(--accent-2); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--holo); border-color: transparent; color: var(--accent-ink); }
.btn.primary:hover { box-shadow: 0 0 0 4px rgba(168, 198, 255, .25); }
.btn.big { font-size: 16px; padding: 14px 26px; }
.btn[disabled] { opacity: .55; cursor: progress; }
.btn.small { padding: 7px 12px; font-size: 13px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; display: grid; gap: 24px; }
.group { display: grid; gap: 10px; }
.group > h2 { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .14em; color: var(--muted); }
.field { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.field input[type="text"], .field textarea {
  width: 100%;
  background: var(--field);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  font-size: 15px;
}
.field textarea { resize: vertical; min-height: 64px; line-height: 1.55; }
.field input::placeholder, .field textarea::placeholder { color: #6f76a8; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.check { display: inline-flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--accent-2); width: 16px; height: 16px; }

.fonts { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.font-chip {
  appearance: none; display: grid; gap: 2px; justify-items: center;
  padding: 10px 6px 8px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--field); color: var(--text); cursor: pointer; font: inherit;
}
.font-chip .sample { font-size: 26px; line-height: 1.2; white-space: nowrap; }
.font-chip .name { font-size: 11px; color: var(--muted); letter-spacing: .06em; }
.font-chip[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: #232b66; }

.themes { display: flex; flex-wrap: wrap; gap: 12px; }
.swatch { appearance: none; display: grid; gap: 4px; justify-items: center; background: none; border: 0; padding: 0; color: var(--muted); font: inherit; font-size: 11px; cursor: pointer; }
.swatch i { display: block; width: 44px; height: 44px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(255, 255, 255, .15) inset; }
.swatch[aria-pressed="true"] { color: var(--text); }
.swatch[aria-pressed="true"] i { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }

.toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.toggle { position: relative; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.toggle span { display: inline-block; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--field); font-size: 13px; color: var(--muted); }
.toggle input:checked + span { background: #2a3478; border-color: var(--accent-2); color: var(--text); }
.toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.range { display: grid; grid-template-columns: 76px 1fr 48px; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); border-radius: 8px; transition: background .2s; }
.range input { width: 100%; accent-color: var(--accent-2); }
.range output { text-align: right; font-variant-numeric: tabular-nums; }
.range.active { color: var(--text); background: rgba(168, 198, 255, .08); box-shadow: 0 0 0 6px rgba(168, 198, 255, .08); }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.note { margin: 0; font-size: 12px; color: var(--muted); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; background: var(--field); }
.seg button { appearance: none; border: 0; background: none; color: var(--muted); font: inherit; font-size: 13px; font-weight: 700; padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.seg small { font-weight: 500; opacity: .75; margin-left: 4px; font-variant-numeric: tabular-nums; }

dialog {
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 0;
  background: linear-gradient(160deg, #1b2260, #121742);
  color: var(--text);
  width: min(560px, calc(100vw - 32px));
  box-shadow: 0 40px 100px -20px rgba(0, 0, 0, .7);
}
dialog::backdrop { background: rgba(5, 8, 30, .6); backdrop-filter: blur(6px); }
.dlg { display: grid; gap: 14px; padding: 26px; }
.dlg h2 { margin: 0; font-size: 20px; }
.dlg-eyebrow { margin: 0; font-size: 28px; }
.dlg-lead { margin: 0; color: var(--muted); font-size: 14px; }
.dlg-body { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; }
.qr { background: #fff; padding: 10px; border-radius: 12px; width: 150px; height: 150px; }
.qr img, .qr canvas { width: 130px !important; height: 130px !important; display: block; }
.dlg-url { display: grid; gap: 10px; min-width: 0; }
@media (max-width: 520px) { .dlg-body { grid-template-columns: 1fr; justify-items: center; } .dlg-url { width: 100%; } }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  transform: translate(-50%, 20px);
  background: #eef0ff; color: #141a44; font-weight: 700; font-size: 14px;
  padding: 10px 18px; border-radius: 999px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100% - 32px); text-align: center; z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 920px) {
  .studio { grid-template-columns: 1fr; }
  .stage { position: static; }
}
@media (prefers-reduced-motion: reduce) {
  .btn, #toast, .frame, .foil, .flip { transition: none; }
  .frame { transform: none; }
}
