:root {
  --bg: #0a0a0f;
  --surface: #111118;
  --surface-2: #18181f;
  --border: #21212b;
  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --text: #e5e5ef;
  --text-2: #8a8a9a;
  --text-3: #484858;
  --green: #10b981;
  --red: #f87171;
  --radius: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  background:
    radial-gradient(ellipse 30% 60% at 0% 50%, rgba(255,110,20,0.045) 0%, transparent 100%),
    radial-gradient(ellipse 30% 60% at 100% 50%, rgba(255,110,20,0.045) 0%, transparent 100%),
    linear-gradient(rgba(8,8,12,0.62), rgba(8,8,12,0.62)),
    url('/static/tavern-bg.png') center center / contain no-repeat fixed,
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100%;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Lift main content above the frame overlay */
.main        { position: relative; z-index: 3; }
.main-portal { position: relative; z-index: 3; }
.login-page  { position: relative; z-index: 3; }
.nav         { z-index: 10; }

/* ── Woodgrain frame around the centered image ── */
.tavern-frame {
  position: fixed;
  top: 50%;
  left: 50%;
  /* min(100vw,100vh) matches how background-size:contain scales a square image */
  width: min(100vw, 100vh);
  height: min(100vw, 100vh);
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 2;
}

/* The four border planks */
.tavern-frame::before {
  content: '';
  position: absolute;
  inset: -22px;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255,255,255,0.022) 0px, rgba(255,255,255,0.022) 1px,
      transparent 1px, transparent 13px
    ),
    repeating-linear-gradient(
      0deg,
      transparent 0px, transparent 8px,
      rgba(0,0,0,0.07) 8px, rgba(0,0,0,0.07) 9px
    ),
    linear-gradient(160deg,
      #5c3218 0%, #3a1e0a 18%, #4e2c14 34%,
      #2e1608 50%, #4a2810 65%, #3a1e0a 82%, #5c3218 100%
    );
  /* Show only the four border strips — cut out the center */
  -webkit-mask:
    linear-gradient(#fff 0 0) top    / 100% 22px no-repeat,
    linear-gradient(#fff 0 0) bottom / 100% 22px no-repeat,
    linear-gradient(#fff 0 0) left   / 22px 100% no-repeat,
    linear-gradient(#fff 0 0) right  / 22px 100% no-repeat;
  mask:
    linear-gradient(#fff 0 0) top    / 100% 22px no-repeat,
    linear-gradient(#fff 0 0) bottom / 100% 22px no-repeat,
    linear-gradient(#fff 0 0) left   / 22px 100% no-repeat,
    linear-gradient(#fff 0 0) right  / 22px 100% no-repeat;
  box-shadow:
    0 0 0 1px #120903,
    0 0 0 3px rgba(80,44,18,0.5),
    0 0 50px rgba(0,0,0,0.9),
    inset 0 0 12px rgba(0,0,0,0.5);
}

/* Corner joints — slightly darker squares where planks meet */
.tavern-frame::after {
  content: '';
  position: absolute;
  inset: -22px;
  background:
    linear-gradient(135deg, #2a1206, #4a2810);
  -webkit-mask:
    linear-gradient(#fff 0 0) top    left  / 22px 22px no-repeat,
    linear-gradient(#fff 0 0) top    right / 22px 22px no-repeat,
    linear-gradient(#fff 0 0) bottom left  / 22px 22px no-repeat,
    linear-gradient(#fff 0 0) bottom right / 22px 22px no-repeat;
  mask:
    linear-gradient(#fff 0 0) top    left  / 22px 22px no-repeat,
    linear-gradient(#fff 0 0) top    right / 22px 22px no-repeat,
    linear-gradient(#fff 0 0) bottom left  / 22px 22px no-repeat,
    linear-gradient(#fff 0 0) bottom right / 22px 22px no-repeat;
}

/* ── Tavern Borders ─────────────────────────────── */

.tavern-side {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 84px;
  display: none;
  z-index: 20;
  pointer-events: none;
}

.tavern-left  { left: 0; }
.tavern-right { right: 0; }

@media (min-width: 1080px) {
  .tavern-side { display: block; }
}

.wood-panel {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      180deg,
      transparent 0px, transparent 12px,
      rgba(0,0,0,0.08) 12px, rgba(0,0,0,0.08) 13px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(255,255,255,0.012) 0px, rgba(255,255,255,0.012) 1px,
      transparent 1px, transparent 18px
    ),
    linear-gradient(180deg,
      #180d03 0%, #26140a 15%, #1e0f06 30%,
      #2e1a09 45%, #1c0e05 60%, #281508 75%,
      #200f04 90%, #170c02 100%
    );
}

.tavern-left .inner-edge {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 8px;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,0.6));
  box-shadow: 3px 0 18px rgba(0,0,0,0.6);
}

.tavern-right .inner-edge {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 8px;
  background: linear-gradient(90deg, rgba(0,0,0,0.6), transparent);
  box-shadow: -3px 0 18px rgba(0,0,0,0.6);
}

/* Candle container */
.candle {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 48px;
}

/* Smoke wisps */
.smoke {
  position: relative;
  height: 28px;
  width: 20px;
  display: flex;
  justify-content: center;
}

.smoke span {
  position: absolute;
  bottom: 0;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(190,170,150,0.25);
  animation: smoke-rise 3s ease-out infinite;
}
.smoke span:nth-child(1) { animation-delay: var(--d, 0s);                      left: 20%; }
.smoke span:nth-child(2) { animation-delay: calc(var(--d, 0s) + 1s);           left: 50%; }
.smoke span:nth-child(3) { animation-delay: calc(var(--d, 0s) + 2s);           left: 35%; }

/* Flame */
.flame-wrap {
  position: relative;
  width: 18px;
  height: 26px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.flame-outer {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 24px;
  background: linear-gradient(to top,
    #c83200 0%,
    #ff5500 20%,
    #ff9200 55%,
    #ffcc00 80%,
    #fff5a0 100%
  );
  border-radius: 50% 50% 22% 22% / 60% 60% 22% 22%;
  transform-origin: 50% 100%;
  animation: flicker 1.7s ease-in-out infinite;
  animation-delay: var(--d, 0s);
  filter: blur(0.6px);
}

.flame-inner {
  position: absolute;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
  width: 7px;
  height: 13px;
  background: linear-gradient(to top, #fff8e0 0%, #ffffff 100%);
  border-radius: 50% 50% 22% 22% / 60% 60% 22% 22%;
  transform-origin: 50% 100%;
  animation: flicker2 1.2s ease-in-out infinite reverse;
  animation-delay: calc(var(--d, 0s) + 0.15s);
  opacity: 0.85;
}

/* Wick */
.wick {
  width: 2px;
  height: 6px;
  background: #1a0f05;
  border-radius: 1px;
  z-index: 3;
}

/* Candle body */
.candle-body {
  width: 15px;
  height: 50px;
  background: linear-gradient(90deg,
    #c8ad80 0%, #ede0b8 30%, #f5ecca 55%, #e0cc98 80%, #c0a870 100%
  );
  border-radius: 2px 2px 1px 1px;
  position: relative;
  z-index: 2;
}

/* Wax drip on body */
.candle-body::before {
  content: '';
  position: absolute;
  top: 0; left: 3px;
  width: 5px; height: 14px;
  background: linear-gradient(180deg, #e8d5a8, transparent);
  border-radius: 0 0 40% 40%;
  opacity: 0.7;
}
.candle-body::after {
  content: '';
  position: absolute;
  top: 4px; right: 2px;
  width: 4px; height: 10px;
  background: linear-gradient(180deg, #e0cb98, transparent);
  border-radius: 0 0 40% 40%;
  opacity: 0.5;
}

/* Holder */
.candle-base {
  width: 26px;
  height: 9px;
  background: linear-gradient(180deg, #6b4020 0%, #3d2208 60%, #2a1606 100%);
  border-radius: 4px 4px 2px 2px;
  box-shadow: 0 3px 6px rgba(0,0,0,0.6);
  position: relative;
  z-index: 2;
}

.candle-base::after {
  content: '';
  position: absolute;
  bottom: -5px; left: -4px; right: -4px;
  height: 6px;
  background: linear-gradient(180deg, #2a1606, #1a0d03);
  border-radius: 2px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* Ambient glow */
.glow {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(255,130,10,0.32) 0%,
    rgba(255,80,0,0.10) 45%,
    transparent 70%
  );
  animation: glow-pulse 2.2s ease-in-out infinite;
  animation-delay: var(--d, 0s);
  pointer-events: none;
  z-index: 1;
}

/* Keyframes */
@keyframes flicker {
  0%   { transform: translateX(-50%) scaleX(1)    scaleY(1)    rotate(0deg);    opacity: 1;    }
  12%  { transform: translateX(-52%) scaleX(0.88) scaleY(1.10) rotate(-2.5deg); opacity: 0.93; }
  28%  { transform: translateX(-48%) scaleX(1.10) scaleY(0.92) rotate(2deg);    opacity: 1;    }
  44%  { transform: translateX(-50%) scaleX(0.93) scaleY(1.07) rotate(-1deg);   opacity: 0.90; }
  60%  { transform: translateX(-51%) scaleX(1.07) scaleY(0.95) rotate(1.5deg);  opacity: 0.97; }
  76%  { transform: translateX(-49%) scaleX(0.96) scaleY(1.04) rotate(-0.5deg); opacity: 1;    }
  88%  { transform: translateX(-50%) scaleX(1.03) scaleY(0.98) rotate(1deg);    opacity: 0.94; }
  100% { transform: translateX(-50%) scaleX(1)    scaleY(1)    rotate(0deg);    opacity: 1;    }
}

@keyframes flicker2 {
  0%, 100% { transform: translateX(-50%) scaleX(1)    scaleY(1);    }
  25%       { transform: translateX(-54%) scaleX(0.88) scaleY(1.12); }
  55%       { transform: translateX(-46%) scaleX(1.12) scaleY(0.88); }
  80%       { transform: translateX(-50%) scaleX(0.94) scaleY(1.06); }
}

@keyframes glow-pulse {
  0%, 100% { opacity: 0.65; transform: translateX(-50%) scale(1);    }
  50%       { opacity: 1;    transform: translateX(-50%) scale(1.28); }
}

@keyframes smoke-rise {
  0%   { transform: translateY(0)    scale(1)   translateX(0);   opacity: 0.5; }
  50%  { transform: translateY(-16px) scale(1.8) translateX(4px);  opacity: 0.25; }
  100% { transform: translateY(-30px) scale(2.8) translateX(-2px); opacity: 0; }
}

a { color: inherit; text-decoration: none; }

/* ── Login ─────────────────────────────────────── */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(139, 92, 246, 0.08), transparent);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 40px;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.wordmark {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: var(--accent);
}

.tagline {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 6px;
  letter-spacing: 0.5px;
}

.form-group { margin-bottom: 14px; }

.form-label {
  display: block;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 6px;
  font-weight: 500;
  letter-spacing: 0.3px;
}

.form-input {
  width: 100%;
  padding: 9px 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: var(--font);
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.btn-primary {
  width: 100%;
  padding: 10px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  margin-top: 10px;
  font-family: var(--font);
  letter-spacing: 0.2px;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.99); }

.error-msg {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: var(--red);
  padding: 10px 13px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── Nav ────────────────────────────────────────── */

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10;
}

.nav-brand {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 5px;
  text-transform: uppercase;
  color: var(--accent);
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-username {
  font-size: 13px;
  color: var(--text-2);
}

.btn-ghost {
  font-size: 13px;
  color: var(--text-3);
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  cursor: pointer;
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

/* ── Main content ───────────────────────────────── */

.main {
  max-width: 920px;
  margin: 0 auto;
  padding: 64px 32px 80px;
}

/* Portal layout: left column + fixed bottom-right health card */
.main-portal {
  position: relative;
  z-index: 3;
  min-height: 100vh;
  padding: 0 32px 120px;
}

.hero {
  padding-top: 56px;
  margin-bottom: 32px;
}

.hero h1 {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin-bottom: 10px;
}

.hero p {
  font-size: 15px;
  color: var(--text-2);
  display: flex;
  align-items: center;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: var(--green);
  border-radius: 50%;
  margin-right: 8px;
  flex-shrink: 0;
  animation: pulse 2.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  50%       { opacity: 0.8; box-shadow: 0 0 0 4px rgba(16, 185, 129, 0); }
}

/* Left column — three cards stacked */
.cards-left {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 300px;
}

/* System health pinned to bottom-right */
.card-health {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 240px;
  z-index: 5;
}

/* ── Cards ──────────────────────────────────────── */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.card-link {
  cursor: pointer;
}

.card-link:hover {
  border-color: rgba(139, 92, 246, 0.5);
  background: var(--surface-2);
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.1), 0 4px 20px rgba(0, 0, 0, 0.3);
}

.card:not(.card-link):hover {
  background: var(--surface-2);
  border-color: #2a2a35;
}

.card-icon {
  font-size: 20px;
  color: var(--accent);
  margin-bottom: 6px;
  line-height: 1;
}

.card h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.card p {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.65;
  flex: 1;
  margin-top: 2px;
}

.card p strong {
  color: var(--text);
  font-weight: 500;
}

.card-cta {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  margin-top: 10px;
  letter-spacing: 0.2px;
}

.card-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  background: rgba(139, 92, 246, 0.1);
  color: var(--accent);
  border: 1px solid rgba(139, 92, 246, 0.2);
  padding: 3px 9px;
  border-radius: 20px;
  font-weight: 500;
  margin-top: 10px;
  width: fit-content;
  letter-spacing: 0.3px;
}

/* ── Admin ──────────────────────────────────────── */

.flash {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 20px;
}
.flash-ok  { background: rgba(16,185,129,.08); border: 1px solid rgba(16,185,129,.25); color: #34d399; }
.flash-err { background: rgba(239,68,68,.08);  border: 1px solid rgba(239,68,68,.25);  color: var(--red); }

.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 26px;
  margin-bottom: 16px;
}

.admin-card h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
}

.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.form-input.sm { width: 180px; }
.btn-primary.sm { width: auto; padding: 9px 16px; margin-top: 0; }

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.user-table th {
  text-align: left;
  padding: 8px 12px;
  color: var(--text-2);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  letter-spacing: 0.3px;
}

.user-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.user-table tr:last-child td { border-bottom: none; }

.td-username { font-weight: 500; }
.td-muted { color: var(--text-2); }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  color: var(--text-2);
}

.badge-admin {
  background: rgba(139,92,246,.12);
  border-color: rgba(139,92,246,.3);
  color: var(--accent);
}

.btn-table {
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid rgba(139,92,246,.3);
  display: inline-block;
  user-select: none;
}
.btn-table:hover { background: rgba(139,92,246,.1); }

.reset-details[open] .btn-table { background: rgba(139,92,246,.1); }

.reset-form {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.btn-danger {
  width: auto;
  padding: 6px 12px;
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--font);
}
.btn-danger:hover { background: rgba(239,68,68,.1); }

/* ── Responsive ─────────────────────────────────── */

@media (max-width: 600px) {
  .main { padding: 40px 16px 60px; }
  .nav  { padding: 0 16px; }
  .hero h1 { font-size: 24px; }
  .login-card { padding: 28px 24px; }
}
