:root {
  --bg-editor: #1e1e1e;
  --bg-sidebar: #252526;
  --bg-activity: #333333;
  --bg-title: #3c3c3c;
  --bg-hover: #2a2d2e;
  --bg-active: #37373d;
  --bg-tab-inactive: #2d2d2d;
  --bg-card: #2d2d2d;
  --border: #3e3e42;
  --border-subtle: #252526;
  --fg: #cccccc;
  --fg-muted: #a8a8a8;
  --fg-dim: #bbbbbb;
  --accent: #3794d0;
  --accent-bar: #007acc;
  --focus: #3794d0;
  --syntax-blue: #569cd6;
  --syntax-green: #6a9955;
  --syntax-orange: #ce9178;
  --syntax-teal: #4ec9b0;
  --syntax-yellow: #dcdcaa;
  --syntax-purple: #c586c0;
  --syntax-num: #b5cea8;
  --syntax-var: #9cdcfe;
  --syntax-punc: #d4d4d4;
  --pdf-red: #f44747;
  --folder: #e8a63a;
  --traffic-red: #ff5f57;
  --traffic-yellow: #ffbd2e;
  --traffic-green: #28c840;
  --font: "JetBrains Mono", "Fira Code", monospace;
  --sidebar-w: 240px;
  --scrollbar-thumb: #424242;
  --bg-pdf-stage: #111111;
  --on-accent: #ffffff;

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

body {
  font-family: var(--font);
  background: var(--bg-editor);
  color: var(--fg);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-size: 12px;
}
.skip-link:focus {
  left: 8px;
  top: 8px;
}

:focus { outline: none; }
:focus-visible {
  outline: 1px solid var(--focus);
  outline-offset: -1px;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-editor); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }

.titlebar {
  background: var(--bg-title);
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--fg);
  flex-shrink: 0;
  position: relative;
  user-select: none;
}
.traffic-lights {
  position: absolute;
  left: 12px;
  display: flex;
  gap: 6px;
}
.traffic {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.traffic.red { background: var(--traffic-red); }
.traffic.yellow { background: var(--traffic-yellow); }
.traffic.green { background: var(--traffic-green); }

.menubar {
  background: var(--bg-title);
  height: 25px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 4px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-subtle);
}
.menu-btn {
  font: inherit;
  font-size: 12px;
  color: var(--fg);
  background: none;
  border: none;
  padding: 2px 8px;
  cursor: pointer;
  border-radius: 3px;
}
.menu-btn:hover { background: rgba(255, 255, 255, 0.08); }

.workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.activity-bar {
  background: var(--bg-activity);
  width: var(--activity-w);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 4px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-subtle);
}

#sidebar {
  background: var(--bg-sidebar);
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: transform 0.2s ease;
}
.sidebar-title {
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--fg-dim);
  text-transform: uppercase;
}

.editor-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

#tabs-bar {
  background: var(--bg-sidebar);
  display: flex;
  height: 35px;
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
  flex-shrink: 0;
}

#main,
.editor-area {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 0;
}

.statusbar {
  background: var(--accent-bar);
  height: 22px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  flex-shrink: 0;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.95);
  justify-content: space-between;
}
.statusbar-left,
.statusbar-right {
  display: flex;
  gap: 12px;
  align-items: center;
}
.status-branch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font: inherit;
  font-size: 11px;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.status-branch:hover { opacity: 0.9; }

#overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
  border: none;
  padding: 0;
  cursor: pointer;
}

#mobile-menu-btn {
  display: none;
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--fg);
  padding: 4px;
}

@media (max-width: 768px) {
  #sidebar {
    transform: translateX(-100%);
    position: fixed;
    z-index: 50;
    left: var(--activity-w);
    width: min(var(--sidebar-w), calc(100vw - var(--activity-w)));
    top: 55px;
    height: calc(100vh - 55px - 22px);
  }
  #sidebar.open { transform: translateX(0); }
  #overlay.open { display: block; }
  #mobile-menu-btn { display: flex !important; }
  .welcome-inner { padding: 32px 20px !important; }
  .welcome-grid { grid-template-columns: 1fr !important; }
  .code-view {
    overflow-x: auto;
    padding: 0 12px 12px;
  }
  .code-body { min-width: 0; }
  .line-numbers { padding-left: 4px; }
}

