:root {
  --bg: #08080c;
  --panel: #121219;
  --panel-2: #1a1a26;
  --line: #232332;
  --text: #f4f4f9;
  --muted: #8d8da3;
  --accent: #7c5cff;
  --accent-soft: #a78bfa;
  --ok: #3ddc84;
  --warn: #ffb020;
  --bad: #ff5d5d;
  --tab-h: 62px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Roboto", sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  overflow: hidden;
}

#app::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 62% at 50% 105%, rgba(124, 92, 255, 0.22), transparent 62%);
  pointer-events: none;
}

/* ---------- верхняя панель ---------- */

#topbar {
  position: relative;
  z-index: 10;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 8px;
  font-size: 13px;
}

.conn {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  transition: color 0.2s;
}

.conn-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bad);
  box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.5);
  transition: background 0.2s, box-shadow 0.2s;
}

.conn[data-state="online"] { color: var(--ok); }
.conn[data-state="online"] .conn-dot {
  background: var(--ok);
  animation: dot-breathe 2.4s ease-in-out infinite;
}
.conn[data-state="reconnecting"] { color: var(--warn); }
.conn[data-state="reconnecting"] .conn-dot { background: var(--warn); animation: dot-blink 1s steps(2) infinite; }
.conn[data-state="offline"] { color: var(--bad); }

@keyframes dot-breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.45); }
  50% { box-shadow: 0 0 0 7px rgba(61, 220, 132, 0); }
}
@keyframes dot-blink { 50% { opacity: 0.3; } }

.conn-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ---------- экраны ---------- */

#screens {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 6px 14px calc(var(--tab-h) + 82px + env(safe-area-inset-bottom));
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.screen.active {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

[data-screen="home"] {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  width: 100%;
  padding: 20px;
  border: 0;
  border-radius: 26px;
  background: linear-gradient(180deg, #16161f, #101017);
  color: var(--text);
  text-align: left;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  transition: transform 0.12s ease, filter 0.12s ease;
  transform: translateZ(0);
}

.tile:active { transform: scale(0.97); filter: brightness(1.12); }

.tile-primary {
  background:
    linear-gradient(160deg, rgba(124, 92, 255, 0.38), rgba(124, 92, 255, 0.06) 62%),
    #121219;
  box-shadow: inset 0 0 0 1px rgba(124, 92, 255, 0.4);
}

.tile-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 17px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--accent-soft);
}

.tile-primary .tile-icon {
  background: linear-gradient(180deg, #8b6cff, #6a45ff);
  color: #fff;
  box-shadow: 0 10px 26px rgba(124, 92, 255, 0.45);
}

.tile-icon svg { width: 27px; height: 27px; }

.tile-text strong { display: block; font-size: 23px; font-weight: 650; letter-spacing: -0.02em; }
.tile-text small { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; }

/* ---------- заглушки ---------- */

.stub {
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
}

.stub-icon { display: block; margin-bottom: 10px; font-size: 46px; opacity: 0.85; }
.stub h2 { margin: 0; color: var(--text); font-size: 22px; font-weight: 600; }
.stub p { margin: 4px 0 0; font-size: 13px; }

/* ---------- Гоша ---------- */

#gosha {
  position: absolute;
  left: 50%;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 25;
  width: 76px;
  height: 76px;
  padding: 0;
  border: 0;
  background: transparent;
  transform: translateX(-50%);
}

.gosha-core {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #b49dff, #6d46ff 58%, #4a2bd6);
  color: #fff;
  box-shadow:
    0 12px 34px rgba(124, 92, 255, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: transform 0.12s ease;
  will-change: transform;
}

.gosha-core svg { width: 34px; height: 34px; }

.gosha-halo {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(124, 92, 255, 0.55), rgba(124, 92, 255, 0) 66%);
  animation: halo 2.6s ease-in-out infinite;
  will-change: transform, opacity;
  pointer-events: none;
}

@keyframes halo {
  0%, 100% { transform: scale(0.9); opacity: 0.45; }
  50% { transform: scale(1.22); opacity: 0.95; }
}

#gosha:active .gosha-core { transform: scale(0.92); }
#gosha.holding .gosha-core { transform: scale(1.06); }
#gosha.holding .gosha-halo { animation-duration: 0.9s; }

/* ---------- нижняя панель ---------- */

#tabbar {
  position: relative;
  z-index: 30;
  display: flex;
  flex: 0 0 auto;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: rgba(10, 10, 16, 0.88);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.tab {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 10px;
  transition: color 0.15s, transform 0.12s;
}

.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent-soft); }
.tab:active { transform: scale(0.92); }

/* ---------- вход ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(6, 6, 10, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transition: opacity 0.22s ease, visibility 0.22s;
}

.overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.login-box { width: 100%; max-width: 380px; text-align: center; }

.logo {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  margin: 0 auto 18px;
  border-radius: 23px;
  background: linear-gradient(160deg, #1b1b27, #0d0d14);
  box-shadow: inset 0 0 0 1px #262638, 0 22px 52px rgba(124, 92, 255, 0.28);
}

.logo-ring {
  width: 34px;
  height: 34px;
  border: 5px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 20px rgba(124, 92, 255, 0.65);
}

.login-box h1 { margin: 0 0 4px; font-size: 28px; letter-spacing: -0.02em; }
.sub { margin: 0 0 30px; color: var(--muted); font-size: 14px; }

.login-step.hidden { display: none; }

.btn {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 18px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  transition: transform 0.12s, filter 0.12s;
}

.btn:active { transform: scale(0.98); filter: brightness(1.08); }
.btn-big { height: 58px; }
.btn-accent {
  background: linear-gradient(180deg, #8b6cff, #6a45ff);
  box-shadow: 0 12px 30px rgba(124, 92, 255, 0.42);
}
.btn-ghost {
  background: #16161f;
  color: var(--text);
  box-shadow: inset 0 0 0 1px #272738;
}

.or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 12px;
}
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.link {
  padding: 16px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

input {
  width: 100%;
  height: 58px;
  margin-bottom: 10px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  outline: none;
  background: #111119;
  color: var(--text);
  font-family: inherit;
  font-size: 22px;
  text-align: center;
  letter-spacing: 0.18em;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.22); }
#name-input { font-size: 16px; letter-spacing: 0; }

label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 13px; text-align: left; }

.error { min-height: 18px; margin-top: 14px; color: var(--bad); font-size: 13px; }

/* ---------- тост ---------- */

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--tab-h) + 112px + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: 86%;
  padding: 12px 18px;
  border-radius: 15px;
  background: rgba(30, 30, 44, 0.97);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 14px;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
