/* ── Reset & Variables ──────────────────────────────────────── */
:root {
  color-scheme: dark;
  /* Dark mode defaults — ocean teal */
  --bg:        #080f14;
  --surf:      rgba(255,255,255,0.07);
  --surf2:     rgba(255,255,255,0.04);
  --surf3:     rgba(255,255,255,0.12);
  --accent:    #2dd4bf;
  --accent2:   #38bdf8;
  --green:     #4ade80;
  --red:       #f87171;
  --amber:     #fbbf24;
  --text:      #f0fdfc;
  --text2:     #94a3b8;
  --muted:     #64748b;
  --radius:    18px;
  --radius-s:  12px;
  --cell-bg:   rgba(255,255,255,0.07);
  --cell-bdr:  rgba(255,255,255,0.14);
  --cell-sel:  #2dd4bf;
  --cell-path: rgba(45,212,191,0.40);
  --cell-act:  #5eead4;
  --blur:      blur(20px) saturate(160%);
  --shadow:    0 8px 32px rgba(0,0,0,0.35);
  --glass-hi:  inset 0 1px 0 rgba(255,255,255,0.10);
}

/* ── Light mode overrides ───────────────────────────────────── */
[data-theme="light"] {
  color-scheme: light;
  --bg:        #f0fdfa;
  --surf:      rgba(255,255,255,0.80);
  --surf2:     rgba(255,255,255,0.60);
  --surf3:     rgba(13,148,136,0.14);
  --accent:    #0d9488;
  --accent2:   #0891b2;
  --green:     #059669;
  --red:       #dc2626;
  --amber:     #d97706;
  --text:      #0f172a;
  --text2:     #334155;
  --muted:     #64748b;
  --cell-bg:   rgba(255,255,255,0.80);
  --cell-bdr:  rgba(13,148,136,0.20);
  --cell-sel:  #0d9488;
  --cell-path: rgba(13,148,136,0.28);
  --cell-act:  #2dd4bf;
  --shadow:    0 4px 24px rgba(13,148,136,0.10);
  --glass-hi:  inset 0 1px 0 rgba(255,255,255,0.85);
}

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

html {
  font-size: 17px;
  height: 100%;
}

html, body {
  height: 100%;
  overflow: hidden;
  color: var(--text);
  font-family: 'Inter', 'Vazirmatn', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  background: linear-gradient(160deg, #080f14 0%, #091a22 40%, #061820 70%, #080e14 100%) fixed;
  background-attachment: fixed;
}

[data-theme="light"] body {
  background: linear-gradient(160deg, #ccfbf1 0%, #e6fffc 30%, #f8fffe 65%, #e0f7fa 100%) fixed;
  background-attachment: fixed;
}

body.lang-fa {
  font-family: 'Vazirmatn', 'Inter', system-ui, sans-serif;
}

/* ── Views ──────────────────────────────────────────────────── */
.view {
  display: none;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  max-width: 520px;
  margin: 0 auto;
}
.view.active { display: flex; }

/* ── Theme Toggle (home screen only) ────────────────────────── */
.theme-toggle {
  display: none; /* hidden everywhere by default */
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: 16px;
  z-index: 150;  /* below modal overlay (z-index 200) */
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--surf3);
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow), var(--glass-hi);
  font-size: 1.2rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
/* Only visible when home view is active */
#view-home.active ~ .theme-toggle {
  display: flex;
}
.theme-toggle:active { transform: scale(0.88); }

/* ── Guide Toggle (home screen only) ────────────────────────── */
.guide-toggle {
  display: none;
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 16px;
  z-index: 150;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--surf3);
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow), var(--glass-hi);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text2);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
#view-home.active ~ .guide-toggle {
  display: flex;
}
.guide-toggle:active { transform: scale(0.88); }

