:root {
  --bg: #f2f2f2;
  --sidebar-width: 360px;
  --sidebar-bg: #ececec;
  --panel-bg: #ffffff;
  --soft-box: #efefef;
  --border: #d0d0d0;
  --heading: #505050;
  --link: #0b63d8;
  --link-hover: #084da6;
  --text: #444444;
  --muted: #707070;
  --done-bg: #dff1dd;
  --done-border: #8db58a;
  --progress-bg: #dddddd;
  --progress-fill: #9aa39f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

body {
  min-height: 100vh;
  overflow: hidden;
}

body.auth-locked {
  overflow: hidden;
}

body.auth-locked .layout {
  visibility: hidden;
}

body.sidebar-hidden .sidebar {
  width: 0;
  flex-basis: 0;
  padding-left: 0;
  padding-right: 0;
  overflow: hidden;
  border-right: 0;
}

.layout {
  display: flex;
  height: 100vh;
  position: relative;
}

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  height: 100vh;
  overflow-y: auto;
  transition: width 0.2s ease, flex-basis 0.2s ease, padding 0.2s ease;
}

.playlist-link,
.home-book-link,
.home-chapter-card {
  color: var(--link);
  text-decoration: none;
}

.playlist-link:hover,
.home-book-link:hover,
.home-chapter-card:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.divider-toggle {
  position: absolute;
  top: 18px;
  left: calc(var(--sidebar-width) + 1px);
  z-index: 5;
  width: 34px;
  height: 34px;
  transform: translateX(-50%);
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--heading);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: left 0.2s ease;
}

body.sidebar-hidden .divider-toggle {
  left: 1px;
}

.divider-toggle-icon {
  font-size: 15px;
  line-height: 1;
}

.nav-book,
.nav-chapter,
.nav-note-card,
.home-book-card {
  border: 1px solid var(--border);
  background: var(--soft-box);
}

.nav-book {
  padding: 0;
}

.nav-book[open],
.nav-chapter[open] {
  background: #e8e8e8;
}

.nav-book-summary,
.nav-chapter-summary {
  list-style: none;
  cursor: pointer;
  padding: 12px;
}

.nav-book-summary::-webkit-details-marker,
.nav-chapter-summary::-webkit-details-marker {
  display: none;
}

.nav-book-summary-row,
.nav-chapter-summary-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.nav-book-name,
.nav-chapter-title {
  font-weight: 700;
  line-height: 1.3;
}

.nav-book-name.active,
.nav-chapter-title.active {
  color: var(--heading);
}

.nav-book-body,
.nav-chapter-body {
  border-top: 1px solid var(--border);
  padding: 10px 12px 12px;
}

.nav-chapter-list,
.nav-video-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.home-chapter-card {
  display: block;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  text-decoration: none;
  padding: 12px;
}

.home-chapter-card:hover {
  background: #e7e7e7;
  text-decoration: none;
}

.chapter-progress-meta,
.playlist-progress,
.player-subtitle,
.save-note,
.player-book-label,
.video-row-meta,
.helper-text {
  color: var(--muted);
}

.chapter-progress-meta,
.playlist-progress,
.video-row-meta,
.helper-text {
  font-size: 13px;
  line-height: 1.35;
}

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--progress-bg);
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--progress-fill);
}

.nav-video-group-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-video-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
}

.nav-video-row.active {
  background: #e7e7e7;
  border-color: #aaaaaa;
}

.nav-video-checkbox {
  width: 18px;
  height: 18px;
  margin-top: 4px;
  flex-shrink: 0;
}

.nav-video-button {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  color: inherit;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font: inherit;
}

.nav-video-thumb-wrap {
  position: relative;
  width: 86px;
  height: 48px;
  flex-shrink: 0;
  display: inline-block;
}

.nav-video-thumb {
  width: 86px;
  height: 48px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: #dddddd;
  display: block;
}

.nav-video-duration {
  position: absolute;
  right: 4px;
  bottom: 4px;
  background: rgba(0, 0, 0, 0.8);
  color: #ffffff;
  font-size: 11px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 2px;
  pointer-events: none;
}

.nav-video-text {
  min-width: 0;
}

.nav-video-title {
  font-size: 14px;
  line-height: 1.35;
  display: block;
}

.nav-note-card {
  padding: 10px 12px;
}

.content {
  flex: 1;
  padding: 24px;
  height: 100vh;
  overflow-y: auto;
}

.content-card {
  max-width: 1400px;
}

.page-title {
  margin: 0 0 12px;
  color: var(--heading);
  font-size: 24px;
  font-weight: 700;
}

.home-subtitle,
.player-subtitle {
  margin: 0;
  font-size: 16px;
}

.workspace-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.workspace-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.player-book-label {
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.player-error {
  border: 1px solid #d8b2b2;
  background: #f7eaea;
  color: #7b3838;
  padding: 10px 12px;
  line-height: 1.45;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.player-panel,
.home-book-card {
  border: 1px solid var(--border);
  background: var(--panel-bg);
}

.home-book-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  color: var(--text);
  text-decoration: none;
}

.home-book-card:hover {
  background: #e7e7e7;
  text-decoration: none;
}

.home-book-title {
  display: block;
  color: var(--heading);
  font-weight: 700;
  font-size: 16px;
  line-height: 1.3;
}

.player-panel {
  padding: 16px;
}

.overview-label,
.current-video-title,
.notes-label {
  color: var(--heading);
  font-weight: 700;
}

.overview-label {
  margin-bottom: 8px;
  font-size: 14px;
}

.video-frame-wrap {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  background: #d8d8d8;
  border: 1px solid var(--border);
}

.video-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000000;
}

.video-tools {
  margin-top: 14px;
}

.current-video-title {
  margin-bottom: 12px;
  font-size: 16px;
  line-height: 1.4;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin-bottom: 14px;
}

.notes-label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
}

.video-note {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  border: 1px solid var(--border);
  padding: 10px;
  font: inherit;
  color: var(--text);
  background: #ffffff;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  padding: 20px;
}

.auth-title {
  margin: 0 0 14px;
  color: var(--heading);
  font-size: 22px;
}

.auth-form {
  display: flex;
  gap: 10px;
}

.auth-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: #ffffff;
}

.auth-button {
  border: 1px solid var(--border);
  background: var(--soft-box);
  color: var(--text);
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
}

.auth-button:disabled,
.auth-input:disabled {
  opacity: 0.7;
  cursor: default;
}

.auth-message {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 1150px) {
  :root {
    --sidebar-width: 320px;
  }

  .sidebar {
    width: var(--sidebar-width);
    flex-basis: var(--sidebar-width);
  }
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .layout {
    flex-direction: column;
    height: auto;
  }

  .sidebar,
  body.sidebar-hidden .sidebar {
    width: 100%;
    flex-basis: auto;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 14px;
    overflow: visible;
  }

  body.sidebar-hidden .sidebar-nav {
    display: none;
  }

  body.sidebar-hidden .sidebar {
    border-bottom: 1px solid var(--border);
  }

  .divider-toggle,
  body.sidebar-hidden .divider-toggle {
    top: 10px;
    left: auto;
    right: 10px;
    transform: none;
  }

  .content,
  body.sidebar-hidden .content {
    padding: 18px;
    height: auto;
    overflow: visible;
  }

  .workspace-head {
    flex-direction: column;
  }
}
