:root{
  --brand:#123b6b;
  --brand-strong:#0a2c54;
  --accent:#d24b43;
  --accent-soft:#f0b25f;
  --surface:#f7f4ee;
  --surface-strong:#fffdf8;
  --ink:#1e2430;
  --muted:#687284;
  --line:rgba(18,59,107,.14);
  --shadow:0 28px 60px rgba(18,40,72,.16);
}

*{box-sizing:border-box}

body{
  margin:0;
  min-height:100vh;
  font-family:"Trebuchet MS","Segoe UI",sans-serif;
  color:var(--ink);
  background:linear-gradient(135deg,#f2eee6,#f8fbff 55%,#eef3fb);
}

body.dark-mode{
  --brand:#ff6b63;
  --brand-strong:#ff8277;
  --accent:#ff7c6f;
  --accent-soft:#ffbd6c;
  --surface:#1f2430;
  --surface-strong:#242b38;
  --ink:#f4f2ec;
  --muted:#b9c2d0;
  --line:rgba(255,255,255,.09);
  --shadow:0 26px 60px rgba(0,0,0,.45);
  background:linear-gradient(135deg,#12161f,#191f2a 48%,#141a23);
}

.theme-toggle{
  position:fixed;
  top:18px;
  right:18px;
  z-index:5;
  width:44px;
  height:44px;
  min-width:44px;
  padding:0;
  border:1px solid rgba(105,83,72,.16);
  border-radius:14px;
  background:rgba(241,238,233,.82);
  color:#273653;
  box-shadow:0 10px 26px rgba(55,47,43,.12);
  backdrop-filter:blur(14px) saturate(1.08);
  -webkit-backdrop-filter:blur(14px) saturate(1.08);
  cursor:pointer;
  transition:background-color .18s ease,border-color .18s ease,color .18s ease,transform .18s ease;
}

.theme-toggle:hover{
  background:rgba(245,242,237,.94);
  border-color:rgba(166,96,90,.26);
  transform:translateY(-1px);
}

.theme-toggle:focus-visible{
  outline:3px solid rgba(166,96,90,.30);
  outline-offset:2px;
}

.theme-toggle .topbar-icon{
  width:19px;
  height:19px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}

.theme-toggle .topbar-icon svg{
  width:100%;
  height:100%;
  fill:none;
  stroke:currentColor;
  stroke-width:1.8;
  stroke-linecap:round;
  stroke-linejoin:round;
}

body.dark-mode .theme-toggle{
  background:rgba(12,18,28,.68);
  color:#f4f1ef;
  border-color:rgba(255,255,255,.10);
  box-shadow:0 10px 28px rgba(0,0,0,.22);
}

body.dark-mode .theme-toggle:hover{
  background:rgba(29,38,52,.86);
  border-color:rgba(176,106,100,.30);
}

.page-shell{
  min-height:100vh;
  position:relative;
  isolation:isolate;
  display:grid;
  grid-template-columns:1.1fr .9fr;
  align-items:stretch;
}

.page-shell::before,
.page-shell::after{
  content:"";
  position:absolute;
  inset:0;
  pointer-events:none;
}

.page-shell::before{
  z-index:0;
  background:url("/static/login_bg_scene.png") center center / cover no-repeat;
  opacity:.96;
}

.page-shell::after{
  z-index:0;
  background:
    linear-gradient(90deg, rgba(244,240,232,.10) 0%, rgba(245,246,249,.08) 52%, rgba(244,247,251,.48) 100%),
    linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.02) 42%, rgba(255,255,255,.09) 100%),
    radial-gradient(circle at top left, rgba(210,75,67,.07), transparent 24%),
    radial-gradient(circle at bottom right, rgba(18,59,107,.08), transparent 26%);
}

body.dark-mode .page-shell::before{
  opacity:1;
  filter:brightness(.68) saturate(.88) hue-rotate(-6deg);
}

body.dark-mode .page-shell::after{
  background:
    linear-gradient(90deg, rgba(13, 18, 28, .22) 0%, rgba(17, 22, 33, .16) 44%, rgba(15, 20, 30, .58) 100%),
    linear-gradient(180deg, rgba(7, 10, 16, .08), rgba(8, 12, 18, .04) 32%, rgba(8, 12, 18, .18) 100%),
    radial-gradient(circle at top left, rgba(255,124,111,.1), transparent 24%),
    radial-gradient(circle at bottom right, rgba(255,189,108,.06), transparent 22%);
}

.story-panel,
.login-panel{
  position:relative;
  z-index:1;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:72px 32px 40px;
}

