* {
  box-sizing: border-box
}

:root {
  --bg: #0e0f13;
  --panel: #171923;
  --panel-2: #1f2331;
  --text: #e8eefc;
  --muted: #9aa3b2;
  --accent: #6bc46b;
  --accent-2: #7aa2ff;
  --danger: #ff7676;
  --tile: #9e9e9e;
  --tile-border: #262c3f;
  --btn: #20263b;
  --btn-active: #2d3654;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, Segoe UI, Roboto, Helvetica, Arial;
  
}

h1,
h2,
h3 {
  margin: .2rem 0;
  color: whitesmoke;
}

.navbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--tile-border);
  position: sticky;
  top: 0;
  z-index: 10
}

#burger {
  font-size: 1.2rem
}

.app-title {
  flex: 1;
  text-align: center;
  font-weight: 700
}

.mixers {
  display: flex;
  gap: 1rem
}

.mixers label {
  font-size: .85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: .4rem
}

.side-menu {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(320px, 85vw);
  background: var(--panel-2);
  padding: 1rem;
  transform: translateX(-100%);
  transition: .2s transform;
  z-index: 20;
  overflow: auto;
  border-right: 1px solid var(--tile-border)
}

.side-menu.hidden {
  transform: translateX(-100%)
}

.side-menu:not(.hidden) {
  transform: translateX(0)
}

#chapter-list {
  list-style: none;
  padding: 0;
  margin: 0
}

#chapter-list li {
  padding: .3rem 0;
  border-bottom: 1px dashed var(--tile-border);
  cursor: pointer
}

#chapter-list li:hover {
  color: var(--accent-2)
}

.layout {
  max-width: 1200px;
  margin: 1rem auto;
  padding: 0 1rem;
  display: grid;
  gap: 1rem
}

.row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem
}

.tile {
  color: whitesmoke;
  background: var(--tile);
  border: 1px solid var(--tile-border);
  border-radius: 16px;
  padding: .6rem;
  min-height: 110px
}

.tile h3 {
  font-size: 1rem;
  /* color: var(--muted); */
  margin-bottom: .4rem
}

.btn-list {  
  display: flex;
  flex-wrap: wrap;
  gap: .5rem
}

.btn-list.scroll {
  max-height: 140px;
  overflow: auto;
  padding-right: .2rem
}

.btn {
  color: whitesmoke;
  background: var(--btn);
  border: 1px solid var(--tile-border);
  padding: .2rem .7rem;
  border-radius: 12px;
  cursor: pointer
}

.solf-btn{
  margin: 0 2px;
    color: whitesmoke;
  background: #9e9e9e;
  border: 1px solid var(--tile-border);
  padding: .2rem .7rem;
  border-radius: 12px;
  cursor: pointer
tile}

.btn.active {
  background: var(--btn-active);
  border-color: var(--accent-2)
}

.btn.danger {
  border-color: var(--danger)
}

.placeholder {
  opacity: .6
}

.story {
  background: var(--panel);
  border: 1px solid var(--tile-border);
  border-radius: 18px;
  padding: 1rem
}

.story-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: .6rem
}

#chapter-content {
  white-space: pre-wrap
}

.chapter-links {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: 1rem
}

.link-btn {
  background: var(--text);
  border: 1px solid var(--tile-border);
  padding: .5rem .7rem;
  border-radius: 12px;
  color: var(--bg);
  cursor: pointer
}

.link-btn:hover {
  border-color: var(--accent)
}

.inline-sound {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .1rem .4rem;
  margin: 0 .1rem;
  border-radius: 10px;
  border: 1px dashed var(--tile-border);
  cursor: pointer
}

.inline-sound:hover {
  border-color: var(--accent-2)
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: grid;
  place-items: center;
  z-index: 30
}

.overlay.hidden {
  display: none
}

.overlay-card {
  background: var(--panel);
  border: 1px solid var(--tile-border);
  padding: 1.2rem;
  border-radius: 16px;
  min-width: min(360px, 90vw);
  text-align: center
}

@media (max-width:900px) {
  .row {
    grid-template-columns: repeat(2, 1fr)
  }
}

/* Chapters Editor – scoped styles (works if the editor is in the light DOM)
   Note: These rules won't penetrate a Shadow DOM. */
/* Chapters Editor overlay container (visible in light DOM) */
#chapters-editor {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(0,0,0,.6);
  display: none; /* shown via JS */
}

#chapters-editor .wrap {
  font-family: system-ui, sans-serif;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 12px;
  padding: 12px;
  height: 100vh;
  box-sizing: border-box;
}

#chapters-editor .card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,.15);
  padding: 12px;
  display: flex;
  flex-direction: column;
}

#chapters-editor .toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  height: auto;
  width: auto;
  box-sizing: border-box;
  flex-wrap: wrap;
}

#chapters-editor .toolbar input[type="search"] {
  flex: 1;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #ddd;
}

#chapters-editor .list {
  height: 76vh;
  overflow: auto;
  border: 1px solid #eee;
  border-radius: 8px;
  box-sizing: border-box;
}

#chapters-editor .row {
  color: gray;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid #f2f2f2;
  cursor: pointer;
}

#chapters-editor .row:hover { background: #f9f9ff; }
#chapters-editor .row.active { background: #eef3ff; font-weight: 600; }

#chapters-editor .btn {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #ddd;
  background: #fff;
  cursor: pointer;
}

#chapters-editor .btn.primary { background: #1a73e8; border-color: #1a73e8; color: #fff; }
#chapters-editor .btn.danger  { background: #e53935; border-color: #e53935; color: #fff; }
#chapters-editor .btn.ghost   { background: transparent; }

#chapters-editor .split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

#chapters-editor .field { display: grid; gap: 6px; margin-bottom: 10px; }
#chapters-editor .field label { font-size: 12px; color: #666; }

#chapters-editor .field input,
#chapters-editor .field textarea,
#chapters-editor .field select {
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 8px;
  width: 100%;
  box-sizing: border-box;
}

#chapters-editor .links { display: grid; gap: 6px; }

#chapters-editor .link-row {
  display: grid;
  grid-template-columns: 1fr 120px 36px;
  gap: 6px;
  align-items: center;
}

#chapters-editor .tags { font-size: 12px; color: #888; }

#chapters-editor .footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

#chapters-editor .errors { color: #b00020; font-size: 12px; white-space: pre-wrap; }

#chapters-editor .header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

#chapters-editor .dim { color: #777; font-size: 12px; }
