/* ─── Custom Properties ──────────────────────────────────────────────────── */
:root {
  --grad-a: #0f172a;
  --grad-b: #1e3a8a;
  --grad-c: #0369a1;
  --glass-bg: rgba(255, 255, 255, 0.07);
  --glass-border: rgba(255, 255, 255, 0.16);
  --glass-highlight: rgba(255, 255, 255, 0.10);
  --text: #f0f9ff;
  --muted: rgba(240, 249, 255, 0.50);
  --handle-size: 56px;
  --track-h: 68px;
  --r-xl: 34px;
  --r-lg: 18px;
  --r-md: 14px;
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--grad-a);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* ─── Screen Transitions ─────────────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px);
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}
.screen.active  { opacity: 1; pointer-events: all; transform: none; }
.screen.exiting { opacity: 0; transform: translateY(-16px); }

/* ─── PIN Screen ─────────────────────────────────────────────────────────── */
#screen-pin {
  background: linear-gradient(135deg, var(--grad-a) 0%, var(--grad-b) 55%, var(--grad-c) 100%);
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* White grid overlay */
.pin-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.045) 1px, transparent 1px);
  background-size: 44px 44px;
  pointer-events: none;
}

/* Glass card */
.pin-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 40px 28px 36px;
  width: min(360px, 100%);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 28px;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow:
    0 32px 64px rgba(0,0,0,0.45),
    0 0 0 1px rgba(255,255,255,0.06) inset,
    0 1px 0 rgba(255,255,255,0.12) inset;
}

.pin-icon {
  width: 60px; height: 60px;
  border-radius: 18px;
  background: rgba(59,130,246,0.22);
  border: 1px solid rgba(96,165,250,0.35);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 28px rgba(59,130,246,0.28);
}
.pin-icon svg { width: 30px; height: 30px; stroke: #93c5fd; }

.pin-title { font-size: 22px; font-weight: 700; letter-spacing: -0.2px; }
.pin-sub   { font-size: 14px; color: var(--muted); }

/* PIN boxes */
.pin-boxes {
  display: flex;
  gap: 12px;
  margin: 8px 0 2px;
}

.pin-box {
  width: 58px; height: 68px;
  border-radius: var(--r-md);
  background: rgba(255,255,255,0.05);
  border: 2px solid rgba(255,255,255,0.10);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700;
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.15s;
  cursor: pointer;
  user-select: none;
}

.pin-box.active {
  border-color: rgba(147,197,253,0.65);
  box-shadow: 0 0 18px rgba(59,130,246,0.32);
  transform: scale(1.05);
}

.pin-box.filled::after {
  content: '';
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #93c5fd;
  box-shadow: 0 0 10px rgba(147,197,253,0.6);
}

.pin-box.error {
  border-color: rgba(239,68,68,0.75);
  box-shadow: 0 0 16px rgba(239,68,68,0.25);
}

/* Hidden real input */
#pin-input {
  position: absolute;
  opacity: 0;
  width: 1px; height: 1px;
  pointer-events: none;
  font-size: 16px; /* prevent iOS zoom */
}

.pin-error   { font-size: 13px; color: #fca5a5; min-height: 20px; text-align: center; }
.pin-lockout { font-size: 13px; color: #fbbf24; min-height: 20px; text-align: center; font-weight: 600; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  15%     { transform: translateX(-9px); }
  30%     { transform: translateX(9px); }
  45%     { transform: translateX(-6px); }
  60%     { transform: translateX(6px); }
  75%     { transform: translateX(-3px); }
  90%     { transform: translateX(3px); }
}
.pin-boxes.shake { animation: shake 0.48s ease; }

/* ─── Servers Screen ─────────────────────────────────────────────────────── */
#screen-servers {
  background: linear-gradient(160deg, var(--grad-a) 0%, var(--grad-b) 60%, var(--grad-c) 100%);
}

