:root {
  --bg1: #0f172a;
  /* slate-900 */
  --bg2: #1e293b;
  /* slate-800 */
  --glass: rgba(255, 255, 255, 0.06);
  --text: #ffffff;
  /* white */
  --muted: #94a3b8;
  /* slate-400 */
  --accent: #60a5fa;
  /* blue-400 */
  --good: #34d399;
  /* emerald-400 */
  --bad: #f87171;
  /* red-400 */
  --caret: #eab308;
  /* yellow-500 */
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --topbar-h: 64px;
  /* header height */
  /* Fallback solid color for the animated topbar title text */
  --topbar-title-color: #e5e7eb;
}

/* Light theme overrides */
.theme-light {
  --bg1: #f1f5f9;
  /* slate-100 */
  --bg2: #f8fafc;
  /* slate-50 */
  --glass: rgba(0, 0, 0, 0.04);
  --text: #0f172a;
  --muted: #475569;
  --accent: #2563eb;
  --good: #059669;
  --bad: #dc2626;
  --caret: #ca8a04;
  --topbar-title-color: #0f172a;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  background-color: var(--bg1);
  /* Prevent white gaps on scroll/rubber-band */
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: transparent;
  min-height: 100vh;
  /* overflow-y ve touch scroling ayarları */
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.theme-light body,
body.theme-light {
  background: transparent;
  color: #334155;
}

.aurora-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
  background: radial-gradient(1200px 800px at 20% 10%, #0b1223, transparent),
    radial-gradient(900px 600px at 90% 20%, #0a1a2f, transparent),
    linear-gradient(135deg, #0b1020 0%, #0e162a 40%, #0f172a 100%);
  background-attachment: fixed;
}

.theme-light .aurora-container {
  background: radial-gradient(1200px 800px at 20% 10%, #cbd5e1, transparent),
    radial-gradient(900px 600px at 80% 15%, #94a3b8, transparent),
    linear-gradient(135deg, #e2e8f0 0%, #f1f5f9 50%, #f8fafc 100%);
}

.theme-light .aurora-container canvas {
  opacity: 0.25;
}

/* Global media defaults: make media fluid by default */
img,
svg,
video,
canvas {
  max-width: 100%;
  height: auto;
}

img {
  display: block;
}

.bg-anim {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: conic-gradient(from 180deg at 50% 50%, #111827, #0f172a, #0a1a2f, #111827);
  mix-blend-mode: plus-lighter;
  filter: blur(80px) opacity(0.4);
  animation: spin 30s linear infinite;
}

.theme-light .bg-anim {
  filter: blur(80px) opacity(0.2);
  mix-blend-mode: normal;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.app {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 32px;
}

/* Oyun alanı kabuğu - mobilde kartı görünür viewport'a göre konumlamak için ayrı katman */
.play-shell {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.card {
  width: min(1300px, 96vw);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.04));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  padding: 28px 28px 20px;
  margin-top: 72px;
}

.theme-light .card {
  background: rgba(255, 255, 255, 0.45);
  border-color: rgba(0, 0, 0, 0.1);
  /* Better visibility on light bg */
}

header {
  display: flex;
  align-items: center;
  /* justify-content: space-between; Removed to allow manual spacing */
  gap: 16px;
  margin-bottom: 16px;
  position: relative;
  /* Context for centered stats */
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0.2px;
  text-decoration: none;
  color: inherit;
}

.brand .logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: radial-gradient(120% 120% at 30% 30%, #60a5fa, #2563eb 60%, #1d4ed8 100%);
  /* Blur etkisini azaltmak için gölgeyi yumuşattık */
  box-shadow: 0 6px 12px rgba(37, 99, 235, 0.40);
  position: relative;
  overflow: hidden;
  transition: transform .18s ease, box-shadow .25s ease;
}

@media (hover:hover) and (prefers-reduced-motion: no-preference) {

  /* Hover'da dönüş ve ölçeklemeyi azalt */
  .brand:hover .logo {
    transform: rotate(2deg) scale(1.03);
    box-shadow: 0 8px 16px rgba(37, 99, 235, 0.50);
  }

  .brand .logo::after {
    content: "";
    position: absolute;
    inset: -1px;
    pointer-events: none;
    background: linear-gradient(120deg,
        rgba(255, 255, 255, 0.40) 0%, rgba(255, 255, 255, 0.16) 16%, rgba(255, 255, 255, 0.0) 36%,
        rgba(255, 255, 255, 0.0) 64%, rgba(255, 255, 255, 0.16) 84%, rgba(255, 255, 255, 0.40) 100%);
    transform: translateX(-120%);
  }

  /* Logo parlama animasyon süresini kısalttık */
  .brand:hover .logo::after {
    animation: logo-shine 600ms ease forwards;
  }

  @keyframes logo-shine {
    to {
      transform: translateX(120%);
    }
  }
}

.brand h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 800;
}

.brand span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.stats {
  display: flex;
  gap: 12px;
  /* Absolute Center */
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  /* Let clicks pass through if needed, though pills aren't interactive usually */
}

.stats>* {
  pointer-events: auto;
}

@media (max-width: 850px) {
  /* 
     MOBİL HEADER - SIFIRLAMA & YENİDEN İNŞA
     Hedef: En basit ve hatasız yapı.
     Absolute pozisyonlamayı SADECE butonlar için kullanacağız.
     İçerik akışı: Logo -> (Boşluk) -> Mode Switch -> (Boşluk) -> Learn Controls -> Stats
  */

  header {
    display: flex;
    flex-wrap: wrap;
    /* İçerik taşarsa alta geçsin */
    position: relative;
    /* Absolute butonlar için referans */
    margin-bottom: 12px;
    padding-top: 44px;
    /* ÜSTTE YER AÇ: Logo ve Restart butonu buraya gelecek (Visual Trick) */
    align-items: flex-start;
    justify-content: center;
  }

  /* --- 1. LOGO & BAŞLIK (Absolute Sol Üst) --- */
  .brand {
    /* Brand flex container olduğu için içindekileri seçip dışarı alacağız */
    display: contents;
    /* Brand wrapper'ı yok et */
  }

  /* Logo: Sol Üst */
  .brand .logo {
    position: absolute;
    top: 0;
    left: 0;
    width: 36px;
    height: 36px;
    margin: 0;
    z-index: 10;
  }

  /* Başlık: Logo'nun Yanı */
  .brand>div:nth-child(2) {
    position: absolute;
    top: 0;
    left: 46px;
    /* 36px logo + 10px boşluk */
    height: 36px;
    display: flex;
    align-items: center;
    white-space: nowrap;
    z-index: 10;
  }

  .brand h1 {
    font-size: 19px;
    margin: 0;
    line-height: 1;
  }

  .brand span {
    display: none;
  }

  /* Yanındaki span gizli */

  /* --- 2. RESTART & SHARE (Absolute Sağ Üst) --- */
  .actions {
    display: contents; /* Wrapper yok, elemanlar serbest */
  }

  .top-actions-group {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    z-index: 20;
  }

  #restart {
    position: static;
    height: 100%;
    font-size: 12px;
    padding: 0 12px;
    margin: 0;
    order: 2;
  }

  #share-btn {
    position: static;
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 0 !important;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    order: 1;
  }

  /* Yeni Paylaş İkonu: Basit bir paylaş düğümü veya dışa aktarma ok */
  #share-btn::after {
    content: "➦";
    /* Veya daha standart bir paylaş sembolü */
    font-size: 18px;
    font-weight: bold;
    color: inherit;
    /* İkonu biraz düzeltmek için */
    transform: rotate(0deg);
  }

  /* --- 3. MODE SWITCH (Esnek Genişlik) --- */
  .brand .mode-switch {
    width: auto;
    flex: 1; /* Kalan alanı doldur */
    max-width: none;
    height: 40px;
    margin: 0;
    margin-top: 12px;
    z-index: 5;
    order: 5;
  }

  /* --- 4. LEARN CONTROLS (Varsa) --- */
  #learn-controls {
    width: 100%;
    margin-top: 6px;
    justify-content: center;
    order: 5;
    gap: 6px;
  }

  #learn-controls .error-btn {
    width: 36px;
    height: 32px;
    padding: 0;
    font-size: 0 !important;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    background: rgba(239, 68, 68, 0.15) !important;
    border: 1px solid rgba(239, 68, 68, 0.3) !important;
    color: #ef4444 !important;
  }

  #learn-controls .error-btn svg {
    margin: 0 !important;
    width: 18px;
    height: 18px;
  }

  .time-selector {
    height: 32px;
  }

  /* --- 5. STATS --- */
  .stats {
    width: 100%;
    margin-top: 12px;
    position: static;
    transform: none;
    display: flex;
    justify-content: center;
    gap: 8px;
    order: 10;
  }

  .stats .pill {
    flex: 1;
    min-width: 0;
    padding: 4px 8px;
    height: auto;
  }

  .stats .pill .val {
    font-size: 16px;
  }

  .stats .pill .lab {
    font-size: 9px;
  }

  /* MOVEMENT FIX */
  .mode-btn {
    min-width: 0;
  }
}