.tab-item {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  background: var(--bg-tab-inactive);
  border: none;
  border-right: 1px solid var(--border-subtle);
  border-bottom: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  min-width: 0;
  font: inherit;
  color: var(--fg);
  font-size: 12px;
}
.tab-item.active {
  background: var(--bg-editor);
  border-bottom-color: var(--accent);
}
.tab-close {
  width: 18px;
  height: 18px;
  min-width: 44px;
  min-height: 44px;
  margin: -13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-muted);
  font-size: 14px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  border-radius: 3px;
  flex-shrink: 0;
}
.tab-close:hover { background: rgba(255, 255, 255, 0.1); color: var(--fg); }

.file-item {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 6px;
  font: inherit;
  color: var(--fg);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  user-select: none;
  padding: 2px 4px;
}
.file-item:hover { background: var(--bg-hover); }
.file-item.active { background: var(--bg-active); }
.file-item .label {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-item.folder .label { font-weight: 600; }
.file-item.folder { gap: 4px; }

.folder-arrow {
  transition: transform 0.15s;
  display: inline-block;
  font-size: 10px;
  color: var(--fg);
  width: 10px;
  flex-shrink: 0;
}
.folder-arrow.open { transform: rotate(90deg); }
.folder-children[hidden] { display: none !important; }

.act-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  cursor: pointer;
  color: var(--fg-muted);
  background: none;
  border: none;
  border-left: 2px solid transparent;
  transition: color 0.1s;
  padding: 0;
}
.act-btn:hover { color: var(--fg); }
.act-btn.active { color: var(--on-accent); border-left-color: var(--on-accent); }

.sidebar-panel { display: none; overflow-y: auto; flex: 1; }
.sidebar-panel.active { display: block; }
.panel-pad { padding: 8px 0; }
.panel-label {
  font-size: 11px;
  color: var(--fg-muted);
  padding: 4px 12px 8px;
}
.panel-hint {
  color: var(--syntax-green);
  font-style: italic;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.search-recent-label {
  font-size: 11px;
  color: var(--fg-muted);
  padding: 4px 12px 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.search-result:focus-visible { background: var(--bg-hover); }

.welcome-explorer-link {
  margin-top: 16px;
  font: inherit;
  font-size: 12px;
  color: var(--syntax-blue);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 4px 0;
}
.welcome-explorer-link:hover { color: var(--fg); }

.search-input {
  width: calc(100% - 16px);
  margin: 8px;
  padding: 6px 8px;
  background: var(--bg-title);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--fg);
  font-family: inherit;
  font-size: 12px;
}
.search-input:focus { outline: 1px solid var(--focus); border-color: var(--focus); }

.search-result {
  display: block;
  width: 100%;
  padding: 6px 12px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  color: var(--fg);
  background: none;
  border: none;
  text-align: left;
}
.search-result:hover { background: var(--bg-hover); }
.search-empty {
  padding: 12px;
  font-size: 12px;
  color: var(--fg-muted);
}

.git-branch-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 4px 12px;
  font: inherit;
  font-size: 12px;
  color: var(--fg);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
}
.git-branch-item:hover { background: var(--bg-hover); }
.git-branch-item.active { background: var(--bg-active); }

.welcome-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
  font: inherit;
  color: inherit;
  text-align: left;
}
.welcome-card:hover { background: var(--bg-active); }
.welcome-card-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.welcome-card-title svg { flex-shrink: 0; }
.welcome-card-sub { font-size: 11px; color: var(--fg-muted); }

.welcome-panel {
  flex: 1;
  overflow-y: auto;
  display: none;
  flex-direction: column;
  padding: 60px 40px;
}
.welcome-panel.active { display: flex; }
.welcome-inner { max-width: 640px; margin: 0 auto; width: 100%; }
.welcome-hero {
  display: flex;
  align-items: center;
  gap: 28px;
  margin-bottom: 36px;
  flex-wrap: wrap;
}
.avatar {
  flex-shrink: 0;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  border: 2px solid var(--border);
  overflow: hidden;
  background: var(--bg-active);
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar-fallback {
  font-size: 28px;
  font-weight: 600;
  color: var(--fg-dim);
  display: none;
}
.avatar.is-fallback img { display: none; }
.avatar.is-fallback .avatar-fallback { display: block; }

.signature {
  width: 100%;
  max-width: 340px;
  height: auto;
  display: block;
  margin-bottom: 6px;
}
.signature path { stroke: var(--fg); }
.welcome-tagline {
  font-size: 12px;
  color: var(--fg-muted);
  letter-spacing: 0.05em;
}
.welcome-hint {
  color: var(--fg-muted);
  font-size: 13px;
  line-height: 2;
  border-left: 2px solid var(--accent);
  padding-left: 16px;
  margin-bottom: 32px;
}
.welcome-hint .cmt { color: var(--syntax-green); }
.welcome-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.content-panel {
  flex: 1;
  overflow: hidden;
  display: none;
  flex-direction: column;
}
.content-panel.active { display: flex; }

.content-panel[hidden] { display: none !important; }

.code-view {
  display: flex;
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
}
.code-body { flex: 1; padding: 4px 0 4px 8px; }

.line-numbers {
  user-select: none;
  min-width: 3.5rem;
  text-align: right;
  padding-right: 1.5rem;
  color: var(--fg-muted);
  font-size: 13px;
  line-height: 1.7;
}
.code-line {
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
}

.empty-state {
  flex: 1;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--fg-muted);
  padding: 40px;
  text-align: center;
}
.empty-state.active { display: flex; }
.empty-state p { font-size: 13px; line-height: 1.6; max-width: 320px; }
.empty-btn {
  font: inherit;
  font-size: 12px;
  color: #fff;
  background: var(--accent);
  border: none;
  padding: 8px 14px;
  border-radius: 3px;
  cursor: pointer;
}
.empty-btn:hover { filter: brightness(1.08); }

