/* Pattern Game widget — shared by the public page (/pattern-game/) and the
   dashboard Pattern Game view. Everything is scoped under .pg-root and declares
   its OWN custom properties, so dropping it into the dashboard (which has a
   different token set) can never inherit or clash with the host page's theme. */

.pg-root {
  --pg-accent:  #00d4ff;
  --pg-violet:  #7a9bff;
  --pg-up:      #00e676;
  --pg-down:    #ff3d57;
  --pg-surface: #0e141d;
  --pg-deep:    #080c12;
  --pg-border:  rgba(255,255,255,0.09);
  --pg-text:    #cbd7e4;
  --pg-bright:  #f4f9ff;
  --pg-muted:   #6d8199;
  --pg-mono:    'Roboto Mono', ui-monospace, monospace;
  --pg-sans:    'Inter', -apple-system, 'Segoe UI', sans-serif;

  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  /* Column is kept near the card's own width (a 640px-tall 9:16 card is 360px
     across) so the controls read as part of the card, not a wider toolbar. */
  max-width: 400px;
  margin: 0 auto;
  font-family: var(--pg-sans);
  color: var(--pg-text);
}
.pg-root *, .pg-root *::before, .pg-root *::after { box-sizing: border-box; }
.pg-hidden { display: none !important; }

/* ── top bar: difficulty + cards left ─────────────────────────────────── */
.pg-top {
  display: flex; align-items: stretch; justify-content: center;
  gap: 10px; flex-wrap: wrap; width: 100%;
}
/* Levels take one full row and the cards-left pill the next, at every width —
   in a 400px column the two would otherwise wrap into a lopsided layout. */
.pg-levels { display: flex; gap: 6px; flex: 1 1 100%; }
.pg-level {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 6px; cursor: pointer;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--pg-border);
  border-radius: 11px;
  color: var(--pg-muted);
  font-family: inherit;
  transition: border-color .15s, background .15s, color .15s;
}
.pg-level:hover { border-color: rgba(0,212,255,0.3); color: var(--pg-text); }
.pg-level.on {
  background: linear-gradient(180deg, rgba(0,212,255,0.16), rgba(0,212,255,0.05));
  border-color: rgba(0,212,255,0.5);
  color: var(--pg-bright);
}
.pg-level-name { font-family: var(--pg-mono); font-size: 11px; font-weight: 700; letter-spacing: 0.14em; }
.pg-level-bars { font-size: 9.5px; font-weight: 500; letter-spacing: 0.06em; opacity: .75; }

.pg-quota {
  display: flex; flex-direction: row; align-items: center; justify-content: center;
  gap: 8px; flex: 1 1 100%;
  padding: 8px 16px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--pg-border);
  border-radius: 11px;
}
.pg-quota.low { border-color: rgba(255,61,87,0.45); background: rgba(255,61,87,0.07); }
.pg-quota-n { font-family: var(--pg-mono); font-size: 17px; font-weight: 700; color: var(--pg-bright); line-height: 1; }
.pg-quota.low .pg-quota-n { color: var(--pg-down); }
.pg-quota-l { font-family: var(--pg-mono); font-size: 8px; font-weight: 600; letter-spacing: 0.14em; color: var(--pg-muted); }

/* ── the 9:16 card ────────────────────────────────────────────────────── */
.pg-stage { width: 100%; display: flex; justify-content: center; }
.pg-card {
  position: relative;
  aspect-ratio: 9 / 16;
  height: min(74vh, 640px);
  max-width: 100%;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, #101823, var(--pg-deep));
  border: 1px solid var(--pg-border);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.05);
  transition: border-color .25s, box-shadow .25s;
}
/* Fallback for browsers without aspect-ratio: keep the 9:16 proportion. */
@supports not (aspect-ratio: 9 / 16) {
  .pg-card { width: 340px; height: 604px; }
}
.pg-card.win  { border-color: rgba(0,230,118,0.5);  box-shadow: 0 24px 60px rgba(0,0,0,0.55), 0 0 0 1px rgba(0,230,118,0.25); }
.pg-card.lose { border-color: rgba(255,61,87,0.45); box-shadow: 0 24px 60px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,61,87,0.22); }