/* Mode Switcher */
.mode-switch {
  margin-left: 12px;
  display: flex;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  gap: 2px;
  position: relative;
  /* Context for glider */
  isolation: isolate;
  /* Create stacking context */
}

/* Glider (The animated ball/pill) */
.mode-glider {
  position: absolute;
  top: 4px;
  left: 4px;
  bottom: 4px;
  width: calc(50% - 4px);
  /* Assuming 2 buttons share width */
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  z-index: 1;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  /* Bouncy pop effect */
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  pointer-events: none;
}

/* Move glider based on parent state */
.mode-switch[data-active="test"] .mode-glider {
  transform: translateX(0);
}

.mode-switch[data-active="learn"] .mode-glider {
  transform: translateX(100%);
  /* Moves to the right slot */
}

/* Buttons */
.mode-btn {
  flex: 1;
  /* Equal width for math to work */
  background: transparent !important;
  /* Glider provides bg */
  border: none;
  color: var(--muted);
  box-shadow: none !important;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: color 0.2s ease;
  letter-spacing: 0.3px;
  z-index: 2;
  /* Above glider */
  position: relative;
  text-align: center;
}

.mode-btn.active {
  color: var(--text);
}

@media (hover: hover) {
  .mode-btn:hover:not(.active) {
    color: var(--text);
  }
}

/* Light Theme Overrides */
.theme-light .mode-switch {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.08);
}

.theme-light .mode-glider {
  background: #2563eb;
  /* Blue-600 */
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.theme-light .mode-btn {
  color: #64748b;
}

.theme-light .mode-btn.active {
  color: #ffffff;
  /* White text on blue glider */
}

.theme-light .mode-btn:hover:not(.active) {
  color: #334155;
}

@media (max-width: 720px) {
  .mode-switch {
    order: 2;
    width: 100%;
    justify-content: center;
  }
}

.pill {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 6px 16px;
  min-width: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  backdrop-filter: blur(4px);
  transition: background 0.2s, transform 0.2s;
}

.pill:hover {
  background: rgba(255, 255, 255, 0.06);
  transform: translateY(-1px);
}

.theme-light .pill {
  background: rgba(255, 255, 255, 0.7);
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  color: #1e293b;
}

.pill .val {
  font-weight: 800;
  font-size: 20px;
  line-height: 1.1;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
  /* Prevent jitter when numbers change */
  min-width: 3ch;
  /* Reserve space for at least 3 chars */
  text-align: center;
}

.pill .lab {
  color: rgba(255, 255, 255, 0.7);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.theme-light .pill .val {
  color: var(--accent);
}

.theme-light .pill .lab {
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 12px;
}

.top-actions-group {
  display: flex;
  gap: 12px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 0 20px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.btn:active {
  transform: translateY(0);
}

.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  filter: grayscale(.3);
}

/* Restart Button (Primary) */
#restart {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(96, 165, 250, 0.3);
}

@media (hover: hover) {
  #restart:hover {
    background: #ffffff;
    color: var(--accent);
    transform: translateY(-3px);
    box-shadow: 0 0 25px rgba(255, 255, 255, 0.4);
  }
}

/* Share Button (Secondary) */
#share-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
}

@media (hover: hover) {
  #share-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
    transform: translateY(-3px);
    box-shadow: 0 4px 15px rgba(96, 165, 250, 0.4);
  }
}

.theme-light #restart {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.theme-light #share-btn {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  color: #475569;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

