:root {
  --ink: #14161f;
  --ink-soft: #565a72;
  --line: #e6e7ef;
  --surface: #ffffff;
  --surface-sunk: #f6f7fb;
  --primary: #5b5ce0;
  --primary-dark: #4644c9;
  --primary-soft: #eeeefb;
  --danger: #d64545;
  --danger-soft: #fdecec;
  --success: #1b9e6b;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(20, 22, 31, 0.05), 0 1px 1px rgba(20, 22, 31, 0.03);
  --shadow-md: 0 8px 24px rgba(20, 22, 31, 0.08), 0 2px 6px rgba(20, 22, 31, 0.04);
  --shadow-lg: 0 20px 50px rgba(20, 22, 31, 0.16), 0 6px 16px rgba(20, 22, 31, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface-sunk);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; font-weight: 700; margin: 0 0 0.3em; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 2rem 0 0.75em; color: var(--ink); }

/* ---------- shell / topbar ---------- */

.shell { max-width: 980px; margin: 0 auto; padding: 0 1.5rem 4rem; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.5rem;
  margin-bottom: 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--ink);
}

.topbar .brand svg { flex: none; }

.topbar nav a {
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 0.92rem;
  margin-left: 1.25rem;
}
.topbar nav a:hover { color: var(--ink); text-decoration: none; }

/* ---------- cards / surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  animation: rise 0.35s ease both;
}

.card + .card { margin-top: 1rem; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 1px 2px rgba(91, 92, 224, 0.25);
}
.btn-primary:hover {
  color: #fff;
  box-shadow: 0 6px 16px rgba(91, 92, 224, 0.35);
  transform: translateY(-1px);
}

.btn-ghost {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink-soft);
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8rem; }

/* ---------- forms ---------- */

input[type=text], input[type=password], input[type=file], textarea {
  font: inherit;
  font-size: 0.92rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
  width: 100%;
}
input[type=text]:focus, input[type=password]:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

label { font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); display: block; margin-bottom: 0.3rem; }

.field { margin-bottom: 1rem; max-width: 420px; }

form.row { display: flex; gap: 0.5rem; align-items: center; }

/* ---------- table ---------- */

table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
table.data td {
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr { transition: background 0.1s ease; }
table.data tbody tr:hover { background: var(--surface-sunk); }

.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-sunk);
  color: var(--ink-soft);
}
.badge.locked { background: var(--danger-soft); color: var(--danger); }
.badge.active { background: #e8f8f1; color: var(--success); }

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 2.5rem 1rem;
  font-size: 0.92rem;
}

/* ---------- alerts ---------- */

.alert {
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  font-size: 0.87rem;
  margin-bottom: 1rem;
}
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-warn { background: #fff6e0; color: #8a6300; }

/* ---------- auth (login / replace) pages ---------- */

.auth-wrap {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  background: #05060c;
}

.auth-wrap video {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.auth-wrap::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  background: linear-gradient(180deg, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0.15) 30%, rgba(0,0,0,0.55) 100%);
}

@media (prefers-reduced-motion: reduce) {
  .auth-wrap video { display: none; }
  .auth-wrap { background-image: url("/static/space-poster.webp"); background-size: cover; background-position: center; }
}

.auth-tag {
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 2;
  padding: 3rem;
  animation: rise 0.6s ease both;
}
.auth-tag h2 {
  color: #fff;
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
}
.auth-tag p { color: rgba(255,255,255,0.82); font-size: 0.95rem; max-width: 340px; margin: 0; }

.auth-form {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.auth-box {
  width: 100%;
  max-width: 340px;
  background: rgba(20, 22, 31, 0.55);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  animation: rise 0.45s ease both;
}

.auth-box .logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 2rem;
  color: #fff;
}

.auth-box h1 { font-size: 1.3rem; margin-bottom: 0.3rem; color: #fff; }
.auth-box p.sub { color: rgba(255,255,255,0.7); font-size: 0.88rem; margin: 0 0 1.5rem; }
.auth-box label { color: rgba(255,255,255,0.7); }
.auth-box input[type=text],
.auth-box input[type=password],
.auth-box input[type=file] {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.18);
  color: #fff;
}
.auth-box input[type=text]::placeholder,
.auth-box input[type=password]::placeholder { color: rgba(255,255,255,0.4); }
.auth-box input[type=text]:focus,
.auth-box input[type=password]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 92, 224, 0.35);
}
.auth-box a { color: #c7c8ff; }

@media (max-width: 760px) {
  .auth-tag { display: none; }
}

/* ---------- trainee replace page ---------- */

.warn-box {
  background: #fff6e0;
  border: 1px solid #f4dfa0;
  color: #7a5a00;
  border-radius: 8px;
  padding: 0.9rem 1rem;
  font-size: 0.87rem;
  margin-bottom: 1.25rem;
}

/* ---------- editor overlay link ---------- */

#replace-link {
  position: fixed;
  bottom: 10px;
  right: 12px;
  z-index: 9999;
  font: 500 12px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink-soft);
  text-decoration: none;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(4px);
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  transition: color 0.12s ease, box-shadow 0.12s ease;
}
#replace-link:hover { color: var(--primary); box-shadow: var(--shadow-md); text-decoration: none; }

/* ---------- editor splash screen ---------- */

#splash {
  position: fixed;
  inset: 0;
  z-index: 10000;
  opacity: 1;
  transition: opacity 0.4s ease;
}
#splash.splash-hide { opacity: 0; pointer-events: none; }

.splash-content {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: #fff;
  text-align: center;
}
.splash-content p {
  margin: 0;
  font-size: 0.92rem;
  color: rgba(255,255,255,0.75);
}
.splash-spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- trainee private page ---------- */
.alert-ok { background: #e6f6ec; color: #17653a; }
.portal-body { margin: 0; min-height: 100vh; background: #070a1c; position: relative; }
.portal-bg { position: fixed; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; }
.portal-shade { position: fixed; inset: 0; background: rgba(6,8,22,0.55); z-index: 1; }
.portal-main { position: relative; z-index: 2; max-width: 760px; margin: 0 auto; padding: 3rem 1.25rem 4rem; }
.portal-head h1 { color: #fff; margin: 0 0 0.4rem; font-size: 1.9rem; }
.portal-head p { color: rgba(255,255,255,0.8); margin: 0 0 1.5rem; }
.portal-card { background: rgba(255,255,255,0.96); border-radius: 16px; padding: 0.5rem 1.25rem; box-shadow: 0 20px 50px rgba(0,0,0,0.35); }
.file-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: 1rem 0; border-bottom: 1px solid var(--line); }
.file-row:last-child { border-bottom: 0; }
.file-info { display: flex; align-items: center; gap: 0.85rem; min-width: 0; }
.file-ext { background: #eef0ff; color: var(--primary); font-weight: 700; font-size: 0.7rem; letter-spacing: 0.04em; padding: 0.45rem 0.55rem; border-radius: 8px; }
.file-title { font-weight: 600; word-break: break-word; }
.file-sub { font-size: 0.8rem; color: var(--ink-soft); }
.file-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