/* ── Guide Modal ─────────────────────────────────────────────── */
.guide-sheet {
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  padding: 0;
}
.guide-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 0;
  flex-shrink: 0;
}
.guide-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}
.guide-body {
  overflow-y: auto;
  padding: 16px 20px max(24px, env(safe-area-inset-bottom));
  flex: 1;
}
.guide-section { margin-bottom: 22px; }
.guide-section:last-child { margin-bottom: 0; }
.guide-section-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--accent2);
  margin-bottom: 10px;
}
.guide-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.guide-list li {
  font-size: .93rem;
  color: var(--text2);
  padding-inline-start: 14px;
  position: relative;
  line-height: 1.55;
}
.guide-list li::before {
  content: '·';
  position: absolute;
  inset-inline-start: 0;
  color: var(--accent);
  font-weight: 700;
}

/* ── Solo button ─────────────────────────────────────────────── */
.btn-solo {
  display: block;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius-s);
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  min-height: 52px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 4px 20px rgba(45,212,191,0.40);
  transition: opacity .15s, transform .15s;
}
[data-theme="light"] .btn-solo {
  box-shadow: 0 4px 20px rgba(13,148,136,0.3);
}
.btn-solo:active { opacity: .85; transform: scale(.98); }
.btn-solo:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ── Edit Game button (top-left of results) ──────────────────── */

/* ── Result best score ───────────────────────────────────────── */
.result-best {
  font-size: .8rem;
  color: var(--text2);
  font-weight: 500;
  margin-top: 3px;
}

/* ── Solo settings body ──────────────────────────────────────── */
.solo-settings-body .cfg-row { margin-bottom: 16px; }
.solo-settings-body .cfg-row:last-child { margin-bottom: 0; }

/* ── Home ───────────────────────────────────────────────────── */
.logo-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 0 20px;
  text-align: center;
  gap: 8px;
}
.logo-icon { font-size: 3.5rem; animation: float 3s ease-in-out infinite; }
@keyframes float {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.logo-title {
  font-size: 2.8rem;
  font-weight: 900;
  background: linear-gradient(135deg, #34d399, #06b6d4, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
}
.logo-sub {
  color: var(--text2);
  font-size: 1rem;
  font-weight: 500;
}

/* Glass card base */
.card {
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--surf3);
  border-radius: var(--radius);
  box-shadow: var(--shadow), var(--glass-hi);
  padding: 22px;
  margin-bottom: 16px;
}

.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 8px;
}

input[type="text"] {
  width: 100%;
  padding: 14px 16px;
  background: var(--surf2);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--surf3);
  border-radius: var(--radius-s);
  color: var(--text);
  font-size: 1.05rem;
  font-family: inherit;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
[data-theme="light"] input[type="text"] {
  background: rgba(255,255,255,0.85);
}
input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45,212,191,0.15);
}
[data-theme="light"] input[type="text"]:focus {
  box-shadow: 0 0 0 3px rgba(45,212,191,0.12);
}
input[type="text"]::placeholder { color: var(--muted); }

.lang-toggle { display: flex; gap: 8px; }
.lang-btn {
  flex: 1;
  padding: 13px;
  background: var(--surf2);
  border: 1px solid var(--surf3);
  border-radius: var(--radius-s);
  color: var(--text2);
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
  min-height: 48px;
}
.lang-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-color: transparent;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(45,212,191,0.30);
}

.btn {
  display: block;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius-s);
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
  text-align: center;
  min-height: 52px;
}
.btn.full { width: 100%; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 4px 20px rgba(45,212,191,0.40);
}
[data-theme="light"] .btn-primary {
  box-shadow: 0 4px 20px rgba(99,102,241,0.3);
}
.btn-primary:active { opacity: .85; transform: scale(.98); }
.btn-secondary {
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--surf3);
  color: var(--text);
  box-shadow: var(--glass-hi);
}

.divider {
  text-align: center;
  color: var(--muted);
  font-size: 1rem;
  margin: 16px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--surf3);
}

.join-or-label {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 8px;
}
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; }
.join-row .btn { width: auto; padding: 14px 22px; flex-shrink: 0; }

