:root {
  --ink: #1a2330;
  --muted: #66758a;
  --line: rgba(26, 35, 48, 0.08);
  --panel: rgba(255, 255, 255, 0.72);
  --panel-solid: #ffffff;
  --accent: #ff7a59;
  --accent-2: #3ecf8e;
  --accent-soft: rgba(255, 122, 89, 0.12);
  --sky: #e8f4ff;
  --danger: #e11d48;
  --shadow: 0 1px 2px rgba(26, 35, 48, 0.04), 0 16px 40px rgba(26, 35, 48, 0.06);
  --radius: 20px;
  --radius-sm: 14px;
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 500px at 0% -10%, #ffe8c8 0%, transparent 55%),
    radial-gradient(800px 480px at 100% 0%, #d4f5e8 0%, transparent 50%),
    radial-gradient(700px 420px at 80% 100%, #dcebff 0%, transparent 45%),
    #f6f8fb;
  background-attachment: fixed;
}

* { box-sizing: border-box; }
html, body, #app { margin: 0; min-height: 100%; }
body { min-height: 100vh; -webkit-font-smoothing: antialiased; }
button, textarea, select, input { font: inherit; }
button {
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}
button:hover:not(:disabled) { transform: translateY(-1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.app {
  display: grid;
  grid-template-columns: 272px 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 1.5rem 1.15rem;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.brand h1 {
  font-family: "Plus Jakarta Sans", sans-serif;
  font-weight: 700;
  font-size: 1.55rem;
  letter-spacing: -0.04em;
  margin: 0.2rem 0 0;
  color: var(--ink);
}

.eyebrow {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.section h2, .card h3, .top h2 {
  font-family: "Plus Jakarta Sans", sans-serif;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0 0 0.55rem;
}

.section { display: flex; flex-direction: column; gap: 0.4rem; }

.chat-item, .ghost, .primary {
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  padding: 0.72rem 0.9rem;
  background: var(--panel-solid);
  text-align: left;
}

.primary {
  background: var(--ink);
  color: white;
  border-color: transparent;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 8px 24px rgba(26, 35, 48, 0.18);
}

.primary:hover:not(:disabled) {
  background: #2a3648;
  box-shadow: 0 10px 28px rgba(26, 35, 48, 0.22);
}

.ghost {
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}

.ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: rgba(255, 255, 255, 0.65);
  cursor: pointer;
}

.chat-item:hover {
  background: white;
  border-color: rgba(255, 122, 89, 0.25);
}

.chat-item.active {
  background: white;
  border-color: rgba(255, 122, 89, 0.45);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chat-item-main {
  min-width: 0;
  flex: 1;
}

.chat-item strong, .chat-item small { display: block; }
.chat-item strong { font-weight: 650; }
.chat-item small {
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}

.icon-btn svg {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
}

.icon-btn:hover:not(:disabled) {
  background: rgba(26, 35, 48, 0.06);
  color: var(--ink);
  transform: none;
}

.icon-btn.danger:hover:not(:disabled) {
  background: rgba(225, 29, 72, 0.1);
  color: var(--danger);
}

.ghost.danger {
  color: var(--danger);
  border-color: rgba(225, 29, 72, 0.28);
}

.ghost.danger:hover:not(:disabled) {
  background: rgba(225, 29, 72, 0.08);
  color: #be123c;
}

.top-actions,
.player-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: rgba(26, 35, 48, 0.42);
  backdrop-filter: blur(6px);
  animation: fade-in 0.16s ease;
}

.modal {
  width: min(100%, 420px);
  padding: 1.35rem 1.4rem 1.25rem;
  border-radius: var(--radius);
  background: var(--panel-solid);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  animation: rise-in 0.18s ease;
}

.modal h2 {
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 1.15rem;
  letter-spacing: -0.03em;
  margin: 0 0 0.55rem;
}

.modal p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.95rem;
}

.modal-check {
  margin-top: 1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  margin-top: 1.25rem;
}

.danger-solid {
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 0.72rem 0.95rem;
  background: var(--danger);
  color: white;
  font-weight: 650;
  box-shadow: 0 8px 22px rgba(225, 29, 72, 0.22);
}

.danger-solid:hover:not(:disabled) {
  background: #be123c;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field span {
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--muted);
}

select, textarea, input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
  background: white;
  color: var(--ink);
}

select:focus, textarea:focus, input[type="text"]:focus {
  outline: none;
  border-color: rgba(255, 122, 89, 0.55);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.cover-preview {
  width: 100%;
  max-width: 240px;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.memory {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.memory li {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.88rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
}

.memory strong {
  font-size: 0.78rem;
  color: var(--accent);
}

.memory span { color: var(--muted); line-height: 1.35; }

.main { display: flex; flex-direction: column; min-width: 0; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 1rem;
  padding: 1.4rem 1.5rem 0.6rem;
}

.top p, .hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  max-width: 42rem;
}

.error {
  margin: 0 1.5rem;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  background: #fff1f2;
  color: var(--danger);
  border: 1px solid #fecdd3;
  font-weight: 600;
}

.status {
  margin: 0 1.5rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  background: rgba(62, 207, 142, 0.12);
  color: #0f766e;
  border: 1px solid rgba(62, 207, 142, 0.3);
  font-weight: 600;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.85fr);
  gap: 1rem;
  padding: 0.85rem 1.5rem 1.5rem;
  min-height: 0;
  flex: 1;
}

.chat-pane {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  overflow: hidden;
  backdrop-filter: blur(12px);
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 55vh;
  max-height: calc(100vh - 220px);
}

.bubble {
  max-width: 88%;
  border-radius: 18px;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  background: white;
  animation: rise 0.28s ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.bubble.user {
  align-self: flex-end;
  background: var(--ink);
  color: white;
  border-color: transparent;
  border-bottom-right-radius: 6px;
}

.bubble.user header { color: rgba(255, 255, 255, 0.55); }

.bubble.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.95);
  border-bottom-left-radius: 6px;
}

.bubble header {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-weight: 700;
}

.bubble-actions,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.7rem;
}

.ghost.tiny {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
}

.bubble.assistant .ghost.tiny {
  background: #f4f7fb;
}

.bubble.user .ghost.tiny {
  background: rgba(255, 255, 255, 0.12);
  color: white;
  border-color: rgba(255, 255, 255, 0.2);
}

.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

.bubble pre, .event pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: inherit;
  line-height: 1.5;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  padding: 0.95rem;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
}

