:root {
  color-scheme: dark;
  --background: #020617;
  --surface: #0f172a;
  --surface-raised: #172033;
  --border: #334155;
  --text: #f8fafc;
  --muted: #a8b3c7;
  --accent: #22c55e;
  --accent-hover: #16a34a;
  --danger: #f87171;
  --focus: #86efac;
  font-family: "IBM Plex Sans", Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--background); }
body { margin: 0; min-height: 100vh; background: var(--background); color: var(--text); line-height: 1.55; }
a { color: var(--focus); }
button, input { font: inherit; }
button { min-height: 44px; cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.topbar { position: sticky; top: 0; z-index: 10; border-bottom: 1px solid var(--border); background: rgba(2, 6, 23, 0.94); backdrop-filter: blur(14px); }
.topbar-inner { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; letter-spacing: -0.02em; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--accent); color: #052e16; }
.brand-mark svg { width: 20px; height: 20px; }
.muted { color: var(--muted); }
.main { padding: 48px 0 72px; }
.hero { max-width: 760px; padding: 56px 0 32px; }
.eyebrow { margin: 0 0 12px; color: var(--focus); font-size: 13px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
h1 { margin: 0; max-width: 820px; font-size: clamp(36px, 7vw, 68px); line-height: 1.02; letter-spacing: -0.045em; }
h2 { margin: 0 0 20px; font-size: 24px; letter-spacing: -0.02em; }
.lead { max-width: 700px; margin: 24px 0 0; color: var(--muted); font-size: clamp(17px, 2.5vw, 21px); }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 32px; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 10px 18px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-raised); color: var(--text); text-decoration: none; font-weight: 600; transition: background-color 180ms ease, border-color 180ms ease; }
.button:hover { border-color: #64748b; background: #1e293b; }
.button-primary { border-color: var(--accent); background: var(--accent); color: #052e16; }
.button-primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.button-quiet { background: transparent; }
.button-danger { color: #fecaca; }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.card { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); padding: 22px; }
.metric-label { color: var(--muted); font-size: 14px; }
.metric-value { margin-top: 8px; font-size: 34px; line-height: 1; font-weight: 700; font-variant-numeric: tabular-nums; }
.section { margin-top: 40px; }
.panel { overflow: hidden; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 14px 18px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
td { font-size: 14px; }
tbody tr:last-child td { border-bottom: 0; }
.status { display: inline-flex; align-items: center; min-height: 26px; padding: 3px 9px; border-radius: 999px; background: #1e293b; color: #cbd5e1; font-size: 12px; font-weight: 600; }
.status-good { background: #052e16; color: #86efac; }
.empty { padding: 40px 22px; color: var(--muted); text-align: center; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 420px); }
.login-card h1 { font-size: 36px; }
.field { display: grid; gap: 8px; margin-top: 24px; }
label { color: #dbe4f0; font-weight: 600; }
input { width: 100%; min-height: 48px; padding: 10px 13px; border: 1px solid var(--border); border-radius: 10px; background: #020617; color: var(--text); }
.error { min-height: 24px; margin: 10px 0 0; color: #fecaca; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.prose { max-width: 760px; padding: 56px 0 80px; }
.prose h1 { font-size: clamp(34px, 6vw, 54px); }
.prose h2 { margin-top: 40px; }
.prose p, .prose li { color: #d5deeb; }
.notice { margin-top: 28px; border-left: 4px solid var(--accent); padding: 18px 20px; background: #071525; color: #dffbe8; }

.miniapp-body {
  min-height: 100dvh;
  padding: max(20px, var(--tg-content-safe-area-inset-top, 0px)) max(16px, var(--tg-content-safe-area-inset-right, 0px)) calc(96px + var(--tg-content-safe-area-inset-bottom, 0px)) max(16px, var(--tg-content-safe-area-inset-left, 0px));
  background: var(--tg-theme-bg-color, var(--background));
  color: var(--tg-theme-text-color, var(--text));
}
.miniapp-policy { width: min(100%, 680px); margin: 0 auto; }
.miniapp-policy__header { display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 14px; align-items: start; padding: 8px 0 24px; }
.miniapp-policy__header h1 { margin: 0; font-size: clamp(28px, 8vw, 42px); line-height: 1.08; letter-spacing: -0.035em; }
.policy-icon { width: 48px; height: 48px; display: grid; place-items: center; border: 1px solid #166534; border-radius: 14px; background: #052e16; color: #86efac; }
.policy-icon svg { width: 26px; height: 26px; }
.policy-summary, .policy-section, .policy-warning { margin-top: 14px; padding: 20px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); }
.policy-summary { border-color: #166534; background: #071b16; }
.policy-section h2, .policy-summary h2, .policy-warning h2 { margin: 0 0 10px; font-size: 18px; }
.policy-section p, .policy-summary p, .policy-warning p { margin: 0; color: #d5deeb; }
.policy-section ul { margin: 0; padding-left: 20px; color: #d5deeb; }
.policy-section li + li { margin-top: 8px; }
.policy-warning { border-color: #854d0e; background: #1c1407; }
.policy-warning h2 { color: #fde68a; }
.policy-draft { margin: 18px 4px 0; color: var(--muted); font-size: 13px; }
.miniapp-footer { position: fixed; z-index: 20; right: 0; bottom: 0; left: 0; padding: 12px max(16px, var(--tg-content-safe-area-inset-right, 0px)) calc(12px + var(--tg-content-safe-area-inset-bottom, 0px)) max(16px, var(--tg-content-safe-area-inset-left, 0px)); border-top: 1px solid var(--border); background: rgba(2, 6, 23, 0.96); backdrop-filter: blur(12px); }
.miniapp-close { width: min(100%, 680px); margin: 0 auto; display: flex; }
.admin-title { font-size: clamp(34px, 5vw, 54px); }
.detail-button { min-height: 40px; padding: 7px 12px; white-space: nowrap; }
.user-dialog { width: min(1080px, calc(100% - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--border); border-radius: 18px; background: var(--background); color: var(--text); box-shadow: 0 24px 80px rgba(0,0,0,.55); }
.user-dialog::backdrop { background: rgba(0,0,0,.66); backdrop-filter: blur(4px); }
.dialog-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 24px; border-bottom: 1px solid var(--border); background: rgba(2,6,23,.97); }
.dialog-head h2 { margin: 0; }
.user-detail { display: grid; gap: 18px; padding: 24px; }
.detail-loading { min-height: 180px; display: grid; place-items: center; color: var(--muted); }
.detail-section { padding: 20px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.detail-section h3 { margin: 0 0 16px; font-size: 18px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; margin: 0; }
.detail-item { min-width: 0; padding: 12px; border-radius: 10px; background: var(--surface-raised); }
.detail-item dt { color: var(--muted); font-size: 12px; }
.detail-item dd { overflow-wrap: anywhere; margin: 5px 0 0; font-weight: 650; font-variant-numeric: tabular-nums; }
.stage-list { display: grid; gap: 8px; }
.stage-row { display: grid; grid-template-columns: minmax(160px,1fr) auto minmax(230px,auto); gap: 16px; align-items: center; padding: 12px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.timeline { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.timeline-item { position: relative; padding: 15px 16px 15px 20px; border-left: 3px solid var(--accent); border-radius: 0 10px 10px 0; background: var(--surface-raised); }
.timeline-top { display: flex; justify-content: space-between; gap: 16px; }
.timeline-top time, .timeline-gap { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.timeline-item p { margin: 8px 0; overflow-wrap: anywhere; color: #d5deeb; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.settings-note { margin: -12px 0 0; }
.settings-form { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)) auto; gap: 16px; align-items: end; padding: 0 22px 22px; }
.settings-form .field { margin: 0; }
.settings-status { grid-column: 1 / -1; min-height: 20px; margin: 0; color: var(--focus); }

@media (max-width: 900px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) { .settings-form { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) {
  .shell { width: min(100% - 24px, 1180px); }
  .main { padding-top: 28px; }
  .hero { padding-top: 28px; }
  .grid { grid-template-columns: 1fr; }
  .topbar-inner { min-height: 64px; }
  .brand-label { display: none; }
  .actions { display: grid; }
  .button { width: 100%; }
  .user-dialog { width: 100%; max-height: 100dvh; height: 100dvh; border: 0; border-radius: 0; }
  .dialog-head, .user-detail { padding: 16px; }
  .dialog-head .button { width: auto; }
  .detail-grid { grid-template-columns: 1fr; }
  .stage-row { grid-template-columns: 1fr auto; gap: 6px 12px; }
  .stage-row small { grid-column: 1 / -1; }
  .timeline-top { display: grid; gap: 4px; }
  .settings-form { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