/* ── Lobby ──────────────────────────────────────────────────── */
.lobby-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-top: 4px;
}
.back-btn {
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--surf3);
  box-shadow: var(--glass-hi);
  color: var(--text);
  border-radius: var(--radius-s);
  font-size: 1.3rem;
  width: 48px;
  height: 48px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.room-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--surf3);
  box-shadow: var(--glass-hi);
  border-radius: var(--radius-s);
  padding: 10px 16px;
  flex: 1;
  font-size: .95rem;
  color: var(--text2);
  overflow: hidden;
}
.room-badge strong {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--accent2);
  letter-spacing: .15em;
  flex: 1;
}
.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 6px 8px;
  border-radius: var(--radius-s);
  transition: background .1s;
  line-height: 1;
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text2);
}
.icon-btn:hover { background: var(--surf3); }

/* Glass section card */
.section-card {
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--surf3);
  border-radius: var(--radius);
  box-shadow: var(--shadow), var(--glass-hi);
  padding: 18px;
  margin-bottom: 12px;
}
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text2);
  margin-bottom: 14px;
}
.pill {
  background: var(--surf3);
  color: var(--text);
  font-size: .85rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
}

/* player rows */
.player-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--surf3);
}
.player-row:last-child { border-bottom: none; padding-bottom: 0; }
.avatar-char {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
}
.av-emoji {
  display: block;
  line-height: 1;
  transform: translateY(0.07em);
}

/* Avatar trigger button */
.name-avatar-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 18px;
}
.name-avatar-row input[type="text"],
.avatar-compact {
  height: 52px;
  box-sizing: border-box;
}
.avatar-col {
  display: flex;
  flex-direction: column;
}
.avatar-col label {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 8px;
}
.avatar-trigger {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surf2);
  border: 1px solid var(--surf3);
  border-radius: var(--radius-s);
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  width: 100%;
  min-height: 56px;
  transition: border-color 0.15s;
}
.avatar-trigger:hover { border-color: var(--accent); }
.av-change-hint {
  margin-left: auto;
  font-size: .9rem;
  color: var(--muted);
  font-weight: 500;
}
.avatar-compact {
  width: 52px;
  min-width: 52px;
  min-height: unset;
  padding: 8px;
  justify-content: center;
}
.avatar-compact > span { display: none; }
.avatar-compact > div { font-size: 1.8rem; line-height: 1; }

/* Avatar modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}
[data-theme="light"] .modal-overlay {
  background: rgba(30,27,75,0.4);
}
.modal-overlay.open { opacity: 1; }
.modal-sheet {
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--surf3);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow), var(--glass-hi);
  padding: 24px 20px max(24px, env(safe-area-inset-bottom));
  width: 100%;
  max-width: 520px;
  transform: translateY(40px);
  transition: transform 0.25s ease;
}
.modal-overlay.open .modal-sheet { transform: translateY(0); }
.modal-title {
  font-weight: 700;
  font-size: 1.05rem;
  text-align: center;
  margin-bottom: 18px;
  color: var(--text2);
}

/* Avatar picker grid */
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(6, 56px);
  justify-content: center;
  gap: 12px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 4px 2px;
}
.av-option {
  width: 56px;
  height: 56px;
  cursor: pointer;
  border-radius: 50%;
  border: 3px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.av-option:hover { transform: scale(1.1); }
.av-option.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45,212,191,0.30);
}

/* Avatar animations */
@keyframes av-cheer {
  0%,100% { transform: scale(1) translateY(0); }
  30%     { transform: scale(1.25) translateY(-9px); }
  60%     { transform: scale(1.1) translateY(-4px); }
}
@keyframes av-shake {
  0%,100% { transform: translateX(0) rotate(0deg); }
  25%     { transform: translateX(-6px) rotate(-10deg); }
  75%     { transform: translateX(6px) rotate(10deg); }
}
@keyframes av-bounce {
  0%,100% { transform: scale(1); }
  50%     { transform: scale(1.18); }
}
@keyframes av-excited {
  0%,100% { transform: rotate(0deg) scale(1); }
  25%     { transform: rotate(-12deg) scale(1.1); }
  75%     { transform: rotate(12deg) scale(1.1); }
}
@keyframes av-celebrate {
  0%,100% { transform: scale(1) rotate(0deg); }
  20%     { transform: scale(1.3) rotate(-6deg); }
  40%     { transform: scale(1.3) rotate(6deg); }
  60%     { transform: scale(1.2) rotate(-3deg); }
  80%     { transform: scale(1.2) rotate(3deg); }
}
@keyframes av-worried {
  0%,100% { transform: translateX(0) rotate(0deg); }
  20%,60% { transform: translateX(-3px) rotate(-4deg); }
  40%,80% { transform: translateX(3px) rotate(4deg); }
}

