/* ============================================================
   浮光剧场 · Layout
   ============================================================ */

/* === App Shell === */
.app-shell {
  position: relative; isolation: isolate;
  display: block;
  width: 100%; height: 100%; min-height: 0; overflow: hidden;
}

/* === Side Panel === */
.side-panel {
  min-width: 0; overflow-y: auto;
  background: var(--bg-grouped);
  padding: 20px 16px;
  backdrop-filter: var(--material-blur);
  -webkit-backdrop-filter: var(--material-blur);
}
.library-panel {
  position: fixed;
  z-index: 100;
  top: calc(max(12px, env(safe-area-inset-top)) + 58px);
  bottom: 10px;
  left: 10px;
  width: 280px;
  isolation: isolate;
  display: flex; flex-direction: column;
  margin: 0;
  padding: 18px 14px 14px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius-xl);
  background: rgba(12,12,15,.96);
  box-shadow:
    0 24px 80px rgba(0,0,0,.38),
    0 6px 20px rgba(0,0,0,.18),
    inset 0 1px 0 rgba(255,255,255,.08);
  transform: translateX(0);
  transition: opacity .24s ease, transform .35s var(--ease-fluid), visibility 0s;
  overflow: hidden;
}
.library-panel::before,
.controls-panel::before {
  content: "";
  position: absolute;
  z-index: 3;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: var(--glass-edge-shadow);
}
.library-collapsed .library-panel {
  opacity: 0;
  visibility: hidden;
  transform: translateX(calc(-100% - 24px));
  pointer-events: none;
  transition: opacity .2s ease, transform .35s var(--ease-fluid), visibility 0s .35s;
}

/* Brand */
.brand-row {
  display: flex; align-items: center; gap: 12px;
  flex-shrink: 0;
  padding: 0 4px 14px;
  margin-bottom: 0;
}
.brand-row > div { display: grid; gap: 2px; flex: 1; min-width: 0; }
.brand-row strong {
  font-size: 17px; font-weight: 600; letter-spacing: -0.02em;
}
.library-close-btn { margin-left: auto; }

/* Labels */
.section-label {
  display: block; padding: 0 4px;
  color: var(--text-tertiary); font-size: 12px; font-weight: 500;
  letter-spacing: 0.02em;
  margin: 20px 0 8px;
  text-transform: uppercase;
}
.section-head { display: flex; align-items: center; justify-content: space-between; }
.section-head .section-label { margin: 0; }

.library-panel-body {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 0;
  scrollbar-width: thin;
}
.library-group { margin-bottom: 16px; }
.library-group > .section-label,
.library-group > .section-head {
  padding-inline: 8px;
  margin-bottom: 6px;
}
.library-group .section-label {
  margin-top: 0;
  padding: 0;
  font-size: 11px;
}
.library-create-btn {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  flex-shrink: 0;
  width: 100%; min-height: 40px;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: inset 0 1px rgba(255,255,255,.06);
  font-size: 13px; font-weight: 600;
  transition: background .18s, transform .18s var(--ease-fluid);
}
.library-create-btn:hover { background: rgba(255,255,255,.10); }
.library-create-btn:active { transform: scale(.985); }
.library-create-btn svg { width: 16px; height: 16px; }
.library-add-btn {
  display: grid; place-items: center;
  width: 28px; height: 28px;
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  background: rgba(255,255,255,.05);
}
.library-add-btn:hover { color: var(--text-primary); background: rgba(255,255,255,.10); }
.library-add-btn svg { width: 14px; height: 14px; }

/* === Story / Chapter Lists === */
.story-list, .chapter-list { display: grid; gap: 2px; }
.branch-list { display: grid; gap: 3px; }