@media (hover: hover) {
  .theme-light #share-btn:hover {
    background: #ffffff;
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
  }
}

.display {
  position: relative;
  line-height: 1.3;
  font-size: clamp(22px, 4vw, 36px);
  padding: 22px 16px;
  border-radius: 16px;
  min-height: clamp(120px, 22vh, 200px);
  /* Blue Box (Dark Mode Default) */
  background: linear-gradient(90deg, rgba(30, 41, 59, 0.95) 60%, rgba(60, 80, 120, 0.90) 100%);
  box-shadow: 0 4px 24px 0 rgba(0, 0, 0, 0.35), 0 0 0 3px #33415599;
  border: none;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  cursor: default;
  color: #e2e8f0;
}

.theme-light .display {
  /* Stylish Gray (Light Mode) */
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08), 0 0 0 3px rgba(203, 213, 225, 0.6);
  color: #1e293b;
}

.words {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(calc(-50% + var(--tx, 0px)), -50%);
  white-space: nowrap;
  display: block;
  transition: transform .18s cubic-bezier(.4, 0, .2, 1);
  will-change: transform;
}

.display.mobile-flow {
  overflow-y: visible;
  overflow-x: hidden;
  padding-top: 12px;
  padding-bottom: 12px;
  min-height: auto;
  transition: min-height 0.2s ease;
  background: rgba(30, 41, 59, 0.5);
  box-shadow: 0 2px 12px 0 rgba(0,0,0,0.2), 0 0 0 2px #33415599;
}

.theme-light .display.mobile-flow {
  background: rgba(241, 245, 249, 0.6);
  box-shadow: 0 2px 12px rgba(0,0,0,0.04), 0 0 0 2px rgba(203,213,225,0.4);
}


.above-words,
.below-words {
  position: relative;
  z-index: 1;
}

.target-box.mobile-target {
  position: relative !important;
  z-index: 2;
}

.word {
  display: inline-flex;
  gap: 0;
  padding: 2px 6px;
  border-radius: 10px;
}

.word.active {
  background: linear-gradient(90deg, rgba(30, 41, 59, 0.92) 60%, rgba(60, 80, 120, 0.85) 100%);
  box-shadow: 0 2px 16px 0 rgba(0, 0, 0, 0.22), 0 0 0 3px #33415599;
  border-radius: 12px;
  z-index: 2;
  position: relative;
  transition: background 0.18s, box-shadow 0.18s;
}

.theme-light .word.active {
  background: rgba(203, 213, 225, 0.6);
  /* Darker gray for active word */
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.theme-light .char.current {
  color: #0f172a;
}

.theme-light .char.pending {
  color: #64748b;
  opacity: 0.8;
}

.theme-light .char.correct {
  color: #059669;
}

.theme-light .char.wrong {
  color: #dc2626;
}

.char.wrong.shake-char {
  animation: charWrong .18s ease;
}

@keyframes charWrong {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); }
}

.char {
  position: relative;
  padding: 0 1px;
  border-radius: 4px;
  transition: color .08s ease, background .08s ease, transform .08s ease;
}

.char.pending {
  color: #9aa4b2;
  opacity: 0.65;
}

.char.correct {
  color: #34d399;
  background: transparent;
}

.char.wrong {
  color: #f87171;
  background: transparent;
}

.char.current {
  color: #ffffff;
  background: transparent;
  box-shadow: none;
}

.char.current::after {
  content: "";
  position: absolute;
  left: -1px;
  top: 12%;
  bottom: 12%;
  width: 2px;
  border-radius: 1px;
  background: var(--caret);
  animation: blink 1.1s steps(1, start) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.end-caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--caret);
  margin-left: 0px;
  transform: translateY(2px);
  opacity: 0;
  /* hidden by default */
}

.end-caret.show {
  opacity: 1;
  animation: blink 1.1s steps(1, start) infinite;
}

/* Removed side words entrance animations (no transition on word changes) */
.shake {
  animation: shake .18s ease;
}

@keyframes shake {

  10%,
  90% {
    transform: translateX(-1px);
  }

  20%,
  80% {
    transform: translateX(2px);
  }

  30%,
  50%,
  70% {
    transform: translateX(-3px);
  }

  40%,
  60% {
    transform: translateX(3px);
  }
}

.kbd {
  margin-top: 18px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 14px;
  display: grid;
  gap: 8px;
}

.theme-light .kbd {
  background: rgba(255, 255, 255, 0.7);
  border-color: rgba(0, 0, 0, 0.08);
}

.row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
}

.key {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.04));
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
  color: var(--text);
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
  -webkit-user-select: none;
  user-select: none;
  transition: transform .08s ease, background .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.theme-light .key {
  background: #ffffff;
  border-color: #cbd5e1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  color: #0f172a;
}

.key.space {
  grid-column: span 5;
}

.key.wide {
  grid-column: span 2;
}

.key.active {
  transform: translateY(2px) scale(0.95);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
  background: rgba(255, 255, 255, 0.15);
}

.theme-light .key.active {
  background: rgba(0, 0, 0, 0.1);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.06);
}

.theme-light .key.correct {
  background: #34d399 !important;
  color: #ffffff !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) !important;
  border-color: #059669 !important;
}

.theme-light .key.wrong {
  background: #f87171 !important;
  color: #ffffff !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) !important;
  border-color: #dc2626 !important;
}

.key.correct {
  background: rgba(52, 211, 153, 0.6) !important;
  border-color: rgba(52, 211, 153, 1) !important;
  box-shadow: 0 0 15px rgba(52, 211, 153, 0.6) !important;
  color: #ffffff !important;
  transform: scale(1.1) !important;
  z-index: 10;
}

.key.wrong {
  background: rgba(248, 113, 113, 0.6) !important;
  border-color: rgba(248, 113, 113, 1) !important;
  box-shadow: 0 0 15px rgba(248, 113, 113, 0.6) !important;
  color: #ffffff !important;
  transform: scale(1.1) !important;
  z-index: 10;
}

.hint {
  margin-top: 10px;
  color: #cbd5e1;
  font-size: 12px;
  text-align: center;
}

.theme-light .hint {
  color: #475569;
  font-weight: 600;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  /* place title at far left */
  height: var(--topbar-h);
  background: rgba(20, 20, 30, 0.5);
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.10);
  padding: 0 24px;
  -webkit-backdrop-filter: blur(12px) saturate(120%);
  backdrop-filter: blur(12px) saturate(120%);
  transition: background .3s;
  gap: 0;
}

