@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Noto+Sans+SC:wght@400;500;700&display=swap');

:root {
  --bg-main: #fff7e8;
  --bg-panel: #fffdf6;
  --bg-card: #fffaf0;
  --bg-card-2: #fff3d5;
  --text-main: #2a220f;
  --text-sub: #5d5035;
  --text-mute: #8f7f5c;
  --accent-blue: #26a8ff;
  --accent-purple: #7f5af0;
  --accent-green: #2ec27e;
  --accent-amber: #f5a524;
  --accent-red: #d7263d;
  --accent-cyan: #00b8d4;
  --border-main: #2a220f;
  --border-soft: #8f7f5c;
  --shadow-main: 6px 6px 0 #2a220f;
  --shadow-soft: 3px 3px 0 #8f7f5c;
  --font-display: 'Press Start 2P', monospace;
  --font-body: 'Noto Sans SC', 'Microsoft YaHei', 'Segoe UI', sans-serif;
}

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

*:focus-visible {
  outline: 3px dashed var(--accent-blue);
  outline-offset: 2px;
}

html,
body,
#root {
  height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--text-main);
  background-color: var(--bg-main);
  background-image:
    linear-gradient(90deg, rgba(42, 34, 15, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(42, 34, 15, 0.05) 1px, transparent 1px);
  background-size: 14px 14px;
}

.app-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  height: 100vh;
}

