/* «Тетрис» — группа «Работа и развлечения»: фиолетовый фон, светлые формы из матового фарфора.
   Токены — из общего ТЗ на иконки (08_tetris_TZ.md). */
:root {
  --bg-hi: #A081E3;
  --bg: #7351C6;
  --bg-lo: #4B318C;
  --ivory: #FFF4DF;
  --ivory-hi: #FFF9EC;
  --ivory-lo: #D8CDB8;
  --ink: #3A2477;
  --ink-soft: #6A55A3;
  --field-hi: #422985;
  --field-lo: #2D1A62;
  --inset: rgba(40, 22, 96, 0.36);
  --text-muted: rgba(255, 244, 223, 0.72);
  --porcelain: linear-gradient(150deg, var(--ivory-hi), var(--ivory) 55%, #F1E4CB);
  --porcelain-shadow:
    inset 2px 2px 1px rgba(255, 255, 255, 0.95),
    inset -2px -3px 2px rgba(150, 128, 98, 0.28),
    6px 10px 24px rgba(20, 8, 56, 0.5);

  --rim: 10px;      /* фарфоровая рамка вокруг поля */
  --gap: 10px;
  --btn: clamp(52px, 15.5vw, 70px);

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: linear-gradient(150deg, var(--bg-hi) 0%, var(--bg) 46%, var(--bg-lo) 100%) fixed var(--bg);
  color: var(--ivory);
  font-family: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

output { font-variant-numeric: tabular-nums; }

/* подсказки только для пальцев или только для клавиатуры */
@media not (pointer: coarse) { .only-touch { display: none !important; } }
@media (pointer: coarse) { .only-keys { display: none !important; } }

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* не шире экрана, даже если внутри длинный логин */
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--gap);
  padding:
    max(8px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

/* ── шапка ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 40px;
}

.menu-btn {
  flex: none;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 14px 0 11px;
  border: 0;
  border-radius: 14px;
  color: var(--ink);
  background: var(--porcelain);
  box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.9), inset -1px -2px 2px rgba(150, 128, 98, 0.3), 0 3px 10px rgba(24, 10, 62, 0.35);
  font-size: 15px;
  font-weight: 700;
}
.menu-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.menu-btn:active { transform: translateY(1px); }
.app[data-mode="idle"] .menu-btn { animation: nudge 2.4s ease-in-out 1s 2; }
@keyframes nudge {
  0%, 100% { transform: none; }
  45% { transform: translateY(-2px); box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.9), 0 0 0 4px rgba(255, 244, 223, 0.28), 0 6px 14px rgba(24, 10, 62, 0.4); }
}

.brand {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.brand img {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  box-shadow: 0 2px 8px rgba(30, 14, 72, 0.35);
}
.brand span { display: none; }

.mode-badge {
  flex: none;
  padding: 4px 10px;
  border-radius: 10px;
  background: var(--inset);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.app[data-view="rating"] .mode-badge { visibility: hidden; }

.player-chip {
  margin-left: auto;
  min-width: 0;
  max-width: 180px;
  height: 36px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px 0 9px;
  border: 0;
  border-radius: 18px;
  background: rgba(255, 244, 223, 0.14);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
  font-size: 14px;
  font-weight: 600;
}
.player-chip[hidden] { display: none; }
.player-chip:hover { background: rgba(255, 244, 223, 0.22); }
.player-chip svg { flex: none; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.player-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-chip[hidden] + .icon-btn { margin-left: auto; }

.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 244, 223, 0.14);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: background 0.15s, opacity 0.15s;
}
.icon-btn:hover { background: rgba(255, 244, 223, 0.22); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.app:not([data-mode="play"]) #pause-btn,
.app[data-view="rating"] #pause-btn { opacity: 0; pointer-events: none; }

.menu-btn:focus-visible, .player-chip:focus-visible, .icon-btn:focus-visible, .back-btn:focus-visible,
.seg button:focus-visible, .mode-card:focus-visible, .menu-row:focus-visible, .menu-resume:focus-visible {
  outline: 3px solid var(--bg-hi);
  outline-offset: 2px;
}

/* вкладка «Рейтинг» заменяет поле и кнопки */
.rating { display: none; }
.app[data-view="rating"] .stage,
.app[data-view="rating"] .pad { display: none; }
.app[data-view="rating"] .rating { display: flex; }

/* ── сцена: телефон по умолчанию ───────────────────────── */
.stage {
  min-height: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "hold stats next"
    "well well  well";
  gap: var(--gap);
  touch-action: none;
}

.side { display: contents; }

.card {
  border: 0;
  margin: 0;
  border-radius: 18px;
  background: var(--inset);
  box-shadow: inset 0 2px 10px rgba(18, 8, 52, 0.32), inset 0 -1px 0 rgba(255, 255, 255, 0.07);
  padding: 8px 10px;
  text-align: left;
}

.label {
  display: block;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.hold { grid-area: hold; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.hold:disabled { cursor: default; }
.hold.used canvas { opacity: 0.45; }
.next { grid-area: next; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.hold canvas, .next canvas { display: block; }

/* на телефоне — сетка 2×2 */
.stats {
  grid-area: stats;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-content: center;
  gap: 3px 10px;
}
.stats .label { letter-spacing: 0.04em; overflow: hidden; text-overflow: ellipsis; }
.stat { min-width: 0; }
.stat output { display: block; font-size: 16px; font-weight: 700; line-height: 1.2; white-space: nowrap; }
.stat.main output { font-size: 19px; }

.keys { display: none; }

/* ── стакан ────────────────────────────────────────────── */
.well-slot {
  grid-area: well;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.well {
  position: relative;
  padding: var(--rim);
  border-radius: 26px;
  background: linear-gradient(145deg, var(--ivory-hi) 0%, var(--ivory) 45%, #EBDDC2 100%);
  box-shadow:
    inset 2px 2px 1px rgba(255, 255, 255, 0.9),
    inset -2px -3px 2px rgba(150, 128, 98, 0.32),
    7px 10px 22px rgba(28, 12, 70, 0.45);
}

#board {
  display: block;
  border-radius: 16px;
  background:
    radial-gradient(120% 70% at 25% 0%, rgba(160, 129, 227, 0.22), transparent 60%),
    linear-gradient(165deg, var(--field-hi), var(--field-lo));
  box-shadow: inset 2px 3px 10px rgba(10, 4, 34, 0.6), inset -1px -1px 0 rgba(255, 255, 255, 0.08);
  touch-action: none;
}

/* ── надписи за действия: «ТЕТРИС!», «КОМБО ×3» ──────────── */
.popups {
  position: absolute;
  inset: var(--rim);
  pointer-events: none;
  overflow: hidden;
  border-radius: 16px;
}
.popup {
  position: absolute;
  left: 50%;
  top: 28%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  white-space: nowrap;
  text-align: center;
  animation: pop 1.25s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}
.popup b {
  font-size: clamp(18px, 6.5vw, 30px);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--ivory);
  text-shadow: 0 2px 0 rgba(58, 36, 119, 0.9), 0 4px 14px rgba(18, 8, 52, 0.7);
}
.popup small {
  font-size: clamp(12px, 3.6vw, 15px);
  font-weight: 700;
  color: #FFE07A;
  text-shadow: 0 1px 0 rgba(58, 36, 119, 0.9), 0 3px 10px rgba(18, 8, 52, 0.7);
}
.popup.toast b { font-size: clamp(14px, 4.4vw, 18px); color: #FFE07A; }
.popup.toast { top: 12%; }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.7); }
  14% { opacity: 1; transform: translate(-50%, 0) scale(1.08); }
  24% { transform: translate(-50%, 0) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -26px) scale(1); }
}

/* ── подсказки и карточки поверх стакана ───────────────── */
.overlay {
  position: absolute;
  inset: var(--rim);
  border-radius: 16px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 10px;
  touch-action: manipulation;
}
.app:not([data-mode="play"]) .overlay { display: flex; }
.app[data-mode="idle"] .overlay,
.app[data-mode="paused"] .overlay { cursor: pointer; }
.app[data-mode="paused"] .overlay,
.app[data-mode="login"] .overlay,
.app[data-mode="over"] .overlay {
  background: rgba(34, 18, 80, 0.6);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.hint-card, .sheet { display: none; }
.app[data-mode="idle"] .hint-card[data-for="idle"],
.app[data-mode="paused"] .hint-card[data-for="paused"],
.app[data-mode="login"] .sheet[data-for="login"],
.app[data-mode="over"] .sheet[data-for="over"] { display: flex; }

/* подсказка без окна: просто текст на поле */
.hint-card {
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 250px;
  text-align: center;
  pointer-events: none;
}
.hint-card p { margin: 0; }
.hint-title { font-size: 18px; font-weight: 800; line-height: 1.3; }
.hint-card[data-for="paused"] .hint-title { font-size: 28px; }
.hint-mode {
  padding: 4px 12px;
  border-radius: 999px;
  color: var(--ink);
  background: var(--porcelain);
  font-size: 14px;
  font-weight: 700;
}
.hint-sub { font-size: 13px; line-height: 1.4; color: var(--text-muted); }

.sheet {
  width: min(100%, 300px);
  max-height: 100%;
  overflow: auto;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  padding: 22px 18px 18px;
  border-radius: 22px;
  text-align: center;
  color: var(--ink);
  background: var(--porcelain);
  box-shadow: var(--porcelain-shadow);
}
.sheet h2, .sheet p { margin: 0; }
.sheet h2 { font-size: 21px; font-weight: 800; }
.sheet-icon {
  align-self: center;
  width: 76px;
  height: 76px;
  border-radius: 20px;
  box-shadow: 3px 5px 14px rgba(40, 20, 100, 0.35);
}
.sheet-best { font-size: 15px; color: var(--ink-soft); }
.sheet-best b { color: var(--ink); font-variant-numeric: tabular-nums; }
.big-score { font-size: 40px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.over-stats { font-size: 13px; line-height: 1.45; color: var(--ink-soft); }
.over-stats:empty { display: none; }
.record {
  align-self: center;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--ivory);
  font-size: 13px;
  font-weight: 700;
}
.record[hidden], .sheet-rank[hidden], .form-error[hidden] { display: none; }
.sheet-rank { font-size: 14.5px; color: var(--ink); font-weight: 600; }
.hint { font-size: 12.5px; line-height: 1.4; color: var(--ink-soft); }

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--bg);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.field {
  width: 100%;
  min-height: 50px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: inset 0 2px 5px rgba(80, 56, 140, 0.22), inset 0 0 0 1.5px rgba(115, 81, 198, 0.3);
  color: var(--ink);
  font: inherit;
  font-size: 18px; /* от 16px — иначе iOS увеличивает страницу при фокусе */
  font-weight: 600;
  text-align: center;
  -webkit-user-select: text;
  user-select: text;
}
.field::placeholder { color: rgba(106, 85, 163, 0.55); font-weight: 500; }
.field:focus { outline: none; box-shadow: inset 0 2px 5px rgba(80, 56, 140, 0.22), inset 0 0 0 2.5px var(--bg); }
.form-error { font-size: 13px; line-height: 1.35; color: #B0306A; font-weight: 600; }

.primary, .secondary {
  min-height: 48px;
  border: 0;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 700;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.primary {
  color: var(--ivory);
  background: linear-gradient(160deg, #8B6BDD, var(--bg) 55%, #5D3DB3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 4px 12px rgba(60, 30, 140, 0.4);
}
.primary:hover { filter: brightness(1.06); }
.primary:disabled { filter: saturate(0.6) brightness(0.95); cursor: progress; }
.secondary {
  color: var(--ink);
  background: rgba(115, 81, 198, 0.1);
  box-shadow: inset 0 0 0 1.5px rgba(115, 81, 198, 0.35);
}
.primary:active, .secondary:active { transform: translateY(1px); }
.primary:focus-visible, .secondary:focus-visible, .stepper button:focus-visible, .link:focus-visible {
  outline: 3px solid var(--bg-hi);
  outline-offset: 2px;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--ink-soft);
}
.stepper span { margin-right: auto; }
.stepper button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 11px;
  color: var(--ink);
  font-size: 19px;
  font-weight: 700;
  line-height: 1;
  background: rgba(115, 81, 198, 0.12);
}
.stepper button:disabled { opacity: 0.35; cursor: default; }
.stepper output { min-width: 2ch; text-align: center; font-size: 18px; font-weight: 800; color: var(--ink); }

/* ── меню ──────────────────────────────────────────────── */
.menu {
  position: fixed;
  inset: 0;
  z-index: 10;
}
.menu[hidden] { display: none; }
.menu-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(30, 14, 72, 0.45);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  animation: fade 0.15s ease-out;
}
.menu-panel {
  position: absolute;
  top: calc(max(8px, env(safe-area-inset-top)) + 48px);
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  max-height: calc(100% - max(8px, env(safe-area-inset-top)) - 60px - max(10px, env(safe-area-inset-bottom)));
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-radius: 24px;
  color: var(--ink);
  background: var(--porcelain);
  box-shadow: var(--porcelain-shadow);
  animation: drop 0.18s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes fade { from { opacity: 0; } }
@keyframes drop { from { opacity: 0; transform: translateY(-8px) scale(0.98); } }

.menu-resume {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 8px 16px;
  border: 0;
  border-radius: 18px;
  color: var(--ivory);
  background: linear-gradient(160deg, #8B6BDD, var(--bg) 55%, #5D3DB3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 4px 12px rgba(60, 30, 140, 0.4);
  text-align: left;
}
.menu-resume[hidden] { display: none; }
.menu-resume svg { flex: none; width: 26px; height: 26px; fill: currentColor; }
.menu-resume b { display: block; font-size: 17px; }
.menu-resume small { display: block; font-size: 13px; opacity: 0.85; }

.menu-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: 18px;
  background: rgba(115, 81, 198, 0.08);
}
.menu-section h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-height: 74px;
  padding: 10px;
  border: 0;
  border-radius: 14px;
  color: var(--ivory);
  background: linear-gradient(160deg, #8B6BDD, var(--bg) 55%, #5D3DB3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 3px 10px rgba(60, 30, 140, 0.35);
  text-align: left;
}
.mode-card b { font-size: 15px; }
.mode-card small { font-size: 11.5px; line-height: 1.3; opacity: 0.88; }
.mode-card:active { transform: translateY(1px); }

.menu-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 0 14px;
  border: 0;
  border-radius: 16px;
  color: var(--ink);
  background: rgba(115, 81, 198, 0.1);
  box-shadow: inset 0 0 0 1.5px rgba(115, 81, 198, 0.25);
  font-size: 16px;
  font-weight: 700;
}
.menu-row svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 34px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.toggle span { flex: 1; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i {
  flex: none;
  position: relative;
  width: 46px;
  height: 28px;
  border-radius: 14px;
  background: rgba(106, 85, 163, 0.28);
  box-shadow: inset 0 1px 3px rgba(40, 20, 100, 0.25);
  transition: background 0.15s;
}
.toggle i::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, var(--ivory) 60%, #E6D8BC);
  box-shadow: 0 1px 3px rgba(40, 20, 100, 0.35);
  transition: transform 0.15s;
}
.toggle input:checked + i { background: var(--bg); }
.toggle input:checked + i::after { transform: translateX(18px); }
.toggle input:focus-visible + i { outline: 3px solid var(--bg-hi); outline-offset: 2px; }

.menu-player { margin: 0 4px 2px; font-size: 14px; color: var(--ink-soft); }
.menu-player b { color: var(--ink); overflow-wrap: anywhere; }
.menu-player[hidden] { display: none; }

/* ── рейтинг ───────────────────────────────────────────── */
.rating {
  min-height: 0;
  justify-content: center;
}

.rating-card {
  width: min(100%, 620px);
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-radius: 24px;
  background: var(--inset);
  box-shadow: inset 0 2px 12px rgba(18, 8, 52, 0.32), inset 0 -1px 0 rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.rating-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 8px;
}
.rating-head h2 { flex: 1; margin: 0; font-size: 21px; font-weight: 800; text-align: center; }
.back-btn {
  height: 38px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px 0 6px;
  border: 0;
  border-radius: 12px;
  color: var(--ink);
  background: var(--porcelain);
  box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.9), 0 2px 8px rgba(24, 10, 62, 0.35);
  font-size: 14.5px;
  font-weight: 700;
}
.back-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

.seg {
  display: flex;
  margin: 2px 12px 6px;
  padding: 3px;
  border-radius: 14px;
  background: rgba(18, 8, 52, 0.28);
}
.seg button {
  flex: 1;
  min-height: 36px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14.5px;
  font-weight: 700;
}
.seg button[aria-selected="true"] {
  color: var(--ink);
  background: var(--porcelain);
  box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.9), 0 2px 6px rgba(24, 10, 62, 0.35);
}
.seg-small button { min-height: 30px; font-size: 13px; }

