:root {
  --sidebar-width: 220px;
  --topbar-h: 42px;
  --browser-h: 370px;
  --status-h: auto;
  --font-ui: "Lucida Grande", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font-ui);
  font-size: 13px;
  overflow: hidden;
}

/* == App shell: sidebar + main on top, status bar pinned at bottom == */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: 1fr auto;
  height: 100vh;
}

.statusbar {
  grid-column: 1 / -1;
}

/* == Sidebar == */
.sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 160px;
  max-width: 450px;
  overflow: hidden;
}

.sidebar-resizer {
  position: absolute;
  right: 0;
  top: 0;
  width: 4px;
  height: 100%;
  cursor: ew-resize;
  z-index: 20;
}

.sidebar-section {
  border-bottom: 1px solid;
  min-height: 60px;
  display: flex;
  flex-direction: column;
}

.sidebar-section header {
  padding: 6px 10px;
  letter-spacing: 0.02em;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.rotunes-header {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.03em;
  padding: 8px 10px 4px;
}

.tree {
  overflow: auto;
  padding: 4px 8px 8px;
}

.tree-item {
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
}

.tree-children {
  margin-left: 14px;
}

.flex-grow {
  flex: 1;
  min-height: 100px;
}

.sidebar-library {
  min-height: 40px;
  max-height: 200px;
}

.tree-group-header {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 2px;
}

.tree-group-header .disclosure {
  display: inline-block;
  width: 14px;
  font-size: 11px;
}

.tree-children.collapsed {
  display: none;
}

/* +New button (playlists) - RoWeb light-blue style */
.new-btn {
  margin-left: auto;
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 5px;
  border: 1px solid #3a7bd5;
  background: #2563a8;
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}

.new-btn:hover {
  background: #3a7bd5;
}

.empty-hint {
  opacity: 0.5;
  font-style: italic;
  cursor: default;
}

/* == Art / Lyrics panel (A-or-B toggle) == */
.art-lyrics-panel {
  height: 260px;
  flex-shrink: 0;
}

.art-lyrics-panel header {
  display: flex;
  gap: 0;
  padding: 0 !important;
  justify-content: center;
}

.panel-toggle {
  flex: 0 1 auto;
  padding: 6px 18px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
  border: none;
  cursor: pointer;
  background: transparent;
  opacity: 0.5;
  transition: opacity 0.15s;
}

.panel-toggle.active {
  opacity: 1;
}

.pane {
  display: none;
  flex: 1;
  min-height: 0;
}

.pane.active {
  display: flex;
}

#albumArtPane {
  padding: 8px;
  align-items: center;
  justify-content: center;
}

#albumArt {
  width: 100%;
  max-height: 185px;
  object-fit: cover;
  border-radius: 6px;
}

#lyricsPane {
  padding: 8px;
}

#lyricsText {
  width: 100%;
  height: 100%;
  resize: none;
}

.queue-list {
  list-style: none;
  margin: 0;
  padding: 4px 8px;
  overflow-y: auto;
  height: 100%;
  font-size: 12px;
}