.theme-light .topbar {
  background: rgba(255, 255, 255, 0.65);
  /* Much more transparent for light mode */
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.topbar-spacer {
  flex: 1 1 auto;
}


.site-title {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.04em;
  flex: 0 0 auto;
  text-decoration: none;
  cursor: pointer;
  padding-bottom: 4px;
  /* Ensure descenders (y, g, p) are not clipped */
  position: relative;
  z-index: 200;
  /* Ensure it stays above the absolute main-nav */
}

/* Removed old gradient text and title-char animations to prevent conflict with Shuffle animation */

.settings-btn {
  position: absolute;
  right: 32px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text);
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, color .3s;
  box-shadow: none;
  overflow: hidden;
}

.settings-btn:hover {
  background: rgba(255, 255, 255, 0.10);
  color: var(--accent);
}

.theme-light .settings-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.btn.small {
  padding: 6px 14px;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.08);
  /* Default dark mode bg */
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  border-radius: 8px;
  /* Slightly tighter radius for small buttons */
}

.theme-light .btn.small {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #475569;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.theme-light .btn.small:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #f8fafc;
}

.btn.danger {
  background: #7f1d1d;
  color: #fecaca;
  border: 1px solid rgba(254, 202, 202, 0.2);
}

.theme-light .btn.danger {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fca5a5;
}

.leaderboard {
  margin-top: 22px;
}

.leaderboard h2 {
  font-size: 18px;
  margin: 8px 0 10px;
}

.lb-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(12px);
}

.theme-light .lb-table {
  background: rgba(255, 255, 255, 0.75);
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}

.lb-table th,
.lb-table td {
  padding: 14px 16px;
  font-size: 14px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  transition: background 0.2s;
}

.theme-light .lb-table th,
.theme-light .lb-table td {
  border-bottom-color: rgba(0, 0, 0, 0.06);
}

.lb-table thead th {
  background: rgba(255, 255, 255, 0.03);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.theme-light .lb-table thead th {
  background: rgba(0, 0, 0, 0.03);
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

.lb-table tbody tr:last-child td {
  border-bottom: none;
}

.lb-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.015);
}

.theme-light .lb-table tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.015);
}

.lb-table tbody tr:hover {
  background: rgba(96, 165, 250, 0.12);
}

.theme-light .lb-table tbody tr:hover {
  background: rgba(37, 99, 235, 0.08);
}

@keyframes rowPopIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.row-anim {
  animation: rowPopIn 0.3s cubic-bezier(0.2, 0, 0.2, 1) forwards;
}



/* Load more wrapper */
.lb-more-wrap {
  display: flex;
  justify-content: center;
  margin: 8px 0 18px;
}

.lb-more-wrap .btn.small {
  font-weight: 700;
  width: 100%;
  max-width: 200px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.lb-more-wrap .btn.small:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  color: var(--text);
  transform: translateY(-1px);
}

.theme-light .lb-more-wrap .btn.small {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #64748b;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.theme-light .lb-more-wrap .btn.small:hover {
  background: #f8fafc;
  border-color: #94a3b8;
  color: #334155;
}

/* Leaderboard loading state */
.leaderboard[data-loading="true"] .lb-panels {
  display: none;
}

.lb-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 160px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px dashed rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  color: var(--muted);
  font-weight: 700;
}

.theme-light .lb-loading {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.1);
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--muted);
  border-radius: 50%;
  opacity: .6;
  animation: dotPulse 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: .2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: .4s;
}

@keyframes dotPulse {

  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: .4;
  }

  40% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* Small screens: keep table layout stable and readable */