.story-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border-radius: var(--radius-sm);
}
.story-row:hover { background: var(--glass-bg); }
.story-row .story-item { min-width: 0; }
.story-row .story-item:hover { background: transparent; }
.story-row .story-item.active {
  color: var(--text-primary);
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
.story-row:has(.story-item.active) {
  color: var(--text-primary);
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.10);
  box-shadow: inset 0 1px rgba(255,255,255,.06);
}
.story-row-actions {
  display: flex; align-items: center;
  padding-right: 6px;
  opacity: 0;
  transition: opacity .15s;
}
.story-row:hover .story-row-actions,
.story-row:focus-within .story-row-actions { opacity: 1; }
.story-row.renaming .story-item,
.chapter-row.renaming .chapter-item { display: none; }
.story-row.renaming .story-row-actions,
.chapter-row.renaming .chapter-row-actions { opacity: 1; }
.inline-title-input {
  width: calc(100% - 8px);
  min-width: 0;
  height: 36px;
  margin: 4px;
  padding: 0 10px;
  border: 1px solid rgba(0,122,255,.34);
  border-radius: var(--radius-sm);
  outline: none;
  color: var(--text-primary);
  background: var(--glass-bg-thick);
  box-shadow: 0 0 0 3px rgba(0,122,255,.1), inset 0 1px rgba(255,255,255,.12);
  font: inherit;
  font-weight: 650;
}
.story-mini-btn {
  display: grid; place-items: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  color: var(--text-tertiary);
  background: transparent;
}
.story-mini-btn:hover { color: var(--red); background: var(--red-glass); }
.story-mini-btn svg { width: 14px; height: 14px; }

.story-item, .chapter-item, .branch-item {
  width: 100%; display: grid; gap: 2px; padding: 10px 12px;
  border-radius: var(--radius-sm); text-align: left;
  color: var(--text-secondary); background: transparent;
  border: 1px solid transparent;
  transition: transform .18s var(--ease-fluid), background .15s, border-color .15s;
}
.chapter-item {
  min-height: 42px;
  gap: 0;
  padding: 4px 10px;
}
.chapter-item strong { line-height: 1.25; }
.chapter-item small { line-height: 1.2; }
.story-item:hover, .chapter-item:hover {
  background: var(--glass-bg); color: var(--text-primary);
}
.branch-item:hover {
  background: rgba(255,255,255,.06); color: var(--text-primary);
}
.story-item:active, .chapter-item:active, .branch-item:active { transform: scale(0.98); }
.story-item.active {
  color: #fff;
  background: rgba(255,255,255,.045);
  border-color: transparent;
  box-shadow: none;
}
.story-item strong, .chapter-item strong {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; font-weight: 500;
}
.story-item small, .chapter-item small {
  font-size: 11px; color: var(--text-tertiary);
}
.story-item.active small, .chapter-item.active small {
  color: var(--text-secondary);
}

.chapter-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  align-items: center; min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition: background .18s, border-color .18s, box-shadow .18s, transform .18s var(--ease-fluid);
}
.chapter-row:hover { background: var(--glass-bg); }
.chapter-row:active { transform: scale(.985); }
.chapter-row .chapter-item { min-width: 0; }
.chapter-row .chapter-item:hover { background: transparent; }
.chapter-row .chapter-item.active {
  color: var(--text-primary);
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
.chapter-row:has(.chapter-item.active) {
  color: var(--text-primary);
  background: rgba(255,255,255,.07);
  border-color: rgba(255,255,255,.10);
  box-shadow: inset 0 1px rgba(255,255,255,.06);
}
.chapter-row-actions {
  display: flex; align-items: center; gap: 1px;
  padding-right: 6px;
  opacity: 0; transition: opacity .15s;
}
.chapter-row:hover .chapter-row-actions, .chapter-row:focus-within .chapter-row-actions { opacity: 1; }
.chapter-row:has([data-confirming="true"]) .chapter-row-actions { opacity: 1; }

.chapter-mini-btn {
  display: grid; place-items: center; width: 28px; height: 28px;
  border-radius: var(--radius-pill);
  color: var(--text-tertiary); background: transparent;
  transition: width .36s var(--ease-fluid), padding .36s var(--ease-fluid),
    background .24s, color .24s, transform .24s var(--ease-fluid);
}
.chapter-mini-btn:hover { color: var(--text-primary); background: var(--glass-bg); }
.chapter-mini-btn.danger:hover { color: var(--red); background: var(--red-glass); }
.chapter-mini-btn svg { width: 14px; height: 14px; }

.library-footer {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  flex-shrink: 0;
  margin-top: 0; padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.06);
}

.library-tool-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: transparent;
  font-size: 12px;
  transition: background .16s, color .16s;
}
.library-tool-btn:hover { color: var(--text-primary); background: rgba(255,255,255,.07); }
.library-tool-btn svg { width: 14px; height: 14px; }
.install-app-entry {
  grid-column: 1 / -1;
  min-height: 36px;
  color: var(--text-primary);
  background: rgba(255,255,255,.055);
  border: 1px solid rgba(255,255,255,.07);
}
.install-app-entry[hidden] { display: none; }
[data-theme="light"] .install-app-entry {
  color: rgba(0,0,0,.76);
  background: rgba(60,60,67,.055);
  border-color: rgba(60,60,67,.08);
}