.queue-list li {
  padding: 3px 4px;
  border-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.queue-list li.queue-current {
  font-weight: 700;
}

/* == Queue wrap (main area, hidden by default) == */
.queue-wrap {
  overflow: auto;
  min-height: 0;
  padding: 0;
}

.queue-wrap header {
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

/* == Main area == */
.main-area {
  display: grid;
  grid-template-rows: var(--topbar-h) var(--browser-h) 5px 1fr;
  min-width: 0;
  overflow: hidden;
}

/* == Topbar: single line with 3 sections == */
.topbar {
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 10px;
  min-height: var(--topbar-h);
  max-height: var(--topbar-h);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 420px;
  margin: 0 auto;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* RoWeb-style buttons (dark blue + white text + lighter blue border) */
.roweb-btn {
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid #3a7bd5;
  background: #1a3a5c;
  color: #e6edf3;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.roweb-btn:hover {
  background: #244a6e;
}

.roweb-btn.active {
  background: #3a7bd5;
  color: #fff;
  border-color: #58a6ff;
}

.theme-toggle-btn {
  padding: 5px 8px;
  font-size: 14px;
}

.search-capsule {
  display: flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  height: 30px;
  width: 100%;
}

.search-icon {
  font-size: 13px;
  margin-right: 4px;
}

.search-capsule input {
  flex: 1;
  border: 0;
  background: transparent;
  outline: 0;
}

/* == Browser == */
.browser-wrap {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  position: relative;
}

.three-browser {
  height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
}

.browser-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid;
}

.browser-col:last-child {
  border-right: 0;
}

.browser-col header {
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.browser-col ul {
  list-style: none;
  margin: 0;
  padding: 4px;
  overflow-y: auto;
  height: 0;
  flex: 1;
}

.browser-col li {
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.browser-resizer {
  height: 5px;
  cursor: ns-resize;
  flex-shrink: 0;
}

.browser-col.drag-over {
  outline: 2px solid var(--accent-b);
  outline-offset: -2px;
}

.browser-col[draggable="true"] header {
  cursor: grab;
}

.browser-col[draggable="true"] header:active {
  cursor: grabbing;
}

.browser-col.col-hidden {
  display: none;
}

/* Column resizer between browser columns */
.col-resizer {
  width: 5px;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  z-index: 5;
  position: relative;
}

.col-resizer:hover,
.col-resizer.active {
  background: #3a7bd5;
}

/* Browser column header context menu */
.col-ctx-menu {
  position: fixed;
  z-index: 200;
  border-radius: 6px;
  padding: 4px 0;
  min-width: 160px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.col-ctx-item {
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.col-ctx-item:hover {
  background: rgba(58, 123, 213, 0.3);
}

.col-ctx-check {
  width: 14px;
  text-align: center;
  font-size: 11px;
}

/* == Song list == */
.songlist-wrap {
  overflow: auto;
  min-height: 0;
}

#songTable {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

#songTable th,
#songTable td {
  border-right: 1px solid;
  padding: 5px 6px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

#songTable th {
  position: sticky;
  top: 0;
  z-index: 5;
  user-select: none;
}

#songTable th .resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
}

/* == Status bar / Footer (pinned bottom, full width) == */
.statusbar {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr auto;
  align-items: center;
  padding: 6px 12px;
  font-size: 12px;
  grid-column: 1 / -1;
  padding-top: 6px;
  padding-bottom: 6px;
}

.status-left {
  padding-left: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  align-self: center;
}

.status-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.now-playing-info {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.playlist-label {
  font-weight: 600;
  margin-right: 4px;
}

.playlist-label:empty {
  display: none;
}

.now-title {
  font-weight: 700;
}

.now-meta {
  opacity: 0.8;
}

.now-sep {
  opacity: 0.5;
}

/* Transport row: circular buttons */
.transport-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.transport-btn {
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, transform 0.1s;
}

.transport-btn:active {
  transform: scale(0.92);
}

/* Play button: largest, circular */
.transport-btn.play-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 18px;
}

/* Rewind / Forward: medium, circular */
.transport-btn.rw-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 14px;
}

/* Skip buttons: smallest, circular */
.transport-btn.skip-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 12px;
}

/* Replay / Shuffle: square icons */
.transport-btn.square-btn {
  width: 28px;
  height: 28px;
  border-radius: 5px;
  font-size: 14px;
}

.transport-btn.square-btn.active {
  color: #58a6ff;
}

/* Seek row */
.seek-row {
  display: grid;
  grid-template-columns: 38px 1fr 38px;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 460px;
  font-size: 11px;
}

#seekBar {
  width: 100%;
}

/* Volume (status right) */
.status-right {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}

.vol-icon {
  font-size: 14px;
}

#statusRight #volumeSlider,
.status-right #volumeSlider {
  width: 90px;
}

/* == Overlay / Login == */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay.active {
  display: flex;
}

.login-card {
  width: 360px;
  border-radius: 10px;
  padding: 20px;
}

.login-card form {
  display: grid;
  gap: 10px;
}

.login-card label {
  display: grid;
  gap: 4px;
}

.error {
  min-height: 18px;
  font-size: 12px;
}

.hidden {
  display: none !important;
}

.dirty-indicator {
  font-size: 10px;
  margin-left: 6px;
}

/* == Smart panel == */
.smart-panel {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
}

.smart-col {
  border: 1px solid;
  border-radius: 8px;
  padding: 6px;
}

.smart-col ul {
  margin: 0;
  padding: 6px 6px 6px 18px;
}

.smart-controls {
  grid-column: span 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* == Modals == */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 130;
}

.modal-card {
  width: min(840px, 90vw);
  height: min(600px, 90vh);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-card > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
}

.modal-body {
  padding: 10px;
  overflow: auto;
  flex: 1;
}

.wiki-card {
  width: min(920px, 94vw);
}

.wiki-body {
  padding: 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#wikiEditor {
  width: 100%;
  flex: 1;
  resize: none;
}

.wiki-footer {
  padding: 10px;
}

#wikiChatInput {
  width: 100%;
}

/* == Responsive == */
@media (max-width: 1100px) {
  :root {
    --topbar-h: 42px;
  }

  .app-shell {
    grid-template-columns: 180px 1fr;
  }
}