@media (max-width: 720px) {
  .lb-table {
    table-layout: fixed;
    width: 100%;
  }

  .lb-table th,
  .lb-table td {
    white-space: nowrap;
  }

  .lb-table td {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Column widths for better alignment */
  .lb-table th:nth-child(1),
  .lb-table td:nth-child(1) {
    width: 36px;
  }

  .lb-table th:nth-child(2),
  .lb-table td:nth-child(2) {
    width: 28%;
  }

  .lb-table th:nth-child(3),
  .lb-table td:nth-child(3) {
    width: 52px;
  }

  .lb-table th:nth-child(4),
  .lb-table td:nth-child(4) {
    width: 56px;
  }

  .lb-table th:nth-child(5),
  .lb-table td:nth-child(5) {
    width: 64px;
  }

  .lb-table th:nth-child(6),
  .lb-table td:nth-child(6) {
    width: 120px;
  }
}

/* Extra-compact: adjust widths but show all columns */
@media (max-width: 560px) {

  .lb-table th:nth-child(6),
  .lb-table td:nth-child(6) {
    width: 80px;
    font-size: 11px;
  }
}

@media (max-width: 420px) {

  .lb-table th,
  .lb-table td {
    font-size: 11px;
    padding: 4px 2px;
  }

  .lb-table th:nth-child(2),
  .lb-table td:nth-child(2) {
    width: 25%;
  }

  /* Name */
  .lb-table th:nth-child(3),
  .lb-table td:nth-child(3) {
    width: 30px;
  }

  /* Lang */
  .lb-table th:nth-child(6),
  .lb-table td:nth-child(6) {
    width: 60px;
  }

  /* Date */
}

/* Leaderboard tabs */
.lb-tabs {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  background: rgba(255, 255, 255, 0.02);
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}

.theme-light .lb-tabs {
  border-color: rgba(0, 0, 0, 0.12);
  background: rgba(0, 0, 0, 0.03);
}

@media (max-width: 600px) {
  .lb-tabs {
    display: flex;
    width: 100%;
    justify-content: space-between;
    gap: 4px;
  }

  .lb-tab {
    flex: 1;
    text-align: center;
    padding: 8px 2px;
    font-size: 12px;
  }
}

.lb-tab {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.lb-tab[aria-selected="true"] {
  background: rgba(96, 165, 250, 0.12);
  color: var(--accent);
  border-color: rgba(96, 165, 250, 0.35);
  box-shadow: 0 1px 6px rgba(96, 165, 250, 0.12) inset;
}

.theme-light .lb-tab[aria-selected="true"] {
  background: rgba(37, 99, 235, 0.08);
  /* blue-600 low alpha */
  border-color: rgba(37, 99, 235, 0.2);
  box-shadow: none;
}

.lb-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.lb-panels>[role="tabpanel"] {
  display: none;
}

.lb-panels>[role="tabpanel"][data-active="true"] {
  display: block;
  max-height: 480px;
  overflow-y: auto;
  border-radius: 0 0 12px 12px;
  /* Scrollbar styling */
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.theme-light .lb-panels>[role="tabpanel"][data-active="true"] {
  scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.lb-panels>[role="tabpanel"]::-webkit-scrollbar {
  width: 6px;
}

.lb-panels>[role="tabpanel"]::-webkit-scrollbar-track {
  background: transparent;
}

.lb-panels>[role="tabpanel"]::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.theme-light .lb-panels>[role="tabpanel"]::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
}

/* Mobile specific target box adjustments */
@media (max-width: 900px) {
  .shuffle-suffix {
    display: none !important;
  }

  .left-words,
  .right-words {
    display: none !important;
  }

  .display {
    min-height: 55vh;
    overflow-y: visible;
  }
}

/* Light theme: target-box (small focus window) neutral gray background */
.target-box {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.theme-light .target-box,
.theme-light .target-box.mobile-target {
  background: rgba(203, 213, 225, 0.6);
  /* Darker gray (Slate-300) */
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  color: #0f172a;
}

.settings-btn:active::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 120%;
  height: 120%;
  background: rgba(96, 165, 250, 0.18);
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(1.1);
  animation: ripple .4s cubic-bezier(.4, 0, .2, 1);
  pointer-events: none;
  z-index: 1;
}

@keyframes ripple {
  0% {
    opacity: 0.5;
    transform: translate(-50%, -50%) scale(0.7);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.2);
  }
}

@media (hover: hover) {

  .settings-btn:hover,
  .settings-btn:focus-visible {
    background: rgba(96, 165, 250, 0.13);
    box-shadow: 0 2px 8px rgba(96, 165, 250, 0.10);
    outline: none;
    color: var(--accent);
  }
}

/* Open state styling for settings toggle */
.settings-btn[aria-expanded="true"] {
  background: rgba(96, 165, 250, 0.13);
  box-shadow: 0 2px 8px rgba(96, 165, 250, 0.10);
  color: var(--accent);
}

/* Remove focus background to prevent sticky hover effect on click */
.settings-btn:focus-visible {
  background: transparent;
  box-shadow: none;
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.settings-btn .gear {
  transform-origin: 50% 50%;
  transition: transform .3s ease;
  width: 32px;
  height: 32px;
}

.settings-btn:hover .gear,
.settings-btn:focus-visible .gear {
  transform: rotate(18deg);
}

.settings-dropdown {
  position: absolute;
  top: var(--topbar-h);
  right: 24px;
  min-width: 180px;
  max-width: 220px;
  background: linear-gradient(180deg, rgba(20, 20, 30, 0.98), rgba(20, 20, 30, 0.94));
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  padding: 8px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-12px) scale(0.98);
  transition: opacity .22s cubic-bezier(.4, 0, .2, 1), transform .22s cubic-bezier(.4, 0, .2, 1);
  will-change: opacity, transform;
}

.theme-light .settings-dropdown {
  background: rgba(255, 255, 255, 0.98);
  border-color: rgba(0, 0, 0, 0.10);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}

.settings-dropdown[hidden] {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-12px) scale(0.98);
}

.settings-dropdown:not([hidden]) {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.settings-dropdown .group {
  padding: 6px 2px;
  animation: fadein .35s cubic-bezier(.4, 0, .2, 1);
}

@keyframes fadein {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.settings-dropdown .group-title {
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 6px;
  font-weight: 700;
  letter-spacing: .4px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.settings-dropdown .dd-item {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: .2px;
  font-size: 0.95rem;
  transition: background .15s, border-color .15s, color .2s;
}

.settings-dropdown .dd-item:hover,
.settings-dropdown .dd-item:focus {
  background: rgba(96, 165, 250, 0.10);
  border-color: rgba(96, 165, 250, 0.18);
  color: var(--accent);
}

.theme-light .settings-dropdown .dd-item:hover,
.theme-light .settings-dropdown .dd-item:focus {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.10);
  color: var(--accent);
}

.settings-dropdown .dd-item[aria-checked="true"] {
  background: rgba(96, 165, 250, 0.18);
  border-color: rgba(96, 165, 250, 0.4);
  color: var(--accent);
}

/* Smooth theme transitions */
body,
.card,
.btn,
.display,
.key,
.topbar,
.nav-link,
  .settings-dropdown,
.pill,
.target-box,
.word.active,
.upcoming-word,
.settings-btn,
.logo {
  transition: background-color 0.6s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.6s cubic-bezier(0.4, 0, 0.2, 1), color 0.6s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.6s cubic-bezier(0.4, 0, 0.2, 1), fill 0.6s cubic-bezier(0.4, 0, 0.2, 1), stroke 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .bg-anim {
    animation: none;
  }

  .shake {
    animation: none;
  }

  .char.current::after {
    animation: none;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: 0 8px;
    position: sticky;
    top: 0;
  }

  .settings-btn {
    right: 8px;
  }

  .settings-dropdown {
    right: 4px;
  }
}

/* (light theme removed) */

/* Modal Redesign */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 500;
  animation: fadeIn 0.2s ease-out;
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal-dialog {
  width: min(480px, 92vw);
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(20px) saturate(180%);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.theme-light .modal-dialog {
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.modal-title {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff 0%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-align: center;
}

.theme-light .modal-title {
  background: linear-gradient(135deg, #0f172a 0%, #475569 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal-desc {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
  line-height: 1.5;
}

.modal-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 8px 0;
}

.mstat {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.2s;
}

.mstat:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.05);
}

.theme-light .mstat {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.06);
}

.mstat-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mstat-val {
  font-weight: 800;
  font-size: 32px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.modal-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  margin-left: 4px;
}

.modal-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font-size: 16px;
  transition: all 0.2s;
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(0, 0, 0, 0.4);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

.theme-light .modal-input {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #0f172a;
}

.theme-light .modal-input:focus {
  background: #fff;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}

.modal-actions .btn {
  width: 100%;
  justify-content: center;
  padding: 14px;
  font-size: 15px;
}

/* Extra Info Grid */
.modal-extra-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 16px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.theme-light .modal-extra-grid {
  background: rgba(0, 0, 0, 0.02);
  border-color: rgba(0, 0, 0, 0.05);
}

.extra-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.extra-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.extra-title.error { color: #f87171; }
.extra-title.success { color: #4ade80; }

.theme-light .extra-title.error { color: #ef4444; }
.theme-light .extra-title.success { color: #16a34a; }

.char-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.char-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 16px;
}

.char-tag.error {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.char-tag.success {
  background: rgba(74, 222, 128, 0.15);
  color: #86efac;
  border: 1px solid rgba(74, 222, 128, 0.2);
}

.theme-light .char-tag.error {
  background: #fef2f2;
  color: #ef4444;
  border-color: #fecaca;
}

.theme-light .char-tag.success {
  background: #f0fdf4;
  color: #16a34a;
  border-color: #bbf7d0;
}

@keyframes modalPop {
  0% { opacity: 0; transform: scale(0.95) translateY(10px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* Mobile IME input (hidden off-screen) */
.mobile-ime {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Mobile optimizations */
@media (max-width: 720px) {
  .card {
    width: 96vw;
    margin-top: 16px;
    padding: 16px;
    -webkit-backdrop-filter: blur(8px) saturate(120%);
    backdrop-filter: blur(8px) saturate(120%);
  }

  header {
    flex-wrap: wrap;
    gap: 10px;
  }

  .stats {
    width: 100%;
    justify-content: space-between;
  }

  .display {
    min-height: 50vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow-y: visible;
  }

  .kbd {
    display: none !important;
  }

  .upcoming-word {
    font-size: clamp(14px, 3.5vw, 20px);
    letter-spacing: 0.5px;
  }

  .leaderboard {
    margin-top: 14px;
  }

  .lb-table th,
  .lb-table td {
    padding: 8px;
    font-size: 12px;
  }

  body {
    overscroll-behavior: contain;
  }

  .app {
    padding: 12px 10px calc(60px + env(safe-area-inset-bottom, 0px));
    place-items: stretch;
  }

  .play-shell {
    flex-direction: column;
  }

  .card {
    width: 100%;
  }

  /* Liderboard'u kaydırılabilir alt panel yap */
  .leaderboard {
    max-height: 42vh;
    overflow-y: auto;
    padding-right: 4px;
  }

  .leaderboard::-webkit-scrollbar {
    width: 6px;
  }

  .leaderboard::-webkit-scrollbar-track {
    background: transparent;
  }

  .leaderboard::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
  }

  .theme-light .leaderboard::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
  }

  /* Odak kutusunun (target-box) çok aşağı kaçmaması için */
  .target-box {
    max-width: 94%;
  }
}

/* Mobile dikey kelime akışı (üst / hedef / alt)
   Not: UA ile mobil tespit JS tarafında yapılıyor; bu yüzden bu stiller
   genişlikten bağımsız uygulanabilir. Bu sayede tablet (>=720px) cihazlarda da
   alt alta görünüm korunur. */
.above-words,
.below-words {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: clamp(14px, 4vw, 22px);
  line-height: 1.15;
  font-weight: 600;
  pointer-events: none;
  text-align: center;
  max-width: 92%;
  word-break: break-word;
  margin-left: auto;
  margin-right: auto;
}

.above-words span,
.below-words span {
  opacity: .55;
  transition: opacity .25s;
}

.above-words span:nth-last-child(1),
.below-words span:nth-child(1) {
  opacity: .75;
}

.target-box.mobile-target {
  position: relative !important;
  left: auto !important;
  top: auto !important;
  transform: none !important;
  margin: 22px 0;
}

.target-box.mobile-target .char {
  padding: 0 2px;
}

.target-box.mobile-target {
  transition: all 0.15s ease;
}

.target-box.mobile-target .char.current::after {
  top: 20%;
  bottom: 20%;
}

/* Upcoming words (Mobile) */
.upcoming-word {
  font-size: clamp(16px, 4vw, 20px);
  color: #94a3b8;
  /* slate-400 (Dark Mode: Dimmed but readable) */
  transition: color 0.3s ease;
}

.theme-light .upcoming-word {
  color: #475569;
  /* slate-600 (Light Mode: Dark gray for contrast) */
  font-weight: 600;
}

/* Minimal toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #1f2937;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  z-index: 9999;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.theme-light .toast {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #0f172a;
  /* Explicit dark text */
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
}

/* Nav and footer */
.main-nav {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.brand-title {
  display: none !important;
}

/* Old brand title styles commented out or overridden above
.brand-title {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text);
  text-decoration: none;
  font-weight: 900;
  font-size: 28px;
  letter-spacing: .6px;
  line-height: 1;
  transition: color .16s ease, transform .16s cubic-bezier(.4,0,.2,1), text-shadow .16s ease;
  transform-origin: left center;
  will-change: transform, color, text-shadow;
}
*/
@media (hover: hover) {
  .brand-title {
    position: absolute;
    background: none;
    transition: color .2s ease, transform .18s cubic-bezier(.4, 0, .2, 1);
    will-change: transform;
  }

  .brand-title::after {
    content: none;
  }

  .brand-title:hover,
  .brand-title:focus-visible {
    /* Degrade yazı rengi + kısa pan animasyonu ve hafif büyütme */
    background-image: linear-gradient(90deg, #60a5fa, #a78bfa, #f472b6);
    background-size: 200% 100%;
    background-position: 0% 50%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    text-shadow: 0 6px 24px rgba(96, 165, 250, 0.35);
    transform: translateY(-50%) translateY(-1px) scale(1.06);
    letter-spacing: .4px;
    animation: brand-text-pan 900ms cubic-bezier(.4, 0, .2, 1) 1;
  }
}

@keyframes brand-text-pan {
  from {
    background-position: 0% 50%;
  }

  to {
    background-position: 100% 50%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .brand-title {
    transition: color .2s ease;
  }

  .brand-title:hover,
  .brand-title:focus-visible {
    transform: translateY(-50%);
    color: var(--accent);
    background: none;
    text-shadow: none;
    -webkit-text-fill-color: initial;
  }
}

@media (max-width: 900px) {
  .brand-title {
    font-size: 24px;
    left: 12px;
  }
}

.main-nav .nav-links {
  display: flex;
  align-items: center;
  gap: 10px;
}

.menu-btn {
  display: none;
}

.nav-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
  opacity: .95;
  padding: 8px 10px;
  border-radius: 10px;
  position: relative;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--accent);
}

.theme-light .nav-link:hover {
  background: rgba(15, 23, 42, 0.1);
  /* Dark gray hover effect for light mode */
  color: var(--accent);
}

/* Fancy hover underline + subtle lift for hover-capable devices */
@media (hover: hover) {
  .nav-link {
    transition: color .2s ease, transform .18s cubic-bezier(.4, 0, .2, 1);
  }

  .nav-link::after {
    content: "";
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 6px;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), #93c5fd);
    border-radius: 1px;
    transform: scaleX(0);
    transform-origin: 20% 50%;
    transition: transform .25s cubic-bezier(.4, 0, .2, 1), opacity .25s ease;
    opacity: 0.9;
    pointer-events: none;
  }

  .nav-link:hover,
  .nav-link:focus-visible {
    transform: translateY(-1px);
  }

  .nav-link:hover::after,
  .nav-link:focus-visible::after {
    transform: scaleX(1);
  }
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  .nav-link {
    transition: none;
  }

  .nav-link::after {
    transition: none;
  }
}

.site-footer {
  max-width: 1200px;
  margin: 40px auto 0;
  padding: 32px 16px calc(32px + env(safe-area-inset-bottom, 0px));
  color: var(--muted);
  font-size: 14px;
}

.theme-light .site-footer {
  background: rgba(0, 0, 0, 0.05);
  border-top-color: rgba(0, 0, 0, 0.1);
}

.site-footer .footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 16px;
}

.site-footer .footer-col h4 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
}

.site-footer .footer-col ul {
  margin: 0;
  padding-left: 16px;
}

.site-footer .footer-col li {
  margin: 6px 0;
}

.site-footer .footer-col a {
  color: var(--text);
  text-decoration: none;
}

.site-footer .footer-col a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.footer-copy {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin-top: 10px;
}

@media (max-width: 900px) {

  /* Mobile nav: show hamburger, collapse links into dropdown panel */
  .menu-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: 72px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text);
    padding: 8px;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    transition: background .15s, box-shadow .15s, color .2s;
  }

  .menu-btn .bar {
    display: block;
    width: 22px;
    height: 2px;
    background: currentColor;
    margin: 3px 0;
    border-radius: 2px;
  }

  .menu-btn .bar {
    transform-origin: center;
    transition: transform .22s cubic-bezier(.4, 0, .2, 1), opacity .2s ease, background .2s ease;
  }

  /* Hover/focus highlight only on devices that actually support hover */
}

@media (hover: hover) and (max-width: 900px) {

  .menu-btn:hover,
  .menu-btn:focus {
    background: rgba(96, 165, 250, 0.13);
    color: var(--accent);
    box-shadow: 0 2px 8px rgba(96, 165, 250, 0.10);
  }
}

@media (max-width: 900px) {

  /* Keep visual state when menu open; removed automatically on close (second tap) */
  .main-nav[data-open="true"] .menu-btn {
    background: rgba(96, 165, 250, 0.13);
    color: var(--accent);
    box-shadow: 0 2px 8px rgba(96, 165, 250, 0.10);
  }

  .menu-btn .bar {
    transition: background .2s ease;
  }

  .main-nav .nav-links {
    display: none;
  }

  .main-nav[data-open="true"] .nav-links {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: var(--topbar-h);
    left: 8px;
    right: 8px;
    background: linear-gradient(180deg, rgba(20, 20, 30, 0.98), rgba(20, 20, 30, 0.94));
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    padding: 8px;
    z-index: 180;
  }

  .theme-light .main-nav[data-open="true"] .nav-links {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(0, 0, 0, 0.10);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
  }

  /* Animate hamburger into X when open */
  .main-nav[data-open="true"] .menu-btn .bar {
    position: absolute;
    left: 50%;
    top: 50%;
    margin: 0;
  }

  .main-nav[data-open="true"] .menu-btn .bar:nth-child(1) {
    transform: translate(-50%, -50%) rotate(45deg);
  }

  .main-nav[data-open="true"] .menu-btn .bar:nth-child(2) {
    opacity: 0;
  }

  .main-nav[data-open="true"] .menu-btn .bar:nth-child(3) {
    transform: translate(-50%, -50%) rotate(-45deg);
  }

  .main-nav[data-open="true"] .nav-link {
    display: block;
    padding: 10px 12px;
    border-radius: 10px;
  }

  .main-nav[data-open="true"] .nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
  }

  .site-footer .footer-inner {
    grid-template-columns: 1fr;
  }
}

/* Content pages */
.page-container {
  max-width: 900px;
  margin: 90px auto 24px;
  padding: 0 16px;
}

.page h1 {
  font-size: 28px;
  margin: 0 0 12px;
}

.page h2 {
  font-size: 20px;
  margin: 18px 0 8px;
}

.page p {
  color: var(--text);
  opacity: .95;
  line-height: 1.7;
}

.page a {
  color: var(--accent);
}

.well {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 14px;
}

.theme-light .well {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.12);
}

.well ul {
  padding-left: 18px;
  margin: 8px 0;
}

.well li {
  line-height: 1.7;
  margin: 4px 0;
}

.well .btn {
  display: inline-flex;
}

/* Cookie bar */
.cookiebar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9998;
  background: rgba(17, 24, 39, 0.98);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.theme-light .cookiebar {
  background: rgba(255, 255, 255, 0.98);
  border-top-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
}

.cookiebar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.cookie-text {
  font-size: 13px;
  color: var(--muted);
}

/* Rich content sections on home (increase text depth for SEO/AdSense) */
.content-rich {
  max-width: 1100px;
  margin: 28px auto 0;
  padding: 0 16px;
}

.content-rich .section {
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 12px;
  padding: 16px;
  margin: 12px 0;
}

.theme-light .content-rich .section {
  background: rgba(255, 255, 255, 0.65);
  border-color: rgba(0, 0, 0, 0.12);
}

.content-rich h2 {
  font-size: 20px;
  margin: 0 0 8px;
}

.content-rich p {
  color: var(--text);
  opacity: .95;
  line-height: 1.7;
  margin: 8px 0;
}

.content-rich ul {
  margin: 6px 0 10px 18px;
}

.content-rich li {
  line-height: 1.7;
  opacity: .95;
}

.content-rich a {
  color: var(--accent);
  text-decoration: none;
}

.content-rich a:hover {
  text-decoration: underline;
}

.content-rich details {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 8px 0;
}

.theme-light .content-rich details {
  background: rgba(0, 0, 0, 0.02);
  border-color: rgba(0, 0, 0, 0.08);
}

.content-rich summary {
  cursor: pointer;
  font-weight: 800;
}

.content-rich summary::-webkit-details-marker {
  display: none;
}

.content-rich summary::after {
  content: " +";
  color: var(--muted);
  font-weight: 700;
}

.content-rich details[open] summary::after {
  content: " –";
}

/* Accordion in Settings Dropdown */
.settings-accordion {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.accordion-item {
  border-radius: 8px;
  overflow: hidden;
}

.accordion-header {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background .15s, color .15s;
}

.accordion-header:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.theme-light .accordion-header:hover {
  background: rgba(0, 0, 0, 0.04);
}

.accordion-header::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid currentColor;
  transition: transform 0.2s ease;
}

.accordion-item[data-open="true"] .accordion-header::after {
  transform: rotate(180deg);
}

.accordion-content {
  display: none;
  padding: 4px 0;
  animation: slideDown 0.2s ease;
}

.accordion-item[data-open="true"] .accordion-content {
  display: block;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Shuffle Logo Animation Styles */
.shuffle-parent {
  display: inline-block !important;
  /* Force inline-block to override flex from .site-title */
  white-space: nowrap;
  will-change: transform;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  transform-origin: center center;
  /* Ensure scaling happens from center */
}

.shuffle-parent:hover {
  transform: scale(1.1);
}

.shuffle-char-wrapper {
  display: inline-block;
  overflow: hidden;
  vertical-align: bottom;
  /* Better alignment */
  position: relative;
  margin-right: 0.02em;
  /* Slight spacing between chars */
}

.shuffle-inner {
  display: inline-flex;
  white-space: nowrap;
  will-change: transform;
}

.shuffle-char {
  display: inline-block;
  text-align: center;
  min-width: 0.6em;
  /* Ensure space for narrow chars */
}

.shuffle-suffix {
  font-size: 0.45em;
}

/* Ensure suffix is hidden on mobile, overriding wrapper display */
@media (max-width: 900px) {
  .shuffle-suffix {
    display: none !important;
  }
}

/* Review/Error Word Indicators */
.review-word {
  text-decoration: underline;
  text-decoration-color: var(--bad);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.review-target {
  /* Subtle red glow for the active target box if it's a review word */
  box-shadow: 0 4px 20px rgba(220, 38, 38, 0.15), 0 0 0 1px rgba(220, 38, 38, 0.3) !important;
}

.theme-light .review-target {
  box-shadow: 0 4px 20px rgba(220, 38, 38, 0.1), 0 0 0 1px rgba(220, 38, 38, 0.25) !important;
}

.review-target .char.pending {
  color: rgba(248, 113, 113, 0.9);
  /* Subtle tint on pending chars */
}

.theme-light .review-target .char.pending {
  color: #ef4444;
}

/* Time Selector */
.time-selector {
  display: flex;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  padding: 2px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.theme-light .time-selector {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.08);
}

.time-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.time-btn.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.theme-light .time-btn.active {
  background: #ffffff;
  color: #0f172a;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.time-btn:hover:not(.active) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.theme-light .time-btn:hover:not(.active) {
  color: #334155;
  background: rgba(0, 0, 0, 0.03);
}

.error-btn {
  color: var(--bad) !important;
  background: rgba(239, 68, 68, 0.1) !important;
  border: 1px solid rgba(239, 68, 68, 0.2) !important;
}

.theme-light .error-btn {
  background: #fff1f2 !important;
  border-color: #fda4af !important;
}

/* Learn Controls Container & Hard Keys */
#learn-controls {
  display: none;
  align-items: center;
  gap: 12px;
  order: 3;
}

#learn-controls .error-btn {
  margin-left: auto;
}

@media (max-width: 720px) {
  #learn-controls {
    width: 100%;
    justify-content: center;
    margin-top: 8px;
    order: 4;
  }
}

/* Learned Hard Keys - Orange Highlight */
.char.hard-key {
  color: #fdba74 !important;
  /* Orange-300 (Lighter) */
  font-weight: 600 !important;
  text-shadow: 0 0 10px rgba(253, 186, 116, 0.5);
}

.theme-light .char.hard-key {
  color: #f97316 !important;
  /* Orange-500 (Lighter than 600) */
  text-shadow: none;
}

/* When typed correctly, turn Green! */
.char.hard-key.correct {
  color: #4ade80 !important;
  /* Green-400 */
  text-shadow: 0 0 10px rgba(74, 222, 128, 0.5);
  font-weight: 700 !important;
}

.theme-light .char.hard-key.correct {
  color: #16a34a !important;
  /* Green-600 */
  text-shadow: none;
}

/* Learn Info Icon & Bubble */
.learn-info-wrapper {
  position: relative;
  display: none; /* Hidden by default */
  align-items: center;
  margin-left: 8px;
  animation: fadeInIcon 0.3s ease forwards;
}

@keyframes fadeInIcon {
  from { opacity: 0; transform: translateX(-5px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Show when Learn mode is active */
#mode-switch-cont[data-active="learn"] + .learn-info-wrapper {
  display: flex;
}

.info-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--muted);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  font-family: serif; /* for a nice 'i' */
  cursor: help;
  transition: all 0.2s;
}

.info-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(96, 165, 250, 0.1);
}

.info-icon.tapped {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(96, 165, 250, 0.1);
}

.info-bubble {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  width: 240px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(8px);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  text-align: center;
}

.theme-light .info-bubble {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  color: #334155;
}

.info-bubble::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid rgba(255, 255, 255, 0.1);
}

.theme-light .info-bubble::before {
  border-bottom-color: rgba(0, 0, 0, 0.1);
}

.learn-info-wrapper:hover .info-bubble,
.learn-info-wrapper.tap-active .info-bubble {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(6px);
}