/* =========================================================
   源码贴 CodePaste — 视觉规范参考 VS Code Dark+
   ========================================================= */

:root {
  --bg:            #181818;
  --surface:       #1E1E1E;
  --surface-2:     #252526;
  --surface-3:     #2D2D30;
  --border:        #2B2B2E;
  --border-strong: #3C3C40;

  --text:          #E7E7E7;
  --text-soft:     #A5A5A5;
  --text-dim:      #757575;

  --accent:        #007ACC;
  --accent-hover:  #1A8CD8;
  --accent-soft:   rgba(0, 122, 204, 0.14);

  --code-size:     14px;
  --code-lh:       1.62;
  --code-pad-y:    14px;
  --code-pad-x:    16px;

  --radius:        12px;
  --shadow:        0 18px 40px -18px rgba(0, 0, 0, 0.75), 0 1px 0 rgba(255,255,255,0.03) inset;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
             "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  --font-code: Consolas, "Cascadia Mono", "JetBrains Mono", "SFMono-Regular",
               Menlo, Monaco, "Liberation Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 340px;
  background: radial-gradient(80% 100% at 50% 0%, rgba(0, 122, 204, 0.10), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

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

/* ------------------------------------------------ 顶栏 */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 58px;
  padding: 0 18px;
  background: rgba(24, 24, 24, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  padding: 4px 6px;
  border-radius: 8px;
  transition: background 0.15s ease;
}
.brand:hover { background: rgba(255, 255, 255, 0.04); }

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: #4FC1FF;
  background: linear-gradient(160deg, #232326, #171719);
  border: 1px solid var(--border-strong);
  box-shadow: 0 1px 0 rgba(255,255,255,0.05) inset;
}

.brand-text {
  display: flex;
  align-items: baseline;
  gap: 7px;
  line-height: 1;
}
.brand-text strong {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.brand-text em {
  font-style: normal;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.topbar-spacer { flex: 1; }

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

/* ------------------------------------------------ 按钮 */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-soft);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(0.5px); }
.btn svg { flex: none; opacity: 0.95; }

.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-primary {
  background: var(--accent);
  border-color: #1A8CD8;
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.16) inset, 0 6px 16px -8px rgba(0, 122, 204, 0.9);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-outline {
  border-color: var(--border-strong);
  color: #CFCFCF;
  background: rgba(255, 255, 255, 0.015);
}
.btn-outline:hover {
  border-color: #4E4E54;
  background: var(--surface-2);
  color: #fff;
}

.btn-sm { height: 30px; padding: 0 11px; font-size: 12.5px; border-radius: 7px; }

.lbl-short { display: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ------------------------------------------------ 主体 */

main {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 22px 20px 56px;
}

.view { animation: fadeUp 0.28s ease both; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* ------------------------------------------------ 标题行 */

.meta-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.meta-title, .meta-author {
  height: 42px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.meta-title { flex: 1; min-width: 0; font-size: 15px; font-weight: 500; }
.meta-author { width: 190px; flex: none; }

.meta-title::placeholder, .meta-author::placeholder { color: var(--text-dim); font-weight: 400; }

.meta-title:focus, .meta-author:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ------------------------------------------------ 编辑器卡片 */

.editor-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 46px;
  padding: 0 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.editor-bar-left, .editor-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* 下拉 */
.select-wrap { position: relative; display: inline-flex; align-items: center; }

#langSelect {
  appearance: none;
  -webkit-appearance: none;
  height: 30px;
  padding: 0 28px 0 10px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--surface-3);
  color: #DCDCDC;
  font-family: var(--font-code);
  font-size: 12.5px;
  cursor: pointer;
  outline: none;
  max-width: 200px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
#langSelect:hover { border-color: #4E4E54; }
#langSelect:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.select-caret {
  position: absolute;
  right: 10px;
  color: var(--text-dim);
  pointer-events: none;
}

.detect-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: 20px;
  font-size: 11.5px;
  color: #7FD1B9;
  background: rgba(78, 201, 176, 0.12);
  border: 1px solid rgba(78, 201, 176, 0.22);
  white-space: nowrap;
}

/* 行号开关 */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-soft);
  cursor: pointer;
  user-select: none;
  padding: 3px 4px;
}
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-box {
  position: relative;
  width: 26px;
  height: 15px;
  border-radius: 20px;
  background: #3A3A3E;
  transition: background 0.16s ease;
}
.toggle-box::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #B4B4B4;
  transition: transform 0.16s ease, background 0.16s ease;
}
.toggle input:checked + .toggle-box { background: var(--accent); }
.toggle input:checked + .toggle-box::after { transform: translateX(11px); background: #fff; }

/* 字号 */
.fontsize {
  display: inline-flex;
  align-items: center;
  height: 28px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  overflow: hidden;
}
.fontsize button {
  width: 26px;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.fontsize button:hover { background: var(--surface-3); color: #fff; }
.fontsize span {
  min-width: 26px;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  line-height: 26px;
}

/* 编辑区 */
.editor-body {
  display: flex;
  height: clamp(340px, calc(100vh - 330px), 720px);
  background: var(--surface);
  overflow: hidden;
}

.gutter {
  flex: none;
  min-width: 46px;
  padding: var(--code-pad-y) 10px var(--code-pad-y) 14px;
  overflow: hidden;
  text-align: right;
  color: #5C5C5C;
  background: var(--surface);
  border-right: 1px solid var(--border);
  font-family: var(--font-code);
  font-size: var(--code-size);
  line-height: var(--code-lh);
  user-select: none;
  white-space: pre;
  font-variant-numeric: tabular-nums;
}
.gutter-inner { will-change: transform; }

.code-scroll {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.hl-layer, #src {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: var(--code-pad-y) var(--code-pad-x);
  border: 0;
  font-family: var(--font-code);
  font-size: var(--code-size);
  line-height: var(--code-lh);
  letter-spacing: 0;
  tab-size: 4;
  -moz-tab-size: 4;
  white-space: pre;
  word-wrap: normal;
  overflow-wrap: normal;
}

.hl-layer {
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
  color: #D4D4D4;
  background: transparent;
  will-change: transform;
}
.hl-layer code {
  font: inherit;
  background: none;
  padding: 0;
  white-space: inherit;
  display: block;
}

#src {
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  resize: none;
  outline: none;
  overflow: auto;
  background: transparent;
  color: transparent;
  caret-color: #AEAFAD;
  -webkit-text-fill-color: transparent;
}
#src::placeholder {
  color: #5E5E5E;
  -webkit-text-fill-color: #5E5E5E;
}
#src::selection {
  background: rgba(38, 79, 120, 0.72);
}

