@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/ibm-plex-sans-arabic-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../assets/fonts/ibm-plex-sans-arabic-arabic-500-normal.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../assets/fonts/ibm-plex-sans-arabic-latin-500-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../assets/fonts/ibm-plex-sans-arabic-arabic-700-normal.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../assets/fonts/ibm-plex-sans-arabic-latin-700-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #0b0d12;
  --surface: #141924;
  --surface-2: #1a2130;
  --surface-3: #222b3d;
  --line: rgba(151, 168, 205, 0.13);
  --line-strong: rgba(151, 168, 205, 0.26);
  --text: #f2f5fb;
  --text-2: #a8b3c9;
  --text-3: #76829c;
  --blue: #2b59e0;
  --blue-hi: #7da2ff;
  --blue-deep: #16264f;
  --gold: #f0c25c;
  --danger: #ef6b6b;
  --danger-deep: #3a171c;
  --danger-text: #ffd9d9;
  --bar-bg: rgba(11, 13, 18, 0.82);
  --scrollbar-thumb: #2a3347;
  --mark-glow: rgba(43, 89, 224, 0.35);
  --radius: 16px;
  --radius-s: 12px;
  --shadow-1: 0 1px 2px rgba(2, 4, 10, 0.5), 0 10px 30px rgba(2, 4, 10, 0.4);
  --bar-blur: saturate(1.4) blur(18px);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  /* keypad glass tokens — dark is default */
  --key-glass: rgba(255, 255, 255, 0.055);
  --key-glass-strong: rgba(255, 255, 255, 0.09);
  --key-border: rgba(255, 255, 255, 0.09);
  --key-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  --key-shadow: 0 4px 16px rgba(0, 0, 0, 0.18), 0 1px 3px rgba(0, 0, 0, 0.14);
  --display-glass: linear-gradient(135deg, rgba(43, 89, 224, 0.07), rgba(126, 58, 242, 0.05) 50%, rgba(240, 194, 92, 0.04));
  --display-border: rgba(255, 255, 255, 0.08);
  --aura-1: rgba(43, 89, 224, 0.18);
  --aura-2: rgba(126, 58, 242, 0.14);
  --aura-3: rgba(240, 194, 92, 0.11);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #eef1f7;
  --surface: #ffffff;
  --surface-2: #f3f5fa;
  --surface-3: #e4e9f4;
  --line: rgba(23, 37, 84, 0.12);
  --line-strong: rgba(23, 37, 84, 0.24);
  --text: #131824;
  --text-2: #445069;
  --text-3: #5d6a85;
  --blue: #2b59e0;
  --blue-hi: #2450d8;
  --blue-deep: #dfe7fb;
  --gold: #a4770e;
  --danger: #c4393e;
  --danger-deep: #fbe9e9;
  --danger-text: #7c1d21;
  --bar-bg: rgba(238, 241, 247, 0.85);
  --scrollbar-thumb: #c2cbde;
  --mark-glow: rgba(43, 89, 224, 0.22);
  --shadow-1: 0 1px 2px rgba(20, 30, 60, 0.08), 0 10px 28px rgba(20, 30, 60, 0.12);
  /* light glass overrides */
  --key-glass: rgba(255, 255, 255, 0.72);
  --key-glass-strong: rgba(255, 255, 255, 0.92);
  --key-border: rgba(23, 37, 84, 0.07);
  --key-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.95);
  --key-shadow: 0 4px 16px rgba(20, 30, 60, 0.08), 0 1px 3px rgba(20, 30, 60, 0.06);
  --display-glass: linear-gradient(135deg, rgba(43, 89, 224, 0.05), rgba(126, 58, 242, 0.03) 55%, rgba(240, 194, 92, 0.03));
  --display-border: rgba(23, 37, 84, 0.07);
  --aura-1: rgba(43, 89, 224, 0.09);
  --aura-2: rgba(126, 58, 242, 0.07);
  --aura-3: rgba(240, 194, 92, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans Arabic', -apple-system, 'SF Arabic', 'Segoe UI', Tahoma, sans-serif;
  font-size: 15.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

::selection { background: rgba(123, 145, 255, 0.35); }

:focus-visible {
  outline: 2px solid var(--blue-hi);
  outline-offset: 2px;
  border-radius: 6px;
}

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

input {
  font: inherit;
  color: inherit;
}

#app {
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

@media (min-width: 520px) {
  #app {
    border-inline-start: 1px solid var(--line);
    border-inline-end: 1px solid var(--line);
    min-height: 100dvh;
  }
}

