/* ─── Tokens ─────────────────────────────────────────── */
:root {
  --bg-base:     #F3F0FA;
  --bg-surface:  rgba(248,244,255,0.70);
  --color-stone: #665878;
  --color-sage:  #A99CC8;   /* лаванда — правильно, акцент */
  --color-clay:  #C4A3BE;   /* орхидея светлая */
  --color-wrong: #BC7FA4;   /* насыщенная роза — ошибка */
  --shadow-ambient: 0 10px 30px -10px rgba(90,70,120,0.13),
                    0 4px 10px -5px rgba(90,70,120,0.07);
  --radius-card: 2rem;
  --radius-pill: 9999px;
}

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

body {
  min-height: 100dvh;
  background: var(--bg-base);
  font-family: 'Montserrat', sans-serif;
  color: var(--color-stone);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  opacity: 0.03;
  pointer-events: none;
  z-index: 0;
}

sup {
  font-size: 0.72em;
  vertical-align: super;
  line-height: 0;
}

/* ─── Screen base ────────────────────────────────────── */
.screen {
  position: fixed; inset: 0;
  display: flex;
  flex-direction: column;
  z-index: 1;
}

/* ─── HOME ───────────────────────────────────────────── */
.screen--home {
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}

.home-auth {
  position: fixed;
  top: 1rem; right: 1.5rem;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
}

.home-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding-top: 5rem;
  text-align: center;
}

.home-title {
  font-family: 'Lora', serif;
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 600;
  line-height: 1.2;
}

.home-sub {
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  opacity: 0.5;
}

/* ─── Buttons ────────────────────────────────────────── */
.btn-primary {
  padding: 0.85rem 2.5rem;
  border-radius: var(--radius-pill);
  border: none;
  background: var(--color-sage);
  color: #fff;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
  box-shadow: 0 4px 14px -4px rgba(169,156,200,0.55);
}
.btn-primary:hover  { opacity: 0.88; }
.btn-primary:active { transform: scale(0.97); }

.auth-bar__name { opacity: 0.6; }
.auth-bar__btn {
  padding: 0.35rem 0.9rem;
  border-radius: var(--radius-pill);
  border: 1.5px solid rgba(100,80,130,0.22);
  background: var(--bg-surface);
  backdrop-filter: blur(8px);
  color: var(--color-stone);
  text-decoration: none;
  cursor: pointer;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  transition: border-color 0.2s;
}
.auth-bar__btn:hover { border-color: var(--color-sage); }

/* ─── Author footer ──────────────────────────────────── */
.author-footer {
  position: fixed;
  bottom: 1.25rem; left: 0; right: 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--color-stone);
  opacity: 0.45;
  line-height: 1.6;
}
.author-footer__label { font-weight: 400; display: block; }
.author-footer__name {
  font-weight: 600;
  color: var(--color-stone);
  text-decoration: none;
  transition: opacity 0.2s;
}
.author-footer__name:hover { opacity: 0.7; }

/* ─── GAME screen ────────────────────────────────────── */
.screen--game {
  background: var(--bg-base);
}

.g-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.5rem;
  flex-shrink: 0;
}

.g-back {
  background: none;
  border: none;
  color: var(--color-stone);
  font-family: 'Montserrat', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  opacity: 0.65;
  transition: opacity 0.2s;
  padding: 0.25rem 0;
}
.g-back:hover { opacity: 1; }

.g-progress {
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.5;
  letter-spacing: 0.04em;
}

/* ─── Formula card ───────────────────────────────────── */
.g-card {
  margin: 0.75rem 1rem;
  padding: 1.25rem 1.25rem 1.5rem;
  background: var(--bg-surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(100,80,130,0.12);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-ambient);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: background 0.35s;
}

.g-card.flash-correct {
  animation: flashCorrect 0.55s ease forwards;
}
.g-card.flash-wrong {
  animation: flashWrong 0.55s ease forwards;
}

@keyframes flashCorrect {
  0%   { background: rgba(169,156,200,0.15); }
  40%  { background: rgba(169,156,200,0.38); }
  100% { background: var(--bg-surface); }
}
@keyframes flashWrong {
  0%   { background: rgba(188,127,164,0.12); }
  40%  { background: rgba(188,127,164,0.30); }
  100% { background: var(--bg-surface); }
}

