:root {
  color-scheme: dark;
  --bg: #0a0c10;
  --panel: #12161c;
  --panel-2: #161b22;
  --line: #242a33;
  --text: #e9ecf1;
  --text-2: #c3c9d2;
  --muted: #8a929e;
  --faint: #656d79;
  --accent: #e8b34b;
  --accent-strong: #f2c76c;
  --accent-dim: rgba(232, 179, 75, 0.12);
  --green: #6ee7b7;
  --green-dim: rgba(110, 231, 183, 0.1);
  --red: #f07167;
  --blue: #7aa2f7;
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 520px at 88% -12%, rgba(232, 179, 75, 0.07), transparent 62%),
    radial-gradient(760px 460px at -8% 108%, rgba(90, 130, 220, 0.055), transparent 62%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #2a303a;
  border: 2px solid var(--bg);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: #38404c;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, filter 0.16s ease;
}

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

.btn-primary {
  border-color: rgba(255, 255, 255, 0.14);
  background: linear-gradient(180deg, #f2c76c, #dcae45);
  color: #221a08;
  font-weight: 600;
  box-shadow: 0 3px 14px rgba(232, 179, 75, 0.18);
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-ghost {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-2);
}

.btn-ghost:hover {
  border-color: #3a4150;
  background: rgba(255, 255, 255, 0.065);
  color: var(--text);
}

.btn-sm {
  padding: 6px 11px;
  border-radius: 7px;
  font-size: 12px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
}

.icon-btn:hover {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

/* ---------- 仓库骨架 ---------- */
.repo-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.repo-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 12, 16, 0.84);
  backdrop-filter: blur(12px);
}

.repo-menu-btn {
  display: none;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-size: 16px;
  cursor: pointer;
}

.repo-brand {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: linear-gradient(135deg, #f4cd7c, #d99f33);
  color: #1c1507;
  font-size: 16px;
  font-weight: 800;
}

.repo-title-block {
  flex: 1 1 auto;
  min-width: 0;
}

.repo-title {
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.repo-meta {
  margin-top: 2px;
  color: var(--faint);
  font-size: 10.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.repo-status {
  flex: 0 0 auto;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--muted);
  font-size: 10.5px;
  white-space: nowrap;
}

.repo-status.ok {
  border-color: rgba(110, 231, 183, 0.32);
  background: var(--green-dim);
  color: var(--green);
}

.repo-status.warn {
  border-color: rgba(232, 179, 75, 0.32);
  background: var(--accent-dim);
  color: var(--accent-strong);
}

.repo-status.error {
  border-color: rgba(240, 113, 103, 0.35);
  background: rgba(240, 113, 103, 0.08);
  color: var(--red);
}

.repo-layout {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.repo-side {
  flex: 0 0 246px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #0e1116, #0b0e12);
}

.repo-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 12px 10px;
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.repo-side-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.repo-files {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 8px 12px;
}

.repo-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 3px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}

.repo-file:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.repo-file.active {
  border-color: rgba(232, 179, 75, 0.26);
  background: var(--accent-dim);
  color: var(--accent-strong);
}

.repo-file-name {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.repo-file-size {
  flex: 0 0 auto;
  color: var(--faint);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.repo-side-foot {
  flex: 0 0 auto;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.repo-lock {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  font-size: 11px;
}

.repo-lock.unlocked {
  border-color: rgba(110, 231, 183, 0.26);
  background: var(--green-dim);
  color: var(--green);
}

.repo-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.repo-links button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--faint);
  font-family: inherit;
  font-size: 10.5px;
  cursor: pointer;
}

.repo-links button:hover {
  color: var(--text-2);
}

.repo-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.repo-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.repo-filename {
  min-width: 0;
  width: 220px;
  max-width: 34vw;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  outline: none;
}

.repo-count {
  flex: 1 1 auto;
  color: var(--faint);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
}

.repo-seg {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}

.repo-seg button {
  padding: 5px 11px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}

.repo-seg button.active {
  background: var(--accent-dim);
  color: var(--accent-strong);
  font-weight: 600;
}

.repo-editor-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

#repo-editor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 20px 22px calc(24px + env(safe-area-inset-bottom));
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.9;
  outline: none;
  resize: none;
}

#repo-editor::placeholder {
  color: #59616c;
}

#repo-editor[readonly] {
  color: var(--muted);
  cursor: not-allowed;
}

.repo-preview {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 20px 22px calc(28px + env(safe-area-inset-bottom));
  font-size: 14.5px;
  line-height: 1.85;
  color: var(--text-2);
}