.view {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  animation: view-in 0.32s var(--ease);
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bar-bg);
  backdrop-filter: var(--bar-blur);
  -webkit-backdrop-filter: var(--bar-blur);
  border-bottom: 1px solid var(--line);
}

.header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  flex: 1;
  text-align: center;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:active { background: var(--surface-2); color: var(--text); }

.header .spacer { width: 40px; }

.content {
  flex: 1;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.bottom-bar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bar-bg);
  backdrop-filter: var(--bar-blur);
  -webkit-backdrop-filter: var(--bar-blur);
  border-top: 1px solid var(--line);
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 54px;
  padding: 12px 20px;
  border-radius: 14px;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  transition: transform 0.12s var(--ease), background 0.15s, opacity 0.15s, border-color 0.15s;
}

.btn:active { transform: scale(0.975); }

.btn-primary {
  background: var(--blue);
  color: #fff;
  box-shadow: var(--shadow-1);
}

.btn-primary:disabled {
  opacity: 0.38;
  box-shadow: none;
  cursor: default;
}

.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  color: var(--text);
}

.btn-quiet {
  color: var(--text-2);
  min-height: 46px;
  font-weight: 500;
}

.btn-danger-ghost {
  color: var(--danger);
  border: 1px solid rgba(239, 107, 107, 0.35);
  background: transparent;
}

.btn-danger-ghost.armed {
  background: var(--danger-deep);
  border-color: var(--danger);
  color: var(--danger-text);
}

.stack { display: flex; flex-direction: column; gap: 10px; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: 0.01em;
  margin: 22px 2px 10px;
}

.section-title:first-child { margin-top: 4px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: start;
  transition: background 0.15s, border-color 0.15s;
}

button.row:active { background: var(--surface-2); }

.row .grow { flex: 1; min-width: 0; }

.row .name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row .meta {
  font-size: 13px;
  color: var(--text-3);
}

.row .ic { color: var(--text-3); flex-shrink: 0; }

.avatar {
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  isolation: isolate;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.avatar-img {
  border-radius: 50%;
  display: block;
  background: var(--surface-2);
  object-fit: cover;
}

.avatar-stack { display: flex; }
.avatar-stack .avatar { box-shadow: 0 0 0 2px var(--surface), 0 1px 3px rgba(0, 0, 0, 0.18); margin-inline-start: -10px; }
.avatar-stack .avatar:first-child { margin-inline-start: 0; }

.badge {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  display: inline-grid;
  place-items: center;
  background: var(--surface-3);
  border-radius: 11px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-2);
}

.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  text-align: center;
  padding: env(safe-area-inset-top) 20px calc(20px + env(safe-area-inset-bottom));
  position: relative;
}

.theme-btn {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  inset-inline-end: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text-2);
  box-shadow: var(--shadow-1);
}

.theme-btn:hover { color: var(--text); }

.welcome .brand {
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 6vh;
}

.welcome .mark {
  width: 128px;
  height: 128px;
  filter: drop-shadow(0 18px 40px var(--mark-glow));
  animation: mark-float 5.5s ease-in-out infinite;
}

@keyframes mark-float {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-8px) rotate(1deg); }
}

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

.welcome .wordmark {
  font-size: clamp(21px, 6.2vw, 30px);
  font-weight: 700;
  letter-spacing: 0.16em;
  text-indent: 0.16em;
  margin-top: 22px;
  direction: ltr;
  white-space: nowrap;
}

.welcome .wordmark .n1 { color: var(--blue-hi); }