.composer .primary {
  align-self: end;
  min-width: 6.5rem;
}

.side-pane { display: flex; flex-direction: column; gap: 1rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 1.05rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  backdrop-filter: blur(12px);
}

.events {
  max-height: 280px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.event {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.55rem 0.7rem;
  background: rgba(255, 255, 255, 0.85);
  font-size: 0.82rem;
}

.event.error {
  border-color: #fecdd3;
  background: #fff1f2;
}

.event.tool_action {
  border-color: rgba(62, 207, 142, 0.35);
  background: rgba(62, 207, 142, 0.08);
}

.event strong {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.95rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.user-menu {
  position: relative;
}

.user-menu-btn {
  width: 2.15rem;
  height: 2.15rem;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  font-weight: 700;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(26, 35, 48, 0.06);
}

.user-menu-btn:hover:not(:disabled) {
  transform: none;
  border-color: rgba(255, 122, 89, 0.35);
}

.user-menu-pop {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  min-width: 11.5rem;
  padding: 0.55rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
  box-shadow: var(--shadow);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.user-menu-name {
  margin: 0;
  padding: 0.25rem 0.45rem 0;
  font-weight: 700;
  font-size: 0.88rem;
}

.user-menu-email {
  margin: 0 0 0.35rem;
  padding: 0 0.45rem 0.45rem;
  color: var(--muted);
  font-size: 0.75rem;
  border-bottom: 1px solid var(--line);
  word-break: break-all;
}

.user-menu-pop > button {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0.55rem 0.55rem;
  border-radius: 10px;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.9rem;
}

.user-menu-pop > button:hover:not(:disabled) {
  background: rgba(26, 35, 48, 0.05);
  transform: none;
}

.login-pane {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
}

.login-card {
  width: min(100%, 420px);
  padding: 1.6rem 1.5rem;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: center;
}

.login-card h2 {
  font-family: "Plus Jakarta Sans", sans-serif;
  letter-spacing: -0.03em;
  margin: 0.35rem 0 0.55rem;
}

.google-btn {
  display: flex;
  justify-content: center;
  margin-top: 1.25rem;
  min-height: 44px;
}

.admin-modal {
  width: min(100%, 640px);
  max-height: min(88vh, 820px);
  overflow: auto;
}

.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.admin-row {
  display: flex;
  gap: 0.5rem;
  margin: 0.65rem 0 1rem;
  flex-wrap: wrap;
}

.admin-row input,
.admin-row select {
  flex: 1;
  min-width: 140px;
}

.grant-row input {
  flex: 2;
}

.admin-group {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}

.admin-group header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.admin-group h3 {
  margin: 0.7rem 0 0.35rem;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.admin-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.admin-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
  padding: 0.45rem 0.55rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--line);
  font-size: 0.9rem;
}

.admin-list code {
  font-size: 0.82rem;
}

.linked-story-row {
  margin-top: 0.25rem;
  cursor: default;
}

.linked-story-row:hover {
  transform: none;
}

.brand-inline h1 {
  font-family: "Plus Jakarta Sans", sans-serif;
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: -0.04em;
  margin: 0.1rem 0 0;
}

.mode-switch {
  display: inline-flex;
  padding: 0.25rem;
  gap: 0.25rem;
  border-radius: 999px;
  background: rgba(26, 35, 48, 0.06);
  border: 1px solid var(--line);
}

.mode-switch button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  padding: 0.55rem 1rem;
  border-radius: 999px;
}

.mode-switch button.active {
  background: var(--ink);
  color: white;
  box-shadow: 0 6px 18px rgba(26, 35, 48, 0.18);
}

.banner {
  margin: 0.85rem 1.25rem 0 !important;
}

.listen-app {
  display: grid;
  grid-template-columns: minmax(220px, 300px) 1fr;
  gap: 0;
  flex: 1;
  min-height: 0;
}

.listen-shelf {
  padding: 1.25rem;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.5);
  overflow: auto;
}

