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

:root {
  --r: 22px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

html[data-theme="dark"] {
  --bg: #0a0812;
  --bg2: #150d24;
  --surface: rgba(255, 255, 255, .05);
  --surface-2: rgba(255, 255, 255, .09);
  --border: rgba(255, 255, 255, .1);
  --text: #f3eefd;
  --muted: #a89ec6;
  --accent: #b56bff;
  --accent-2: #ff5fa2;
  --accent-3: #4ad6ff;
  --gold: #ffc861;
  --glow: 0 0 40px rgba(181, 107, 255, .45);
  --shadow: 0 24px 60px rgba(0, 0, 0, .55);
  --wheel-bg: #140d22;
  --danger: #ff5d6c;
}

html[data-theme="light"] {
  --bg: #f7f3ff;
  --bg2: #efe6ff;
  --surface: rgba(255, 255, 255, .78);
  --surface-2: rgba(255, 255, 255, .95);
  --border: rgba(94, 48, 170, .16);
  --text: #24163d;
  --muted: #6c5b8d;
  --accent: #7b2ff7;
  --accent-2: #e83e8c;
  --accent-3: #0aa6d6;
  --gold: #d99400;
  --glow: 0 0 34px rgba(123, 47, 247, .25);
  --shadow: 0 20px 50px rgba(76, 34, 148, .16);
  --wheel-bg: #ffffff;
  --danger: #d92b3d;
}

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 12% -10%, rgba(181, 107, 255, .28), transparent 62%),
    radial-gradient(900px 620px at 92% 8%, rgba(255, 95, 162, .22), transparent 60%),
    radial-gradient(900px 700px at 50% 110%, rgba(74, 214, 255, .18), transparent 62%),
    linear-gradient(160deg, var(--bg), var(--bg2));
  background-attachment: fixed;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

[hidden] { display: none !important; }

.blobs { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .5; animation: drift 22s ease-in-out infinite; }
.b1 { width: 380px; height: 380px; background: #b56bff; top: -140px; left: -110px; }
.b2 { width: 320px; height: 320px; background: #ff5fa2; top: 18%; right: -140px; animation-delay: -7s; }
.b3 { width: 340px; height: 340px; background: #4ad6ff; bottom: -160px; left: 30%; animation-delay: -14s; }
@keyframes drift {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(30px, -40px, 0) scale(1.14); }
}

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 12px clamp(12px, 3vw, 26px);
  padding-top: max(12px, env(safe-area-inset-top));
  backdrop-filter: blur(18px) saturate(140%);
  background: color-mix(in srgb, var(--bg) 62%, transparent);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 900; letter-spacing: .14em; font-size: 14px;
  text-decoration: none; color: var(--text); white-space: nowrap;
  margin-right: auto;
}
.brand span {
  display: block; font-size: 10px; letter-spacing: .34em; color: var(--accent);
  margin-top: 2px;
}

.top-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 13px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font-size: 16px; cursor: pointer; text-decoration: none;
  transition: transform .2s var(--ease), background .2s, box-shadow .3s, border-color .2s;
}
.icon-btn:hover { transform: translateY(-2px); background: var(--surface-2); border-color: var(--accent); box-shadow: var(--glow); }
.icon-btn:active { transform: scale(.94); }

.wrap { position: relative; z-index: 1; max-width: 1240px; margin: 0 auto; padding: clamp(16px, 3vw, 30px) clamp(12px, 3vw, 26px) 70px; }

.view { animation: viewIn .5s var(--ease) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.view-title { font-size: clamp(21px, 4.4vw, 30px); margin: 0 0 6px; letter-spacing: -.02em; }
.view-title em { color: var(--accent-2); font-style: normal; }
.view-sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; line-height: 1.5; max-width: 60ch; }

.stage {
  display: grid; gap: 22px; grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
}

.wheel-card {
  position: relative; padding: 16px; border-radius: var(--r);
  border: 1px solid var(--border);
  background: linear-gradient(165deg, var(--surface-2), var(--surface));
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  transition: transform .75s var(--ease), opacity .6s, filter .6s, box-shadow .5s, border-color .4s;
  transform-origin: center top;
}
.wheel-card::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: radial-gradient(120% 90% at 50% 0%, rgba(181, 107, 255, .18), transparent 60%);
  opacity: 0; transition: opacity .5s;
}
.wheel-card.active { border-color: color-mix(in srgb, var(--accent) 55%, transparent); box-shadow: var(--shadow), var(--glow); }
.wheel-card.active::after { opacity: 1; }

