/* A4 Lua 创意工坊 — 视觉重构(墨绿暖纸主题,移动优先) */
:root {
  --paper: #f4f2ec;
  --card: #ffffff;
  --ink: #1e1c18;
  --ink-soft: #6f6a5f;
  --line: #e4e0d3;
  --accent: #0f3d2e;
  --accent-strong: #0a2c21;
  --accent-soft: #e3efe8;
  --accent-tint: #f0f6f2;
  --gold: #b8872e;
  --ok: #1f7a45;
  --ok-soft: #e6f3ea;
  --bad: #b3261e;
  --bad-soft: #fae9e7;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(30, 28, 24, .05);
  --shadow-lg: 0 10px 28px rgba(15, 61, 46, .10);
  --mono: ui-monospace, "Cascadia Code", Consolas, "Courier New", monospace;
  --header-h: 58px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 80% -10%, var(--accent-tint), transparent 60%),
    var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  /* flex 布局保证 footer 始终贴底(不足一屏时也能钉在底部) */
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.wrap { max-width: 1060px; margin: 0 auto; padding: 0 18px; width: 100%; }
.muted { color: var(--ink-soft); font-size: 14px; }
.small { font-size: 13px; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

code {
  font-family: var(--mono); font-size: 13px; background: var(--accent-soft);
  padding: 1px 6px; border-radius: 5px; word-break: break-all;
}
pre {
  background: #1b2420; color: #e6ede8; padding: 14px 16px; border-radius: var(--radius-sm);
  overflow-x: auto; font-size: 13px; line-height: 1.55;
  -webkit-overflow-scrolling: touch;
}
pre code { background: none; color: inherit; padding: 0; }

/* ---------- 头部 ---------- */
.site-header {
  background: rgba(255, 255, 255, .86);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 10px; height: var(--header-h); }
.brand {
  font-size: 19px; font-weight: 800; color: var(--ink); text-decoration: none;
  letter-spacing: .5px; display: inline-flex; align-items: center; gap: 8px; min-width: 0;
}
.brand-dot { font-size: 20px; }
.brand-accent { color: var(--accent); }
.site-nav { display: flex; gap: 4px; }
.site-nav a {
  color: var(--ink-soft); text-decoration: none; padding: 7px 14px; border-radius: 999px;
  font-size: 15px; transition: background .18s var(--ease), color .18s var(--ease);
}
.site-nav a:hover { background: var(--accent-tint); color: var(--accent); }
.site-nav a.active { background: var(--accent); color: #fff; font-weight: 600; }

/* ---------- 主体 ---------- */
main { flex: 1 0 auto; padding: 26px 18px 48px; }
h1 { font-size: 26px; margin: 4px 0 6px; letter-spacing: .3px; }
h2 { font-size: 19px; margin: 26px 0 12px; }

/* ---------- 按钮 ---------- */
button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); padding: 9px 18px; border-radius: var(--radius-sm);
  transition: border-color .18s var(--ease), color .18s var(--ease),
              background .18s var(--ease), transform .12s var(--ease), box-shadow .18s var(--ease);
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; min-height: 40px; -webkit-tap-highlight-color: transparent;
}
button:hover, .btn:hover { border-color: var(--accent); color: var(--accent); }
button:active, .btn:active { transform: translateY(1px); }
button.primary, .btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
  box-shadow: 0 4px 14px rgba(15, 61, 46, .22);
}
button.primary:hover, .btn.primary:hover { background: var(--accent-strong); color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---------- 首页工具栏 ---------- */
.hero { margin-bottom: 4px; }
.hero .sub { color: var(--ink-soft); margin: 0 0 4px; font-size: 15px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0 12px; align-items: center; }
.toolbar input[type="search"] {
  flex: 1; min-width: 200px; font: inherit; font-size: 16px; /* iOS 防聚焦放大 */
  padding: 10px 16px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); outline: none; min-height: 44px;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.toolbar input[type="search"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.toolbar select {
  font: inherit; font-size: 15px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--card); min-height: 44px; outline: none;
}
.toolbar select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.toolbar .primary { border-radius: 999px; padding: 10px 22px; min-height: 44px; }

/* ---------- 标签条 ---------- */
.tag-bar { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 6px; min-height: 30px; }
.tag-chip {
  font: inherit; font-size: 13px; padding: 4px 14px; border-radius: 999px; min-height: 30px;
  background: var(--card); border: 1px solid var(--line); color: var(--ink-soft);
  text-decoration: none; display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
  transition: border-color .18s var(--ease), color .18s var(--ease), background .18s var(--ease);
}
.tag-chip span { opacity: .65; font-size: 12px; }
.tag-chip:hover { border-color: var(--accent); color: var(--accent); }
.tag-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---------- 作品卡片 ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 18px 14px; display: flex; flex-direction: column; gap: 8px;
  text-decoration: none; color: inherit; box-shadow: var(--shadow);
  transition: transform .18s var(--ease), box-shadow .18s var(--ease), border-color .18s var(--ease);
}
.card:hover { border-color: var(--accent); box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.card .title-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.card .name { font-size: 17px; font-weight: 700; letter-spacing: .2px; }
.card .desc {
  color: var(--ink-soft); font-size: 14px; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 44px;
}
.card .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 12.5px; color: var(--ink-soft); }
.chip {
  display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; font-size: 12px;
  background: var(--paper); border: 1px solid var(--line); color: var(--ink-soft);
}
.chip.v2 { background: var(--accent-soft); border-color: #bcd6c8; color: var(--accent); }
.chip.ver { font-family: var(--mono); }
.chip.tag { background: var(--accent-soft); border-color: #bcd6c8; color: var(--accent); }
.card .foot {
  border-top: 1px dashed var(--line); padding-top: 9px; display: flex;
  justify-content: space-between; font-size: 12.5px; color: var(--ink-soft); margin-top: auto;
}

.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 26px; }
.pager .info { font-size: 14px; color: var(--ink-soft); }

.empty {
  text-align: center; padding: 56px 20px; color: var(--ink-soft);
  border: 1.5px dashed var(--line); border-radius: var(--radius); background: var(--card);
}

/* ---------- 详情 ---------- */
.back-link {
  text-decoration: none; font-size: 14px; display: inline-flex; align-items: center;
  min-height: 36px; margin-bottom: 8px; color: var(--ink-soft);
}
.back-link:hover { color: var(--accent); }
.detail-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.meta-table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; font-size: 14px; }
.meta-table th { text-align: left; color: var(--ink-soft); font-weight: 500; white-space: nowrap; }
.meta-table th, .meta-table td { padding: 9px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.meta-table tr:last-child td, .meta-table tr:last-child th { border-bottom: none; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
table.versions { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; font-size: 14px; }
table.versions th { text-align: left; color: var(--ink-soft); font-weight: 500; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--accent-tint); white-space: nowrap; }
table.versions td { padding: 10px 14px; border-bottom: 1px solid var(--line); }
table.versions tr:last-child td { border-bottom: none; }
.sha { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); }