.theme-block {
  margin-bottom: 1.35rem;
}

.theme-block h2 {
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 0.95rem;
  margin: 0 0 0.55rem;
  letter-spacing: -0.02em;
}

.story-chip {
  width: 100%;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.35rem;
  padding: 0.4rem 0.55rem 0.4rem 0.4rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
  text-align: left;
  cursor: pointer;
}

.story-chip:hover:not(:disabled) {
  transform: none;
}

.chip-cover {
  width: 44px;
  height: 44px;
  min-width: 44px;
  max-width: 44px;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(160deg, #ffe8c8, #d4f5e8 55%, #dcebff);
}

.chip-cover img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  display: block;
}

.chip-cover-fallback {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-family: "Plus Jakarta Sans", sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: rgba(26, 35, 48, 0.55);
}

.story-chip .chip-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
}

.story-chip strong {
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.story-chip small {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.story-chip .langs {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.15rem;
}

.story-chip .langs em {
  font-style: normal;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
}

.story-chip.active {
  border-color: rgba(255, 122, 89, 0.45);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: white;
}

.player-pane {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  text-align: center;
}

.player-pane.empty {
  color: var(--muted);
}

.cover-frame {
  width: min(100%, 320px);
  aspect-ratio: 1;
  border-radius: 28px;
  overflow: hidden;
  background: linear-gradient(160deg, #ffe8c8, #d4f5e8 55%, #dcebff);
  box-shadow: var(--shadow);
}

.cover-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cover-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.4rem;
  padding: 1.4rem;
  text-align: left;
  color: var(--ink);
}

.cover-fallback span {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(26, 35, 48, 0.55);
}

.cover-fallback strong {
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 1.55rem;
  letter-spacing: -0.04em;
  line-height: 1.15;
}

.player-copy h2 {
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: -0.04em;
  margin: 0.2rem 0 0.35rem;
}

.player-copy .hint,
.story-summary {
  max-width: 28rem;
  margin-inline: auto;
}

.story-summary {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.45;
}

.lang-toggle {
  display: inline-flex;
  gap: 0.35rem;
  padding: 0.25rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--line);
}

.lang-toggle button {
  border: 0;
  background: transparent;
  font-weight: 700;
  color: var(--muted);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
}

.lang-toggle button.active {
  background: var(--ink);
  color: white;
}

.story-audio {
  width: min(100%, 420px);
  margin-top: 0.25rem;
}

.shell.create .app {
  flex: 1;
}

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .workspace { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .listen-app { grid-template-columns: 1fr; }
  .listen-shelf {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
    padding: 0.85rem 1rem;
  }
  .player-pane { padding: 1rem; gap: 0.85rem; }
  .cover-frame {
    width: min(100%, 220px);
    border-radius: 20px;
  }
  .app-nav {
    padding: 0.75rem 1rem;
    gap: 0.65rem;
  }
  .brand-inline h1 { font-size: 1.15rem; }
  .mode-switch button { padding: 0.45rem 0.8rem; font-size: 0.88rem; }
}