.rating-sub { margin: 4px 20px 8px; font-size: 13px; color: var(--text-muted); }

.rating-list {
  list-style: none;
  margin: 0;
  padding: 0 10px 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.rating-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 8px;
  border-radius: 16px;
}
.rating-row + .rating-row { margin-top: 2px; }
.rating-row:nth-child(odd):not(.me) { background: rgba(255, 244, 223, 0.04); }

.rating-place {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  justify-self: center;
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}
/* первые три места — фарфоровые жетоны */
.rating-row.top .rating-place {
  border-radius: 50%;
  color: var(--ink);
  background: radial-gradient(circle at 32% 28%, var(--ivory-hi), var(--ivory) 50%, #E3D3B5);
  box-shadow: inset 1px 1.5px 1px rgba(255, 255, 255, 0.9), inset -1px -2px 2px rgba(150, 128, 98, 0.35), 2px 3px 8px rgba(18, 8, 52, 0.4);
}

.rating-name { min-width: 0; }
.rating-name b {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 700;
}
.rating-name small { display: block; margin-top: 1px; font-size: 12.5px; color: var(--text-muted); }

.rating-score {
  font-size: 19px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* строка текущего игрока — светлая, как фарфор */
.rating-row.me {
  color: var(--ink);
  background: var(--porcelain);
  box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.9), 0 3px 10px rgba(18, 8, 52, 0.35);
}
.rating-row.me .rating-place, .rating-row.me small { color: var(--ink-soft); }
.rating-row.me.top .rating-place { color: var(--ink); background: rgba(115, 81, 198, 0.14); box-shadow: none; }

.rating-gap {
  padding: 2px 0 4px;
  text-align: center;
  color: var(--text-muted);
  letter-spacing: 0.3em;
}

.rating-status {
  margin: 0;
  padding: 0 20px 18px;
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}
.rating-status:empty { display: none; }

/* ── кнопки под пальцы ─────────────────────────────────── */
.pad { display: none; }

.pad button {
  width: var(--btn);
  height: var(--btn);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--ink);
  background: radial-gradient(circle at 32% 28%, var(--ivory-hi) 0%, var(--ivory) 45%, #E9DBC0 100%);
  box-shadow:
    inset 1.5px 2px 1px rgba(255, 255, 255, 0.9),
    inset -2px -3px 3px rgba(150, 128, 98, 0.35),
    4px 6px 14px rgba(24, 10, 62, 0.42);
  touch-action: none;
  transition: transform 0.06s, box-shadow 0.06s;
}
.pad button.rotate { width: calc(var(--btn) * 1.18); height: calc(var(--btn) * 1.18); }
.pad button.down {
  transform: translateY(2px) scale(0.97);
  box-shadow:
    inset 1px 1px 1px rgba(255, 255, 255, 0.8),
    inset -1px -2px 2px rgba(150, 128, 98, 0.35),
    2px 3px 6px rgba(24, 10, 62, 0.4);
}
.pad svg { width: 46%; height: 46%; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

@media (pointer: coarse) {
  .pad {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2px;
  }
  .pad-group { display: flex; align-items: center; gap: clamp(8px, 2.5vw, 14px); }
}

/* узкий телефон: значок режима не помещается в шапку — режим виден на поле и в меню */
@media (max-width: 389px) {
  .mode-badge { display: none; }
}

/* ── широкий экран: запас и счёт слева, очередь справа ─── */
@media (min-width: 720px) and (min-height: 520px) {
  :root { --rim: 12px; --gap: 16px; }

  .app { padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); }

  .brand span { display: inline; }

  .stage {
    grid-template-columns: 188px auto 188px;
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "left well right";
    justify-content: center;
    column-gap: 24px;
  }

  .side {
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    min-height: 0;
  }
  .side-left { grid-area: left; }
  .side-right { grid-area: right; }

  .card { padding: 14px 16px; border-radius: 22px; }
  .label { font-size: 11.5px; }
  .hold, .next { align-items: stretch; gap: 10px; }
  .hold canvas, .next canvas { align-self: center; }
  .hold:not(:disabled):hover { background: rgba(40, 22, 96, 0.46); }

  .stats { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .stats .label { letter-spacing: 0.09em; }
  .stat output { font-size: 22px; }
  .stat.main output { font-size: 30px; }
  .stat.best { order: 1; }

  .keys { display: block; }
  .keys dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 7px 12px;
    margin: 12px 0 0;
    font-size: 13.5px;
  }
  .keys dt { font-weight: 700; white-space: nowrap; }
  .keys dd { margin: 0; color: var(--text-muted); }

  .menu-panel { right: auto; width: 380px; }
}

@media (pointer: coarse) and (min-width: 720px) {
  .keys { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