.pg-card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 11px 12px 9px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex: none;
}
.pg-card-head-l, .pg-card-head-r { display: flex; align-items: center; gap: 6px; min-width: 0; }
.pg-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px; border-radius: 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.07);
  font-family: var(--pg-mono);
  font-size: 10px; font-weight: 600; letter-spacing: 0.08em;
  color: var(--pg-text); white-space: nowrap;
}
.pg-chip-inst { color: var(--pg-bright); }
.pg-chip-name { font-weight: 700; }
.pg-chip-tf { color: var(--pg-accent); border-color: rgba(0,212,255,0.28); background: rgba(0,212,255,0.08); }
.pg-chip-sess { color: var(--pg-violet); border-color: rgba(122,155,255,0.25); background: rgba(122,155,255,0.08); }
.pg-chip-ico { display: inline-flex; align-items: center; width: 16px; height: 16px; flex: none; }
.pg-chip-ico img { width: 16px; height: 16px; object-fit: contain; }
.pg-chip-ico-flags { width: 22px; position: relative; }
.pg-flag { width: 12px; height: 9px; border-radius: 2px; background-size: cover; position: absolute; top: 3px; }
.pg-flag-a { left: 0; z-index: 2; box-shadow: 0 0 0 1px rgba(8,12,18,0.9); }
.pg-flag-b { left: 8px; z-index: 1; }
.pg-chip-glyph { font-size: 13px; line-height: 1; color: #f97316; }

.pg-canvas { flex: 1 1 auto; width: 100%; min-height: 0; display: block; }

.pg-card-foot {
  flex: none; padding: 10px 13px 13px;
  border-top: 1px solid rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.25);
  min-height: 74px;
}
.pg-foot-q { font-size: 12.5px; color: var(--pg-bright); margin-bottom: 5px; }
.pg-foot-note { font-size: 10.5px; line-height: 1.5; color: var(--pg-muted); }