.repo-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  justify-items: center;
  color: var(--faint);
  font-size: 12.5px;
}

.repo-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(4, 6, 10, 0.55);
}

/* ---------- 首次连接 ---------- */
.repo-setup {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 26px 18px calc(26px + env(safe-area-inset-bottom));
}

.setup-card {
  width: min(560px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 80%), var(--panel);
}

.setup-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
}

.setup-brand span {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #f4cd7c, #d99f33);
  color: #1c1507;
  font-weight: 800;
}

.setup-desc {
  margin: 12px 0 20px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.75;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 11.5px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1318;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
  outline: none;
}

.field input:focus {
  border-color: rgba(232, 179, 75, 0.55);
}

.field input::placeholder {
  color: #59616c;
}

.setup-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.setup-status {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--faint);
  font-size: 11.5px;
}

.setup-status.error {
  color: var(--red);
}

.setup-guide {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.8;
}

.setup-guide summary {
  cursor: pointer;
  color: var(--text-2);
  font-size: 12px;
}

.setup-guide ol {
  margin: 10px 0;
  padding-left: 20px;
}

.setup-guide a {
  color: var(--accent);
}

.setup-guide code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  font-family: var(--mono);
  font-size: 10.5px;
}

/* ---------- 弹窗 ---------- */
.repo-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(4px);
}

.repo-modal-card {
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.repo-modal-card h2 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 650;
}

.modal-body .field:last-child {
  margin-bottom: 0;
}

.modal-error {
  min-height: 16px;
  margin: 10px 0 0;
  color: var(--red);
  font-size: 11.5px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 16px;
}

/* ---------- 提示 ---------- */
.repo-toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  z-index: 80;
  max-width: min(88vw, 440px);
  padding: 10px 16px;
  border: 1px solid rgba(232, 179, 75, 0.3);
  border-radius: 10px;
  background: #1a1f27;
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.6;
  text-align: center;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  transform: translateX(-50%);
}

.repo-toast.error {
  border-color: rgba(240, 113, 103, 0.4);
  color: #f3a39d;
}

/* ---------- Markdown ---------- */
.md h1,
.md h2,
.md h3,
.md h4,
.md h5,
.md h6 {
  margin: 1.4em 0 0.55em;
  color: var(--text);
  line-height: 1.35;
}

.md h1 {
  font-size: 1.55em;
}
.md h2 {
  font-size: 1.3em;
}
.md h3 {
  font-size: 1.13em;
}
.md h4,
.md h5,
.md h6 {
  font-size: 1em;
}

.md p {
  margin: 0.7em 0;
}

.md a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(232, 179, 75, 0.35);
}

.md strong {
  color: var(--text);
}

.md mark {
  padding: 0 3px;
  border-radius: 3px;
  background: rgba(232, 179, 75, 0.22);
  color: var(--accent-strong);
}

.md del {
  color: var(--faint);
}

.md code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.07);
  font-family: var(--mono);
  font-size: 0.88em;
}

.md pre {
  padding: 14px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #0c0f13;
}

.md pre code {
  padding: 0;
  background: transparent;
}

.md blockquote {
  margin: 0.8em 0;
  padding: 2px 14px;
  border-left: 2px solid rgba(232, 179, 75, 0.45);
  color: var(--muted);
}

.md ul,
.md ol {
  margin: 0.7em 0;
  padding-left: 22px;
}

.md li {
  margin: 0.28em 0;
}

.md hr {
  margin: 1.5em 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.md img {
  max-width: 100%;
  border-radius: 8px;
}

.md .md-table {
  margin: 1em 0;
  overflow-x: auto;
}

.md table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94em;
}

.md th,
.md td {
  padding: 7px 10px;
  border: 1px solid var(--line);
  text-align: left;
}

.md th {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-weight: 600;
}

/* ---------- 手机 ---------- */
@media (max-width: 820px) {
  .repo-menu-btn {
    display: inline-grid;
    place-items: center;
  }

  .repo-side {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    width: min(78vw, 300px);
    padding-top: env(safe-area-inset-top);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 24px 0 48px rgba(0, 0, 0, 0.45);
  }

  .repo-side.open {
    transform: none;
  }

  .repo-filename {
    width: 120px;
    max-width: 30vw;
  }

  .repo-toolbar {
    flex-wrap: wrap;
    padding: 8px 12px;
  }

  .repo-count {
    order: 9;
    flex-basis: 100%;
    text-align: left;
  }

  #repo-editor,
  .repo-preview {
    padding-left: 16px;
    padding-right: 16px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }
}
