@import url("../design-system/tokens.css");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body.experience-page {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", sans-serif;
  background: var(--aycm-bg-dark);
  color: var(--aycm-text-primary);
  overflow: hidden;
}

.experience-exit-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: rgba(8, 13, 26, 0.96);
  border-bottom: 1px solid var(--aycm-border);
  flex-shrink: 0;
}

.experience-exit-bar a {
  color: var(--aycm-brand-cyan);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}

.experience-exit-bar a:hover {
  text-decoration: underline;
}

.experience-exit-note {
  font-size: 12px;
  color: var(--aycm-text-secondary);
}

.ms-shell {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 45px);
  min-height: 620px;
  background: #0e1218;
}

.ms-hint-banner {
  padding: 8px 16px;
  background: rgba(51, 204, 255, 0.08);
  border-bottom: 1px solid rgba(51, 204, 255, 0.18);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.72);
  text-align: center;
  flex-shrink: 0;
}

.ms-hint-banner strong {
  color: var(--aycm-brand-cyan);
}

.ms-app {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Sidebar */
.ms-sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 10px 12px;
  background: #121820;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  overflow-y: auto;
}

.ms-sidebar-section {
  margin-bottom: 18px;
}

.ms-sidebar-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.32);
  padding: 0 10px 8px;
}

.ms-nav-item {
  display: flex;
  align-items: center;
  width: 100%;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.62);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 2px;
}

.ms-nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.88);
}

.ms-nav-item.active {
  background: rgba(212, 168, 67, 0.14);
  color: #e8c96a;
}

.ms-nav-item.active::after {
  content: "✓";
  margin-left: auto;
  font-size: 11px;
  opacity: 0.8;
}

.ms-nav-item.subtle {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.38);
}

.ms-sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.ms-feedback-btn {
  width: 100%;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.55);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.ms-feedback-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* Main area */
.ms-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #141a22;
}

.ms-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: #171e28;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.ms-topbar-title {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
}

.ms-topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ms-icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  font-size: 14px;
}

.ms-icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.ms-spark-btn {
  margin-left: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(212, 168, 67, 0.35), rgba(180, 120, 40, 0.25));
  border: 1px solid rgba(212, 168, 67, 0.35);
  color: #f0d48a;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.ms-spark-btn:hover {
  filter: brightness(1.08);
}

.ms-subheader {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  flex-shrink: 0;
}

.ms-kicker {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.42);
}

.ms-subheader-sep {
  color: rgba(255, 255, 255, 0.2);
}

.ms-subheader-project {
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.55);
}

.ms-tab-row {
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 0 20px 14px;
  flex-shrink: 0;
}

.ms-tab {
  min-width: 100px;
  padding: 8px 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.55);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.ms-tab:hover {
  background: rgba(255, 255, 255, 0.07);
}

.ms-tab.active {
  background: rgba(212, 168, 67, 0.18);
  border-color: rgba(212, 168, 67, 0.45);
  color: #e8c96a;
}

.ms-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.ms-pane.hidden {
  display: none;
}

/* Action bar */
.ms-action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 20px 16px;
  flex-shrink: 0;
}

.ms-action-btn {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.82);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.ms-action-btn:hover {
  background: rgba(255, 255, 255, 0.09);
}

.ms-action-btn.primary {
  background: rgba(56, 115, 97, 0.35);
  border-color: rgba(56, 115, 97, 0.5);
  color: #8fd4b8;
}

/* Editor layout */
.ms-editor-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 0;
  padding: 0 20px 20px;
}

.ms-grid-column {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding-right: 16px;
}

.ms-chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  align-content: start;
}

.ms-chapter-card {
  position: relative;
  padding: 16px 14px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.ms-chapter-card:hover {
  transform: translateY(-1px);
}

.ms-chapter-card.selected {
  box-shadow: 0 0 0 2px rgba(212, 168, 67, 0.55), 0 8px 24px rgba(0, 0, 0, 0.35);
}

.ms-chapter-card.plot-main {
  background: linear-gradient(160deg, rgba(120, 45, 90, 0.35), rgba(60, 28, 50, 0.5));
  border-color: rgba(180, 80, 120, 0.35);
}

.ms-chapter-card.plot-sub {
  background: linear-gradient(160deg, rgba(100, 70, 45, 0.4), rgba(55, 40, 28, 0.55));
  border-color: rgba(160, 110, 60, 0.35);
}

.ms-chapter-card.plot-empty {
  background: linear-gradient(160deg, rgba(50, 55, 65, 0.45), rgba(30, 34, 42, 0.6));
  border-color: rgba(255, 255, 255, 0.08);
}

.ms-card-number {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.45);
  margin-bottom: 6px;
}

.ms-card-title {
  font-size: 14px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.92);
  line-height: 1.35;
  margin-bottom: auto;
  padding-bottom: 12px;
}

.ms-card-footer {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ms-plot-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  width: fit-content;
  background: rgba(0, 0, 0, 0.25);
  color: rgba(255, 255, 255, 0.75);
}