.av-cheer     { animation: av-cheer     0.5s ease forwards; }
.av-shake     { animation: av-shake     0.5s ease forwards; }
.av-bounce    { animation: av-bounce    0.4s ease forwards; }
.av-excited   { animation: av-excited   0.6s ease forwards; }
.av-celebrate { animation: av-celebrate 0.7s ease forwards; }
.av-worried   { animation: av-worried   0.5s ease forwards; }
.player-name { flex: 1; font-weight: 600; font-size: 1.05rem; }
.host-tag {
  font-size: .78rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  padding: 3px 9px;
  border-radius: 6px;
  font-weight: 700;
}
.you-tag {
  font-size: .78rem;
  background: var(--surf3);
  color: var(--text2);
  padding: 3px 9px;
  border-radius: 6px;
  font-weight: 600;
}

/* config */
.cfg-row { margin-bottom: 18px; }
.cfg-row:last-child { margin-bottom: 0; }
.cfg-label { font-size: 1rem; color: var(--text2); margin-bottom: 10px; font-weight: 600; }
.cfg-opts { display: flex; gap: 8px; flex-wrap: wrap; }
.opt {
  padding: 11px 18px;
  background: var(--surf2);
  border: 1px solid var(--surf3);
  border-radius: var(--radius-s);
  color: var(--text2);
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
  min-height: 46px;
  min-width: 46px;
}
.opt.active {
  background: rgba(45,212,191,0.15);
  border-color: var(--accent);
  color: var(--accent2);
  font-weight: 700;
  box-shadow: 0 0 0 1px var(--accent);
}
[data-theme="light"] .opt.active {
  background: rgba(13,148,136,0.12);
}

.dict-badge {
  text-align: center;
  font-size: .9rem;
  color: var(--text2);
  padding: 9px;
  background: var(--surf2);
  border-radius: var(--radius-s);
  margin-bottom: 12px;
  border: 1px dashed var(--surf3);
}

.lobby-footer { margin-top: auto; padding-top: 8px; }
.waiting-msg {
  text-align: center;
  color: var(--text2);
  font-size: 1rem;
  font-weight: 500;
  padding: 18px;
}

/* ── Game ───────────────────────────────────────────────────── */
#view-game {
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  gap: 10px;
  overflow: hidden;
}

.game-head { flex-shrink: 0; }
.timer-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.timer-track {
  flex: 1;
  height: 8px;
  background: var(--surf2);
  border: 1px solid var(--surf3);
  border-radius: 8px;
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--amber), var(--red));
  background-size: 300% 100%;
  border-radius: 8px;
  transition: width 1s linear, background-position 1s linear;
}
.timer-fill.urgent { animation: blink .6s ease-in-out infinite; }
@keyframes blink { 0%,100% { opacity:1 } 50% { opacity:.4 } }
#timerText {
  font-size: 1.15rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 52px;
  text-align: right;
  color: var(--text);
}

.word-feedback {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: .06em;
  color: var(--accent2);
  transition: color .1s;
}
.word-feedback.ok  { color: var(--green); animation: pop .35s ease; }
.word-feedback.bad { color: var(--red);   animation: shake .3s ease; }
.word-feedback.dup { color: var(--amber); animation: shake .3s ease; }
@keyframes pop   { 0%,100%{transform:scale(1)} 50%{transform:scale(1.12)} }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)} }

.live-scores {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}
.ls-chip {
  font-size: .9rem;
  padding: 5px 12px 5px 7px;
  border-radius: 20px;
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--surf3);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ls-chip.me {
  border-color: var(--accent);
  color: var(--accent2);
  font-weight: 700;
  box-shadow: 0 0 0 1px var(--accent);
}