[data-theme="light"] .library-panel {
  background: rgba(250,250,252,.94);
  border-color: rgba(255,255,255,.78);
  box-shadow:
    0 18px 48px rgba(15,23,42,.10),
    0 4px 14px rgba(15,23,42,.05),
    inset 0 1px 0 rgba(255,255,255,.78);
}
[data-theme="light"] .library-panel::before,
[data-theme="light"] .controls-panel::before {
  box-shadow: var(--glass-edge-shadow);
}
[data-theme="light"] .library-create-btn {
  color: rgba(0,0,0,.82);
  background: rgba(60,60,67,.055);
  border-color: rgba(60,60,67,.08);
  box-shadow: inset 0 1px rgba(255,255,255,.7);
}
[data-theme="light"] .library-create-btn:hover,
[data-theme="light"] .library-tool-btn:hover,
[data-theme="light"] .library-add-btn:hover {
  background: rgba(60,60,67,.10);
}

[data-theme="light"] .story-row:has(.story-item.active) {
  color: var(--text-primary);
  background: rgba(255,255,255,.42);
  border-color: rgba(255,255,255,.82);
  box-shadow: 0 10px 28px rgba(70,76,88,.08), inset 0 1px rgba(255,255,255,.9);
}
[data-theme="light"] .story-row .story-item.active {
  color: var(--text-primary);
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
[data-theme="light"] .story-row .story-item.active small {
  color: var(--text-secondary);
}
[data-theme="light"] .chapter-row:has(.chapter-item.active) {
  color: var(--text-primary);
  background: rgba(255,255,255,.42);
  border-color: rgba(255,255,255,.82);
  box-shadow: 0 10px 28px rgba(70,76,88,.08), inset 0 1px rgba(255,255,255,.9);
}
[data-theme="light"] .chapter-row:has(.chapter-item.active) small {
  color: var(--text-secondary);
}
.settings-entry {
  grid-column: 1 / -1; display: flex; align-items: center;
  justify-content: center; gap: 8px;
  min-height: 36px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.045);
  border-color: rgba(255,255,255,.06);
}
.settings-entry svg { width: 15px; height: 15px; }

.welcome-mode .library-panel-body {
  display: none;
}
.welcome-mode .library-close-btn { display: none; }

/* === Controls Panel === */
.controls-panel {
  position: fixed; z-index: 100;
  top: calc(max(12px, env(safe-area-inset-top)) + 58px);
  right: 10px;
  bottom: 10px;
  width: min(92vw, 320px);
  display: flex; flex-direction: column;
  padding: 20px 0 0;
  border-radius: var(--radius-xl);
  background:
    linear-gradient(180deg, rgba(255,255,255,.03), transparent),
    rgba(12,12,15,.92);
  box-shadow:
    0 24px 80px rgba(0,0,0,.55),
    0 6px 20px rgba(0,0,0,.24),
    inset 0 1px 0 rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.08);
  transform: translateX(calc(100% + 24px)); opacity: 0;
  pointer-events: none;
  overflow: hidden;
  isolation: isolate;
  transition: transform .35s var(--ease-fluid), opacity .25s ease;
}
.controls-panel.open {
  transform: none; opacity: 1; pointer-events: auto;
}

.restoring-panels .library-panel,
.restoring-panels .controls-panel {
  transition: none !important;
}

.panel-title-row {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0; padding: 0 20px 16px;
}
.panel-title-row > div { display: grid; gap: 2px; flex: 1; }
.panel-title-row strong { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }

.controls-panel,
.controls-panel * { user-select: none; }
.controls-panel input,
.controls-panel textarea { user-select: auto; }

.controls-panel-body {
  overflow-y: auto; overscroll-behavior: contain;
  min-height: 0; flex: 1;
  padding: 0 20px 24px;
  scrollbar-width: thin;
}

/* === Controls Panel Layout — iOS flat list === */
.control-card { margin-bottom: 20px; }
.memory-card { margin-bottom: 12px; }

/* Section header — same hierarchy across panel */
.control-card .section-label {
  margin: 0 0 12px;
  color: var(--text-primary);
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.02em;
}