.ms-card-meta {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.42);
}

/* Detail panel */
.ms-detail-column {
  width: 340px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 4px 0 4px 4px;
  border-left: 1px solid rgba(255, 255, 255, 0.06);
}

.ms-detail-column::-webkit-scrollbar,
.ms-grid-column::-webkit-scrollbar {
  width: 4px;
}

.ms-detail-column::-webkit-scrollbar-thumb,
.ms-grid-column::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

.ms-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.ms-detail-chapter-num {
  font-size: 13px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.55);
}

.ms-edit-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 10px;
  border: none;
  background: #387361;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.ms-edit-btn:hover {
  filter: brightness(1.08);
}

.ms-detail-title {
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  line-height: 1.35;
  margin-bottom: 14px;
}

.ms-detail-section {
  margin-bottom: 16px;
}

.ms-section-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.35);
  margin-bottom: 8px;
}

.ms-progress-card {
  padding: 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.ms-progress-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.ms-progress-count {
  font-size: 22px;
  font-weight: 800;
  color: #fff;
}

.ms-progress-pct {
  font-size: 12px;
  font-weight: 700;
  color: #5ec49a;
}

.ms-progress-bar {
  height: 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-bottom: 6px;
}

.ms-progress-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #387361, #5ec49a);
}

.ms-progress-goal {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.45);
}

.ms-badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ms-badge {
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
}

.ms-badge.status {
  background: rgba(56, 115, 97, 0.25);
  color: #8fd4b8;
}

.ms-badge.plot-type {
  background: rgba(51, 160, 180, 0.2);
  color: #7dd4e8;
}

.ms-badge.plot-pos {
  background: rgba(120, 80, 180, 0.22);
  color: #c4a8f0;
}

.ms-scenes-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.ms-scenes-scroll::-webkit-scrollbar {
  height: 4px;
}

.ms-scenes-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
}

.ms-scene-tile {
  flex: 0 0 120px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

.ms-scene-tile:hover,
.ms-scene-tile.selected {
  border-color: rgba(56, 115, 97, 0.5);
  background: rgba(56, 115, 97, 0.12);
}

.ms-scene-tile-head {
  font-size: 9px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.4);
  margin-bottom: 4px;
}

.ms-scene-tile-title {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1.35;
}

.ms-scene-tile.accent-purple .ms-scene-tile-head { color: #c4a0e0; }
.ms-scene-tile.accent-orange .ms-scene-tile-head { color: #e8a860; }

.ms-characters-empty {
  padding: 14px;
  border-radius: 10px;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.38);
  text-align: center;
}

.ms-characters-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ms-character-chip {
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 11px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.78);
}

.ms-content-preview {
  padding: 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.55);
  max-height: 120px;
  overflow: hidden;
}

.ms-empty-detail {
  padding: 40px 20px;
  text-align: center;
  color: rgba(255, 255, 255, 0.38);
  font-size: 13px;
}

/* Book tab */
.ms-book-layout {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px 24px;
}

.ms-book-overview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}

.ms-book-card {
  padding: 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.ms-book-card-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.35);
  margin-bottom: 6px;
}

.ms-book-card-title {
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  margin-bottom: 4px;
}

.ms-book-card-meta {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
}

.ms-book-stats {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.ms-stat-tile {
  padding: 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
}

.ms-stat-value {
  display: block;
  font-size: 22px;
  font-weight: 800;
  color: #e8c96a;
  margin-bottom: 4px;
}

.ms-stat-label {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.45);
}

.ms-charts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.ms-chart-card {
  padding: 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.ms-chart-title {
  font-size: 12px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.72);
  margin-bottom: 14px;
}

.ms-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.ms-bar-row:last-child {
  margin-bottom: 0;
}

.ms-bar-label {
  width: 72px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
  flex-shrink: 0;
}

.ms-bar-track {
  flex: 1;
  height: 10px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.ms-bar-fill {
  height: 100%;
  border-radius: 99px;
}

.ms-bar-value {
  width: 36px;
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.55);
  text-align: right;
}

/* Toast */
.ms-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 12px;
  background: rgba(15, 22, 41, 0.96);
  border: 1px solid rgba(51, 204, 255, 0.25);
  color: rgba(255, 255, 255, 0.88);
  font-size: 13px;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
}

.ms-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1024px) {
  .ms-detail-column {
    width: 300px;
  }

  .ms-sidebar {
    width: 180px;
  }
}

@media (max-width: 820px) {
  .ms-app {
    flex-direction: column;
  }

  .ms-sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    max-height: 120px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .ms-sidebar-section {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
  }

  .ms-sidebar-label,
  .ms-sidebar-footer {
    display: none;
  }

  .ms-editor-layout {
    flex-direction: column;
  }

  .ms-detail-column {
    width: 100%;
    border-left: none;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    padding-top: 16px;
    max-height: 360px;
  }

  .ms-book-overview,
  .ms-charts {
    grid-template-columns: 1fr;
  }

  .ms-topbar-actions .ms-spark-btn {
    display: none;
  }
}
