/* ═══════════════════════════════════════════
   RESET & CUSTOM PROPERTIES
═══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #12121f;
  --bg2:        #1a1a2e;
  --bg3:        #222238;
  --bg4:        #2a2a44;
  --bg-hover:   #30305a;
  --toolbar-bg: #0d0d1a;

  --border:     rgba(255,255,255,0.07);
  --border2:    rgba(255,255,255,0.13);

  --text:       #e2e2f0;
  --text2:      #9090b8;
  --text3:      #5a5a80;

  --accent:     #4a9eff;
  --accent-h:   #6ab4ff;
  --danger:     #e74c3c;
  --danger-h:   #ff6b5b;
  --success:    #2ecc71;
  --warn:       #f39c12;

  --toolbar-h:  46px;
  --sidebar-l:  196px;
  --sidebar-r:  224px;
  --radius:     6px;
  --radius-sm:  4px;
}

/* ═══════════════════════════════════════════
   BASE
═══════════════════════════════════════════ */
html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════ */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ═══════════════════════════════════════════
   TOOLBAR
═══════════════════════════════════════════ */
#toolbar {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0 10px;
  height: var(--toolbar-h);
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
  user-select: none;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 3px;
}

.toolbar-group.ml-auto { margin-left: auto; }

.toolbar-sep {
  width: 1px;
  height: 22px;
  background: var(--border2);
  margin: 0 4px;
  flex-shrink: 0;
}

.toolbar-label {
  font-size: 11px;
  color: var(--text3);
  white-space: nowrap;
}

.app-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: -0.2px;
}

#zoom-label {
  font-size: 11px;
  color: var(--text2);
  min-width: 38px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════ */
button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  user-select: none;
}

button:hover  { background: var(--bg-hover); border-color: var(--border2); }
button:active { transform: translateY(1px); }

button.icon-btn { padding: 5px 7px; }

button.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.btn-accent:hover { background: var(--accent-h); border-color: var(--accent-h); }

button.btn-danger, button.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
button.btn-danger:hover, button.danger:hover { background: var(--danger); color: #fff; }

button.secondary {
  background: transparent;
  border-color: transparent;
  color: var(--text2);
}
button.secondary:hover { background: var(--bg4); border-color: var(--border2); }

button.toggle-btn { color: var(--text2); }
button.toggle-btn.active {
  background: rgba(74, 158, 255, 0.15);
  border-color: rgba(74, 158, 255, 0.4);
  color: var(--accent);
}

button.btn-small { padding: 3px 8px; font-size: 11px; }

button.full-btn {
  width: 100%;
  justify-content: center;
  padding: 7px;
  margin-bottom: 6px;
}

.hidden { display: none !important; }

/* ═══════════════════════════════════════════
   SELECT
═══════════════════════════════════════════ */
select {
  padding: 5px 8px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  max-width: 140px;
}
select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ═══════════════════════════════════════════
   INPUTS
═══════════════════════════════════════════ */
input[type="text"],
input[type="number"] {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
  font-family: inherit;
  width: 100%;
}
input[type="text"]:focus,
input[type="number"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}
input[type="text"].error { border-color: var(--danger); }

input[type="color"] {
  width: 32px;
  height: 28px;
  padding: 2px 3px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
}

input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ═══════════════════════════════════════════
   MAIN BODY
═══════════════════════════════════════════ */
#main-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ═══════════════════════════════════════════
   SIDEBARS
═══════════════════════════════════════════ */
aside {
  background: var(--bg2);
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

#left-sidebar {
  width: var(--sidebar-l);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: hidden;
}

#right-sidebar {
  width: var(--sidebar-r);
  border-left: 1px solid var(--border);
}

.sidebar-section {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.sidebar-header > span {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text3);
}

