:root {
  --ink: #3b2f5c;
  --ink-soft: #7a6c99;
  --card: rgba(255, 255, 255, 0.86);
  --line: rgba(120, 90, 180, 0.16);
  --accent: #ff5c9d;
  --accent-2: #7c5cff;
  --chip: #f5efff;
  --shadow: 0 10px 30px rgba(80, 50, 140, 0.18);
  --radius: 22px;
  font-family: 'Fredoka', ui-rounded, 'Segoe UI', system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #ffe9f6; overscroll-behavior: none; }
body {
  -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; touch-action: manipulation;
}
img, a { -webkit-user-drag: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- top bar */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 0;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); backdrop-filter: blur(10px);
  padding: 6px 16px 6px 8px; border-radius: 999px; box-shadow: var(--shadow);
}
.logo { font-size: 30px; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, #ffd6f0, #d3ecff); }
.brand h1 { white-space: nowrap; margin: 0; font-size: 20px; font-weight: 700; line-height: 1.1; background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand p { margin: 0; font-size: 12px; color: var(--ink-soft); }

.actions { display: flex; align-items: center; gap: 8px; }
.pill, .icon, .lang, .fab {
  background: var(--card); backdrop-filter: blur(10px); box-shadow: var(--shadow);
  border-radius: 999px; transition: transform 0.15s ease, background 0.15s ease;
}
.pill { padding: 10px 16px; font-weight: 600; }
.icon { width: 44px; height: 44px; font-size: 20px; display: grid; place-items: center; }
.icon.small { width: 34px; height: 34px; font-size: 14px; box-shadow: none; background: var(--chip); }
.pill:hover, .icon:hover, .fab:hover { transform: translateY(-2px); }
.pill:active, .icon:active, .fab:active { transform: scale(0.95); }
.lang { display: flex; padding: 4px; }
.lang button { padding: 7px 12px; border-radius: 999px; font-weight: 700; font-size: 14px; color: var(--ink-soft); }
.lang button.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }

/* ---------- caption */
.caption {
  position: fixed; top: 84px; left: 50%; transform: translateX(-50%);
  max-width: min(560px, calc(100% - 32px));
  background: #fff; padding: 10px 20px; border-radius: 20px; box-shadow: var(--shadow);
  font-size: 17px; font-weight: 500; text-align: center; pointer-events: none;
  animation: bob 3s ease-in-out infinite;
}
.caption::after {
  content: ''; position: absolute; left: 50%; bottom: -8px; width: 16px; height: 16px;
  background: #fff; transform: translateX(-50%) rotate(45deg); border-radius: 3px;
}
@keyframes bob { 50% { transform: translate(-50%, -4px); } }
.hint { position: fixed; bottom: 108px; left: 50%; transform: translateX(-50%); margin: 0; font-size: 13px; color: var(--ink-soft); background: rgba(255,255,255,0.6); padding: 4px 12px; border-radius: 999px; pointer-events: none; white-space: nowrap; }

/* ---------- panel */
#panel {
  position: fixed; top: 84px; right: 16px; bottom: 112px; width: 340px;
  display: flex; flex-direction: column;
  background: var(--card); backdrop-filter: blur(14px);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.panel-head { display: flex; align-items: flex-start; gap: 6px; padding: 10px 10px 0; }
.close { display: none; margin-left: auto; }
.tabs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; flex: 1; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; border-radius: 14px; color: var(--ink-soft); transition: background 0.15s; }
.tab .ti { font-size: 22px; }
.tab .tl { font-size: 11px; font-weight: 600; }
.tab:hover { background: var(--chip); }
.tab.active { background: linear-gradient(135deg, #ffe1f0, #e8e0ff); color: var(--ink); }
.tab-body { padding: 8px 16px 18px; overflow-y: auto; flex: 1; }
.field { margin-top: 12px; }
.field h3 { margin: 0 0 8px; font-size: 15px; font-weight: 600; }
.field.disabled .choices, .field.disabled .swatches { opacity: 0.35; pointer-events: none; }
.note { margin: 6px 0 0; font-size: 13px; color: var(--accent); }
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.choice {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px; border-radius: 16px; background: #fff; border: 2px solid var(--line);
  transition: transform 0.12s, border-color 0.12s;
}
.choice .ci { font-size: 26px; line-height: 1.1; }
.choice .cl { font-size: 13px; font-weight: 500; text-align: center; }
.choice:hover { transform: translateY(-2px); }
.choice.active { border-color: var(--accent); background: #fff0f7; box-shadow: 0 4px 12px rgba(255, 92, 157, 0.25); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 40px; height: 40px; border-radius: 50%; background: var(--c);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,0.12), 0 0 0 2px #fff, 0 0 0 3px var(--line);
  transition: transform 0.12s;
}
.swatch:hover { transform: scale(1.1); }
.swatch.active { box-shadow: inset 0 -4px 0 rgba(0,0,0,0.12), 0 0 0 3px #fff, 0 0 0 6px var(--accent); transform: scale(1.08); }

.fab { display: none; position: fixed; right: 16px; bottom: 112px; padding: 12px 18px; font-weight: 600; font-size: 16px; }

/* ---------- bottom bar */
.bottombar {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; max-width: calc(100% - 32px);
}
.nav { flex: none; font-size: 16px; }
.scenes {
  display: flex; gap: 6px; padding: 6px; overflow-x: auto; scrollbar-width: none;
  background: var(--card); backdrop-filter: blur(10px); border-radius: 26px; box-shadow: var(--shadow);
}
.scenes::-webkit-scrollbar { display: none; }
.scene-btn {
  flex: none; display: flex; flex-direction: column; align-items: center; gap: 1px;
  min-width: 76px; padding: 8px 10px; border-radius: 20px; transition: background 0.15s, transform 0.15s;
}
.scene-btn .si { font-size: 28px; line-height: 1.1; }
.scene-btn .sl { font-size: 12px; font-weight: 600; white-space: nowrap; }
.scene-btn:hover { background: var(--chip); transform: translateY(-2px); }
.scene-btn.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }

/* ---------- credit */
.credit {
  position: fixed; right: 16px; bottom: max(14px, env(safe-area-inset-bottom)); margin: 0;
  font-size: 12px; color: var(--ink-soft); background: rgba(255,255,255,0.7); backdrop-filter: blur(8px);
  padding: 4px 12px; border-radius: 999px;
}
.credit a { color: var(--accent); font-weight: 600; text-decoration: none; }
.credit a:hover { text-decoration: underline; }
.credit a.holding {
  background: linear-gradient(90deg, #ffd6ec 50%, transparent 50%) 100% 0 / 200% 100% no-repeat;
  animation: hold 1.5s linear forwards; border-radius: 6px;
}
@keyframes hold { to { background-position: 0 0; } }
#btn-kid.on { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

.toast {
  position: fixed; left: 50%; top: 152px; transform: translate(-50%, -10px); opacity: 0;
  max-width: min(460px, calc(100% - 32px)); padding: 12px 18px; border-radius: 18px;
  background: #3b2f5c; color: #fff; font-size: 15px; text-align: center; box-shadow: var(--shadow);
  pointer-events: none; transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- overlays */
#fade { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity 0.22s ease; }
#fade.on { opacity: 1; }
#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#flash.go { animation: flash 0.5s ease-out; }
@keyframes flash { 0% { opacity: 0.9; } 100% { opacity: 0; } }
body:not(.ready) .topbar, body:not(.ready) #panel, body:not(.ready) .bottombar { opacity: 0; }

/* ---------- mobile */
@media (max-width: 820px) {
  .brand p, .pill span:last-child { display: none; }
  .brand { padding-right: 14px; }
  .brand h1 { font-size: 17px; }
  .pill { width: 44px; height: 44px; padding: 0; font-size: 20px; }
  .caption { top: 76px; font-size: 15px; }
  .hint { display: none; }
  #panel {
    top: auto; left: 12px; right: 12px; bottom: 104px; width: auto; max-height: 48vh;
    transform: translateY(calc(100% + 120px)); transition: transform 0.3s cubic-bezier(.2,.9,.3,1.2);
  }
  #panel.open { transform: none; }
  .close { display: grid; }
  .fab { display: block; bottom: 104px; }
  #panel.open ~ .fab { display: none; }
  .scene-btn { min-width: 64px; padding: 6px 8px; }
  .scene-btn .si { font-size: 24px; }
  .choices { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
}
@media (max-width: 420px) {
  .brand .logo { width: 36px; height: 36px; font-size: 24px; }
  .brand h1 { display: none; }
  .brand { padding: 4px; }
  .actions { gap: 6px; }
  .icon, .pill { width: 40px; height: 40px; font-size: 18px; }
  .lang button { padding: 6px 9px; font-size: 13px; }
  .nav { display: none; }
}
@media (max-width: 1400px) {
  .bottombar { bottom: max(34px, env(safe-area-inset-bottom)); }
  .credit { left: 50%; right: auto; transform: translateX(-50%); bottom: 6px; padding: 0 10px; font-size: 11px; white-space: nowrap; background: none; backdrop-filter: none; }
}