.welcome .tagline {
  color: var(--text-2);
  margin-top: 6px;
  font-size: 16px;
}

.welcome .actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 40px;
}

.resume-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: linear-gradient(135deg, var(--blue-deep), var(--surface));
  border: 1px solid rgba(125, 162, 255, 0.35);
  border-radius: var(--radius);
  text-align: start;
  margin-bottom: 14px;
}

.resume-card:active { filter: brightness(1.15); }

.resume-card .grow { flex: 1; }

.resume-card .t1 { font-weight: 700; }

.resume-card .t2 {
  font-size: 13px;
  color: var(--text-2);
  margin-top: 2px;
}

.resume-card .go {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--blue);
  display: grid;
  place-items: center;
  color: #fff;
  flex-shrink: 0;
}

.formation-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.formation {
  padding: 14px 12px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: border-color 0.15s, background 0.15s;
}

.formation .diagram { color: var(--text-2); }

.formation .f-label { font-weight: 700; font-size: 15px; }

.formation .f-sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: -6px;
}

.formation[aria-pressed="true"] {
  background: var(--blue-deep);
  border-color: var(--blue-hi);
}

.formation[aria-pressed="true"] .diagram,
.formation[aria-pressed="true"] .f-sub { color: var(--blue-hi); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 10px 16px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text-2);
  transition: all 0.15s;
}

.chip:active { transform: scale(0.96); }

.chip[aria-pressed="true"] {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 700;
}

.chip:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
}

.chip .avatar { box-shadow: none; }

.pill-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--blue-hi);
}

.team-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.team-box .team-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 14px;
  color: var(--text-2);
  margin-bottom: 10px;
}

.team-box .chips { gap: 6px; }

.team-box .chip { padding: 7px 10px; min-height: 40px; font-size: 13.5px; }

.team-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.team-input-row .team-input { flex: 1; margin-top: 0; }

.spark-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  color: var(--text-2);
}

.spark-btn:hover { color: var(--text); border-color: var(--blue-hi); }

.team-input {
  width: 100%;
  margin-top: 10px;
  min-height: 44px;
  padding: 9px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  font-size: 14.5px;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s;
}

.team-input:focus {
  outline: none;
  border-color: var(--blue-hi);
  background: var(--surface);
}

.team-input::placeholder { color: var(--text-3); }

.field input[type="text"],
.field input[type="number"] {
  width: 100%;
  min-height: 54px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  font-size: 16.5px;
  font-weight: 500;
  transition: border-color 0.15s;
}

.field input:focus {
  outline: none;
  border-color: var(--blue-hi);
}

.field input::placeholder { color: var(--text-3); }

.avatar-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 8px 0 18px;
}

.avatar-preview {
  display: inline-grid;
  place-items: center;
  animation: avatar-pop 0.32s var(--ease-spring, cubic-bezier(0.175, 0.885, 0.32, 1.275));
}

.avatar-preview .avatar {
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.22), 0 2px 6px rgba(0, 0, 0, 0.14);
}

@keyframes avatar-pop {
  0% { transform: scale(0.82); opacity: 0; }
  60% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

.regen-btn { gap: 8px; }
.regen-btn:active { transform: scale(0.96); }

.scoreboard {
  display: grid;
  gap: 10px;
  margin-bottom: 6px;
}

.scoreboard.cols-2 { grid-template-columns: 1fr 1fr; }
.scoreboard.cols-3 { grid-template-columns: repeat(3, 1fr); }
.scoreboard.cols-4 { grid-template-columns: 1fr 1fr; }

.side-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
  transition: border-color 0.3s, background 0.3s;
}

.side-card.leading {
  border-color: rgba(125, 162, 255, 0.55);
  background: linear-gradient(180deg, rgba(43, 89, 224, 0.16), var(--surface) 70%);
}

.side-card .side-names {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 20px;
}

.side-card .side-name {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 5px;
}