/* ═══════════════════════════════════════════
   LEFT SIDEBAR TABS
═══════════════════════════════════════════ */
.left-tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.left-tab {
  flex: 1;
  padding: 7px 4px;
  font-size: 12px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  color: var(--text2);
  transition: color 0.12s, border-color 0.12s;
}
.left-tab:hover { color: var(--text); }
.left-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.left-tab-pane {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.left-tab-pane.hidden { display: none; }

/* ═══════════════════════════════════════════
   SCENE LIST
═══════════════════════════════════════════ */
#scene-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.scene-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}
.scene-item:hover { background: var(--bg4); }
.scene-item.selected {
  background: rgba(74,158,255,0.1);
  border-color: rgba(74,158,255,0.35);
}
.scene-num {
  font-size: 11px;
  color: var(--text3);
  min-width: 16px;
  text-align: right;
  flex-shrink: 0;
}
.scene-name {
  flex: 1;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#scene-edit-section .scene-edit-actions {
  gap: 6px;
}
#scene-edit-section .scene-edit-actions .btn-small {
  flex: 1;
}

/* ═══════════════════════════════════════════
   PERFORMER LIST
═══════════════════════════════════════════ */
#performer-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.performer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}
.performer-item:hover { background: var(--bg4); }
.performer-item.selected {
  background: rgba(74,158,255,0.1);
  border-color: rgba(74,158,255,0.35);
}

.performer-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,0.3);
}
.performer-dot.square { border-radius: 2px; }

.performer-name {
  flex: 1;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.performer-type-badge {
  font-size: 10px;
  color: var(--text3);
  font-weight: 600;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════
   CENTER COLUMN  (stage + notes, between sidebars)
═══════════════════════════════════════════ */
#center-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ═══════════════════════════════════════════
   STAGE AREA
═══════════════════════════════════════════ */
#stage-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  position: relative;
}

#stage-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  cursor: default;
}

#stage-svg {
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  -webkit-user-select: none;
}

#stage-coords {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.55);
  color: rgba(255,255,255,0.5);
  font-size: 11px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  padding: 2px 10px;
  border-radius: 10px;
  pointer-events: none;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════
   SIDEBAR FORM ELEMENTS
═══════════════════════════════════════════ */
.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}
.field-row:last-child { margin-bottom: 0; }

.field-row > label {
  font-size: 11px;
  color: var(--text2);
  width: 48px;
  flex-shrink: 0;
}

.field-inp-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
.field-inp-wrap input { flex: 1; min-width: 0; }

.unit {
  font-size: 11px;
  color: var(--text3);
  flex-shrink: 0;
}

.flex-inp { flex: 1; }

.hint-text {
  font-size: 11px;
  color: var(--text2);
  line-height: 1.5;
}

/* ═══ NOTES PANEL (PowerPoint-style bottom bar) ═══ */
#notes-panel {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 120px;
  min-height: 32px;
  background: var(--bg2);
  border-top: 1px solid var(--border2);
  position: relative;
  overflow: hidden;
}

#notes-panel.collapsed {
  height: 32px !important;
}
#notes-panel.collapsed #scene-note { display: none; }
#notes-panel.collapsed #btn-notes-toggle { transform: rotate(-90deg); }

#notes-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  cursor: ns-resize;
  z-index: 10;
  background: transparent;
}
#notes-resize-handle:hover { background: var(--accent); opacity: 0.4; }

#notes-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: 32px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  user-select: none;
}

#notes-icon { font-size: 13px; }

#notes-scene-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#notes-label {
  font-size: 11px;
  color: var(--text3);
}

#btn-notes-toggle {
  margin-left: auto;
  background: transparent;
  border: none;
  color: var(--text2);
  padding: 2px 6px;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.15s;
}
#btn-notes-toggle:hover { color: var(--text); background: transparent; }

#scene-note {
  flex: 1;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  line-height: 1.6;
  padding: 8px 16px;
  resize: none;
  outline: none;
}
#scene-note::placeholder { color: var(--text3); font-style: italic; }

/* ═══════════════════════════════════════════
   MODAL
═══════════════════════════════════════════ */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  backdrop-filter: blur(6px);
}

#modal-box {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 24px;
  width: 340px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}

#modal-box h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 18px;
  color: var(--text);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

#color-presets {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
}

.color-preset {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  flex-shrink: 0;
  transition: transform 0.1s, border-color 0.1s;
}
.color-preset:hover {
  transform: scale(1.25);
  border-color: rgba(255,255,255,0.7);
}

