:root {
  --bg: #02010a;
  --glass: rgba(18, 14, 48, 0.42);
  --glass-border: rgba(170, 150, 255, 0.28);
  --text: #eef0ff;
  --muted: #a9a8d6;
  --accent: #8b6bff;
  --accent-2: #ff5fd2;
  --accent-3: #4fc3ff;
  --danger: #ff7a9a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

#galaxy {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(2, 1, 10, 0.75) 100%);
  z-index: 1;
}

.flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 50;
  transition: opacity 0.5s ease-in 1.1s;
}
body.warping .flash { opacity: 1; }

.stage {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

/* ---------- Login card ---------- */
.card {
  width: min(440px, 100%);
  padding: 40px 36px 34px;
  border-radius: 28px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.55),
    0 0 60px rgba(139, 107, 255, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transition: transform 0.25s ease-out, opacity 0.6s, filter 0.6s;
  animation: rise 1.1s cubic-bezier(.2, .8, .2, 1) both;
  position: relative;
}
.card::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: conic-gradient(from var(--angle, 0deg), var(--accent), var(--accent-2), var(--accent-3), var(--accent));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  animation: spin 6s linear infinite;
  opacity: 0.8;
  pointer-events: none;
}
@property --angle { syntax: '<angle>'; initial-value: 0deg; inherits: false; }
@keyframes spin { to { --angle: 360deg; } }
@keyframes rise {
  from { opacity: 0; transform: translateY(40px) rotateX(18deg) scale(0.94); }
  to { opacity: 1; transform: none; }
}
body.warping .card { opacity: 0; filter: blur(10px); transform: scale(0.85) translateZ(-200px); }