/* 底部信息条 */
.editor-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 34px;
  padding: 0 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 11.5px;
  color: var(--text-dim);
}
.foot-stats { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.foot-stats .dot { color: #4A4A4A; }
.foot-tips { display: inline-flex; align-items: center; gap: 4px; }
.foot-tips span { color: #5A5A5A; }
kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  background: #2A2A2D;
  color: #9C9C9C;
  font-family: var(--font-code);
  font-size: 10.5px;
  line-height: 1.5;
}

/* ------------------------------------------------ 底部操作行 */

.action-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.action-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-left: auto;
}

/* ------------------------------------------------ 只读视图 */

.read-head { margin-bottom: 16px; }

.read-title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.2px;
  line-height: 1.35;
  word-break: break-word;
}

.read-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--text-dim);
}
.meta-item { display: inline-flex; align-items: center; gap: 5px; }
.meta-item::before {
  content: "";
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #4A4A4A;
  margin-right: 3px;
}
.lang-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 9px;
  border-radius: 5px;
  font-family: var(--font-code);
  font-size: 11.5px;
  color: #4FC1FF;
  background: rgba(0, 122, 204, 0.14);
  border: 1px solid rgba(0, 122, 204, 0.28);
}

.read-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 44px;
  padding: 0 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.read-toolbar-actions { display: flex; align-items: center; gap: 4px; }

.read-code {
  max-height: calc(100vh - 300px);
  min-height: 160px;
  overflow: auto;
  background: var(--surface);
}
.read-code .hl-layer.static {
  position: static;
  transform: none !important;
  overflow: visible;
  padding: var(--code-pad-y) var(--code-pad-x);
}
.read-code .hl-layer.static code { padding-left: 0; }

.read-foot-note {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.7;
}

/* ------------------------------------------------ 弹窗 / 抽屉 */

.sheet-mask, .drawer-mask {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fadeIn 0.18s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.sheet-mask {
  display: grid;
  place-items: center;
  padding: 20px;
}

.sheet {
  width: 100%;
  max-width: 580px;
  padding: 20px;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: #232326;
  box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.9);
  animation: popIn 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.97) translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.sheet-head h2 { margin: 0; font-size: 16px; font-weight: 600; }

.sheet-desc {
  margin: 8px 0 14px;
  font-size: 12.5px;
  color: var(--text-soft);
  line-height: 1.6;
}

.link-box { display: flex; gap: 8px; }
.link-box input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: #1A1A1C;
  color: #9CDCFE;
  font-family: var(--font-code);
  font-size: 12px;
  outline: none;
}
.link-box input:focus { border-color: var(--accent); }

.sheet-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.sheet-len { font-size: 11.5px; color: var(--text-dim); }
.sheet-foot-actions { display: flex; gap: 6px; }

/* 抽屉 */
.drawer-mask { display: flex; justify-content: flex-end; }

