:root {
  --bg: #fff6e9;
  --card: #ffffff;
  --ink: #2b2140;
  --muted: #7a6d8c;
  --line: #eadcc8;
  --accent: #ff6b5b;
  --accent-2: #6b5bff;
  --soft: #f6ecff;
  --ok: #2fb56f;
  --r: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: Fredoka, ui-rounded, system-ui, -apple-system, sans-serif;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font: inherit; color: inherit; cursor: pointer; }
#video { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; left: 0; top: 0; }

.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 22px; }
.logo { font-size: 28px; }
.chip { background: var(--card); border: 2px solid var(--line); border-radius: 99px; padding: 4px 12px; font-size: 14px; color: var(--muted); }
.chip.ok { color: var(--ok); border-color: #bfe8d1; }
.chip.warn { color: #c27a00; border-color: #f3dcad; }
.top-actions { margin-left: auto; display: flex; gap: 8px; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--line); background: var(--card); font-size: 20px; }

.app { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 340px; gap: 12px; padding: 0 12px 12px; }
@media (max-aspect-ratio: 1/1), (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(260px, 42%); }
}

.stage-area { position: relative; min-height: 0; min-width: 0; display: grid; place-items: center; }
.stage-box { position: relative; border-radius: var(--r); overflow: hidden; box-shadow: 0 10px 30px rgba(80, 50, 20, .18); background: #fff; }
#stage { display: block; width: 100%; height: 100%; touch-action: none; }

.page-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 56px; height: 84px; border: 0; border-radius: 16px;
  background: rgba(43, 33, 64, .35); color: #fff; font-size: 44px; line-height: 1;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.page-btn.prev { left: 10px; } .page-btn.next { right: 10px; }
.page-btn:active { background: rgba(43, 33, 64, .6); }
.page-btn[hidden] { display: none; }

.rec-badge { position: absolute; top: 12px; right: 12px; background: rgba(0, 0, 0, .6); color: #fff; border-radius: 99px; padding: 6px 14px; display: flex; gap: 8px; align-items: center; font-weight: 600; }
.rec-badge .dot { width: 12px; height: 12px; border-radius: 50%; background: #ff3b30; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: 180px; font-weight: 700; color: #fff; text-shadow: 0 6px 30px rgba(0, 0, 0, .45); background: rgba(43, 33, 64, .25); }
.countdown.pop { animation: pop .9s ease-out; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } 30% { opacity: 1; } to { transform: scale(1); } }
.hint { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); background: rgba(255, 255, 255, .92); border-radius: 99px; padding: 6px 16px; font-weight: 500; }

.start { position: absolute; inset: 0; display: grid; place-items: center; background: linear-gradient(135deg, #ffe3c7, #e9dcff); padding: 16px; overflow: auto; }
.start-card { max-width: 520px; text-align: center; }
.start-chars { font-size: 44px; letter-spacing: 6px; }
.start h1 { font-size: clamp(26px, 4vw, 40px); line-height: 1.1; margin: 10px 0; }
.start p { color: #5a4d6c; font-size: 17px; margin: 0 0 18px; }
.start .small { margin-top: 12px; font-size: 14px; min-height: 1em; }
.big-btn { border: 0; background: var(--accent); color: #fff; font-size: 22px; font-weight: 600; padding: 16px 34px; border-radius: 99px; box-shadow: 0 6px 0 #d64a3c; }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #d64a3c; }
.big-btn:disabled { opacity: .6; }
.link-btn { display: block; margin: 14px auto 0; background: none; border: 0; color: var(--accent-2); text-decoration: underline; font-size: 16px; }

.rec-btn {
  position: absolute; right: 18px; bottom: 18px; width: 84px; height: 84px; border-radius: 50%;
  border: 6px solid #fff; background: rgba(255, 255, 255, .35); display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25); z-index: 3;
}
.rec-core { width: 56px; height: 56px; border-radius: 50%; background: #ff3b30; transition: all .2s; }
.rec-btn.on .rec-core { width: 30px; height: 30px; border-radius: 6px; }
.rec-btn:disabled { opacity: .4; }
.mic-meter { position: absolute; right: 118px; bottom: 34px; width: 10px; height: 52px; border-radius: 6px; background: rgba(255, 255, 255, .6); overflow: hidden; z-index: 3; display: flex; align-items: flex-end; }
.mic-meter span { display: block; width: 100%; height: 0%; background: linear-gradient(#ff6b5b, #2fb56f); transition: height .08s; }

.panel { background: var(--card); border-radius: var(--r); border: 2px solid var(--line); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.tabs { display: flex; border-bottom: 2px solid var(--line); }
.tab { flex: 1; border: 0; background: none; padding: 8px 2px; font-size: 22px; display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; color: var(--muted); }
.tab span { font-size: 12px; font-weight: 500; }
.tab.active { color: var(--ink); background: var(--soft); }
.tab i { position: absolute; top: 4px; right: 12%; background: var(--accent); color: #fff; font-style: normal; font-size: 11px; border-radius: 99px; padding: 1px 6px; }
.pane { display: none; padding: 14px; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.pane.active { display: block; }
.pane h2 { margin: 0 0 10px; font-size: 20px; }
.pane h3 { margin: 16px 0 8px; font-size: 15px; color: var(--muted); font-weight: 600; }
.small { font-size: 13px; color: var(--muted); line-height: 1.4; }

.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.char { border: 3px solid transparent; background: var(--soft); border-radius: 16px; padding: 4px 4px 8px; text-align: center; font-size: 13px; font-weight: 500; }
.char img { width: 100%; aspect-ratio: 1; display: block; }
.char.active { border-color: var(--accent-2); background: #ebe6ff; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg.three { grid-template-columns: repeat(3, 1fr); }
.seg button { border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 10px 6px; font-size: 15px; font-weight: 500; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.seg button small { font-size: 11px; color: var(--muted); font-weight: 400; }
.seg button.active { border-color: var(--accent-2); background: #ebe6ff; }

.slider { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; font-size: 14px; color: var(--muted); }
.slider input { width: 100%; accent-color: var(--accent-2); }
.toggle { display: flex; gap: 8px; align-items: center; margin-top: 14px; font-size: 15px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent-2); }

.backdrops { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.backdrops button { border: 3px solid transparent; border-radius: 12px; height: 54px; font-size: 11px; color: #fff; font-weight: 600; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); display: flex; align-items: flex-end; justify-content: center; padding: 4px; }
.backdrops button.active { border-color: var(--accent-2); box-shadow: 0 0 0 2px #fff inset; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.field input { font: inherit; font-size: 16px; color: var(--ink); padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); -webkit-user-select: text; user-select: text; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.row.center { justify-content: center; }
.btn { border: 2px solid var(--line); background: #fff; border-radius: 99px; padding: 9px 16px; font-size: 15px; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.ghost { background: none; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; font-size: 100px; }
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.thumb { position: relative; border: 3px solid transparent; border-radius: 10px; overflow: hidden; background: #f3eee6; aspect-ratio: 4/3; padding: 0; }
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb.active { border-color: var(--accent-2); }
.thumb b { position: absolute; left: 4px; top: 4px; background: rgba(43, 33, 64, .7); color: #fff; font-size: 11px; border-radius: 6px; padding: 0 5px; }
.thumb .x { position: absolute; right: 2px; top: 2px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .9); font-size: 13px; line-height: 24px; padding: 0; }

.voice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.voice-grid button { border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 10px 4px; display: flex; flex-direction: column; align-items: center; font-size: 28px; }
.voice-grid button span { font-size: 13px; font-weight: 500; }
.voice-grid button.active { border-color: var(--accent-2); background: #ebe6ff; }
.voice-grid button:disabled { opacity: .4; }

.takes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.take { border: 0; padding: 0; background: var(--soft); border-radius: 12px; overflow: hidden; text-align: left; }
.take img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: #ddd; }
.take div { padding: 6px 8px; font-size: 13px; }
.empty { grid-column: 1 / -1; color: var(--muted); text-align: center; padding: 20px 0; }

.modal { position: fixed; inset: 0; background: rgba(43, 33, 64, .55); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 22px; padding: 14px; width: min(900px, 100%); }
.modal video { width: 100%; max-height: 66vh; border-radius: 14px; background: #000; display: block; }
[hidden] { display: none !important; }
.char.loading img { background: linear-gradient(90deg, #efe7fb, #fff, #efe7fb); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; border-radius: 12px; }
@keyframes shimmer { to { background-position: -200% 0; } }
