:root {
  --bg: #0b1020;
  --bg-grad-1: #1b2350;
  --bg-grad-2: #0b1020;
  --bg-grad-3: #15103a;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-solid: #141a30;
  --surface-2: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #eaeefb;
  --text-soft: #aab3d4;
  --text-muted: #717aa0;
  --accent: #7c5cff;
  --accent-2: #34d4ff;
  --accent-grad: linear-gradient(135deg, #7c5cff 0%, #34d4ff 100%);
  --danger: #ff5d73;
  --ok: #38e8a0;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --radius-sm: 12px;
  --mono: "JetBrains Mono", "Fira Code", "SFMono-Regular", "Cascadia Code", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
}

[data-theme="light"] {
  --bg: #f3f5fc;
  --bg-grad-1: #e7ecff;
  --bg-grad-2: #f3f5fc;
  --bg-grad-3: #eef0ff;
  --surface: rgba(255, 255, 255, 0.75);
  --surface-solid: #ffffff;
  --surface-2: rgba(20, 26, 48, 0.03);
  --border: rgba(20, 26, 48, 0.10);
  --border-strong: rgba(20, 26, 48, 0.18);
  --text: #161a2c;
  --text-soft: #46506e;
  --text-muted: #8088a3;
  --shadow: 0 20px 50px rgba(60, 70, 120, 0.18);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(1200px 800px at 12% -10%, var(--bg-grad-1), transparent 55%),
    radial-gradient(1000px 700px at 110% 0%, var(--bg-grad-3), transparent 50%),
    linear-gradient(180deg, var(--bg-grad-2), var(--bg));
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 22px 20px 64px;
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 2px 26px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.2px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }

.logo {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--accent-grad);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px rgba(124, 92, 255, 0.45);
  flex: none;
}
.logo svg { width: 22px; height: 22px; color: #fff; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--text-muted); letter-spacing: 1px; }

.icon-btn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-soft);
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, color .15s ease;
  backdrop-filter: blur(8px);
}
.icon-btn:hover { transform: translateY(-1px); color: var(--text); border-color: var(--border-strong); }
.icon-btn svg { width: 20px; height: 20px; }
.theme-moon { display: none; }
[data-theme="light"] .theme-sun { display: none; }
[data-theme="light"] .theme-moon { display: block; }

/* ---------- Hero ---------- */
.hero { text-align: center; margin-bottom: 26px; }
.hero h1 {
  font-size: clamp(28px, 5vw, 44px);
  line-height: 1.1;
  margin: 6px 0 10px;
  letter-spacing: -0.5px;
}
.hero h1 .grad {
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero p { color: var(--text-soft); font-size: 16px; margin: 0 auto; max-width: 560px; }

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow: hidden;
}

.card-pad { padding: 22px; }

/* ---------- Editor ---------- */
.editor-head {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.editor-head .title-input { flex: 1 1 260px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--text-muted); font-weight: 600; letter-spacing: .4px; }

input[type="text"], select, textarea {
  font-family: var(--sans);
  font-size: 15px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
  width: 100%;
}
input[type="text"]::placeholder, textarea::placeholder { color: var(--text-muted); }
input[type="text"]:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.22);
  background: var(--surface-2);
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238088a3' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 38px;
  cursor: pointer;
}

/* 下拉展开后的选项：用不透明背景+主题文字色，避免深色主题下看不清 */
select option,
select optgroup {
  background-color: var(--surface-solid);
  color: var(--text);
}

.editor-body { margin-top: 16px; position: relative; }
textarea#content {
  font-family: var(--mono);
  font-size: 14.5px;
  line-height: 1.6;
  min-height: 320px;
  resize: vertical;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
}

.editor-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.controls { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.controls .field { min-width: 140px; }

.meta-line { font-size: 12.5px; color: var(--text-muted); display: flex; gap: 14px; }
.meta-line b { color: var(--text-soft); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform .12s ease, box-shadow .15s ease, border-color .15s, background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); border-color: var(--border-strong); }
.btn:active { transform: translateY(0); }
.btn svg { width: 18px; height: 18px; }
.btn.primary {
  background: var(--accent-grad);
  border: none;
  color: #fff;
  box-shadow: 0 10px 26px rgba(124, 92, 255, 0.42);
  padding: 13px 26px;
}
.btn.primary:hover { box-shadow: 0 14px 32px rgba(124, 92, 255, 0.55); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.sm { padding: 9px 13px; font-size: 13.5px; }

.kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-muted);
}

/* ---------- Result ---------- */
.result { margin-top: 18px; display: none; animation: pop .35s ease; }
.result.show { display: block; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98);} to {opacity:1; transform: none;} }

.result-inner {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--surface-2);
}
.result h3 { margin: 0 0 4px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.result h3 .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 4px rgba(56,232,160,.18); }
.result .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 14px; }