.side-card .total {
  font-size: clamp(44px, 13vw, 64px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.side-card .total.bump { animation: bump 0.5s var(--ease); }

@keyframes bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.12); color: var(--blue-hi); }
  100% { transform: scale(1); }
}

.side-card .lead-crown {
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--gold);
  filter: drop-shadow(0 2px 6px rgba(240, 194, 92, 0.4));
}

.target-track {
  height: 5px;
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
  width: 100%;
  max-width: 120px;
}

.target-fill {
  height: 100%;
  width: 100%;
  background: var(--blue-hi);
  border-radius: 3px;
  transform: scaleX(var(--p, 0));
  transform-origin: 100% 50%;
  transition: transform 0.5s var(--ease);
}

.target-meta {
  font-size: 11.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.round-entry {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 14px;
  margin-top: 16px;
}

.record-bar { padding: 14px 0 0; }

.round-entry .q {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 10px;
}

/* ── score display — glass capsule, big & colorful ── */
.points-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 18px 0 16px;
  min-height: 92px;
  padding: 14px 22px;
  background: var(--display-glass), var(--surface);
  backdrop-filter: blur(16px) saturate(1.35);
  -webkit-backdrop-filter: blur(16px) saturate(1.35);
  border: 1px solid var(--display-border);
  border-radius: 20px;
  box-shadow: var(--key-highlight), 0 8px 28px rgba(0, 0, 0, 0.14), 0 2px 6px rgba(0, 0, 0, 0.08);
  direction: ltr;
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.points-display::before {
  content: "";
  position: absolute;
  inset: -30% -10%;
  background:
    radial-gradient(ellipse 45% 60% at 18% 50%, var(--aura-1), transparent 62%),
    radial-gradient(ellipse 40% 55% at 84% 45%, var(--aura-2), transparent 60%),
    radial-gradient(ellipse 65% 40% at 50% 88%, var(--aura-3), transparent 65%);
  opacity: 0.9;
  pointer-events: none;
  z-index: -1;
}

.points-value {
  font-size: clamp(48px, 14vw, 62px);
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  background: linear-gradient(180deg, var(--text) 30%, color-mix(in srgb, var(--text) 82%, var(--blue-hi)));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.06));
  transition: transform 0.18s var(--ease-out-expo);
}

.points-value.is-empty {
  background: none;
  -webkit-text-fill-color: var(--text-3);
  color: var(--text-3);
  opacity: 0.9;
}

.points-value.is-bumped { animation: display-bump 0.42s var(--ease-spring); }

@keyframes display-bump {
  0% { transform: scale(1); }
  36% { transform: scale(1.14); }
  68% { transform: scale(0.98); }
  100% { transform: scale(1); }
}

.points-unit {
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.9;
  align-self: center;
  margin-top: 10px;
}

/* ── keypad — glassy, big, colorful, motion-rich ── */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  direction: ltr;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
}

.keypad::before {
  content: "";
  position: absolute;
  inset: -28% -12%;
  background:
    radial-gradient(ellipse 55% 45% at 16% 18%, var(--aura-1), transparent 58%),
    radial-gradient(ellipse 48% 42% at 88% 22%, var(--aura-2), transparent 58%),
    radial-gradient(ellipse 70% 38% at 52% 92%, var(--aura-3), transparent 62%);
  filter: blur(18px);
  opacity: 1;
  pointer-events: none;
  z-index: -1;
}

.key {
  position: relative;
  min-height: 64px;
  border-radius: 16px;
  background: var(--key-glass);
  backdrop-filter: blur(14px) saturate(1.45);
  -webkit-backdrop-filter: blur(14px) saturate(1.45);
  border: 1px solid var(--key-border);
  box-shadow: var(--key-highlight), var(--key-shadow);
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  user-select: none;
  overflow: hidden;
  isolation: isolate;
  transition:
    transform 0.12s var(--ease-out-expo),
    background 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    color 0.18s ease;
  /* stagger entrance */
  animation: key-in 0.52s var(--ease-out-expo) both;
}