/* ═══════════════════════════════════════════
   IMPORT / EXPORT TOAST
═══════════════════════════════════════════ */
.io-toast {
  position: absolute;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
  animation: toast-in 0.2s ease, toast-out 0.3s ease 2.5s forwards;
}
.io-toast-ok {
  background: rgba(46, 204, 113, 0.2);
  border: 1px solid rgba(46, 204, 113, 0.5);
  color: #2ecc71;
}
@keyframes toast-in  { from { opacity: 0; transform: translateX(-50%) translateY(6px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; } }

/* ═══════════════════════════════════════════
   GITHUB LINK
═══════════════════════════════════════════ */
.toolbar-gh-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 28px;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text2);
  text-decoration: none;
  background: var(--bg3);
  transition: color 0.12s, background 0.12s, border-color 0.12s;
  flex-shrink: 0;
}
.toolbar-gh-link:hover {
  color: var(--text);
  background: var(--bg-hover);
  border-color: var(--border2);
}

/* ═══════════════════════════════════════════
   MUSIC PANEL
═══════════════════════════════════════════ */
#music-panel {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 6px 10px 5px;
  gap: 5px;
  user-select: none;
}

#music-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.music-filename {
  flex: 1;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 11px;
}

.music-play-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  background: var(--bg4);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}
.music-play-btn:hover:not(:disabled) { background: var(--bg-hover); }
.music-play-btn:disabled { opacity: 0.4; cursor: default; }

.music-time {
  color: var(--text2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 72px;
  text-align: right;
}

/* Timeline track */
#music-timeline-wrap {
  padding: 2px 0;
}

#music-timeline {
  position: relative;
  height: 40px;
  background: rgba(255,255,255,0.04);
  border-radius: 3px;
  cursor: pointer;
  overflow: hidden;
}

#music-waveform {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  border-radius: 3px;
}

#music-progress-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0;
  background: var(--accent);
  border-radius: 3px;
  opacity: 0.20;
  pointer-events: none;
}

#music-thumb {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 12px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  pointer-events: none;
  left: 0;
  box-shadow: 0 1px 6px rgba(0,0,0,0.6);
  z-index: 2;
}

/* Scene markers on the timeline */
#music-markers {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.music-scene-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255,255,255,0.45);
  transform: translateX(-50%);
}

.music-scene-label {
  position: absolute;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--text2);
  white-space: nowrap;
  pointer-events: none;
  background: var(--bg2);
  padding: 1px 3px;
  border-radius: 2px;
}

/* ═══════════════════════════════════════════
   SHARE / PREVIEW BANNER
═══════════════════════════════════════════ */
#share-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  font-size: 13px;
  background: #1a3a5c;
  color: #c8e0f8;
  border-bottom: 1px solid #2a5a8c;
  flex-shrink: 0;
  z-index: 10;
}
#share-banner.hidden { display: none; }
#share-banner.banner-error   { background: #4a1a1a; color: #f8c8c8; border-color: #7a3a3a; }
#share-banner.banner-ok      { background: #1a4a1a; color: #c8f8c8; border-color: #3a7a3a; }
#share-banner.banner-loading { background: #2a2a3a; color: #c8c8e8; border-color: #4a4a6a; }

#share-banner .banner-icon { font-size: 15px; flex-shrink: 0; }
#share-banner .banner-text { flex: 1; }
#share-banner .banner-actions { display: flex; gap: 6px; margin-left: auto; flex-shrink: 0; }

.preview-save-btn, .preview-exit-btn {
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.12);
  color: inherit;
  font-size: 12px;
  cursor: pointer;
}
.preview-save-btn:hover, .preview-exit-btn:hover {
  background: rgba(255,255,255,0.22);
}

/* ═══════════════════════════════════════════
   SCROLLBARS
═══════════════════════════════════════════ */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }

/* ═══════════════════════════════════════════
   RESPONSIVE — TABLET / MOBILE
═══════════════════════════════════════════ */
@media (max-width: 900px) {
  :root {
    --sidebar-l: 160px;
    --sidebar-r: 180px;
  }
}

@media (max-width: 680px) {
  #right-sidebar { display: none; }
  :root { --sidebar-l: 140px; }
  #toolbar { gap: 2px; padding: 0 6px; }
}

@media (max-width: 480px) {
  #left-sidebar { display: none; }
  #toolbar .toolbar-label, #toolbar .app-title { display: none; }
}
