:root {
  --sage: #bfe0b8;
  --sage-deep: #9dc493;
  --sage-shadow: #8ab87f;
  --cream: #f7f3e8;
  --cream-dark: #ebe4d6;
  --ink: #2f3428;
  --ink-soft: #5a6250;
  --bubble-zh: #ffd6e8;
  --bubble-zh-border: #f0b8d0;
  --bubble-en: #d4f0dc;
  --bubble-en-border: #9dccae;
  --mega-ring: #fff;
  --mega-play: #a83232;
  --chrome-h: 3.25rem;
  --font-ui: "Nunito", "Noto Sans SC", system-ui, sans-serif;
  --font-zh: "Noto Sans SC", system-ui, sans-serif;
  --font-en: "Fraunces", "Noto Serif SC", Georgia, serif;
  --radius-lg: 20px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--cream);
  line-height: 1.5;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app.script-collapsed .panel-script {
  display: none;
}

.app.script-collapsed .panel-visual {
  flex: 1 1 auto;
  max-width: none;
}

/* —— Top chrome (HiKid-style bar) —— */
.chrome {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: var(--chrome-h);
  padding: 0.5rem 0.85rem 0.5rem 1rem;
  background: linear-gradient(180deg, #f0ebe2 0%, #e8e2d8 100%);
  border-bottom: 1px solid rgba(47, 52, 40, 0.08);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.chrome-left {
  min-width: 0;
}

.chrome-title {
  margin: 0;
  font-size: clamp(0.95rem, 2.5vw, 1.1rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  font-family: var(--font-ui);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chrome-sub {
  margin: 0.1rem 0 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.chrome-center {
  display: flex;
  align-items: center;
}

.chrome-pill {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(47, 52, 40, 0.1);
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
}

.chrome-right {
  flex-shrink: 0;
}

.btn-toggle-script {
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.65rem;
  border-radius: 999px;
  border: 2px solid rgba(47, 52, 40, 0.15);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}

.btn-toggle-script:hover {
  border-color: rgba(47, 52, 40, 0.28);
}

.toggle-icon {
  font-size: 0.95rem;
  line-height: 1;
  opacity: 0.75;
}

/* —— Split layout —— */
.split {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.panel-visual {
  flex: 1 1 62%;
  min-width: 0;
  position: relative;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: linear-gradient(165deg, var(--sage) 0%, var(--sage-deep) 48%, var(--sage-shadow) 100%);
}

.leaf-layer {
  position: absolute;
  inset: 0;
  opacity: 0.22;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cpath fill='%232f3428' d='M60 8c8 18 6 38-4 52 10-6 22-8 34-6-12 14-28 22-46 24 4 8 6 18 4 28 18-22 22-50 12-98z'/%3E%3C/svg%3E");
  background-size: 100px 100px;
  pointer-events: none;
}

.visual-inner {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 1rem 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.illustration-frame {
  margin: 0;
  width: 100%;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #fff;
  box-shadow:
    0 4px 0 rgba(47, 52, 40, 0.06),
    0 18px 40px rgba(47, 52, 40, 0.12);
  border: 3px solid rgba(255, 255, 255, 0.85);
}

.illustration {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  vertical-align: middle;
}

/* Mega play (like HiKid mic) */
.mega-dock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.15rem;
}

.btn-mega {
  width: 5.5rem;
  height: 5.5rem;
  border-radius: 50%;
  border: none;
  background: var(--mega-ring);
  box-shadow:
    0 6px 0 rgba(47, 52, 40, 0.08),
    0 16px 32px rgba(47, 52, 40, 0.15);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  touch-action: manipulation;
}

.btn-mega:hover {
  transform: scale(1.03);
}

.btn-mega:active {
  transform: scale(0.97);
}

.btn-mega-icon {
  font-size: 1.65rem;
  color: var(--mega-play);
  margin-left: 0.15rem;
}

.btn-mega.is-playing {
  outline: 4px solid rgba(255, 255, 255, 0.9);
  outline-offset: 3px;
  box-shadow:
    0 4px 0 rgba(47, 52, 40, 0.06),
    0 12px 28px rgba(168, 50, 50, 0.25);
}

.mega-caption {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  color: rgba(47, 52, 40, 0.75);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

.mini-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
}

.btn-chip {
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.65);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.45);
  color: var(--ink);
  touch-action: manipulation;
}

.btn-chip:hover {
  background: rgba(255, 255, 255, 0.7);
}

.btn-chip-zh.is-playing,
.btn-chip-en.is-playing {
  background: #fff;
  border-color: #fff;
  box-shadow: 0 4px 14px rgba(47, 52, 40, 0.12);
}

.btn-chip-stop {
  border-style: dashed;
  border-color: rgba(47, 52, 40, 0.2);
  background: transparent;
  color: var(--ink-soft);
}

.pager {
  display: flex;
  gap: 0.5rem;
}

.btn-page {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.85rem;
  min-width: 5.5rem;
  padding: 0.45rem 0.75rem;
  border-radius: 12px;
  border: 2px solid rgba(47, 52, 40, 0.12);
  background: rgba(255, 255, 255, 0.35);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}

.btn-page:hover {
  background: rgba(255, 255, 255, 0.55);
}

.btn-page:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.status-row {
  margin-top: 0.15rem;
}

.status-pill {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 0.32rem 0.75rem;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

.status-ready {
  background: #3d9a5c;
  color: #fff;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}

.status-busy {
  background: #e8a849;
  color: #fff;
}

/* —— Script panel (chat-style) —— */
.panel-script {
  flex: 0 0 34%;
  max-width: 380px;
  min-width: 260px;
  background: var(--cream);
  border-left: 1px solid rgba(47, 52, 40, 0.08);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: -8px 0 24px rgba(47, 52, 40, 0.04);
}

.script-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem 1rem 5.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.bubble-row {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  max-width: 100%;
}

.bubble-row-zh {
  justify-content: flex-start;
}

.bubble-row-en {
  justify-content: flex-end;
}

.bubble-avatar {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 800;
  color: #fff;
  margin-bottom: 0.2rem;
}

.bubble-avatar-zh {
  background: linear-gradient(145deg, #f0b8d0, #e07a9a);
}

.bubble-avatar-en {
  background: linear-gradient(145deg, #9dccae, #4a9d6a);
  font-size: 0.55rem;
}

.bubble {
  max-width: calc(100% - 2.75rem);
  padding: 0.65rem 0.85rem;
  border-radius: 16px 16px 16px 6px;
  box-shadow: 0 2px 0 rgba(47, 52, 40, 0.06);
}

.bubble-zh {
  background: var(--bubble-zh);
  border: 2px solid var(--bubble-zh-border);
  border-radius: 16px 16px 16px 6px;
}

.bubble-en {
  background: var(--bubble-en);
  border: 2px solid var(--bubble-en-border);
  border-radius: 16px 16px 6px 16px;
}

.bubble-text {
  margin: 0;
  font-size: clamp(0.95rem, 2.4vw, 1.05rem);
  font-weight: 600;
  font-family: var(--font-zh);
  line-height: 1.55;
  color: var(--ink);
}

.bubble-text-en {
  font-family: var(--font-en);
  font-style: italic;
  font-weight: 600;
  color: var(--ink-soft);
}

.script-hint {
  margin: 0.5rem 0 0;
  font-size: 0.72rem;
  color: var(--ink-soft);
  line-height: 1.45;
}

.script-hint code {
  font-size: 0.9em;
  background: rgba(255, 255, 255, 0.7);
  padding: 0.08em 0.28em;
  border-radius: 4px;
}

.wave-deco {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4.5rem;
  background: linear-gradient(180deg, transparent 0%, rgba(74, 157, 180, 0.15) 40%, rgba(74, 157, 180, 0.35) 100%);
  pointer-events: none;
}

.wave-deco::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2.2rem;
  height: 2.5rem;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 120' preserveAspectRatio='none'%3E%3Cpath fill='%234a9d6a' fill-opacity='0.35' d='M0 80c120-40 240-40 360 0s240 40 360 0 240-40 360 0 240 40 360 0v40H0z'/%3E%3Cpath fill='%233d8a9a' fill-opacity='0.4' d='M0 100c160-30 320-30 480 0s320 30 480 0 320-30 480 0v20H0z'/%3E%3C/svg%3E")
    center bottom / 100% 100% no-repeat;
  opacity: 0.9;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* —— Responsive: stack like mobile HiKid —— */
@media (max-width: 820px) {
  .split {
    flex-direction: column;
  }

  .panel-script {
    flex: none;
    max-width: none;
    min-width: 0;
    min-height: 42vh;
    border-left: none;
    border-top: 1px solid rgba(47, 52, 40, 0.08);
    box-shadow: 0 -8px 24px rgba(47, 52, 40, 0.05);
  }

  .app.script-collapsed .panel-script {
    display: none;
  }

  .visual-inner {
    max-width: 480px;
    padding-bottom: 1rem;
  }
}

@media (max-width: 420px) {
  .btn-mega {
    width: 5rem;
    height: 5rem;
  }

  .chrome-pill {
    display: none;
  }
}