/* Preset grid */
.preset-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.preset-grid button {
  min-height: 38px; padding: 8px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: rgba(255,255,255,.055);
  border: 1px solid rgba(255,255,255,.06);
  font-size: 12px; font-weight: 500;
  transition: all .15s var(--ease-out);
  line-height: 1.3;
}
.preset-grid button:hover {
  background: rgba(255,255,255,.10); color: var(--text-primary);
  border-color: rgba(255,255,255,.12);
}
.preset-grid button:active { transform: scale(0.96); }
[data-theme="light"] .preset-grid button {
  background: rgba(60,60,67,.07);
  border-color: rgba(60,60,67,.10);
}
[data-theme="light"] .preset-grid button:hover {
  background: rgba(60,60,67,.12);
}

/* Settings rows — label left, control right */
.settings-grid { display: grid; gap: 3px; }
.settings-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  align-items: center;
  gap: 0;
  min-height: 40px;
}
.settings-label {
  color: var(--text-primary); font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden;
}
.settings-row select {
  width: 100%; min-width: 0;
  color: var(--text-secondary); font-size: 13px; font-weight: 400;
  text-align: center;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  line-height: 1.4;
}
.settings-row input {
  width: 100%; min-width: 0;
  color: var(--text-secondary); font-size: 13px; font-weight: 400;
  text-align: right;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  line-height: 1.4;
}
.settings-row select option { background: var(--bg-elevated); color: var(--text-primary); }
.settings-row input::placeholder { color: var(--text-quaternary); }
#playerRoleInput { text-align: center; }
.settings-readonly {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 34px;
  padding: 5px 10px;
  border: 1px solid rgba(255,255,255,.045);
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  background: rgba(255,255,255,.025);
  font-size: 13px;
  cursor: default;
}
[data-theme="light"] .settings-readonly {
  color: rgba(60,60,67,.42);
  background: rgba(60,60,67,.035);
  border-color: rgba(60,60,67,.07);
}
[data-theme="light"] .settings-row select,
[data-theme="light"] .settings-row input {
  background: rgba(60,60,67,.06);
  border-color: rgba(60,60,67,.18);
}

/* Textarea group — full-width block below inline rows */
.settings-textarea-group {
  display: flex; flex-direction: column; gap: 6px;
  margin-top: 4px;
}
.settings-textarea-group .settings-label {
  color: var(--text-primary); font-size: 13px; font-weight: 500;
}
.settings-textarea-group textarea {
  width: 100%; min-height: 72px;
  color: var(--text-secondary); font-size: 13px; font-weight: 400;
  text-align: left;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  line-height: 1.5;
  resize: vertical;
}
#styleInput { min-height: 82px; }
.settings-textarea-group textarea::placeholder { color: var(--text-quaternary); }
[data-theme="light"] .settings-textarea-group textarea {
  background: rgba(60,60,67,.06);
  border-color: rgba(60,60,67,.18);
}

.settings-grid .switch-label {
  justify-self: end;
  gap: 10px;
  color: var(--text-primary); font-size: 13px; font-weight: 500;
}

/* Memory details — flat, no card background */
.memory-card {
  overflow: hidden;
  padding: 0 0 2px;
  border-bottom: 1px solid var(--separator-light);
}
.memory-card:last-child { border-bottom: none; }
.memory-card summary {
  padding: 12px 0; cursor: pointer;
  font-size: 13px; font-weight: 600; list-style: none;
  color: var(--text-primary);
  letter-spacing: 0.01em;
  display: flex; align-items: center;
  transition: color .15s;
}
.memory-card summary:hover { color: var(--accent-text); }
.memory-card summary::-webkit-details-marker { display: none; }
.memory-card summary::before {
  content: "";
  display: inline-block; width: 6px; height: 6px;
  margin-right: 10px;
  border-right: 1.5px solid var(--text-tertiary);
  border-bottom: 1.5px solid var(--text-tertiary);
  transform: rotate(-45deg);
  transition: transform .25s var(--ease-fluid);
}
.memory-card[open] summary::before { transform: rotate(45deg); }
.memory-toolbar {
  display: flex; justify-content: flex-end; padding: 0 0 6px;
}
.memory-toolbar button {
  color: var(--text-secondary); background: transparent;
  font-size: 12px; font-weight: 500; padding: 4px 10px;
  border-radius: var(--radius-pill);
  transition: all .12s;
}
.memory-toolbar button:hover { background: rgba(255,255,255,.08); color: var(--text-primary); }
.memory-content {
  padding: 0 0 12px;
  color: var(--text-secondary); font-size: 12px;
  line-height: 1.7; white-space: pre-wrap;
}