.stage[data-active="1"] .wheel-card[data-wheel="1"],
.stage[data-active="2"] .wheel-card[data-wheel="2"],
.stage[data-active="3"] .wheel-card[data-wheel="3"] { transform: scale(1.045); }

.stage[data-active="1"] .wheel-card:not([data-wheel="1"]),
.stage[data-active="2"] .wheel-card:not([data-wheel="2"]),
.stage[data-active="3"] .wheel-card:not([data-wheel="3"]) {
  transform: scale(.9); opacity: .42; filter: blur(2.5px) saturate(.65);
}
.wheel-card.locked { pointer-events: none; }
.wheel-card.done { opacity: .82; filter: none; transform: scale(.94); }

.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; margin: 0; letter-spacing: .04em; text-transform: uppercase; }
.step {
  width: 25px; height: 25px; border-radius: 9px; display: grid; place-items: center;
  font-size: 12px; font-weight: 800;
  background: linear-gradient(140deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 6px 18px rgba(181, 107, 255, .45);
}

.wheel-host { position: relative; width: 100%; aspect-ratio: 1; max-width: 340px; margin: 0 auto; }
.wheel-host svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 14px 34px rgba(0, 0, 0, .4)); }
.sector { stroke: rgba(0, 0, 0, .22); stroke-width: 1.2; }
.wheel-host text { fill: #fff; font-weight: 800; letter-spacing: .02em; text-shadow: 0 1px 3px rgba(0,0,0,.5); pointer-events: none; }
.wheel-host .t-sub { font-weight: 600; opacity: .82; }

.wheel-pointer {
  position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
  width: 0; height: 0; z-index: 3;
  border-left: 12px solid transparent; border-right: 12px solid transparent;
  border-top: 22px solid var(--accent-2);
  filter: drop-shadow(0 0 10px rgba(255, 95, 162, .9));
}
.wheel-host::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  box-shadow: inset 0 0 0 6px var(--wheel-bg), inset 0 0 0 7px var(--border);
  pointer-events: none; z-index: 2;
}

.perc-legend { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 12px; flex-wrap: wrap; min-height: 26px; }
.perc-pill {
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
}
.perc-pill b { color: var(--accent); }
.perc-reset {
  font-size: 11px; padding: 4px 9px; border-radius: 999px; cursor: pointer;
  border: 1px dashed var(--border); background: transparent; color: var(--muted);
  transition: .2s;
}
.perc-reset:hover { color: var(--accent); border-color: var(--accent); }

.card-actions { display: flex; gap: 9px; margin-top: 14px; }
.btn {
  flex: 1; border: 0; border-radius: 14px; cursor: pointer;
  padding: 12px 16px; font-size: 14px; font-weight: 700; font-family: inherit;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border);
  transition: transform .18s var(--ease), box-shadow .3s, opacity .25s, filter .25s, background .25s;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .35; cursor: not-allowed; }