.key:nth-child(1) { --i: 0; animation-delay: 0ms; }
.key:nth-child(2) { --i: 1; animation-delay: 32ms; }
.key:nth-child(3) { --i: 2; animation-delay: 64ms; }
.key:nth-child(4) { --i: 3; animation-delay: 96ms; }
.key:nth-child(5) { --i: 4; animation-delay: 128ms; }
.key:nth-child(6) { --i: 5; animation-delay: 160ms; }
.key:nth-child(7) { --i: 6; animation-delay: 192ms; }
.key:nth-child(8) { --i: 7; animation-delay: 224ms; }
.key:nth-child(9) { --i: 8; animation-delay: 256ms; }
.key:nth-child(10) { --i: 9; animation-delay: 288ms; }
.key:nth-child(11) { --i: 10; animation-delay: 320ms; }
.key:nth-child(12) { --i: 11; animation-delay: 352ms; }

@keyframes key-in {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.key::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(220px circle at var(--x, 50%) var(--y, 50%), rgba(255, 255, 255, 0.18), transparent 42%);
  opacity: 0;
  transition: opacity 0.22s;
  pointer-events: none;
}

.key:hover::after { opacity: 1; }

.key:active,
.key.is-pressed {
  transform: scale(0.94);
  background: color-mix(in srgb, var(--key-glass) 92%, var(--blue) 8%);
  border-color: color-mix(in srgb, var(--key-border) 70%, var(--blue-hi) 30%);
  box-shadow: var(--key-highlight), 0 2px 10px rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(43, 89, 224, 0.08);
}

.key.is-pressed:not(.func) {
  color: var(--blue-hi);
  background: color-mix(in srgb, var(--key-glass) 84%, var(--blue) 16%);
  border-color: color-mix(in srgb, var(--blue-hi) 28%, var(--key-border));
  box-shadow: var(--key-highlight), 0 6px 18px rgba(43, 89, 224, 0.18), 0 0 0 1px rgba(43, 89, 224, 0.12);
}

.key.func {
  color: var(--text-2);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  background: color-mix(in srgb, var(--key-glass) 96%, var(--surface-2) 4%);
}

.key.func[data-action="key-del"] {
  color: color-mix(in srgb, var(--text-2) 88%, var(--danger) 12%);
}

.key.func.is-pressed {
  background: color-mix(in srgb, var(--key-glass) 82%, var(--danger) 10%);
  border-color: color-mix(in srgb, var(--danger) 18%, var(--key-border));
  color: var(--danger);
}

/* the 0 key gets a gold-kissed glass when idle, to anchor the grid */
.key[data-k="0"]:not(.is-pressed) {
  background: linear-gradient(180deg, color-mix(in srgb, var(--key-glass) 92%, var(--gold) 6%), var(--key-glass));
}

/* focus ring stays per system */
.key:focus-visible { outline: 2px solid var(--blue-hi); outline-offset: 2px; }

/* digit fly element */
.digit-fly {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: 26px;
  line-height: 1;
  color: var(--blue-hi);
  text-shadow: 0 2px 12px rgba(43, 89, 224, 0.35);
  will-change: transform, opacity;
}

/* reduced motion / transparency fallbacks */
@media (prefers-reduced-motion: reduce) {
  .key { animation: none !important; transition: background 0.15s, border-color 0.15s !important; }
  .key:active, .key.is-pressed { transform: none !important; }
  .points-value.is-bumped { animation: none !important; }
  .digit-fly { display: none !important; }
}

@media (prefers-reduced-transparency: reduce) {
  .key, .points-display, .keypad { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
  .key { background: var(--surface-2) !important; }
  .points-display { background: var(--surface) !important; }
  .keypad::before, .points-display::before { display: none !important; }
}

@supports not (backdrop-filter: blur(1px)) {
  .key { background: var(--surface-2); }
  .points-display { background: var(--surface); }
}

.rounds-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 24px 2px 10px;
}

.rounds-title h2 { font-size: 16px; font-weight: 700; }