.sidebar {
  border-right: 3px solid var(--border-main);
  background: linear-gradient(180deg, #ffe8b8 0%, #ffe19f 100%);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 3px solid var(--border-main);
}

.sidebar-header h1 {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.08em;
  line-height: 1.45;
}

.sidebar-header .subtitle {
  margin-top: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item {
  width: 100%;
  border: 2px solid var(--border-main);
  background: #fff9e8;
  color: var(--text-main);
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.08s ease;
}

.nav-item:hover {
  transform: translate(-1px, -1px);
}

.nav-item.active {
  background: #dff3ff;
  border-color: var(--accent-blue);
}

.nav-item .icon {
  width: 22px;
  text-align: center;
}

.live-indicator {
  border-top: 3px solid var(--border-main);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.live-dot {
  width: 10px;
  height: 10px;
  background: var(--accent-green);
  border: 2px solid var(--border-main);
}

.live-dot.disconnected {
  background: var(--accent-red);
}

.main-content {
  overflow-y: auto;
  min-width: 0;
  padding: 22px;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.page-header h2 {
  font-size: 22px;
  line-height: 1.2;
  font-weight: 700;
}

.section-page-header {
  margin-top: 18px;
}

.card {
  background: var(--bg-card);
  border: 3px solid var(--border-main);
  box-shadow: var(--shadow-main);
  padding: 16px;
  margin-bottom: 16px;
}

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

.card-title {
  font-size: 17px;
  font-weight: 700;
}

.card-badge {
  border: 2px solid var(--border-main);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  background: #fff;
}

.badge-blue { background: #dff3ff; color: #055d8b; }
.badge-green { background: #dcfce7; color: #0f5132; }
.badge-amber { background: #fff1cd; color: #8a5b00; }
.badge-red { background: #ffe0e5; color: #8f1d30; }
.badge-purple { background: #ece3ff; color: #4a2ea8; }
.badge-cyan { background: #dcfafe; color: #155e75; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.stat-card .stat-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-mute);
}

.stat-card .stat-value {
  font-size: 28px;
  line-height: 1.15;
  margin: 6px 0 2px;
  color: var(--accent-blue);
}

.stat-card .stat-value.plain {
  color: var(--text-main);
}

.stat-sub {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sub);
}

.progress-track {
  margin-top: 8px;
  height: 12px;
  border: 2px solid var(--border-main);
  background: #f8e3b8;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #26a8ff, #7f5af0);
}

.dashboard-section-card {
  margin-bottom: 16px;
}

.strand-bar {
  height: 12px;
  border: 2px solid var(--border-main);
  display: flex;
  margin-bottom: 10px;
}

.strand-bar .segment { height: 100%; }
.strand-quest { background: #26a8ff; }
.strand-fire { background: #ff5c8a; }
.strand-constellation { background: #7f5af0; }

.strand-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 13px;
  color: var(--text-sub);
}

.demo-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.demo-domain-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.demo-domain-tab {
  border: 2px solid var(--border-main);
  background: #fff8e6;
  color: var(--text-main);
  padding: 6px 10px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.demo-domain-tab.active {
  background: #dff3ff;
  border-color: var(--accent-blue);
}

.demo-domain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.domain-stat-number {
  font-size: 30px;
  color: var(--accent-purple);
  margin-bottom: 4px;
}

.demo-group-card {
  margin-bottom: 12px;
}

.table-wrap {
  overflow-x: auto;
  border: 2px solid var(--border-soft);
  background: var(--bg-panel);
}

.data-table {
  width: 100%;
  min-width: 580px;
  border-collapse: collapse;
  font-size: 14px;
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
}

.data-table th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border-soft);
  background: var(--bg-card-2);
  white-space: nowrap;
  font-weight: 700;
}

.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #d8ccb2;
  color: var(--text-main);
  font-weight: 500;
}

.data-table tbody tr:hover td {
  background: #fff4d8;
}

.table-foot-note {
  margin-top: 8px;
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.page-btn {
  border: 2px solid var(--border-main);
  background: #fff8e6;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
}

.page-btn:hover:not(:disabled) {
  background: #e6f7ff;
  border-color: var(--accent-blue);
}

.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-info {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
}

.split-main,
.split-side {
  min-width: 0;
}

.entity-row {
  cursor: pointer;
}

.entity-row.selected td {
  background: #e6f7ff;
}

.entity-name {
  font-weight: 700;
}

.entity-name.protagonist {
  color: #b86a00;
}

.entity-detail {
  font-size: 14px;
  color: var(--text-sub);
  line-height: 1.7;
  font-family: var(--font-body);
}

.entity-detail code {
  border: 1px solid var(--border-soft);
  padding: 1px 4px;
  background: #fff;
}

.entity-desc {
  margin-top: 8px;
}

.entity-current-block {
  margin-top: 10px;
}

.entity-json {
  margin-top: 6px;
  border: 2px solid var(--border-soft);
  background: #fff;
  padding: 8px;
  max-height: 190px;
  overflow: auto;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
}

.entity-history {
  margin-top: 12px;
}

.graph-shell {
  padding: 0;
  overflow: hidden;
  height: calc(100vh - 120px);
  min-height: 520px;
}

.chapter-no {
  font-weight: 700;
  white-space: nowrap;
}

.chapter-characters {
  max-width: 220px;
}

.file-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 12px;
  height: calc(100vh - 130px);
  min-height: 560px;
}

.file-tree-pane {
  height: 100%;
  overflow-y: auto;
  border: 3px solid var(--border-main);
  box-shadow: var(--shadow-soft);
  background: #fffcf5;
  padding: 10px;
}

.file-content-pane {
  min-width: 0;
  height: 100%;
  border: 3px solid var(--border-main);
  box-shadow: var(--shadow-soft);
  background: #fffcf5;
  padding: 10px;
  overflow: hidden;
}

.file-content-pane > div {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.folder-block {
  margin-bottom: 12px;
}

.folder-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
}

.selected-path {
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-mute);
  font-weight: 600;
  word-break: break-all;
}

.file-tree {
  list-style: none;
  font-size: 13px;
  font-family: var(--font-body);
}

.tree-item {
  border: 2px solid transparent;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.tree-item:hover {
  background: #fff4d8;
  border-color: #e0c98d;
}

.tree-item.active {
  background: #e6f7ff;
  border-color: var(--accent-blue);
}

.tree-icon {
  width: 18px;
  text-align: center;
}

.tree-children {
  list-style: none;
  margin-left: 12px;
  padding-left: 8px;
  border-left: 2px dashed #d8ccb2;
}

.file-preview {
  border: 2px solid var(--border-soft);
  background: #fff;
  padding: 12px;
  flex: 1;
  min-height: 0;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.75;
  word-break: break-word;
  font-size: 14px;
  font-family: var(--font-body);
}

.debt-positive { color: var(--accent-red); font-weight: 700; }
.debt-normal { color: var(--text-sub); }

.loading {
  border: 3px solid var(--border-main);
  background: #fff9e8;
  padding: 20px;
  box-shadow: var(--shadow-main);
  font-size: 14px;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 32px 14px;
  color: var(--text-sub);
  font-family: var(--font-body);
}

.file-content-pane .empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.empty-state.compact {
  padding: 20px 10px;
}

.empty-state .empty-icon {
  font-size: 40px;
  margin-bottom: 10px;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.filter-btn {
  border: 2px solid var(--border-main);
  background: #fff8e6;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  padding: 5px 10px;
  cursor: pointer;
}

.filter-btn.active {
  background: #e6f7ff;
  border-color: var(--accent-blue);
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 1280px) {
  .split-layout {
    grid-template-columns: 1fr;
  }

  .graph-shell {
    height: calc(100vh - 128px);
    min-height: 460px;
  }

  .file-layout {
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 500px;
  }
}

@media (max-width: 960px) {
  .app-layout {
    grid-template-columns: 84px minmax(0, 1fr);
  }

  .sidebar-header h1,
  .sidebar-header .subtitle,
  .nav-item span:not(.icon),
  .live-indicator {
    display: none;
  }

  .sidebar {
    border-right-width: 2px;
  }

  .nav-item {
    justify-content: center;
    padding: 12px 8px;
  }

  .main-content {
    padding: 14px;
  }

  .graph-shell {
    height: calc(100vh - 108px);
    min-height: 380px;
  }

  .file-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .file-tree-pane {
    height: 260px;
    border: 2px solid var(--border-soft);
    padding: 8px;
    background: #fff;
  }

  .file-content-pane {
    height: calc(100vh - 430px);
    min-height: 320px;
  }
}

@media (max-width: 720px) {
  .page-header h2 {
    font-size: 18px;
  }

  .dashboard-grid,
  .demo-summary-grid,
  .demo-domain-grid {
    grid-template-columns: 1fr;
  }

  .demo-domain-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
  }

  .demo-domain-tab {
    white-space: nowrap;
  }

  .card {
    padding: 12px;
  }

  .graph-shell {
    height: 58vh;
    min-height: 320px;
  }

  .file-content-pane {
    height: 58vh;
    min-height: 280px;
  }
}