.drawer {
  width: 100%;
  max-width: 400px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #202023;
  border-left: 1px solid var(--border-strong);
  box-shadow: -24px 0 60px -20px rgba(0, 0, 0, 0.8);
  animation: slideIn 0.24s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes slideIn {
  from { transform: translateX(24px); opacity: 0.4; }
  to   { transform: none; opacity: 1; }
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.drawer-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.6;
}

.hist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.14s ease;
}
.hist-item:hover { background: rgba(255, 255, 255, 0.05); }

.hist-main { flex: 1; min-width: 0; }
.hist-title {
  font-size: 13px;
  color: #DCDCDC;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}
.hist-sub {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-code);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hist-del {
  flex: none;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: #6A6A6A;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.hist-item:hover .hist-del { opacity: 1; }
.hist-del:hover { background: rgba(255, 80, 80, 0.14); color: #FF7B72; }

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.8;
}

/* ------------------------------------------------ Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  z-index: 90;
  transform: translate(-50%, 14px);
  padding: 9px 16px;
  border-radius: 9px;
  background: #2D2D31;
  border: 1px solid var(--border-strong);
  color: #EDEDED;
  font-size: 12.5px;
  box-shadow: 0 16px 34px -12px rgba(0, 0, 0, 0.85);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  max-width: min(90vw, 420px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* =========================================================
   代码高亮：VS Code Dark+
   ========================================================= */

.hljs-comment,
.hljs-quote                       { color: #6A9955; font-style: italic; }

.hljs-keyword,
.hljs-literal,
.hljs-type,
.hljs-doctag,
.hljs-template-tag,
.hljs-template-variable           { color: #569CD6; }

.hljs-string,
.hljs-doctag .hljs-type,
.hljs-regexp                      { color: #D69D85; }

.hljs-number,
.hljs-symbol,
.hljs-bullet,
.hljs-link,
.hljs-selector-attr,
.hljs-selector-pseudo             { color: #B5CEA8; }

.hljs-built_in,
.hljs-title.class_,
.hljs-class .hljs-title,
.hljs-selector-class              { color: #4EC9B0; }

.hljs-title.function_,
.hljs-function .hljs-title,
.hljs-section,
.hljs-name                        { color: #DCDCAA; }

.hljs-variable,
.hljs-attr,
.hljs-attribute,
.hljs-params,
.hljs-property,
.hljs-selector-id                 { color: #9CDCFE; }

.hljs-meta,
.hljs-meta .hljs-keyword          { color: #C586C0; }

.hljs-subst                       { color: #D4D4D4; }

.hljs-tag                         { color: #569CD6; }
.hljs-tag .hljs-name              { color: #569CD6; }
.hljs-tag .hljs-attr              { color: #9CDCFE; }
.hljs-tag .hljs-string            { color: #D69D85; }

.hljs-addition                    { color: #B5CEA8; }
.hljs-deletion                    { color: #FF7B72; }

.hljs-emphasis { font-style: italic; }
.hljs-strong   { font-weight: 700; }

.hljs-formula  { color: #D4D4D4; }

/* =========================================================
   响应式
   ========================================================= */

@media (max-width: 860px) {
  main { padding: 16px 14px 44px; max-width: 100%; }
  .meta-row { flex-direction: column; }
  .meta-author { width: 100%; }
  .editor-body { height: clamp(300px, calc(100vh - 380px), 560px); }
  .action-hint { display: none; }
  .brand-text em { display: none; }
  .editor-card, .view, main { min-width: 0; max-width: 100%; }
}

@media (max-width: 620px) {
  .topbar { padding: 0 10px; height: 54px; gap: 4px; }
  .brand { padding: 2px; flex: 0 1 auto; min-width: 0; }
  .brand-text strong { font-size: 14px; }
  .topbar-spacer { min-width: 0; flex: 1 1 0; }
  .topbar-actions { flex: 0 0 auto; gap: 2px; }

  .topbar-actions .btn { padding: 0 9px; gap: 5px; }
  .topbar-actions .btn > span { display: none; }
  .topbar-actions .btn > span.lbl-short { display: inline; }

  .foot-tips { display: none; }
  .editor-bar { gap: 6px; padding: 0 8px; }
  .editor-bar-right { gap: 4px; flex: 0 0 auto; }
  .toggle span:last-child, .fontsize { display: none; }
  .detect-chip { display: none !important; }
  #langSelect { max-width: 118px; }
  .meta-title, .meta-author { height: 40px; font-size: 13.5px; }
  .read-title { font-size: 18px; }
  .read-toolbar { height: auto; flex-wrap: wrap; padding: 8px 10px; gap: 8px; }
  .read-code { max-height: none; }
  .sheet { padding: 16px; }
  .sheet-foot { flex-direction: column; align-items: stretch; gap: 8px; }
  .sheet-foot-actions { justify-content: flex-end; }
  .drawer { max-width: 100%; }
  .action-row .btn { flex: 1 1 auto; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