.srv-header {
  display: flex; align-items: center; gap: 12px;
  padding: max(56px, env(safe-area-inset-top, 56px)) 22px 18px;
  background: rgba(0,0,0,0.22);
  border-bottom: 1px solid var(--glass-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  flex-shrink: 0;
}
.srv-header-icon { width: 26px; height: 26px; stroke: #93c5fd; flex-shrink: 0; }
.srv-header h1   { font-size: 20px; font-weight: 700; }

.srv-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
}

.loading-wrap { display: flex; justify-content: center; padding: 40px 0; }

.srv-card {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
  transition: border-color 0.3s, background 0.3s;
}

.srv-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}
.srv-dot.online  { background: #4ade80; box-shadow: 0 0 8px rgba(74,222,128,0.55); }
.srv-dot.offline { background: #6b7280; }

.srv-info { flex: 1; min-width: 0; }
.srv-name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srv-host { font-size: 12px; color: var(--muted); margin-top: 2px; }
.srv-status-text { font-size: 12px; color: var(--muted); font-weight: 500; flex-shrink: 0; }

/* ─── Slider Section ─────────────────────────────────────────────────────── */
.slider-section {
  padding: 18px 18px max(28px, env(safe-area-inset-bottom, 28px));
  background: rgba(0,0,0,0.28);
  border-top: 1px solid var(--glass-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  flex-shrink: 0;
}

.slider-hint {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

/* The track — glass morphism container */
.slider-track {
  position: relative;
  height: var(--track-h);
  border-radius: var(--r-xl);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow:
    inset 0 2px 8px rgba(0,0,0,0.3),
    inset 0 -1px 0 rgba(255,255,255,0.04),
    0 1px 0 rgba(255,255,255,0.06);
  overflow: hidden; /* clip the fill */
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.slider-track.hidden {
  display: none;
}

/* Gradient fill — grows from left to right edge of handle, driven by JS */
.slider-fill {
  position: absolute;
  inset: 0;
  right: auto;   /* width is set via JS */
  width: 0;
  background: transparent;
  border-radius: var(--r-xl);
  pointer-events: none;
  transition: background 0.08s;
}

/* Center label text */
.slider-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  pointer-events: none;
  transition: opacity 0.15s;
  padding-left: calc(var(--handle-size) + 8px);
}

/* Handle — "glass button" circle with power icon */
.slider-handle {
  position: absolute;
  top: 50%;
  left: 6px;
  /* translateX is set via JS */
  transform: translateY(-50%) translateX(0px);
  width: var(--handle-size);
  height: var(--handle-size);
  border-radius: 50%;
  background: linear-gradient(145deg,
    rgba(255,255,255,0.28) 0%,
    rgba(255,255,255,0.10) 100%
  );
  border: 1.5px solid rgba(255,255,255,0.38);
  display: flex; align-items: center; justify-content: center;
  cursor: grab;
  touch-action: none;
  will-change: transform;
  z-index: 2;
  box-shadow:
    0 4px 20px rgba(0,0,0,0.35),
    0 0 0 1px rgba(255,255,255,0.08) inset,
    0 1px 0 rgba(255,255,255,0.22) inset;
  /* glow ring — intensity driven by CSS variable updated via JS */
  outline: 0 solid rgba(239,68,68,0);
  transition:
    box-shadow 0.2s,
    border-color 0.2s,
    outline-width 0.15s,
    outline-color 0.15s;
}

.slider-handle svg {
  width: 22px; height: 22px;
  stroke: rgba(255,255,255,0.88);
  transition: stroke 0.2s;
  pointer-events: none;
}

/* State: actively dragging */
.slider-handle.dragging {
  cursor: grabbing;
  border-color: rgba(239,68,68,0.55);
}
.slider-handle.dragging svg { stroke: rgba(255,180,180,0.9); }

/* State: locked (reached end) */
.slider-handle.locked {
  cursor: default;
  border-color: rgba(239,68,68,0.80);
  box-shadow:
    0 4px 20px rgba(239,68,68,0.40),
    0 0 36px rgba(239,68,68,0.20),
    0 0 0 1px rgba(255,255,255,0.08) inset;
}
.slider-handle.locked svg { stroke: #fca5a5; }

/* ─── Confirm Button ─────────────────────────────────────────────────────── */
.btn-shutdown {
  display: flex;
  align-items: center; justify-content: center;
  gap: 10px;
  width: 100%;
  margin-top: 14px;
  padding: 17px;
  border-radius: var(--r-lg);
  background: linear-gradient(135deg, #dc2626 0%, #7f1d1d 100%);
  border: 1px solid rgba(239,68,68,0.45);
  color: #fff;
  font-size: 16px; font-weight: 700; letter-spacing: 0.2px;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(220,38,38,0.40);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  animation: btnPop 0.42s var(--ease-spring);
}
.slider-track.hidden + .btn-shutdown {
  margin-top: 0;
}
.btn-shutdown svg { width: 20px; height: 20px; }
.btn-shutdown:active { transform: scale(0.97); box-shadow: 0 4px 14px rgba(220,38,38,0.30); }
.btn-shutdown.hidden { display: none; }

@keyframes btnPop {
  from { transform: scale(0.65); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

/* ─── Shutdown Progress Screen ───────────────────────────────────────────── */
#screen-shutdown {
  background: #06080f;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.sd-container {
  width: min(420px, 100%);
  display: flex; flex-direction: column; gap: 24px;
}

.sd-title {
  font-size: 22px; font-weight: 700;
  text-align: center;
  color: #f87171;
  letter-spacing: -0.2px;
}

.sd-list { display: flex; flex-direction: column; gap: 12px; }

.sd-card {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 20px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--r-lg);
  transition: border-color 0.4s, background 0.4s, box-shadow 0.4s;
}

.sd-card[data-s="connecting"] {
  border-color: rgba(251,191,36,0.40);
  background: rgba(251,191,36,0.05);
}
.sd-card[data-s="shutting_down"] {
  border-color: rgba(239,68,68,0.42);
  background: rgba(239,68,68,0.07);
  animation: cardPulse 1.1s ease-in-out infinite;
}
.sd-card[data-s="offline"] {
  border-color: rgba(107,114,128,0.28);
  background: rgba(107,114,128,0.04);
  opacity: 0.65;
}
.sd-card[data-s="error"] {
  border-color: rgba(239,68,68,0.60);
  background: rgba(239,68,68,0.09);
}

@keyframes cardPulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
  50%     { box-shadow: 0 0 0 5px rgba(239,68,68,0.12); }
}

.sd-icon {
  font-size: 22px;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.sd-info   { flex: 1; min-width: 0; }
.sd-name   { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sd-status { font-size: 13px; color: var(--muted); margin-top: 3px; }

.sd-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}
.sd-dot.pending      { background: rgba(255,255,255,0.18); }
.sd-dot.connecting   { background: #fbbf24; box-shadow: 0 0 8px rgba(251,191,36,0.55); animation: blink 0.75s ease-in-out infinite; }
.sd-dot.shutting_down{ background: #f87171; box-shadow: 0 0 8px rgba(248,113,113,0.55); animation: blink 0.50s ease-in-out infinite; }
.sd-dot.offline      { background: #4b5563; }
.sd-dot.error        { background: #ef4444; }

@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ─── Offline Screen ─────────────────────────────────────────────────────── */
#screen-offline {
  background: #030712;
  align-items: center;
  justify-content: center;
}

.offline-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}

.offline-icon {
  width: 88px; height: 88px;
  border-radius: 50%;
  background: rgba(239,68,68,0.10);
  border: 2px solid rgba(239,68,68,0.28);
  display: flex; align-items: center; justify-content: center;
  animation: offlinePulse 2.2s ease-in-out infinite;
}
.offline-icon svg { width: 42px; height: 42px; stroke: rgba(239,68,68,0.65); }

@keyframes offlinePulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); transform: scale(1); }
  50%     { box-shadow: 0 0 0 18px rgba(239,68,68,0); transform: scale(1.05); }
}

.offline-title { font-size: 24px; font-weight: 700; color: #f87171; }
.offline-sub   { font-size: 14px; color: var(--muted); }

.offline-dots { display: flex; gap: 8px; margin-top: 4px; }
.offline-dots span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  animation: dotPop 1.4s ease-in-out infinite;
}
.offline-dots span:nth-child(2) { animation-delay: 0.2s; }
.offline-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPop {
  0%,80%,100% { transform: scale(0.65); opacity: 0.35; }
  40%         { transform: scale(1);    opacity: 1; }
}

/* ─── Spinner ────────────────────────────────────────────────────────────── */
.spinner {
  width: 26px; height: 26px;
  border: 2.5px solid rgba(255,255,255,0.18);
  border-top-color: rgba(255,255,255,0.80);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: rgba(255,255,255,0.14); border-radius: 2px; }
