/* ==========================================================================
   Design-system components
   ========================================================================== */

/* ---- labels / tags ---- */
.label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--text-dim);
  text-transform: uppercase;
}
.tag {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  border: 1px solid currentColor;
  line-height: 1;
  white-space: nowrap;
}
.tag-host { color: var(--yellow); }
.tag-you { color: var(--cyan); }
.tag-lost { color: var(--red); animation: blink 1.2s steps(2) infinite; }
.tag-dim { color: var(--text-dim); border-color: var(--line-2); }
@keyframes blink { 50% { opacity: 0.35; } }

/* ---- buttons (chamfered) ---- */
.btn {
  --b: var(--accent);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 22px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  clip-path: polygon(var(--cut) 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%, 0 var(--cut));
  transition: transform 0.12s var(--ease), opacity 0.2s;
  isolation: isolate;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  color: var(--accent-ink);
  background: var(--b);
  box-shadow: 0 0 24px var(--accent-glow);
}
.btn-primary::after {     /* moving sheen — transform only */
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.55) 50%, transparent 70%);
  transform: translateX(-120%);
  animation: sheen 3.6s var(--ease) infinite;
  z-index: -1;
  mix-blend-mode: soft-light;
}
@keyframes sheen { 0%, 60% { transform: translateX(-120%); } 100% { transform: translateX(120%); } }
.btn-ghost {
  color: var(--b);
  background: var(--b);
}
.btn-ghost::before {     /* inner fill leaves a 1.5px chamfered border */
  content: '';
  position: absolute;
  inset: 1.5px;
  background: var(--bg-1);
  clip-path: inherit;
  z-index: -1;
}
.btn-text {
  min-height: 44px;
  color: var(--text-dim);
  font-size: 12px;
  clip-path: none;
}
.btn-xl { min-height: 60px; font-size: 16px; }
.btn-sm { min-height: 40px; padding: 0 14px; font-size: 11px; letter-spacing: 0.12em; --cut: 8px; }
.btn-block { width: 100%; }
.btn.is-busy { opacity: 0.7; pointer-events: none; }
.btn.is-busy span::after { content: ''; display: inline-block; width: 0.6em; animation: blink 0.6s steps(2) infinite; }
.btn:disabled { opacity: 0.4; pointer-events: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  font-size: 26px;
  line-height: 1;
  color: var(--text);
  border: 1px solid var(--line-2);
  background: rgba(255, 255, 255, 0.02);
}
.icon-btn:active { transform: scale(0.94); }

/* ---- inputs ---- */
.input {
  width: 100%;
  height: 56px;
  padding: 0 16px;
  font-family: var(--font-display);
  font-size: 18px;       /* >=16px: iOS won't zoom */
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
  background: rgba(4, 8, 22, 0.7);
  border: 1px solid var(--line-2);
  border-radius: 0;
  outline: none;
  caret-color: var(--accent);
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.2s;
}
.input::placeholder { color: var(--text-faint); }
.input:focus { border-color: var(--accent); }
.input-code {
  height: 76px;
  font-size: 40px;
  text-align: center;
  letter-spacing: 0.5em;
  padding-left: 0.5em;
  color: var(--accent);
}

/* ---- panels ---- */
.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px;
}
.panel::before, .panel::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent);
  pointer-events: none;
}
.panel::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.panel::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }

/* ---- avatar + chip ---- */
.avatar {
  --s: 40px;
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: var(--s);
  height: var(--s);
  color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, transparent);
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
}
.avatar::before {       /* hex outline */
  content: '';
  position: absolute;
  inset: 0;
  background: var(--c);
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%, 2px 50%, calc(25% + 1px) calc(100% - 2px), calc(75% - 1px) calc(100% - 2px), calc(100% - 2px) 50%, calc(75% - 1px) 2px, calc(25% + 1px) 2px, 2px 50%, 0 50%);
  opacity: 0.9;
}
.avatar svg {
  width: 56%;
  height: 56%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 4px var(--c));
}

