:root {
  --bg: #f5f4f0;
  --card: #ffffff;
  --ink: #16161a;
  --ink-2: #3a3a40;
  --muted: #6b6b72;
  --line: #e3e1db;
  --fill: #eceae4;
  --accent: #16161a;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --ok: #1f7a4d;
  --focus: #2f6fde;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 20, 25, .04), 0 12px 32px rgba(20, 20, 25, .06);
  --serif: "Iowan Old Style", "Songti SC", "Noto Serif SC", "Source Han Serif SC", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e10; --card: #17171a; --ink: #f2f2f0; --ink-2: #d6d6d2; --muted: #a1a1a8; --line: #2a2a2e;
    --fill: #222226; --accent: #f2f2f0; --accent-ink: #111113; --danger: #f97066; --ok: #4ade80; --focus: #7aa7ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--bg); color: var(--ink); font: 15px/1.7 var(--sans); }
[hidden] { display: none !important; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------ shell */
.topbar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: max(14px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 14px max(20px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 600; letter-spacing: .02em; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--ink); color: var(--card);
  font: 600 15px/1 var(--serif); }
.topbar-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page { width: min(100%, 960px); margin: 0 auto; padding: 40px max(16px, env(safe-area-inset-right)) 64px max(16px, env(safe-area-inset-left)); }
.eyebrow { margin: 0 0 10px; font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }
h1, h2 { font-family: var(--serif); font-weight: 600; letter-spacing: .01em; }
h1 { font-size: clamp(28px, 6vw, 40px); line-height: 1.2; margin: 0 0 8px; }
h2 { font-size: 21px; margin: 0 0 6px; }
.lede { color: var(--muted); margin: 0; max-width: 40em; }
.section { margin-top: 44px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ------------------------------------------------------------ cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 14px; }
.app-card { display: flex; flex-direction: column; gap: 6px; padding: 22px; min-height: 150px; text-decoration: none;
  transition: transform .25s cubic-bezier(.2, .8, .2, 1), border-color .25s; }
.app-card:hover { transform: translateY(-2px); border-color: var(--muted); }
.app-card .app-title { font: 600 20px/1.3 var(--serif); }
.app-card .app-desc { color: var(--muted); font-size: 13px; flex: 1; }
.app-card .app-meta { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.app-card .arrow { font-size: 18px; color: var(--ink); }
.empty { padding: 26px; color: var(--muted); }
.panel { padding: 26px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 14px; }

/* ------------------------------------------------------------ forms */
.field-label { display: block; margin: 16px 0 7px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input, select.input { display: block; width: 100%; min-height: 46px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 11px;
  background: var(--bg); color: var(--ink); font: 16px/1.4 var(--sans); }
.input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.hint { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; margin-top: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.check input { width: 17px; height: 17px; margin: 0; accent-color: var(--ink); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 0 16px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font: 500 14px/1 var(--sans); text-decoration: none; cursor: pointer;
  transition: background .2s, border-color .2s, opacity .2s; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; min-height: 48px; margin-top: 18px; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.message { min-height: 22px; margin: 12px 0 0; font-size: 14px; color: var(--danger); overflow-wrap: anywhere; }
.message.ok { color: var(--ok); }
.note { margin: 14px 0 0; padding: 12px 14px; border-radius: 12px; background: var(--fill); color: var(--muted); font-size: 12px; line-height: 1.8; }

/* ------------------------------------------------------------ login */
.auth-shell { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.auth-card { width: min(100%, 440px); padding: clamp(24px, 6vw, 40px); }
.auth-card h1 { font-size: clamp(26px, 7vw, 32px); margin-top: 22px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 24px 0 6px; padding: 4px; border-radius: 12px; background: var(--fill); }
.tabs button { min-height: 42px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font: 500 14px/1 var(--sans); cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.tabs button:disabled { cursor: not-allowed; opacity: .55; }
.footer-note { margin-top: 22px; text-align: center; font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------ admin table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 13px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
td select.input { min-height: 36px; padding: 4px 10px; font-size: 14px; width: auto; min-width: 140px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--fill); color: var(--muted); font-size: 12px; }
.badge.admin { background: var(--ink); color: var(--card); }
dialog { width: min(92vw, 400px); padding: 26px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 10, 12, .45); backdrop-filter: blur(3px); }
dialog h2 { margin-bottom: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ------------------------------------------------------------ session warning */
.session-warning { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 14px; width: min(calc(100% - 32px), 520px); padding: 14px 16px; border-radius: 14px;
  background: var(--ink); color: var(--card); box-shadow: var(--shadow); font-size: 14px; }
.session-warning p { margin: 0; flex: 1; }
.session-warning .btn { flex: none; }

@media (max-width: 560px) {
  .page { padding-top: 28px; }
  .who { display: none; }
  .panel { padding: 20px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