.g-title {
  font-family: 'Lora', serif;
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 1rem;
  text-align: center;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}
.g-title.long-pressed {
  color: var(--color-sage);
}

/* ─── Workspace (LHS + slots) ────────────────────────── */
.workspace {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.8rem;
  width: 100%;
}

.ws-lhs {
  font-size: 1.05rem;
  font-weight: 600;
  font-family: 'Lora', serif;
  white-space: nowrap;
  margin-right: 0.1rem;
}

.ws-static {
  font-size: 1.3rem;
  font-weight: 700;
  font-family: 'Lora', serif;
  color: var(--color-stone);
  opacity: 0.55;
  line-height: 1;
}

.slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.2rem;
  min-height: 2.1rem;
  padding: 0.2rem 0.45rem;
  border: 2px dashed rgba(100,80,130,0.28);
  border-radius: 0.6rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-stone);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.slot.slot--active {
  border-style: solid;
  border-color: var(--color-sage);
  background: rgba(169,156,200,0.08);
  animation: slotInvite 1.8s ease-in-out infinite;
}
@keyframes slotInvite {
  0%, 100% { box-shadow: 0 0 0 0 rgba(169,156,200,0);    border-color: rgba(169,156,200,0.55); }
  50%       { box-shadow: 0 0 0 5px rgba(169,156,200,0.22); border-color: var(--color-sage); }
}
.slot.slot--filled {
  border-color: var(--color-sage);
  border-style: solid;
  background: rgba(169,156,200,0.14);
  cursor: pointer;
}
.slot.slot--drag-over {
  border-color: var(--color-sage);
  background: rgba(169,156,200,0.22);
}
.slot .phantom-hint {
  opacity: 0.32;
  pointer-events: none;
  font-style: italic;
}

/* ─── Shelf ──────────────────────────────────────────── */
.shelf-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 0.75rem 1rem 0;
}

.shelf {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.55rem;
  width: 100%;
  overflow-y: auto;
  max-height: 100%;
  padding-bottom: 0.5rem;
}

.shelf-block {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.1rem;
  border: 2px solid rgba(100,80,130,0.2);
  border-radius: 0.75rem;
  background: var(--bg-surface);
  backdrop-filter: blur(8px);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--color-stone);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.shelf-block:active { transform: scale(0.95); }
.shelf-block.selected {
  border-color: var(--color-sage);
  background: rgba(169,156,200,0.20);
  color: #4e3f66;
}
.shelf-block.dragging {
  opacity: 0.45;
}

/* ghost element while dragging */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  padding: 0.42rem 0.8rem;
  border: 2px solid var(--color-sage);
  border-radius: 0.75rem;
  background: rgba(169,156,200,0.92);
  color: #fff;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  transform: translate(-50%, -50%) scale(1.08);
  box-shadow: 0 8px 20px -4px rgba(100,80,130,0.3);
}

/* ─── Check button ───────────────────────────────────── */
.g-footer {
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  flex-shrink: 0;
}

.btn-check {
  width: 100%;
  padding: 0.9rem;
  border-radius: var(--radius-pill);
  border: none;
  background: var(--color-sage);
  color: #fff;
  font-family: 'Montserrat', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
  box-shadow: 0 4px 14px -4px rgba(169,156,200,0.55);
}
.btn-check:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-check:not(:disabled):hover  { opacity: 0.88; }
.btn-check:not(:disabled):active { transform: scale(0.98); }

/* ─── RESULTS ────────────────────────────────────────── */
.screen--results {
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.res-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  text-align: center;
}

.res-icon {
  font-size: 3rem;
  color: var(--color-sage);
  line-height: 1;
}

.res-title {
  font-family: 'Lora', serif;
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.3;
}

.res-stat {
  font-size: 0.9rem;
  opacity: 0.6;
}

.btn-home-link {
  margin-top: 0.25rem;
  font-size: 0.82rem;
  color: var(--color-stone);
  opacity: 0.55;
  text-decoration: none;
  font-weight: 600;
  transition: opacity 0.2s;
}
.btn-home-link:hover { opacity: 0.9; }