.story-panel{
  position:relative;
  overflow:hidden;
  background:transparent;
  align-items:flex-start;
  justify-content:flex-start;
  padding:48px 32px 40px 56px;
}

.login-panel{
  justify-content:flex-end;
  padding-right:48px;
}

body.dark-mode .story-panel,
body.dark-mode .login-panel{
  background:transparent !important;
}

body:not(.dark-mode) .story-panel,
body:not(.dark-mode) .login-panel{
  background:transparent !important;
}

.story-panel__inner{
  width:min(100%,560px);
  position:relative;
  z-index:1;
}

.story-badge{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:8px 14px;
  border-radius:999px;
  background:rgba(255,255,255,.55);
  border:1px solid var(--line);
  color:var(--brand-strong);
  font-family:Consolas,"Courier New",monospace;
  font-size:.82rem;
  text-transform:uppercase;
  letter-spacing:.08em;
}

body.dark-mode .story-badge{
  background:rgba(255,255,255,.04);
}

.story-title{
  margin:18px 0 12px;
  font-size:clamp(2.5rem,5.2vw,4.2rem);
  line-height:.92;
  color:var(--brand-strong);
  max-width:9ch;
  text-shadow:0 2px 18px rgba(255,253,248,.72);
}

body.dark-mode .story-title{
  color:var(--accent);
  text-shadow:0 3px 20px rgba(0,0,0,.46);
}

.login-drawer{
  position:relative;
  width:min(100%,430px);
  margin-left:auto;
}

.login-box{
  width:100%;
  padding:30px;
  border-radius:30px;
  background:rgba(255,253,248,.88);
  border:1px solid var(--line);
  box-shadow:var(--shadow);
  backdrop-filter:blur(14px);
}

body.dark-mode .login-box{
  background:rgba(27,34,45,.92);
}

.login-box__top{
  display:flex;
  align-items:flex-start;
  margin-bottom:14px;
}

.eyebrow{
  margin-bottom:6px;
  color:var(--accent);
  font-family:Consolas,"Courier New",monospace;
  font-size:.78rem;
  text-transform:uppercase;
  letter-spacing:.14em;
}

.login-title{
  margin:0;
  color:var(--brand-strong);
  font-size:2rem;
  line-height:1;
}

body.dark-mode .login-title{
  color:var(--accent);
}

.login-copy{
  margin:0 0 24px;
  color:var(--muted);
  line-height:1.6;
}

.helper-status-card{
  display:flex;
  flex-direction:column;
  gap:6px;
  margin:0 0 22px;
  padding:14px 16px;
  border-radius:18px;
  border:1px solid var(--line);
  background:rgba(255,255,255,.62);
  box-shadow:0 10px 24px rgba(18,40,72,.08);
}

body.dark-mode .helper-status-card{
  background:rgba(255,255,255,.04);
}

.helper-status-card__title{
  color:var(--brand-strong);
  font-size:.95rem;
}

.helper-status-card__text{
  color:var(--muted);
  line-height:1.5;
  font-size:.92rem;
}

.helper-status-card__actions{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  margin-top:4px;
}

.helper-status-card__link{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:38px;
  padding:8px 14px;
  border-radius:999px;
  background:var(--brand);
  color:#fff;
  text-decoration:none;
  font-weight:700;
  box-shadow:0 10px 18px rgba(18,59,107,.14);
}

body.dark-mode .helper-status-card__link{
  background:rgba(255,124,111,.9);
  color:#fff;
}

.helper-status-card--checking{
  border-color:rgba(240,178,95,.42);
}

.helper-status-card--connected{
  border-color:rgba(61,166,114,.38);
  background:rgba(122,210,154,.12);
}

.helper-status-card--warning{
  border-color:rgba(210,75,67,.36);
  background:rgba(210,75,67,.08);
}

.field{
  display:grid;
  gap:8px;
  margin-bottom:16px;
  text-align:left;
}

.field span{
  font-size:.88rem;
  color:var(--muted);
}

input{
  width:100%;
  padding:14px 16px;
  border-radius:16px;
  border:1px solid var(--line);
  background:rgba(255,255,255,.76);
  color:var(--ink);
  font-size:1rem;
  transition:border-color .2s ease, transform .2s ease, box-shadow .2s ease;
}

body.dark-mode input{
  background:rgba(255,255,255,.05);
  color:#fff;
}

input:focus{
  outline:none;
  border-color:var(--accent);
  transform:translateY(-1px);
  box-shadow:0 0 0 4px rgba(210,75,67,.12);
}