.chip {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 10px 12px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--c) 10%, transparent), rgba(10, 15, 38, 0.6) 60%);
  border: 1px solid var(--line);
  border-left: 3px solid var(--c);
  transition: opacity 0.3s;
}
.chip-body { flex: 1; min-width: 0; }
.chip-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip-tags { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.chip-tags:empty { display: none; }
.chip.is-offline { opacity: 0.55; }
.chip.is-offline .avatar { filter: grayscale(1); }

/* ---- timer ---- */
.timer { display: flex; align-items: center; gap: 10px; }
.timer-track {
  position: relative;
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}
.timer-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transform-origin: 0 50%;
  box-shadow: 0 0 10px var(--accent-glow);
}
.timer-num {
  min-width: 3.2ch;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.timer.is-warn .timer-fill { background: var(--red); }
.timer.is-warn .timer-num { color: var(--red); animation: blink 0.5s steps(2) infinite; }
.timer.is-zero .timer-num { color: var(--text-faint); }

/* ---- toasts ---- */
.toasts {
  position: fixed;
  z-index: 100;
  top: calc(var(--safe-t) + 10px);
  left: 50%;
  width: min(92vw, 460px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: rgba(6, 10, 28, 0.94);
  border: 1px solid var(--line-2);
  border-left: 3px solid var(--cyan);
  animation: toast-in 0.32s var(--ease-back) both;
}
.toast-glyph { color: var(--cyan); }
.toast-ok { border-left-color: var(--green); } .toast-ok .toast-glyph { color: var(--green); }
.toast-warn { border-left-color: var(--yellow); } .toast-warn .toast-glyph { color: var(--yellow); }
.toast-err { border-left-color: var(--red); } .toast-err .toast-glyph { color: var(--red); }
.toast.out { opacity: 0; transform: translateY(-8px); transition: opacity 0.25s, transform 0.25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(0.96); } }

/* ---- connection badge ---- */
.net {
  position: fixed;
  z-index: 90;
  left: 50%;
  bottom: calc(var(--safe-b) + 10px);
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--bg-0);
  background: var(--red);
  transform: translate(-50%, 160%);
  opacity: 0;
  transition: transform 0.3s var(--ease), opacity 0.3s;
  pointer-events: none;
}
.net.is-on { transform: translate(-50%, 0); opacity: 1; }

/* ---- segmented control ---- */
.seg { display: flex; gap: 6px; }
.seg-btn {
  flex: 1;
  min-height: 48px;
  font-family: var(--font-num);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  border: 1px solid var(--line-2);
  background: rgba(255, 255, 255, 0.02);
  transition: transform 0.12s, color 0.15s, background-color 0.15s;
}
.seg-btn:active { transform: scale(0.96); }
.seg-btn.is-on { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }

/* ---- modal bottom sheet ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(2, 3, 10, 0.72);
  animation: fade-in 0.25s both;
}
.modal.out { opacity: 0; transition: opacity 0.25s; }
.modal .sheet { animation: sheet-up 0.38s var(--ease) both; }
.modal.out .sheet { transform: translateY(40px); transition: transform 0.25s; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-up { from { transform: translateY(100%); } }
.sheet {
  position: relative;
  width: 100%;
  max-width: var(--maxw);
  padding: 14px var(--gutter) calc(var(--safe-b) + 18px);
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border-top: 2px solid var(--accent);
  box-shadow: 0 -10px 40px var(--accent-soft);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sheet-grip { width: 44px; height: 4px; margin: 0 auto 4px; background: var(--line-2); }
.sheet-kicker {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.28em;
  color: var(--accent);
}
.sheet-title {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 26px;
  letter-spacing: 0.06em;
  line-height: 1.05;
}
.sheet-text { color: var(--text-dim); font-size: 15px; }
.options-meta { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.est { font-family: var(--font-num); font-weight: 700; color: var(--accent); letter-spacing: 0.1em; }
.field { display: flex; flex-direction: column; gap: 8px; }

/* ---- leaderboard ---- */
.board-list { display: flex; flex-direction: column; gap: 6px; counter-reset: lb; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 8px 12px;
  background: rgba(10, 15, 38, 0.72);
  border: 1px solid var(--line);
  border-left: 3px solid var(--c);
  animation: row-in 0.45s var(--ease) both;
}
.lb-row.is-me { background: linear-gradient(90deg, color-mix(in srgb, var(--c) 16%, transparent), rgba(10, 15, 38, 0.72)); }
.lb-row.is-first { border-color: color-mix(in srgb, var(--yellow) 50%, transparent); border-left-color: var(--c); }
.lb-rank { font-family: var(--font-mono); font-weight: 700; color: var(--text-dim); width: 2ch; }
.is-first .lb-rank { color: var(--yellow); }
.lb-name {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.06em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-lost { color: var(--red); }
.lb-delta { font-family: var(--font-mono); font-size: 12px; font-weight: 700; color: var(--green); }
.lb-move { font-size: 10px; }
.move-up .lb-move { color: var(--green); }
.move-down .lb-move { color: var(--red); }
.lb-score {
  min-width: 4ch;
  text-align: right;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}
@keyframes row-in { from { opacity: 0; transform: translateX(-24px); } }

/* ---- particle burst ---- */
.burst { position: absolute; left: 50%; top: 45%; width: 0; height: 0; pointer-events: none; z-index: 5; }
.burst i {
  position: absolute;
  width: 6px;
  height: 10px;
  left: -3px;
  top: -5px;
  opacity: 0;
  animation: burst 1.2s var(--ease) forwards;
}
@keyframes burst {
  0% { opacity: 1; transform: translate(0, 0) rotate(0) scale(1); }
  100% { opacity: 0; transform: translate(var(--x), var(--y)) rotate(var(--r)) scale(0.4); }
}

/* ---- glitch transition flash ---- */
.glitch-flash { position: fixed; inset: 0; z-index: 80; pointer-events: none; }
.glitch-flash i {
  position: absolute;
  left: -10%;
  right: -10%;
  height: 9%;
  background: var(--accent);
  opacity: 0;
  mix-blend-mode: screen;
  animation: slice 0.38s steps(3) forwards;
}
.glitch-flash i:nth-child(1) { top: 18%; animation-delay: 0s; }
.glitch-flash i:nth-child(2) { top: 52%; height: 4%; background: var(--accent-2); animation-delay: 0.05s; }
.glitch-flash i:nth-child(3) { top: 74%; height: 6%; animation-delay: 0.1s; }
@keyframes slice {
  0% { opacity: 0.6; transform: translateX(-12%) scaleY(1); }
  50% { opacity: 0.35; transform: translateX(9%) scaleY(0.4); }
  100% { opacity: 0; transform: translateX(0) scaleY(0.1); }
}

/* ---- ACCESS GRANTED (room join) ---- */
.access {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: grid;
  place-items: center;
  background: rgba(2, 3, 10, 0.86);
  pointer-events: none;
  animation: fade-in 0.2s both;
}
.access.out { opacity: 0; transition: opacity 0.45s; }
.access-ring {
  position: absolute;
  width: 160px;
  height: 160px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  opacity: 0;
  animation: ring 1.2s var(--ease) forwards;
}
.access-ring.r2 { border-color: var(--accent-2); animation-delay: 0.12s; }
.access-ring.r3 { animation-delay: 0.26s; border-style: dashed; }
@keyframes ring {
  0% { opacity: 1; transform: scale(0.2); }
  100% { opacity: 0; transform: scale(3.2); }
}
.access-text {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  animation: access-text 0.6s var(--ease-back) both 0.1s;
}
.access-text small { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.3em; color: var(--text-dim); }
.access-text strong {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(26px, 8vw, 40px);
  letter-spacing: 0.1em;
  color: var(--accent);
  text-shadow: 0 0 18px var(--accent-glow), 3px 0 0 rgba(255, 43, 214, 0.5), -3px 0 0 rgba(0, 240, 255, 0.5);
}
@keyframes access-text {
  0% { opacity: 0; transform: scale(1.4); }
  60% { opacity: 1; transform: scale(0.97); }
}