.link-row { display: flex; gap: 10px; flex-wrap: wrap; }
.link-row input {
  flex: 1 1 280px;
  font-family: var(--mono);
  font-size: 14px;
  background: var(--bg);
}
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(30px);
  background: var(--surface-solid);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--danger); color: var(--danger); }

/* ---------- View page ---------- */
.view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.view-title { font-size: 22px; font-weight: 700; margin: 0; word-break: break-word; }
.view-title.untitled { color: var(--text-muted); font-weight: 600; }
.badges { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.badge {
  font-size: 12px;
  color: var(--text-soft);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.badge svg { width: 13px; height: 13px; opacity: .8; }
.view-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12.5px;
  color: var(--text-muted);
}
.dots { display: flex; gap: 6px; }
.dots i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dots i:nth-child(1){ background:#ff5f57; }
.dots i:nth-child(2){ background:#febc2e; }
.dots i:nth-child(3){ background:#28c840; }

.code-wrap {
  display: flex;
  align-items: stretch;
  overflow: auto;
  max-height: 72vh;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.65;
}
.code-wrap pre { margin: 0; }
.gutter {
  flex: none;
  padding: 16px 12px 16px 16px;
  text-align: right;
  color: var(--text-muted);
  user-select: none;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.65;
  white-space: pre;
}
.code-main {
  flex: 1 1 auto;
  padding: 16px 18px;
  overflow: auto;
}
.code-main code {
  font-family: var(--mono);
  background: transparent;
  white-space: pre;
  display: block;
}
.code-wrap.wrap .gutter { display: none; }
.code-wrap.wrap .code-main code { white-space: pre-wrap; word-break: break-word; }

/* Markdown */
.markdown-body { padding: 22px 26px; line-height: 1.7; font-size: 15.5px; overflow-x: auto; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin-top: 1.4em; line-height: 1.3; }
.markdown-body h1 { border-bottom: 1px solid var(--border); padding-bottom: .3em; }
.markdown-body h2 { border-bottom: 1px solid var(--border); padding-bottom: .3em; }
.markdown-body code { font-family: var(--mono); background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: .9em; }
.markdown-body pre { background: var(--surface-2); padding: 14px 16px; border-radius: 12px; overflow: auto; border: 1px solid var(--border); }
.markdown-body pre code { background: transparent; padding: 0; }
.markdown-body blockquote { border-left: 3px solid var(--accent); margin: 1em 0; padding: .2em 1em; color: var(--text-soft); background: var(--surface-2); border-radius: 0 8px 8px 0; }
.markdown-body table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 8px 12px; }
.markdown-body th { background: var(--surface-2); }
.markdown-body img { max-width: 100%; border-radius: 8px; }
.markdown-body a { color: var(--accent-2); }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }

/* States */
.state {
  text-align: center;
  padding: 70px 20px;
  color: var(--text-soft);
}
.state .big { font-size: 60px; line-height: 1; margin-bottom: 12px; }
.state h2 { margin: 6px 0; color: var(--text); }
.state p { margin: 0 0 18px; color: var(--text-muted); }
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 30px;
}

/* ---------- 语法高亮配色（随主题切换） ---------- */
:root {
  --syn-base: #eaeefb;
  --syn-comment: #6b7394;
  --syn-keyword: #c792ea;
  --syn-string: #c3e88d;
  --syn-number: #f78c6c;
  --syn-title: #82aaff;
  --syn-attr: #ffcb6b;
  --syn-builtin: #89ddff;
  --syn-meta: #82aaff;
}
[data-theme="light"] {
  --syn-base: #161a2c;
  --syn-comment: #8a93ad;
  --syn-keyword: #d6336c;
  --syn-string: #2b8a3e;
  --syn-number: #b35900;
  --syn-title: #1d4ed8;
  --syn-attr: #9a6700;
  --syn-builtin: #0b7285;
  --syn-meta: #1d4ed8;
}
.hljs { color: var(--syn-base); background: transparent; }
.hljs-comment, .hljs-quote { color: var(--syn-comment); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-section, .hljs-name, .hljs-doctag {
  color: var(--syn-keyword); font-weight: 600;
}
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-symbol, .hljs-bullet {
  color: var(--syn-string);
}
.hljs-number, .hljs-deletion { color: var(--syn-number); }
.hljs-title, .hljs-title.function_, .hljs-function .hljs-title {
  color: var(--syn-title); font-weight: 600;
}
.hljs-attr, .hljs-attribute, .hljs-property, .hljs-variable.constant_ {
  color: var(--syn-attr);
}
.hljs-built_in, .hljs-builtin-name, .hljs-type, .hljs-class .hljs-title {
  color: var(--syn-builtin);
}
.hljs-meta, .hljs-tag { color: var(--syn-meta); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }
.hljs-link { text-decoration: underline; }

.hidden { display: none !important; }

@media (max-width: 640px) {
  .wrap { padding: 16px 14px 48px; }
  .card-pad { padding: 16px; }
  .controls .field { flex: 1 1 100%; }
  .btn.primary { width: 100%; justify-content: center; }
}