/* ---------- 上传 ---------- */
.dropzone {
  border: 2px dashed var(--line); border-radius: 18px; background: var(--card);
  padding: 48px 24px; text-align: center; cursor: pointer; box-shadow: var(--shadow);
  transition: border-color .18s var(--ease), background .18s var(--ease), transform .18s var(--ease);
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-tint); transform: translateY(-1px); }
.dropzone .big { font-size: 42px; }
.dropzone p { margin: 8px 0 2px; font-weight: 600; }
.progress-wrap { margin-top: 18px; }
.progress-bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-bar > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #1f6a4f); transition: width .2s; }
.result { margin-top: 20px; border-radius: var(--radius-sm); padding: 16px 18px; font-size: 15px; }
.result.ok { background: var(--ok-soft); border: 1px solid #b6d8c2; color: var(--ok); }
.result.bad { background: var(--bad-soft); border: 1px solid #e3bdb9; color: var(--bad); }
.result ul { margin: 8px 0 0; padding-left: 20px; }
.result code { background: rgba(255, 255, 255, .7); }

/* ---------- 折叠说明 ---------- */
details.rules {
  margin-top: 16px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 16px;
}
details.rules summary { cursor: pointer; color: var(--ink-soft); font-size: 14px; user-select: none; min-height: 28px; }
details.rules summary:hover { color: var(--accent); }
details.rules[open] summary { margin-bottom: 4px; }
details.rules ul { margin: 6px 0; padding-left: 20px; font-size: 14px; color: var(--ink-soft); }
details.rules pre { margin: 10px 0 4px; }
details.rules p { margin: 8px 0 4px; }

/* ---------- 登录 / 我的 ---------- */
.auth-card {
  max-width: 400px; margin: 34px auto 0; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; padding: 28px 26px 22px;
  box-shadow: var(--shadow-lg);
}
.auth-card h2 { margin: 0 0 18px; font-size: 20px; }
.auth-card .row { margin-bottom: 14px; }
.auth-card input {
  width: 100%; font: inherit; font-size: 16px; padding: 11px 14px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--paper); outline: none; min-height: 46px;
  transition: border-color .18s var(--ease), background .18s var(--ease), box-shadow .18s var(--ease);
}
.auth-card input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.auth-switch { font-size: 13.5px; color: var(--ink-soft); }
.auth-card .err { color: var(--bad); font-size: 13.5px; margin: 12px 0 0; }

.mine-card .title-row { text-decoration: none; color: inherit; }
.del-btn { font-size: 13px; padding: 6px 14px; border-radius: 8px; min-height: 34px; }
.del-btn:hover { color: var(--bad); border-color: var(--bad); }
.del-btn.armed { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }

/* ---------- 包内文件浏览 ---------- */
.file-list { display: flex; flex-direction: column; gap: 4px; }
.file-item {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  text-align: left; font-size: 13.5px; padding: 8px 14px; border-radius: 9px;
  font-family: var(--mono); background: var(--card); min-height: 38px;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.file-item .fp { word-break: break-all; }
.file-item:hover { border-color: var(--accent); color: var(--accent); }
.file-item.active { background: var(--accent-soft); border-color: #bcd6c8; color: var(--accent); }
#file-view pre { margin-top: 4px; max-height: 480px; overflow: auto; }
.fileview-head { margin: 10px 0 4px; }
.tk-kw { color: #6fc3a1; font-weight: 600; }
.tk-str { color: #a9cf8a; }
.tk-com { color: #8a8f85; font-style: italic; }
.tk-num { color: #7fb3d3; }
.tk-fn { color: #e0c479; }
.tk-key { color: #6fc3a1; }
.tk-bool { color: #7fb3d3; }
.mini-btn { font-size: 12.5px; padding: 4px 12px; border-radius: 8px; margin-left: 6px; min-height: 32px; }
#edit-ta {
  width: 100%; min-height: 440px; resize: vertical; font-family: var(--mono); font-size: 13px;
  line-height: 1.5; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #1b2420; color: #e6ede8; outline: none; tab-size: 4;
}
#edit-ta:focus { border-color: var(--accent); }
.edit-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.edit-actions .err { color: var(--bad); }
.meta-form {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 16px;
}
.meta-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.meta-form input, .meta-form textarea {
  font: inherit; font-size: 15px; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--paper); outline: none; resize: vertical;
}
.meta-form input:focus, .meta-form textarea:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- 标签编辑 ---------- */
.tag-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0 0; }
.tags-input {
  flex: 1; min-width: 220px; font: inherit; font-size: 15px; padding: 9px 14px;
  border: 1px solid var(--accent); border-radius: var(--radius-sm); background: #fff; outline: none;
}

/* ---------- 底部(始终贴底) ---------- */
.site-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--line); background: var(--card);
  padding: 16px 0 calc(16px + env(safe-area-inset-bottom));
}
.footer-inner { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--ink-soft); align-items: center; }
.footer-brand { font-weight: 600; color: var(--ink-soft); }
.site-footer a { color: var(--ink-soft); }
.site-footer a:hover { color: var(--accent); }

/* ---------- 移动端 ---------- */
@media (max-width: 640px) {
  .wrap { padding: 0 14px; }
  main { padding: 20px 14px 40px; }
  .brand { font-size: 17px; }
  .site-nav a { padding: 7px 11px; font-size: 14px; }
  h1 { font-size: 22px; }
  h2 { font-size: 17px; }
  .toolbar { gap: 8px; }
  .toolbar input[type="search"] { min-width: 0; flex: 1 1 100%; }
  .toolbar select { flex: 1; }
  .toolbar .primary { flex: 1; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .card { padding: 16px 16px 12px; }
  .detail-head { flex-direction: column; align-items: stretch; }
  .detail-head .btn, .detail-head button.primary, .detail-head a.primary { width: 100%; }
  .meta-form { grid-template-columns: 1fr; }
  .auth-card { margin: 20px auto 0; padding: 24px 20px 18px; }
  .dropzone { padding: 38px 16px; }
  #edit-ta { min-height: 320px; }
  .footer-inner { justify-content: center; text-align: center; }
}

/* 降低动态偏好 */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
