:root {
  --bg-sky: #fff9ed;
  --bg-wave: #ffe4bd;
  --panel: #ffffffee;
  --ink: #1f2937;
  --accent: #f97316;
  --accent-2: #14b8a6;
  --good: #16a34a;
  --bad: #dc2626;
  --radius: 24px;
  --font-main: "Baloo 2", "Nunito", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-main);
  color: var(--ink);
  background: radial-gradient(circle at 8% 10%, #fff 0, #fff6e7 28%, transparent 40%),
    radial-gradient(circle at 92% 3%, #d8fbff 0, #d8fbff 18%, transparent 34%),
    linear-gradient(165deg, var(--bg-sky), var(--bg-wave));
  min-height: 100vh;
}

.app-shell {
  width: min(980px, 100% - 20px);
  margin: 10px auto 28px;
  display: grid;
  gap: 14px;
}

.child-shell { position: relative; }
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.topbar-title {
  font-weight: 800;
  font-size: 1.1rem;
  color: #0f766e;
}
.burger-btn {
  border: 0;
  border-radius: 12px;
  background: #fff;
  width: 44px;
  height: 44px;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 16px #f0f0f0;
}
.mobile-menu {
  display: none;
  background: #ffffffee;
  border: 2px solid #fff;
  border-radius: 18px;
  box-shadow: 0 10px 24px #f4b2683b;
  padding: 10px;
  gap: 8px;
}
.menu-item {
  border: 0;
  border-radius: 12px;
  background: #fff4dd;
  color: #7c2d12;
  padding: 12px;
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.hero { text-align: center; padding: 20px 18px 10px; }
.eyebrow { margin: 0; font-weight: 800; color: var(--accent-2); }
h1 { margin: 8px 0 6px; font-size: clamp(2rem, 6vw, 2.8rem); }
.subtitle { margin: 0; font-size: 1rem; }

.panel {
  background: var(--panel);
  border: 2px solid #ffffff;
  border-radius: var(--radius);
  box-shadow: 0 10px 24px #f4b2683b;
  padding: 16px;
}

.panel-body {
  display: grid;
  gap: 10px;
}

.panel-toggle {
  margin-left: auto;
  font-weight: 700;
  min-width: 40px;
  width: 40px;
  padding: 8px 0;
  text-align: center;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.panel-toggle-icon {
  display: inline-block;
  font-size: 1.35rem;
  line-height: 1;
  transition: transform .16s ease;
  transform-origin: center;
}

.panel-toggle-icon.is-collapsed {
  transform: rotate(-90deg);
}

.panel.collapsed {
  padding-bottom: 12px;
}

.panel.collapsed .panel-body {
  display: none;
}

.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
h2, h3 { margin: 0 0 12px; }

.children-grid, .choice-grid, .card-grid, .character-compact-grid, .library-list {
  display: grid;
  gap: 10px;
}

.children-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.choice-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.choice-grid.tiny { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.card-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.card-grid.tiny { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.character-compact-grid { grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); }

.tabs-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.tab-btn {
  border: 1px solid #ffd5a8;
  border-radius: 999px;
  background: #fff;
  padding: 7px 12px;
  font: inherit;
  cursor: pointer;
}
.tab-btn.active { background: #fff3df; border-color: #fdba74; font-weight: 700; }

.character-compact-grid.as-list,
.choice-grid.as-list {
  grid-template-columns: 1fr;
}

.card, .chip, .target-btn {
  border: 0;
  background: #fff;
  border-radius: 18px;
  padding: 14px 10px;
  font: inherit;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
  box-shadow: 0 8px 16px #f0f0f0;
}
.card .name { font-weight: 800; display: block; font-size: 1.05rem; }
.card .meta { opacity: .7; font-size: .92rem; }
.card.active, .chip.active, .target-btn.active {
  background: #fff7e8;
  outline: 3px solid #fdba74;
  transform: translateY(-2px);
}

.icon-card {
  border: 2px solid #ffe1be;
  border-radius: 14px;
  background: #fff;
  font: inherit;
  padding: 10px;
  text-align: center;
  cursor: pointer;
  display: grid;
  gap: 6px;
  min-height: 88px;
}
.icon-card span { font-size: 1.5rem; line-height: 1; }
.icon-image {
  width: 100%;
  height: 74px;
  object-fit: cover;
  border-radius: 10px;
}
.icon-card strong {
  font-size: .86rem;
  line-height: 1.25;
  white-space: normal;
  word-break: break-word;
}
.icon-card.active {
  background: #fff7e8;
  border-color: #fdba74;
}

.character-compact {
  position: relative;
  border: 3px solid #ffe8c7;
  background: #fff;
  border-radius: 18px;
  padding: 8px 8px 10px;
  cursor: pointer;
  box-shadow: 0 8px 16px #f0f0f0;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.character-compact:hover { transform: translateY(-2px); }
.character-compact .corner-icon {
  position: absolute;
  right: 7px;
  top: 6px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #ffffff;
  display: grid;
  place-items: center;
  font-size: .9rem;
}
.character-media {
  width: 64px;
  height: 64px;
  margin: 0 auto 8px;
  border-radius: 14px;
  overflow: hidden;
  background: #fff4d8;
  display: grid;
  place-items: center;
}
.character-image { width: 100%; height: 100%; object-fit: cover; }
.character-emoji { font-size: 1.8rem; }
.character-label {
  text-align: center;
  font-size: .9rem;
  font-weight: 800;
  white-space: normal;
  line-height: 1.2;
  word-break: break-word;
  min-height: 2.2em;
}
.character-compact.role-snall { border-color: #6ee7b7; box-shadow: 0 8px 16px #34d39933; }
.character-compact.role-dum { border-color: #fca5a5; box-shadow: 0 8px 16px #f8717133; }
.character-compact.role-barn { border-color: #93c5fd; box-shadow: 0 8px 16px #60a5fa33; }

.entity-row {
  border: 2px solid #ffe8c7;
  border-radius: 14px;
  background: #fff;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  box-shadow: 0 8px 16px #f0f0f0;
}
.entity-row.active {
  border-color: #fdba74;
  background: #fff7e8;
}
.entity-row .row-emoji {
  width: 32px;
  min-width: 32px;
  text-align: center;
  font-size: 1.35rem;
  line-height: 1;
}
.entity-row .row-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.entity-row .row-main strong {
  font-size: .96rem;
  line-height: 1.2;
  white-space: normal;
  word-break: break-word;
}
.entity-row .row-main small {
  font-size: .78rem;
  opacity: .72;
}
.entity-row .row-role {
  margin-left: auto;
  font-weight: 800;
  font-size: .86rem;
}
.entity-row.role-snall { border-color: #6ee7b7; box-shadow: 0 8px 16px #34d39933; }
.entity-row.role-dum { border-color: #fca5a5; box-shadow: 0 8px 16px #f8717133; }
.entity-row.role-barn { border-color: #93c5fd; box-shadow: 0 8px 16px #60a5fa33; }

.pill {
  border: 0;
  border-radius: 999px;
  background: #e2f8f4;
  color: #0f766e;
  font: inherit;
  font-weight: 700;
  padding: 10px 14px;
  cursor: pointer;
}

.action-panel { text-align: center; }
.target-group { display: inline-grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.device-input {
  display: block;
  margin: 0 auto 10px;
  border: 2px solid #fed7aa;
  border-radius: 12px;
  padding: 9px 10px;
  width: min(360px, 90%);
  font: inherit;
}

.start-btn {
  width: min(520px, 95%);
  border: 0;
  border-radius: 999px;
  padding: 18px 20px;
  font: inherit;
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  font-weight: 800;
  color: #fff;
  background: linear-gradient(90deg, #fb923c, #f97316);
  cursor: pointer;
  box-shadow: 0 14px 20px #fb923c55;
}

.progress-wrap {
  width: min(620px, 95%);
  margin: 12px auto 0;
}
.progress-head { display: flex; justify-content: space-between; font-size: .95rem; font-weight: 700; }
.progress-bar {
  margin-top: 6px;
  height: 12px;
  background: #ffe3c4;
  border-radius: 999px;
  overflow: hidden;
}
#progressFill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #14b8a6, #f97316);
  transition: width .35s ease;
}

.status { min-height: 24px; margin: 12px 0 6px; font-weight: 700; }
audio { width: 100%; max-width: 680px; }

.library-list { grid-template-columns: 1fr; }
.library-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 14px;
  padding: 10px;
}
.library-meta { min-width: 0; }
.library-title { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.library-sub { font-size: .86rem; opacity: .75; }
.library-actions { display: flex; gap: 6px; }
.small-btn {
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
  background: #fff2df;
}

.selected-objects { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.selected-title { margin: 0 4px 0 0; font-weight: 700; font-size: .92rem; }
.selected-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 10px;
  background: #fff0db;
  font-size: .82rem;
}
.selected-place-card {
  margin-top: 8px;
  border: 2px dashed #fdba74;
  background: #fff7e8;
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 700;
}

body.simple-mode #characterCategoryTabs,
body.simple-mode #characterSearch,
body.simple-mode #feelingSection,
body.simple-mode #objectSection,
body.simple-mode .subtitle {
  display: none;
}

.parent form { display: grid; gap: 10px; }
.admin-form { display: grid; gap: 10px; }
.admin-link { text-decoration: none; display: inline-block; }
label { display: grid; gap: 4px; font-weight: 700; }
input {
  border: 2px solid #fed7aa;
  border-radius: 12px;
  padding: 10px;
  font: inherit;
}
select {
  border: 2px solid #fed7aa;
  border-radius: 12px;
  padding: 10px;
  font: inherit;
  background: #fff;
}
textarea {
  border: 2px solid #fed7aa;
  border-radius: 12px;
  padding: 10px;
  font: inherit;
  min-height: 120px;
  resize: vertical;
}
.hidden { display: none; }
.sim-response {
  margin: 0;
  padding: 12px;
  border-radius: 12px;
  border: 2px solid #fed7aa;
  background: #fffdf8;
  min-height: 88px;
  max-height: 280px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .82rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.sim-mode-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.sim-mode-badge, .sim-queue-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: .78rem;
  font-weight: 800;
}
.sim-mode-badge {
  border: 2px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
}
.sim-mode-badge.mode-idle {
  border-color: #cbd5e1;
  background: #f8fafc;
  color: #334155;
}
.sim-mode-badge.mode-browsing_old {
  border-color: #fdba74;
  background: #fff7ed;
  color: #9a3412;
}
.sim-mode-badge.mode-volume {
  border-color: #86efac;
  background: #f0fdf4;
  color: #166534;
}
.sim-queue-badge {
  border: 2px solid #e5e7eb;
  background: #fafafa;
  color: #374151;
}
.sim-queue-badge.active {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1d4ed8;
}

@media (max-width: 700px) {
  .child-shell {
    margin-top: 8px;
    gap: 10px;
  }
  .mobile-topbar {
    display: flex;
    position: sticky;
    top: 8px;
    z-index: 20;
    background: #fff9edcc;
    backdrop-filter: blur(6px);
    border: 2px solid #ffffff;
    border-radius: 14px;
    padding: 8px;
  }
  .mobile-menu:not(.hidden) {
    display: grid;
    position: sticky;
    top: 68px;
    z-index: 19;
  }
  .hero {
    padding: 12px 12px 4px;
  }
  h1 { font-size: 1.8rem; }
  .panel { padding: 14px; }
  .panel-header {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .tabs-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 3px;
    -webkit-overflow-scrolling: touch;
  }
  .tab-btn { flex: 0 0 auto; }
  .children-grid { grid-template-columns: repeat(2, 1fr); }
  .choice-grid, .choice-grid.tiny { grid-template-columns: 1fr; }
  .character-compact-grid { grid-template-columns: repeat(3, 1fr); }
  .character-label { font-size: .82rem; }
  .target-group { width: 100%; grid-template-columns: 1fr; }
  .library-item { flex-direction: column; align-items: stretch; }
  .library-actions { justify-content: stretch; }
  .small-btn { flex: 1; }
}