/* Board */
.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  position: relative;
}
.board {
  display: grid;
  gap: 6px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  position: relative;
  direction: ltr;
}
.cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell-bg);
  border: 2px solid var(--cell-bdr);
  border-radius: 14px;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  transition: background .08s, border-color .08s, transform .08s, box-shadow .08s;
  box-shadow: 0 3px 10px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.08);
  position: relative;
  z-index: 1;
}
[data-theme="light"] .cell {
  box-shadow: 0 2px 8px rgba(13,148,136,0.08), inset 0 1px 0 rgba(255,255,255,0.9);
}
.cell.path {
  background: var(--cell-path);
  border-color: var(--accent);
  transform: scale(.94);
  box-shadow: 0 0 12px rgba(45,212,191,0.50);
  z-index: 2;
}
[data-theme="light"] .cell.path {
  box-shadow: 0 0 10px rgba(13,148,136,0.40);
}
.cell.head {
  background: var(--cell-act);
  border-color: #c7d2fe;
  transform: scale(1.06);
  box-shadow: 0 0 20px rgba(165,180,252,0.65);
  z-index: 3;
  color: #1e1b4b;
}
[data-theme="light"] .cell.head {
  box-shadow: 0 0 18px rgba(13,148,136,0.55);
}
.cell.flash-ok  { background: var(--green)  !important; border-color: var(--green)  !important; }
.cell.flash-bad { background: var(--red)    !important; border-color: var(--red)    !important; }
.cell.flash-dup { background: var(--amber)  !important; border-color: var(--amber)  !important; }

/* step number badge */
.cell::after {
  content: attr(data-n);
  position: absolute;
  top: 2px; right: 4px;
  font-size: .5rem;
  font-weight: 400;
  color: rgba(255,255,255,.5);
  pointer-events: none;
}

/* SVG path overlay */
#pathSvg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 5;
}

/* Game foot */
.game-foot {
  flex-shrink: 0;
  max-height: 120px;
  overflow: hidden;
}
.target-panel {
  flex-shrink: 0;
  max-height: 150px;
  overflow-y: auto;
  padding: 8px 12px;
}
.target-panel-hdr {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .95rem;
  color: var(--text2);
  font-weight: 700;
  margin-bottom: 8px;
}
.target-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.t-chip {
  padding: 5px 12px;
  border-radius: var(--radius-s);
  border: 1px solid var(--surf3);
  background: var(--surf2);
  font-size: .95rem;
  color: var(--text);
  transition: all .25s;
}
.t-chip.t-found {
  border-color: #0891b2;
  background: rgba(8,145,178,0.12);
  color: #67e8f9;
  text-decoration: line-through;
  opacity: .65;
}
.found-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: .95rem;
  color: var(--text2);
  font-weight: 700;
}
.score-badge {
  margin-left: auto;
  font-size: .95rem;
  font-weight: 800;
  color: var(--accent2);
}
.found-words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  overflow-y: auto;
  max-height: 80px;
}
.w-chip {
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--surf3);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: .9rem;
  animation: pop .28s ease;
}
.w-chip .pts { color: var(--accent2); font-weight: 700; margin-left: 3px; }

/* ── Exit / Mute Buttons ─────────────────────────────────────── */
.game-exit-btn {
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 700;
  font-family: inherit;
  padding: 6px 10px;
  border-radius: var(--radius-s);
  color: var(--text2);
  transition: all .15s;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 40px;
  -webkit-tap-highlight-color: transparent;
}
.game-exit-btn:hover { color: var(--text); border-color: var(--surf3); background: var(--surf); }
.game-exit-btn.host-end { color: var(--red); }
.game-exit-btn.host-end:hover { background: rgba(248,113,113,.12); border-color: var(--red); }
.game-exit-btn.armed {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  animation: armed-pulse 0.6s ease infinite alternate;
}
@keyframes armed-pulse {
  from { opacity: 1; }
  to   { opacity: 0.75; }
}