.pdf-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.pdf-toolbar-title { font-size: 12px; color: var(--fg); }
.pdf-toolbar-actions,
.pdf-pager { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pdf-page-label {
  font-size: 11px;
  color: var(--fg-muted);
  min-width: 4.5rem;
  text-align: center;
}
.pdf-btn {
  font: inherit;
  font-size: 11px;
  color: var(--fg);
  text-decoration: none;
  padding: 4px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
}
.pdf-btn:hover { background: var(--bg-active); color: #fff; }
.pdf-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  height: 100%;
  border: 0;
  background: var(--bg-editor);
}
.pdf-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: auto;
  background: var(--bg-pdf-stage);
  padding: 16px;
}
.pdf-slide {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  background: #000;
}
.pdf-loading {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(17, 17, 17, 0.72);
  color: var(--fg-muted);
  font-size: 12px;
}
.pdf-loading.active { display: flex; }
.pdf-error {
  flex: 1;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px;
  color: var(--fg-muted);
  font-size: 13px;
  text-align: center;
}
.pdf-error.active { display: flex; }

.help-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 80;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.help-overlay.open { display: flex; }
.help-overlay[hidden] { display: none !important; }
.help-dialog {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-width: 420px;
  width: 100%;
  padding: 20px 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.help-dialog h2 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--fg);
}
.help-dialog dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  font-size: 12px;
}
.help-dialog dt { color: var(--syntax-blue); }
.help-dialog dd { color: var(--fg-muted); }
.help-close {
  margin-top: 16px;
  font: inherit;
  font-size: 12px;
  color: #fff;
  background: var(--accent);
  border: none;
  padding: 6px 12px;
  border-radius: 3px;
  cursor: pointer;
}

.kw { color: var(--syntax-blue); }
.str { color: var(--syntax-orange); }
.cmt { color: var(--syntax-green); font-style: italic; }
.num { color: var(--syntax-num); }
.typ { color: var(--syntax-teal); }
.var { color: var(--syntax-var); }
.fn { color: var(--syntax-yellow); }
.punc { color: var(--syntax-punc); }
.hl { color: var(--syntax-purple); }
.url { color: var(--syntax-teal); text-decoration: underline; cursor: pointer; }

.icon-file { stroke: var(--fg); }
.icon-pdf { stroke: var(--pdf-red); }
.icon-folder { fill: var(--folder); }
.icon-home { stroke: var(--syntax-blue); }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
body.is-ready .titlebar { animation: fade-in 0.35s ease both; }
body.is-ready .menubar { animation: fade-in 0.35s ease 0.06s both; }
body.is-ready .activity-bar { animation: fade-up 0.4s ease 0.1s both; }
body.is-ready #sidebar { animation: fade-up 0.45s ease 0.16s both; }
body.is-ready .editor-shell { animation: fade-up 0.5s ease 0.22s both; }
body.is-ready .statusbar { animation: fade-in 0.4s ease 0.28s both; }

@media (prefers-reduced-motion: reduce) {
  body.is-ready .titlebar,
  body.is-ready .menubar,
  body.is-ready .activity-bar,
  body.is-ready #sidebar,
  body.is-ready .editor-shell,
  body.is-ready .statusbar {
    animation: none;
  }
  #sidebar { transition: none; }
  .folder-arrow { transition: none; }
}