.btn-primary {
  color: #fff; border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 30px rgba(181, 107, 255, .42);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 16px 40px rgba(255, 95, 162, .5); }

.btn-gold {
  color: #2a1a00; border: 0; font-weight: 800;
  background: linear-gradient(135deg, #ffd777, #ff9f45 55%, #ff6fa5);
  box-shadow: 0 14px 36px rgba(255, 159, 69, .45);
  animation: goldPulse 2.6s ease-in-out infinite;
}
@keyframes goldPulse {
  0%, 100% { box-shadow: 0 14px 36px rgba(255, 159, 69, .4); }
  50% { box-shadow: 0 14px 46px rgba(255, 111, 165, .7); }
}

.btn-long { width: 100%; flex: none; margin-top: 14px; padding: 15px; font-size: 15px; text-align: center; display: block; text-decoration: none; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }

.row-btns { display: flex; gap: 10px; margin: 18px 0 0; }

.badge {
  margin-top: 12px; text-align: center; padding: 12px; border-radius: 14px;
  font-weight: 800; letter-spacing: .1em; text-transform: uppercase; font-size: 15px;
  animation: pop .55s var(--ease) both;
}
@keyframes pop { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: scale(1); } }

.badge.m { color: #bfe4ff; background: linear-gradient(135deg, rgba(40, 130, 255, .4), rgba(90, 200, 255, .28)); border: 1px solid rgba(90, 180, 255, .5); }
.badge.f { color: #ffd2e8; background: linear-gradient(135deg, rgba(255, 80, 160, .4), rgba(255, 140, 200, .28)); border: 1px solid rgba(255, 120, 180, .5); }
.badge.how { color: #ecdcff; background: linear-gradient(135deg, rgba(181, 107, 255, .4), rgba(120, 90, 255, .28)); border: 1px solid rgba(181, 107, 255, .5); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin-top: 12px; }
.chip {
  font-size: 12px; font-weight: 700; padding: 6px 11px; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .22); color: #fff;
  animation: pop .45s var(--ease) both;
}
.chips-inline { max-height: 120px; overflow: auto; }

.item-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.item-tile {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 12px; border-radius: 15px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
  transition: .25s var(--ease);
}
.item-tile:hover { transform: translateY(-2px); background: var(--surface-2); }
.item-tile.on { border-color: color-mix(in srgb, var(--accent) 70%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent), var(--glow); }
.item-tile.off { opacity: .45; }
.item-tile.disabled { opacity: .28; cursor: not-allowed; filter: grayscale(.6); }
.item-tile input { position: absolute; opacity: 0; pointer-events: none; }
.tick {
  width: 22px; height: 22px; flex: none; border-radius: 7px; display: grid; place-items: center;
  border: 1px solid var(--border); font-size: 12px; color: transparent;
  transition: .2s;
}
.item-tile.on .tick { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; }
.item-name { font-size: 13px; font-weight: 700; line-height: 1.2; }
.item-meta { font-size: 10px; color: var(--muted); font-weight: 600; margin-left: auto; }

.result-cards { display: grid; gap: 18px; }
.res-card {
  position: relative; border-radius: var(--r); padding: 26px 22px; overflow: hidden;
  border: 1px solid var(--border); box-shadow: var(--shadow);
  animation: cardIn .8s var(--ease) both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(46px) scale(.96); filter: blur(6px); }
  to { opacity: 1; transform: none; filter: none; }
}
.res-card::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 100% at 0% 0%, rgba(255, 255, 255, .22), transparent 55%);
}
.res-label { position: relative; font-size: 11px; letter-spacing: .26em; text-transform: uppercase; color: rgba(255, 255, 255, .78); margin: 0 0 10px; font-weight: 800; }
.res-main { position: relative; font-size: clamp(23px, 4.6vw, 34px); font-weight: 900; margin: 0; color: #fff; letter-spacing: -.02em; line-height: 1.15; text-shadow: 0 4px 22px rgba(0, 0, 0, .4); }

.res-who.m { background: linear-gradient(140deg, #1b6bff, #37c6ff 55%, #8de4ff); }
.res-who.f { background: linear-gradient(140deg, #ff2f86, #ff7fc0 55%, #ffc2e2); }
.res-how { background: linear-gradient(140deg, #7b2ff7, #b56bff 50%, #ff9ee0); }

.res-items { background: var(--surface-2); }
.res-items .res-label, .res-items .res-main { color: var(--text); }
.res-items .res-label { color: var(--muted); }

.res-grid { position: relative; display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-top: 16px; }
.res-tile {
  border-radius: 15px; padding: 14px 12px; color: #fff; font-weight: 800; font-size: 14px;
  display: flex; align-items: center; gap: 9px; min-height: 62px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .3), inset 0 1px 0 rgba(255, 255, 255, .3);
  animation: tileIn .6s var(--ease) both;
  border: 1px solid rgba(255, 255, 255, .28);
}
@keyframes tileIn { from { opacity: 0; transform: translateY(18px) scale(.9); } to { opacity: 1; transform: none; } }
.res-tile .glyph { font-size: 22px; line-height: 1; filter: drop-shadow(0 2px 4px rgba(0,0,0,.35)); }

.history-list { display: grid; gap: 10px; }
.hist-item {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 14px 16px; border-radius: 16px; cursor: pointer; font-family: inherit;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: .22s var(--ease);
  animation: viewIn .4s var(--ease) both;
}
.hist-item:hover { transform: translateX(4px); border-color: var(--accent); background: var(--surface-2); }
.hist-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.hist-dot.m { background: #37c6ff; box-shadow: 0 0 12px #37c6ff; }
.hist-dot.f { background: #ff7fc0; box-shadow: 0 0 12px #ff7fc0; }
.hist-body { flex: 1; min-width: 0; }
.hist-main { display: block; font-weight: 700; font-size: 13.5px; }
.hist-date { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.hist-arrow { color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; padding: 26px; text-align: center; border: 1px dashed var(--border); border-radius: 16px; }

.auth-body { display: grid; place-items: center; padding: 24px; }
.auth-wrap { position: relative; z-index: 1; width: 100%; max-width: 400px; }
.auth-card {
  padding: 30px 26px; border-radius: 26px; border: 1px solid var(--border);
  background: linear-gradient(165deg, var(--surface-2), var(--surface));
  box-shadow: var(--shadow); backdrop-filter: blur(24px);
  animation: cardIn .8s var(--ease) both;
}
.auth-logo {
  width: 62px; height: 62px; border-radius: 50%; margin: 0 auto 18px;
  background: conic-gradient(#b56bff 0 60deg, #ff5fa2 60deg 120deg, #4ad6ff 120deg 180deg, #ffb040 180deg 240deg, #6ef0b4 240deg 300deg, #fff 300deg 360deg);
  box-shadow: 0 0 0 7px var(--wheel-bg), 0 0 34px rgba(181, 107, 255, .6);
  animation: spinSlow 14s linear infinite;
}
@keyframes spinSlow { to { transform: rotate(360deg); } }
.auth-title { text-align: center; font-size: 26px; margin: 0 0 4px; letter-spacing: -.02em; }
.auth-title span { display: block; font-size: 12px; letter-spacing: .34em; color: var(--accent); margin-top: 5px; text-transform: uppercase; }
.auth-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.auth-error { color: var(--danger); font-size: 13px; margin: 0 0 12px; text-align: center; font-weight: 700; }

.field { display: block; margin-bottom: 14px; }
.field > span:first-child { display: block; font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); margin-bottom: 7px; font-weight: 700; }
.field input {
  width: 100%; padding: 13px 14px; border-radius: 13px; font-size: 15px; font-family: inherit;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: .2s;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow); }
.pass-wrap { position: relative; display: block; }
.pass-wrap input { padding-right: 48px; }
.peek {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: transparent; border: 0; cursor: pointer; font-size: 15px; padding: 8px;
  color: var(--muted);
}
.theme-fab { position: fixed; top: 16px; right: 16px; z-index: 5; }

@media (max-width: 940px) {
  .stage { grid-template-columns: 1fr; gap: 16px; }
  .stage[data-active] .wheel-card { transform: none; }
  .stage[data-active="1"] .wheel-card:not([data-wheel="1"]),
  .stage[data-active="2"] .wheel-card:not([data-wheel="2"]),
  .stage[data-active="3"] .wheel-card:not([data-wheel="3"]) {
    transform: scale(.96); opacity: .34; filter: blur(1.5px);
  }
  .stage[data-active="1"] .wheel-card[data-wheel="1"],
  .stage[data-active="2"] .wheel-card[data-wheel="2"],
  .stage[data-active="3"] .wheel-card[data-wheel="3"] { transform: none; opacity: 1; filter: none; }
  .wheel-card.done { opacity: .9; }
  .wheel-host { max-width: 300px; }
}

@media (max-width: 420px) {
  .res-grid { grid-template-columns: 1fr; }
  .card-actions { flex-direction: column; }
  .brand { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---- standalone / iOS ---- */
html { background-color: var(--bg); }
body { background-color: var(--bg); background-attachment: scroll; }
.topbar { -webkit-backdrop-filter: blur(18px) saturate(140%); }

@media (display-mode: standalone) {
  html, body {
    background-attachment: scroll;
    overscroll-behavior: none;
  }
  .topbar {
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    border-bottom-color: transparent;
  }
  .wrap { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
}

/* ---- фон одним fixed-слоем, без полос и обрезки ---- */
html, body { background: var(--bg); }

.blobs {
  background:
    radial-gradient(1100px 700px at 12% -10%, rgba(181, 107, 255, .28), transparent 62%),
    radial-gradient(900px 620px at 92% 8%, rgba(255, 95, 162, .22), transparent 60%),
    radial-gradient(900px 700px at 50% 110%, rgba(74, 214, 255, .18), transparent 62%),
    linear-gradient(160deg, var(--bg), var(--bg2));
  background-repeat: no-repeat;
  background-size: 100% 100%;
}

/* ---- шапка: меньше блюра, больше плотности ---- */
.topbar {
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(12px) saturate(120%);
  backdrop-filter: blur(12px) saturate(120%);
}

@media (display-mode: standalone) {
  .topbar {
    background: var(--bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .blobs .blob { opacity: .38; }
}