.mute-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  padding: 6px 8px;
  border-radius: var(--radius-s);
  opacity: 0.75;
  transition: opacity .15s, background .15s;
  flex-shrink: 0;
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.mute-btn:hover, .mute-btn:active { opacity: 1; background: var(--surf2); }
.mute-btn.muted { opacity: 0.4; }

/* ── Results ────────────────────────────────────────────────── */
#view-results { justify-content: flex-start; gap: 12px; overflow-y: auto; }
.results-title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
}
.speed-btn {
  position: absolute;
  right: 0;
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--surf3);
  color: var(--text2);
  border-radius: var(--radius-s);
  font-size: .9rem;
  font-weight: 800;
  font-family: inherit;
  padding: 8px 14px;
  cursor: pointer;
  transition: all .15s;
  min-height: 44px;
}
.speed-btn.active {
  background: rgba(45,212,191,0.20);
  border-color: var(--accent);
  color: var(--accent2);
}
.edit-game-btn {
  right: auto;
  left: 0;
}
.results-title {
  text-align: center;
  font-size: 2.2rem;
  font-weight: 900;
  background: linear-gradient(135deg, #34d399, #06b6d4, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  padding: 20px 0 4px;
}
.results-list { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.result-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--surf3);
  box-shadow: var(--shadow), var(--glass-hi);
  border-radius: var(--radius);
  transition: border-color .3s, background .3s, transform .2s;
}
.result-row.winner {
  border-color: #fbbf24;
  background: linear-gradient(135deg, var(--surf), rgba(251,191,36,0.12));
  box-shadow: var(--shadow), var(--glass-hi), 0 0 20px rgba(251,191,36,0.15);
}
.result-row.silver { border-color: rgba(148,163,184,0.6); }
.result-row.bronze { border-color: rgba(180,83,9,0.6); }
.rank { font-size: 1.7rem; width: 38px; text-align: center; flex-shrink: 0; }
.result-info { flex: 1; min-width: 0; }
.result-name { font-weight: 700; font-size: 1.1rem; }
.result-wordcount { font-size: .9rem; color: var(--text2); font-weight: 500; margin-top: 2px; }
.result-score {
  font-size: 2rem;
  font-weight: 900;
  color: var(--accent2);
  font-variant-numeric: tabular-nums;
  transition: color .15s;
  min-width: 48px;
  text-align: right;
}
.result-score.score-pop {
  animation: score-pop .4s ease;
  color: var(--green);
}
@keyframes score-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.25); color: var(--green); }
  100% { transform: scale(1); }
}