.logo {
  width: 74px;
  height: 74px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #fff 0 6%, transparent 7%),
    radial-gradient(circle at 50% 50%, #ffd29a 0, #ff5fd2 35%, #6a4bff 65%, transparent 70%);
  box-shadow: 0 0 40px rgba(255, 95, 210, 0.6), 0 0 90px rgba(106, 75, 255, 0.5);
  position: relative;
  animation: float 5s ease-in-out infinite;
}
.logo::after {
  content: '';
  position: absolute;
  inset: 22px -18px;
  border-radius: 50%;
  border: 2px solid rgba(190, 170, 255, 0.7);
  transform: rotate(-18deg);
}
@keyframes float { 50% { transform: translateY(-6px); } }

.welcome {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0;
}

.title {
  margin: 4px 0 28px;
  text-align: center;
  font-family: 'Kanit', sans-serif;
  font-size: clamp(1.9rem, 6vw, 2.5rem);
  font-weight: 700;
  line-height: 1.15;
  background: linear-gradient(100deg, #fff 0%, #cbb8ff 35%, #ff8fe0 60%, #8fd8ff 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
  animation: shimmer 5s linear infinite;
  filter:
    drop-shadow(0 1px 0 #6d4fd8)
    drop-shadow(0 2px 0 #5a3cc4)
    drop-shadow(0 3px 0 #472bb0)
    drop-shadow(0 6px 14px rgba(139, 107, 255, 0.65));
}
.title span { display: block; font-size: 0.55em; font-weight: 400; letter-spacing: 0.32em; -webkit-text-fill-color: transparent; }
@keyframes shimmer { to { background-position: -200% center; } }

.field { position: relative; margin-bottom: 16px; }
.field input {
  width: 100%;
  padding: 16px 48px 16px 18px;
  border-radius: 14px;
  border: 1px solid rgba(170, 150, 255, 0.25);
  background: rgba(6, 4, 24, 0.55);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input::placeholder { color: #7d7aa8; }
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(139, 107, 255, 0.22), 0 0 24px rgba(139, 107, 255, 0.35);
}
.toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 6px;
}

.btn {
  width: 100%;
  margin-top: 8px;
  padding: 16px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(110deg, #6a4bff, #c04bff 50%, #ff5fd2);
  background-size: 200% auto;
  box-shadow: 0 10px 30px rgba(192, 75, 255, 0.45);
  transition: background-position 0.5s, transform 0.15s, box-shadow 0.3s;
}
.btn:hover { background-position: right center; box-shadow: 0 12px 40px rgba(255, 95, 210, 0.55); }
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.7; cursor: progress; }

.error {
  min-height: 1.4em;
  margin: 12px 0 0;
  text-align: center;
  color: var(--danger);
  font-size: 0.95rem;
}
.card.shake { animation: shake 0.45s; }
@keyframes shake {
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}

.foot { margin-top: 22px; text-align: center; color: #6f6c99; font-size: 0.8rem; letter-spacing: 0.1em; }

/* ---------- Dashboard ---------- */
.dash {
  position: relative;
  z-index: 2;
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 16px 60px;
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 36px; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 1.2rem; }
.brand .logo { width: 40px; height: 40px; margin: 0; }
.brand .logo::after { inset: 12px -9px; }
.ghost {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
}
.ghost:hover { background: rgba(255, 255, 255, 0.12); }
.hero { margin-bottom: 30px; }
.hero .title { text-align: left; margin: 0 0 6px; }
.hero p { margin: 0; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.proj {
  display: block;
  padding: 24px;
  border-radius: 20px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: inherit;
  text-decoration: none;
  transition: transform 0.25s, box-shadow 0.25s, border-color 0.25s;
  animation: rise 0.9s cubic-bezier(.2, .8, .2, 1) both;
}
a.proj:hover { transform: translateY(-6px) scale(1.02); border-color: var(--accent); box-shadow: 0 20px 50px rgba(139, 107, 255, 0.35); }
.proj .ico { font-size: 2rem; }
.proj h3 { margin: 12px 0 4px; font-weight: 600; }
.proj p { margin: 0; color: var(--muted); font-size: 0.95rem; }
.proj.pending { opacity: 0.7; }
.badge { display: inline-block; margin-top: 12px; padding: 3px 10px; border-radius: 99px; font-size: 0.8rem; background: rgba(255, 255, 255, 0.08); color: var(--muted); }

@media (max-width: 480px) {
  .card { padding: 32px 22px 26px; border-radius: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

/* ---------- Admin ---------- */
a.brand { color: inherit; text-decoration: none; }
a.ghost { display: inline-block; text-decoration: none; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.tabs a {
  padding: 8px 16px;
  border-radius: 99px;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
}
.tabs a:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.tabs a.active { color: var(--text); border-color: var(--glass-border); background: var(--glass); }
.page-title { text-align: left; margin: 0 0 24px; }
.panel {
  margin-bottom: 24px;
  padding: 24px;
  border-radius: 20px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.panel h2 { margin: 0 0 16px; font-size: 1.15rem; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 18px; align-items: end; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 0.9rem; }
.panel input, .panel select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(170, 150, 255, 0.25);
  background: rgba(6, 4, 24, 0.55);
  color: var(--text);
  font: inherit;
  outline: none;
}
.panel input:focus, .panel select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 107, 255, 0.22); }
.panel small, .hint { color: #8a87b8; font-size: 0.82rem; }
.hint { margin: 14px 0 0; }
.actions { display: flex; gap: 10px; align-items: center; }
.btn.small { width: auto; margin: 0; padding: 10px 22px; font-size: 0.95rem; }
.ghost.danger { color: var(--danger); border-color: rgba(255, 122, 154, 0.4); }
.ghost.danger:hover { background: rgba(255, 122, 154, 0.12); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 10px; text-align: left; vertical-align: middle; border-bottom: 1px solid rgba(170, 150, 255, 0.14); }
th { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
td strong { font-weight: 600; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input, .inline select { width: auto; min-width: 0; flex: 1; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.row-actions form { margin: 0; }
.notice { margin-bottom: 16px; padding: 12px 16px; border-radius: 12px; border: 1px solid; }
.notice.is-ok { border-color: rgba(120, 230, 170, 0.45); background: rgba(60, 200, 130, 0.12); }
.notice.is-error { border-color: rgba(255, 122, 154, 0.5); background: rgba(255, 122, 154, 0.12); color: var(--danger); }
.db-status { margin: 0 0 12px; color: var(--muted); }
.db-status .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #5be3a0; box-shadow: 0 0 10px #5be3a0; }
code { font-family: ui-monospace, monospace; font-size: 0.88em; }
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .inline { flex-wrap: wrap; }
  .row-actions { justify-content: flex-start; }
}