#btnLogin{
  width:100%;
  margin-top:4px;
  padding:14px 18px;
  border:1px solid rgba(125,69,65,.58);
  border-radius:18px;
  background:linear-gradient(135deg,#a6605a 0%,#8d514c 56%,#7d4541 100%);
  color:#fffaf8;
  font-size:1rem;
  font-weight:700;
  letter-spacing:.02em;
  cursor:pointer;
  box-shadow:0 10px 22px rgba(125,69,65,.22),inset 0 1px 0 rgba(255,255,255,.16);
  transition:transform .18s ease,background .18s ease,border-color .18s ease,box-shadow .18s ease;
}

#btnLogin:hover{
  transform:translateY(-1px);
  background:linear-gradient(135deg,#b36d66 0%,#9a5953 56%,#8c4d48 100%);
  border-color:rgba(125,69,65,.72);
  box-shadow:0 14px 26px rgba(125,69,65,.26),inset 0 1px 0 rgba(255,255,255,.18);
}

#btnLogin:active{
  transform:translateY(0) scale(.995);
  box-shadow:0 6px 14px rgba(125,69,65,.20),inset 0 1px 0 rgba(255,255,255,.12);
}

#btnLogin:focus-visible{
  outline:3px solid rgba(166,96,90,.30);
  outline-offset:3px;
}

body.dark-mode #btnLogin{
  background:linear-gradient(135deg,#3b4657 0%,#4b4653 56%,#5a4348 100%);
  color:#f8f3f1;
  border-color:rgba(176,106,100,.34);
  box-shadow:0 10px 24px rgba(0,0,0,.24),inset 0 1px 0 rgba(255,255,255,.07);
}

body.dark-mode #btnLogin:hover{
  background:linear-gradient(135deg,#465267 0%,#584e5b 56%,#684c51 100%);
  border-color:rgba(184,111,103,.48);
  box-shadow:0 14px 28px rgba(0,0,0,.28),0 0 0 1px rgba(176,106,100,.06);
}

body.dark-mode #btnLogin:active{
  box-shadow:0 6px 16px rgba(0,0,0,.24),inset 0 1px 0 rgba(255,255,255,.05);
}

#btnLogin:disabled{
  opacity:.72;
  cursor:not-allowed;
}

.btn-secondary{
  width:100%;
  margin-top:10px;
  padding:13px 18px;
  border-radius:18px;
  border:1px solid var(--line);
  background:rgba(255,255,255,.72);
  color:var(--brand-strong);
  font-size:1rem;
  font-weight:700;
  cursor:pointer;
  transition:transform .2s ease, border-color .2s ease, background .2s ease;
}

body.dark-mode .btn-secondary{
  background:rgba(255,255,255,.05);
  color:#fff4f2;
}

.btn-secondary:hover{
  transform:translateY(-1px);
  border-color:rgba(210,75,67,.34);
}

.btn-secondary:disabled{
  opacity:.72;
  cursor:not-allowed;
}

.error{
  margin-top:12px;
  min-height:22px;
  color:#c8332e;
  font-size:.92rem;
}

.offline-login-card{
  display:grid;
  gap:8px;
  margin-top:18px;
  padding:16px 18px;
  border-radius:20px;
  border:1px solid rgba(18,59,107,.16);
  background:rgba(18,59,107,.06);
}

.offline-login-card[hidden]{
  display:none !important;
}

body.dark-mode .offline-login-card{
  border-color:rgba(255,124,111,.22);
  background:rgba(255,124,111,.08);
}

.offline-login-card__title{
  color:var(--brand-strong);
  font-size:.96rem;
}

.offline-login-card__text,
.offline-login-card__meta{
  margin:0;
  color:var(--muted);
  line-height:1.5;
  font-size:.92rem;
}

.offline-login-card__meta{
  font-family:Consolas,"Courier New",monospace;
  font-size:.84rem;
}

footer{
  margin-top:24px;
  color:var(--muted);
  font-size:.82rem;
}

@media (max-width: 980px){
  .page-shell{
    grid-template-columns:1fr;
  }

  .story-panel{
    padding-bottom:12px;
  }

  .story-title{
    max-width:none;
  }

  .login-panel{
    padding-right:32px;
  }

  .login-drawer{
    width:min(100%,430px);
  }
}

@media (max-width: 640px){
  .theme-toggle{
    top:14px;
    right:14px;
  }

  .story-panel,
  .login-panel{
    padding:68px 18px 24px;
  }

  .story-panel{
    padding:68px 18px 4px;
  }

  .login-panel{
    padding-right:18px;
  }

  .login-box{
    padding:24px 20px;
    border-radius:24px;
  }

  .login-box__top{
    align-items:flex-start;
  }

  .login-title{
    font-size:1.7rem;
  }

}