/* Word reveal */
.word-reveal { flex-shrink: 0; }
.reveal-section {
  font-size: .85rem;
  font-weight: 700;
  color: var(--text2);
  margin: 12px 0 7px;
}
.reveal-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.reveal-chip {
  padding: 4px 11px;
  border-radius: 20px;
  font-size: .88rem;
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--surf3);
  animation: pop .28s ease;
  display: flex;
  align-items: center;
  gap: 5px;
}
.reveal-chip.common { border-color: #0891b2; color: #67e8f9; }
.reveal-chip.unique { border-color: #fbbf24; color: #fde68a; }
/* Word length colours */
.reveal-chip.wl-3, .w-chip.wl-3 { border-color: #38bdf8; color: #7dd3fc; }
.reveal-chip.wl-4, .w-chip.wl-4 { border-color: #34d399; color: #6ee7b7; }
.reveal-chip.wl-5, .w-chip.wl-5 { border-color: #facc15; color: #fde68a; }
.reveal-chip.wl-6, .w-chip.wl-6 { border-color: #fb923c; color: #fdba74; }
.reveal-chip.wl-7, .w-chip.wl-7 { border-color: #c084fc; color: #e9d5ff; }
.reveal-chip .x2-badge {
  font-size: .72rem;
  font-weight: 800;
  background: #fbbf24;
  color: #000;
  padding: 1px 5px;
  border-radius: 4px;
  line-height: 1.4;
}
.reveal-chip .chip-owner {
  font-size: .75rem;
  color: var(--muted);
  font-weight: 500;
}

/* ── Board Solution ─────────────────────────────────────────────── */
.board-solution {
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--surf3);
  border-radius: var(--radius);
  box-shadow: var(--shadow), var(--glass-hi);
  padding: 16px 18px;
  flex-shrink: 0;
}
.sol-header {
  font-size: .9rem;
  font-weight: 700;
  color: var(--text2);
  margin-bottom: 12px;
}
.sol-board-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
}
.mini-board {
  display: grid;
  gap: 4px;
  position: relative;
  direction: ltr;
}
.mc-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell-bg);
  border: 2px solid var(--cell-bdr);
  border-radius: 8px;
  font-weight: 800;
  color: var(--text);
  position: relative;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.mc-cell.mc-traced {
  background: var(--cell-path);
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(45,212,191,0.40);
}
.mc-cell.mc-head {
  background: var(--cell-act);
  border-color: #c7d2fe;
  box-shadow: 0 0 14px rgba(165,180,252,0.55);
  color: #1e1b4b;
}
.sol-word-text {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent2);
  margin-bottom: 12px;
  letter-spacing: .03em;
}
.sol-definition {
  font-size: .95rem;
  color: var(--text2);
  text-align: right;
  line-height: 1.6;
  padding: 8px 12px;
  margin-bottom: 12px;
  background: var(--surf2);
  border: 1px solid var(--surf3);
  border-radius: var(--radius-s);
}
.sol-all-btn {
  width: 100%;
  padding: 12px;
  background: var(--surf2);
  border: 1px solid var(--surf3);
  border-radius: var(--radius-s);
  color: var(--text2);
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  min-height: 48px;
  transition: background .12s, border-color .12s, color .12s;
}
.sol-all-btn:hover, .sol-all-btn.open {
  border-color: var(--accent);
  color: var(--accent2);
  background: rgba(129,140,248,0.08);
}
.all-words-list {
  margin-top: 10px;
  max-height: 200px;
  overflow-y: auto;
}
.aw-group-hdr {
  font-size: .85rem;
  font-weight: 700;
  color: var(--text2);
  margin: 10px 0 6px;
}
.aw-group-hdr:first-child { margin-top: 0; }
.aw-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.aw-chip {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: .88rem;
  background: var(--surf2);
  border: 1px solid var(--surf3);
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  transition: all .1s;
}
.aw-chip:hover { border-color: var(--accent); color: var(--accent2); }
.aw-chip.aw-found { border-color: #0891b2; color: #67e8f9; }
.aw-chip.aw-active {
  background: rgba(45,212,191,0.15);
  border-color: var(--accent);
  color: var(--accent2);
  font-weight: 700;
}

.results-actions { display: flex; gap: 10px; padding-bottom: 8px; flex-shrink: 0; margin-top: auto; }
.results-actions .btn { flex: 1; }

/* ── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--surf3);
  box-shadow: var(--shadow), var(--glass-hi);
  color: var(--text);
  padding: 12px 22px;
  border-radius: 24px;
  font-size: 1rem;
  font-weight: 500;
  z-index: 999;
  transition: transform .25s ease, opacity .25s ease;
  opacity: 0;
  white-space: nowrap;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.ok  { border-color: var(--green); color: var(--green); }
.toast.err { border-color: var(--red); color: var(--red); }

/* ── Connection status ──────────────────────────────────────── */
.conn-status {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%) translateY(-60px);
  background: var(--surf);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--amber);
  box-shadow: var(--shadow), var(--glass-hi);
  color: var(--amber);
  padding: 9px 18px;
  border-radius: 24px;
  font-size: .95rem;
  font-weight: 600;
  z-index: 1000;
  transition: transform .3s ease;
  white-space: nowrap;
  pointer-events: none;
}
.conn-status.show { transform: translateX(-50%) translateY(0); }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surf3); border-radius: 2px; }

/* ── RTL overrides ──────────────────────────────────────────── */
[dir="rtl"] .join-row input { text-align: right; }
[dir="rtl"] .pts { margin-left: 0; margin-right: 3px; }
[dir="rtl"] .score-badge { margin-left: 0; margin-right: auto; }
[dir="rtl"] .result-sub { direction: ltr; }