.pg-result { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.pg-result-tag {
  font-family: var(--pg-mono); font-size: 10px; font-weight: 700; letter-spacing: 0.1em;
  padding: 3px 8px; border-radius: 6px;
}
.pg-result.win  .pg-result-tag { background: rgba(0,230,118,0.16); color: var(--pg-up); }
.pg-result.lose .pg-result-tag { background: rgba(255,61,87,0.14); color: var(--pg-down); }
.pg-result-truth { font-family: var(--pg-mono); font-size: 11px; font-weight: 700; letter-spacing: 0.09em; color: var(--pg-bright); }

/* ── gate overlay ─────────────────────────────────────────────────────── */
.pg-gate {
  display: none;
  position: absolute; inset: 0; z-index: 5;
  background: rgba(6,9,14,0.93);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 24px 20px;
  align-items: center; justify-content: center;
}
.pg-gate.on { display: flex; }
.pg-gate-box { text-align: center; max-width: 300px; }
.pg-gate-kicker {
  font-family: var(--pg-mono); font-size: 9.5px; font-weight: 600; letter-spacing: 0.22em;
  color: var(--pg-accent); margin-bottom: 12px;
}
.pg-gate-title {
  font-family: 'Space Grotesk', var(--pg-sans);
  font-size: 21px; font-weight: 700; line-height: 1.22; color: var(--pg-bright);
  letter-spacing: -0.018em; margin-bottom: 12px;
}
.pg-gate-sub { font-size: 12.5px; line-height: 1.65; color: #8ba0b8; margin-bottom: 20px; }
.pg-gate-btn {
  display: inline-block; width: 100%;
  padding: 13px 18px; border: none; border-radius: 11px;
  background: linear-gradient(135deg, #22ddff, #00a9e8);
  color: #001018; text-decoration: none; cursor: pointer;
  font-family: var(--pg-sans); font-size: 12px; font-weight: 700; letter-spacing: 0.07em;
  box-shadow: 0 6px 22px rgba(0,212,255,0.3), inset 0 1px 0 rgba(255,255,255,0.35);
  transition: transform .15s, box-shadow .15s;
}
.pg-gate-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 30px rgba(0,212,255,0.42), inset 0 1px 0 rgba(255,255,255,0.35); }
.pg-gate-link { display: inline-block; margin-top: 13px; font-size: 12px; color: #8ba0b8; text-decoration: none; }
.pg-gate-link:hover { color: var(--pg-accent); }

/* ── answers ──────────────────────────────────────────────────────────── */
.pg-actions {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px; width: 100%;
}
.pg-answer {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 13px 8px; cursor: pointer;
  background: rgba(255,255,255,0.035);
  border: 1px solid var(--pg-border);
  border-radius: 13px;
  color: var(--pg-text); font-family: inherit;
  transition: transform .12s, border-color .15s, background .15s, opacity .15s;
}
.pg-answer:hover:not(:disabled) { transform: translateY(-2px); }
.pg-answer:disabled { cursor: default; opacity: .6; }
.pg-answer-mark { font-family: var(--pg-mono); font-size: 15px; font-weight: 700; line-height: 1; }
.pg-answer-label { font-family: var(--pg-mono); font-size: 11.5px; font-weight: 700; letter-spacing: 0.1em; color: var(--pg-bright); }
.pg-answer-hint { font-size: 9.5px; color: var(--pg-muted); text-align: center; line-height: 1.35; }
.pg-answer-up   .pg-answer-mark { color: var(--pg-up); }
.pg-answer-down .pg-answer-mark { color: var(--pg-down); }
.pg-answer-side .pg-answer-mark { color: var(--pg-violet); }
.pg-answer-up:hover:not(:disabled)   { border-color: rgba(0,230,118,0.45); background: rgba(0,230,118,0.07); }
.pg-answer-down:hover:not(:disabled) { border-color: rgba(255,61,87,0.45); background: rgba(255,61,87,0.07); }
.pg-answer-side:hover:not(:disabled) { border-color: rgba(122,155,255,0.45); background: rgba(122,155,255,0.07); }
.pg-answer.picked { opacity: 1; border-color: rgba(255,255,255,0.34); }
.pg-answer.right  { opacity: 1; border-color: rgba(0,230,118,0.65); background: rgba(0,230,118,0.12); }
.pg-answer.wrong  { opacity: 1; border-color: rgba(255,61,87,0.6); background: rgba(255,61,87,0.1); }

.pg-next {
  width: 100%;
  padding: 14px 20px; border: none; border-radius: 13px;
  background: linear-gradient(135deg, #22ddff, #00a9e8);
  color: #001018; cursor: pointer;
  font-family: var(--pg-sans); font-size: 12.5px; font-weight: 700; letter-spacing: 0.08em;
  box-shadow: 0 6px 22px rgba(0,212,255,0.28), inset 0 1px 0 rgba(255,255,255,0.35);
  transition: transform .15s, box-shadow .15s;
}
.pg-next:hover { transform: translateY(-1px); box-shadow: 0 10px 30px rgba(0,212,255,0.4), inset 0 1px 0 rgba(255,255,255,0.35); }

/* ── score strip ──────────────────────────────────────────────────────── */
.pg-score {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px; width: 100%;
  padding: 12px 10px;
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--pg-border);
  border-radius: 14px;
}
.pg-score-cell { text-align: center; min-width: 0; }
.pg-score-v { font-family: var(--pg-mono); font-size: 16px; font-weight: 700; color: var(--pg-bright); line-height: 1.1; }
.pg-score-k { font-family: var(--pg-mono); font-size: 8px; font-weight: 600; letter-spacing: 0.1em; color: var(--pg-muted); margin-top: 5px; }

/* Vertical variant used when the host page mounts the strip beside the card
   (opts.scoreHost) instead of under it — five stacked label/value rows. It
   re-declares the tokens because it then lives OUTSIDE .pg-root. */
.pg-score-side {
  --pg-border: rgba(255,255,255,0.09);
  --pg-bright: #f4f9ff;
  --pg-muted:  #6d8199;
  --pg-mono:   'Roboto Mono', ui-monospace, monospace;
  --pg-sans:   'Inter', -apple-system, 'Segoe UI', sans-serif;
  font-family: var(--pg-sans);
  grid-template-columns: minmax(0, 1fr);
  gap: 3px;
  padding: 7px;
}
.pg-score-side .pg-score-cell {
  display: flex; flex-direction: row-reverse; align-items: baseline;
  justify-content: space-between; gap: 10px;
  text-align: left; padding: 9px 11px; border-radius: 9px;
  background: rgba(255,255,255,0.022);
}
.pg-score-side .pg-score-v { font-size: 18px; }
.pg-score-side .pg-score-k { margin-top: 0; font-size: 8.5px; }

/* ── public leaderboard ───────────────────────────────────────────────── */
/* Not inside .pg-root: it stands as its own section on the public page, so it
   re-declares the handful of tokens it needs. */
.pg-lb {
  --pg-accent: #00d4ff;
  --pg-mono: 'Roboto Mono', ui-monospace, monospace;
  --pg-sans: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  font-family: var(--pg-sans);
  max-width: 620px;
}
.pg-lb *, .pg-lb *::before, .pg-lb *::after { box-sizing: border-box; }
.pg-lb-head { margin-bottom: 18px; }
.pg-lb-kicker {
  font-family: var(--pg-mono); font-size: 10px; font-weight: 600; letter-spacing: 0.24em;
  color: var(--pg-accent); margin-bottom: 8px;
}
.pg-lb-title {
  font-family: 'Space Grotesk', var(--pg-sans);
  font-size: 20px; font-weight: 700; color: #f4f9ff; letter-spacing: -0.015em;
}
.pg-lb-sub-title { font-size: 12.5px; line-height: 1.6; color: #8ba0b8; margin-top: 8px; }
.pg-lb-empty {
  padding: 26px 18px; text-align: center;
  border: 1px dashed rgba(255,255,255,0.14); border-radius: 12px;
  font-size: 13px; color: #8ba0b8;
}
.pg-lb-empty-btn { display: block; width: 100%; margin-top: 10px; text-align: center; }
.pg-lb-rows { display: flex; flex-direction: column; gap: 6px; }
.pg-lb-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 10px;
  background: rgba(255,255,255,0.025);
  border: 1px solid rgba(255,255,255,0.07);
}
.pg-lb-row.me { background: rgba(0,212,255,0.06); border-color: rgba(0,212,255,0.35); }
.pg-lb-rank {
  width: 30px; flex: none; text-align: center;
  font-family: var(--pg-mono); font-size: 12.5px; font-weight: 700; color: #55677d;
}
.pg-lb-rank.top1 { color: #ffc500; }
.pg-lb-rank.top2 { color: #b0bec5; }
.pg-lb-rank.top3 { color: #cd7f32; }
.pg-lb-av {
  width: 32px; height: 32px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.09);
  font-family: var(--pg-mono); font-size: 10.5px; font-weight: 700; color: #8ba0b8; letter-spacing: 0.5px;
}
.pg-lb-mid { flex: 1; min-width: 0; }
.pg-lb-name {
  font-size: 13.5px; font-weight: 650; color: #eaf2fa;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pg-lb-sub { font-family: var(--pg-mono); font-size: 9.5px; letter-spacing: 0.08em; color: #55677d; margin-top: 3px; }
.pg-lb-metric { flex: none; text-align: right; }
.pg-lb-best { font-family: var(--pg-mono); font-size: 18px; font-weight: 700; color: #f4f9ff; line-height: 1; }
.pg-lb-unit { font-family: var(--pg-mono); font-size: 8px; font-weight: 600; letter-spacing: 0.14em; color: #55677d; margin-top: 4px; }

.pg-lb-locked { position: relative; margin-top: 6px; }
.pg-lb-blur {
  filter: blur(5px);
  opacity: .55;
  pointer-events: none;
  user-select: none;
}
.pg-lb-gate {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: linear-gradient(180deg, rgba(6,9,14,0.35), rgba(6,9,14,0.82) 55%);
  border-radius: 12px;
}
.pg-lb-gate-box { text-align: center; max-width: 330px; }
.pg-lb-gate-title {
  font-family: 'Space Grotesk', var(--pg-sans);
  font-size: 17px; font-weight: 700; color: #f4f9ff; margin-bottom: 8px; letter-spacing: -0.012em;
}
.pg-lb-gate-sub { font-size: 12.5px; line-height: 1.6; color: #8ba0b8; margin-bottom: 16px; }
.pg-lb-gate-btn {
  display: inline-block; padding: 11px 24px; border-radius: 10px;
  background: linear-gradient(135deg, #22ddff, #00a9e8);
  color: #001018; text-decoration: none;
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em;
  box-shadow: 0 6px 20px rgba(0,212,255,0.3), inset 0 1px 0 rgba(255,255,255,0.35);
  transition: transform .15s, box-shadow .15s;
}
.pg-lb-gate-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 28px rgba(0,212,255,0.42), inset 0 1px 0 rgba(255,255,255,0.35); }

@media (max-width: 560px) {
  .pg-lb-title { font-size: 17px; }
  .pg-lb-row { padding: 10px 11px; gap: 9px; }
  .pg-lb-rank { width: 24px; font-size: 11.5px; }
  .pg-lb-av { width: 28px; height: 28px; font-size: 9.5px; }
  .pg-lb-name { font-size: 12.5px; }
  .pg-lb-best { font-size: 16px; }
  .pg-lb-gate-title { font-size: 15.5px; }
}

/* ── toast ────────────────────────────────────────────────────────────── */
.pg-toast {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  z-index: 20; padding: 10px 16px; border-radius: 10px;
  background: linear-gradient(135deg, rgba(0,230,118,0.95), rgba(0,190,96,0.95));
  color: #00160a;
  font-family: var(--pg-mono); font-size: 10.5px; font-weight: 700; letter-spacing: 0.09em;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  transition: opacity .5s, transform .5s;
}
.pg-toast.out { opacity: 0; transform: translateX(-50%) translateY(-8px); }

/* ── mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 560px) {
  .pg-root { gap: 12px; }
  .pg-card { height: min(66vh, 540px); }
  .pg-level { padding: 8px 4px; border-radius: 10px; }
  .pg-level-name { font-size: 10px; }
  .pg-level-bars { font-size: 8.5px; }
  .pg-quota { padding: 7px 12px; }
  .pg-answer { padding: 11px 5px; border-radius: 11px; }
  .pg-answer-label { font-size: 10.5px; letter-spacing: 0.06em; }
  .pg-answer-hint { display: none; }
  .pg-score { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 6px; }
  .pg-score-v { font-size: 15px; }
  .pg-card-foot { min-height: 68px; padding: 9px 11px 11px; }
  .pg-gate-title { font-size: 18px; }
}
@media (max-width: 380px) {
  .pg-card { height: min(60vh, 470px); }
  .pg-chip { padding: 3px 6px; font-size: 9px; gap: 4px; }
}