.rounds-title .sum {
  font-size: 13px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.round-list {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.round-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  animation: row-in 0.35s var(--ease);
}

.round-row:last-child { border-bottom: 0; }

@keyframes row-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

.round-row .rnum {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-3);
  width: 34px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.round-row .rname {
  flex: 1;
  font-weight: 500;
  font-size: 14.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.round-row .rname .nm {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.round-row .rpts {
  font-weight: 700;
  color: var(--blue-hi);
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.round-row .rrun {
  color: var(--text-3);
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  min-width: 34px;
  text-align: left;
}

.undo-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 11px;
  color: var(--text-2);
  font-weight: 500;
  font-size: 14px;
  border-top: 1px solid var(--line);
  transition: color 0.15s;
}

.undo-row:active { color: var(--text); }

.end-zone {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: center;
}

.end-btn {
  color: var(--danger);
  font-weight: 500;
  font-size: 14.5px;
  padding: 12px 22px;
  border-radius: 12px;
  transition: background 0.15s;
}

.end-btn:active { background: var(--danger-deep); }

.end-btn.armed {
  background: var(--danger-deep);
  color: var(--danger-text);
  font-weight: 700;
}

.gameover {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: 8vh;
}

.gameover .crown {
  color: var(--gold);
  filter: drop-shadow(0 6px 24px rgba(240, 194, 92, 0.45));
  animation: crown-drop 0.6s var(--ease);
}

@keyframes crown-drop {
  from { opacity: 0; transform: translateY(-26px) scale(1.3); }
  to { opacity: 1; transform: none; }
}

.gameover .winner-names {
  font-size: clamp(30px, 9vw, 44px);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 10px;
  line-height: 1.25;
}

.gameover .sub {
  color: var(--text-2);
  margin-top: 6px;
  font-size: 15px;
}

.standings {
  width: 100%;
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.standing-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.standing-row.winner {
  border-color: rgba(240, 194, 92, 0.5);
  background: linear-gradient(180deg, rgba(240, 194, 92, 0.1), var(--surface) 75%);
}

.standing-row .rank {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface-3);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  flex-shrink: 0;
}

.standing-row.winner .rank { background: var(--gold); color: #3a2a05; }

.standing-row .s-total {
  margin-inline-start: auto;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.history-row .h-date {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

.history-row .h-score {
  margin-inline-start: auto;
  font-weight: 700;
  font-size: 16.5px;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
}

.history-row .h-score .win { color: var(--gold); display: inline-flex; }

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  color: var(--text-3);
  padding: 40px 20px;
}

.empty .ic { color: var(--text-3); opacity: 0.8; }

.empty p { font-size: 15px; max-width: 260px; }

.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--line-strong);
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s var(--ease);
  z-index: 100;
  max-width: min(90vw, 420px);
  text-align: center;
}

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

.confirm-inline {
  display: flex;
  gap: 8px;
}

.confirm-inline .btn { min-height: 46px; font-size: 15px; }

.setup-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.setup-progress .step-label {
  font-size: 13px;
  color: var(--text-3);
  font-weight: 500;
}

.diagram { display: block; }

@media (hover: hover) {
  button.row:hover { background: var(--surface-2); border-color: var(--line-strong); }
  .chip:hover:not(:disabled) { border-color: var(--blue-hi); color: var(--text); }
  .chip[aria-pressed="true"]:hover { border-color: var(--blue); color: #fff; }
  .key:hover { background: var(--surface-3); }
  .formation:hover { border-color: var(--line-strong); }
  .formation[aria-pressed="true"]:hover { border-color: var(--blue-hi); }
  .btn-primary:hover:not(:disabled) { background: #3563e8; }
  .btn-secondary:hover { background: var(--surface-3); }
  .btn-quiet:hover { color: var(--text); }
  .icon-btn:hover { background: var(--surface-2); color: var(--text); }
  .undo-row:hover { color: var(--text); }
  .end-btn:hover { background: var(--danger-deep); }
  .resume-card:hover { filter: brightness(1.12); }
  .regen-btn:hover { color: var(--text); }
}

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