:root {
  --bg: #f1ede5;
  --paper: #fffefb;
  --ink: #28251f;
  --muted: #777166;
  --line: rgba(74, 65, 51, 0.18);
  --telegram: #2381c4;
  --telegram-dark: #176ba6;
  --blue: #315fd1;
  --green: #2b8b58;
  --danger: #b64a45;
  --shadow: 0 22px 64px rgba(57, 47, 33, 0.14);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -8rem, rgba(255, 255, 255, 0.96), transparent 32rem),
    var(--bg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(49, 95, 209, 0.34);
  outline-offset: 3px;
}

.auth-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  min-height: 64px;
  padding:
    max(10px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    10px
    max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(247, 244, 237, 0.84);
  backdrop-filter: blur(12px);
}

.back-link,
.brand {
  color: var(--blue);
  font-weight: 650;
  text-decoration: none;
}

.back-link { justify-self: start; white-space: nowrap; }
.back-link:hover, .brand:hover { text-decoration: underline; }

.brand {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-self: center;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
}

.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 9px;
  color: white;
  background: var(--blue);
  font: 700 17px/1 Georgia, "Times New Roman", serif;
}

.header-spacer { justify-self: end; }

.auth-main {
  display: flex;
  min-height: calc(100dvh - 65px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px max(16px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.auth-card {
  width: min(100%, 470px);
  padding: 28px 22px;
  border: 1px solid var(--line);
  border-radius: 22px;
  text-align: center;
  background: rgba(255, 254, 251, 0.98);
  box-shadow: var(--shadow);
}

.telegram-mark {
  display: grid;
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  place-items: center;
  border-radius: 20px;
  background: linear-gradient(145deg, #37a9e7, var(--telegram));
  box-shadow: 0 10px 25px rgba(35, 129, 196, 0.24);
}

.telegram-mark svg { width: 36px; height: 36px; fill: white; }

.eyebrow {
  margin: 0 0 5px;
  color: var(--telegram-dark);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font: 650 clamp(27px, 8vw, 36px)/1.15 Georgia, "Times New Roman", serif;
  letter-spacing: -0.025em;
}

.lead {
  max-width: 390px;
  margin: 13px auto 0;
  color: var(--muted);
  font-size: 15px;
}

.auth-view { margin-top: 26px; }

.checking-view,
.widget-loading {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.checking-view { min-height: 50px; }
.checking-view p { margin: 0; }

.spinner {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  border: 2px solid #d8d2c8;
  border-top-color: var(--telegram);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.widget-view {
  padding: 19px;
  border: 1px solid rgba(35, 129, 196, 0.2);
  border-radius: 16px;
  background: #f2f8fc;
}

.widget-view h2, .error-view h2, .success-view h2 { margin: 0; font-size: 19px; }
.widget-intro { margin: 7px auto 17px; color: var(--muted); font-size: 13px; }

.telegram-widget {
  display: grid;
  min-height: 54px;
  place-items: center;
  overflow: hidden;
}

.telegram-widget iframe { max-width: 100%; }
.widget-loading { min-height: 54px; font-size: 13px; }
.widget-error-note { color: var(--danger); font-size: 13px; }
.widget-expiry { min-height: 18px; margin: 9px 0 0; color: var(--muted); font-size: 12px; }

.telegram-button,
.quiet-button {
  display: inline-flex;
  width: 100%;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  padding: 11px 17px;
  font-weight: 700;
  cursor: pointer;
}

.telegram-button {
  border: 0;
  color: white;
  background: var(--telegram);
  box-shadow: 0 7px 18px rgba(35, 129, 196, 0.2);
}

.telegram-button:hover:not(:disabled) { background: var(--telegram-dark); }
.telegram-button:disabled, .quiet-button:disabled { opacity: 0.55; cursor: default; }

.quiet-button {
  min-height: 42px;
  margin-top: 10px;
  border: 1px solid rgba(35, 129, 196, 0.26);
  color: var(--telegram-dark);
  background: white;
  font-size: 13px;
}

.quiet-button:hover:not(:disabled) { border-color: var(--telegram); }

.error-mark,
.success-mark {
  display: grid;
  width: 44px;
  height: 44px;
  margin: 0 auto 12px;
  place-items: center;
  border-radius: 50%;
  font-size: 23px;
  font-weight: 750;
}

.error-mark { color: var(--danger); background: #f8e7e5; }
.success-mark { color: var(--green); background: #e4f3e9; }
.error-view p, .success-view p { margin: 7px 0 17px; color: var(--muted); }

.auth-status {
  min-height: 20px;
  margin: 15px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.auth-status:empty { min-height: 0; margin-top: 0; }
.auth-status.error { color: var(--danger); }
.auth-status.success { color: var(--green); }

.help-text {
  width: min(100%, 430px);
  margin: 18px auto 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.noscript-message {
  position: fixed;
  right: 16px;
  bottom: 16px;
  left: 16px;
  padding: 12px 16px;
  border-radius: 12px;
  color: white;
  background: var(--danger);
  text-align: center;
}

@media (min-width: 640px) {
  .auth-header { min-height: 70px; padding-right: 24px; padding-left: 24px; }
  .auth-main { min-height: calc(100dvh - 71px); padding-top: 42px; padding-bottom: 48px; }
  .auth-card { padding: 38px 42px; }
}

@media (max-width: 480px) {
  .brand > span:last-child { display: none; }
  .back-link { font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}
