:root {
  --correct-color: #538d4e;
  --present-color: #b59f3b;
  --absent-color: #3a3a3c;
  --bg-color: #121213;
  --bg-gradient: linear-gradient(180deg, #121213 0%, #050505 100%);
  --surface-color: rgba(30, 30, 32, 0.9);
  --text-color: #fff;
  --muted-color: rgba(255, 255, 255, 0.52);
  --border-color: rgba(255, 255, 255, 0.1);
  --border-active: rgba(255, 255, 255, 0.22);
  --key-bg: rgba(255, 255, 255, 0.08);
  --key-text: #fff;
  --enter-color: #538d4e;
  --backspace-color: #9b2335;
  --correct-glow: rgba(83, 141, 78, 0.35);
  --present-glow: rgba(181, 159, 59, 0.35);
  --header-border: rgba(255, 255, 255, 0.07);
  --tile-size: clamp(27px, min(5.3dvh, 11.6vw), 50px);
}

* {
  box-sizing: border-box;
  font-family: "Almarai", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

html, body { margin: 0; width: 100%; height: 100%; }
button, a { font: inherit; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

body {
  background: var(--bg-gradient);
  color: var(--text-color);
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  touch-action: manipulation;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.4;
  background: radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, 0.03), transparent 70%);
}

#splashOverlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  z-index: 2147483000;
  overflow: hidden;
  isolation: isolate;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
}

.waiting-logo-image { display: block; width: min(92vw, 560px); max-height: 52vh; height: auto; object-fit: contain; }
#splashOverlay .waiting-logo-image { opacity: 1; transition: opacity 0.4s ease; }
#splashOverlay.fade-out .waiting-logo-image { opacity: 0; }

header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--header-border);
  background: rgba(18, 18, 19, 0.8);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  column-gap: 6px;
  flex-shrink: 0;
}

header > .header-nav { grid-column: 1; justify-self: start; }
header > .wl-brand { grid-column: 2; justify-self: center; }
header > .header-actions { grid-column: 3; justify-self: end; }
.header-nav, .header-actions { display: flex; align-items: center; gap: 6px; min-width: 0; }

.hdr-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
  font-size: 0.95rem;
  text-decoration: none;
}

.hdr-btn:focus-visible { outline: 2px solid var(--present-color); outline-offset: 2px; }
.hdr-btn:active { transform: scale(0.92); }
.hdr-btn.home {
  background: linear-gradient(135deg, #538d4e, #3a6a36);
  color: #fff;
  border-color: rgba(83, 141, 78, 0.5);
  box-shadow: 0 3px 12px rgba(83, 141, 78, 0.35);
}

.wl-brand { display: inline-flex; align-items: center; gap: 8px; padding: 4px 8px; text-decoration: none; pointer-events: none; min-width: 0; }
.wl-grid-icon { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; width: 28px; height: 28px; flex: 0 0 auto; }
.wl-tile { border-radius: 3px; background: #3a3a3c; border: 1px solid rgba(255, 255, 255, 0.1); }
.wl-tile.g { background: #53ba67; border-color: #53ba67; box-shadow: 0 0 10px rgba(83, 186, 103, 0.45); }
.wl-tile.y { background: #cbb03f; border-color: #cbb03f; box-shadow: 0 0 10px rgba(203, 176, 63, 0.45); }
.wl-brand-text { font-size: clamp(20px, 4vw, 26px); font-weight: 800; color: #f8fafc; line-height: 1; text-shadow: 0 4px 10px rgba(0, 0, 0, 0.3); white-space: nowrap; }

.difficulty-dropdown { position: relative; display: inline-block; }
.difficulty-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 176px;
  padding: 5px;
  background: rgba(30, 30, 32, 0.98);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  z-index: 120;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  display: none;
}
.difficulty-menu.show { display: block; }
.difficulty-option {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  text-align: right;
  border: 0;
  border-bottom: 1px solid var(--border-color);
  border-radius: 6px;
  background: transparent;
  color: var(--text-color);
  font-size: 0.78rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
}
.difficulty-option:last-child { border-bottom: 0; }
.difficulty-option i { width: 17px; text-align: center; color: var(--muted-color); }
.difficulty-option.danger, .difficulty-option.danger i { color: #e86b67; }
.compact-menu-action { display: none; }

.game-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 6px 10px max(5px, env(safe-area-inset-bottom));
  overflow: hidden;
  min-height: 0;
  position: relative;
  z-index: 1;
}

.play-area-container { display: flex; justify-content: center; align-items: center; width: 100%; min-height: 0; flex: 1; }
.board { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(2px, 0.45dvh, 5px); direction: ltr; width: 100%; }
.guess-row { display: flex; align-items: stretch; justify-content: center; gap: clamp(5px, 1.3vw, 9px); height: var(--tile-size); }
.letter-group { display: grid; grid-template-columns: repeat(5, var(--tile-size)); gap: clamp(2px, 0.65vw, 5px); direction: rtl; }

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  border: 2px solid var(--border-color);
  background: transparent;
  color: var(--text-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--tile-size) * 0.5);
  font-weight: 800;
  line-height: 1;
  border-radius: 6px;
  flex-shrink: 0;
  padding: 0;
  transition: border-color 0.15s ease, background-color 0.18s ease, transform 0.15s ease;
}
.tile.filled { border-color: rgba(255, 255, 255, 0.3); }
.tile.just-filled { animation: tile-pop 0.1s ease; }
.guess-row.submitted .tile { cursor: pointer; }
.tile.note-exact { background: var(--correct-color); border-color: var(--correct-color); color: #fff; box-shadow: 0 0 14px var(--correct-glow); }
.tile.note-present { background: var(--present-color); border-color: var(--present-color); color: #fff; box-shadow: 0 0 14px var(--present-glow); }
.tile.note-absent { background: var(--absent-color); border-color: var(--absent-color); color: #fff; }
.tile.flip { animation: tile-flip 0.6s ease both; }

.score-group { display: grid; grid-template-columns: repeat(3, calc(var(--tile-size) * 0.62)); gap: clamp(2px, 0.5vw, 4px); direction: ltr; }
.score { border-radius: 6px; display: grid; place-items: center; font-size: calc(var(--tile-size) * 0.34); font-weight: 800; color: #fff; border: 1px solid transparent; }
.score.exact { background: var(--correct-color); border-color: var(--correct-color); box-shadow: 0 0 10px var(--correct-glow); }
.score.present { background: var(--present-color); border-color: var(--present-color); box-shadow: 0 0 10px var(--present-glow); }
.score.absent { background: var(--absent-color); border-color: var(--absent-color); }
.score.empty { background: transparent; color: rgba(255, 255, 255, 0.25); border-color: var(--border-color); }

.keyboard { width: 100%; max-width: 620px; margin: 3px auto 0; flex-shrink: 0; }
.keyboard-row { display: flex; justify-content: center; gap: 4px; margin-bottom: 6px; width: 100%; direction: rtl; }
.key {
  height: clamp(42px, 6vh, 58px);
  min-width: clamp(28px, 6vw, 43px);
  background: var(--key-bg);
  color: var(--key-text);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-weight: 700;
  font-size: clamp(0.85rem, 3vw, 1.1rem);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 1;
  margin: 0 2px;
  padding: 0 2px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.key.enter { background: var(--enter-color); border-color: var(--enter-color); color: #fff; font-size: clamp(0.7rem, 2.5vw, 0.9rem); }
.key.backspace { background: var(--backspace-color); border-color: var(--backspace-color); color: #fff; }
.key.wide { min-width: 65px; }
.key:active { background: var(--border-active); }
.key.mark-exact, .key.mark-exact:active { background: var(--correct-color); border-color: var(--correct-color); color: #fff; }
.key.mark-present, .key.mark-present:active { background: var(--present-color); border-color: var(--present-color); color: #fff; }
.key.mark-absent, .key.mark-absent:active { background: var(--absent-color); border-color: var(--absent-color); color: #fff; }

.toast {
  position: fixed;
  top: 82px;
  left: 50%;
  z-index: 200;
  transform: translate(-50%, -12px);
  background: #f8fafc;
  color: #111827;
  padding: 10px 16px;
  border-radius: 9px;
  font-weight: 800;
  font-size: 0.78rem;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  white-space: nowrap;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.pm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.pm-overlay.pm-active { opacity: 1; visibility: visible; pointer-events: auto; }
.premium-glass {
  width: 100%;
  max-width: 430px;
  max-height: 88dvh;
  overflow-y: auto;
  background: linear-gradient(145deg, rgba(30, 30, 32, 0.76), rgba(15, 15, 16, 0.97));
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-top-color: rgba(255, 255, 255, 0.15);
  border-radius: 28px;
  padding: 30px 24px 24px;
  position: relative;
  color: #fff;
  text-align: center;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transform: scale(0.95) translateY(18px);
  transition: transform 0.35s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.pm-overlay.pm-active .premium-glass { transform: scale(1) translateY(0); }
.pm-close { position: absolute; top: 13px; right: 13px; width: 30px; height: 30px; border-radius: 9px; background: rgba(255, 255, 255, 0.05); color: rgba(255, 255, 255, 0.45); display: flex; align-items: center; justify-content: center; border: 1px solid rgba(255, 255, 255, 0.06); cursor: pointer; }
.pm-floating-icon { margin: 0 auto 14px; width: 56px; height: 56px; background: linear-gradient(135deg, #1e1e20, #0a0a0b); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.55), inset 0 2px 4px rgba(255, 255, 255, 0.05); }
.pm-icon-gold { color: #d4af37; text-shadow: 0 0 15px rgba(212, 175, 55, 0.4); }
.pm-icon-green { color: var(--correct-color); text-shadow: 0 0 15px var(--correct-glow); }
.pm-icon-red { color: #e74c3c; text-shadow: 0 0 15px rgba(231, 76, 60, 0.4); }
.pm-title { font-size: 1.45rem; font-weight: 800; margin: 5px 0 7px; color: #fff; }
.pm-subtitle { margin: 0 0 15px; color: rgba(255, 255, 255, 0.48); font-size: 0.78rem; font-weight: 700; }
.pm-inset { background: rgba(0, 0, 0, 0.4); border: 1px solid rgba(255, 255, 255, 0.04); border-radius: 18px; padding: 15px; box-shadow: inset 0 4px 15px rgba(0, 0, 0, 0.3); }
.pm-stat-box { background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.06); border-radius: 14px; text-align: center; padding: 10px 6px; box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.2); }
.pm-stat-main { background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.2)); border-color: rgba(212, 175, 55, 0.2); }
.pm-grad-gold { background: linear-gradient(135deg, #f9e583, #b59f3b); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.pm-grad-green { background: linear-gradient(135deg, #74b86d, #42753e); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.pm-btn-primary, .pm-btn-secondary { min-height: 46px; border-radius: 13px; font-weight: 800; font-size: 0.86rem; cursor: pointer; padding: 12px; display: flex; align-items: center; justify-content: center; gap: 7px; }
.pm-btn-primary { background: linear-gradient(135deg, #538d4e, #3a6336); color: #fff; border: 1px solid rgba(255, 255, 255, 0.1); box-shadow: 0 6px 18px rgba(83, 141, 78, 0.25); }
.pm-btn-secondary { background: rgba(255, 255, 255, 0.04); color: rgba(255, 255, 255, 0.85); border: 1px solid rgba(255, 255, 255, 0.08); }
.full-width { width: 100%; margin-top: 10px; }

.feedback-demo { display: grid; grid-template-columns: repeat(3, 46px); justify-content: center; gap: 7px; margin: 15px 0; }
.feedback-demo .score { height: 44px; font-size: 1rem; }
.help-list { display: grid; gap: 8px; margin-bottom: 14px; text-align: right; }
.help-list > div { display: flex; align-items: center; gap: 10px; font-size: 0.8rem; }
.help-list b { width: 34px; height: 34px; border-radius: 7px; display: grid; place-items: center; color: #fff; flex: 0 0 auto; }
.help-list b.correct { background: var(--correct-color); }
.help-list b.present { background: var(--present-color); }
.help-list b.absent { background: var(--absent-color); }
.help-note { color: rgba(255, 255, 255, 0.62); font-size: 0.75rem; line-height: 1.8; text-align: right; margin-bottom: 14px; }

.stats-main { width: 65%; margin: 0 auto 9px; display: grid; gap: 4px; padding: 13px; }
.stats-main span, .stat-grid span { color: rgba(255, 255, 255, 0.43); font-size: 0.67rem; font-weight: 800; }
.stats-main b { font-size: 2.5rem; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat-grid .pm-stat-box { display: grid; gap: 7px; align-content: center; min-height: 78px; }
.stat-grid b { font-size: 1.3rem; direction: ltr; }
.stats-result-info:empty { display: none; }
.stats-result-state { display: grid; justify-items: center; gap: 5px; margin: 0 0 11px; }
.stats-result-state strong { font-size: 0.9rem; }
.stats-result-state.win strong { color: #53ba67; }
.stats-result-state.loss strong { color: #e74c3c; }
.stats-result-state span { min-width: 120px; padding: 7px 14px; border-radius: 9px; background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.07); font-size: 1.15rem; font-weight: 900; }
.history-wrap { padding: 0; overflow: hidden; }
.history-head { padding: 11px 16px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); display: flex; align-items: center; justify-content: space-between; }
.history-head span { color: rgba(255, 255, 255, 0.45); font-size: 0.7rem; font-weight: 800; }
.history-head i { color: rgba(255, 255, 255, 0.3); font-size: 0.75rem; }
.no-attempts { padding: 26px 12px; color: rgba(255, 255, 255, 0.4); font-size: 0.78rem; font-weight: 700; }
.history-scroll { max-height: 190px; overflow-y: auto; padding: 8px 13px; }
.history-scroll::-webkit-scrollbar { width: 4px; }
.history-scroll::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 10px; }
.pm-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.78rem; }
.pm-table th { padding: 8px 6px; color: rgba(255, 255, 255, 0.45); font-size: 0.67rem; font-weight: 900; border-bottom: 1px solid rgba(255, 255, 255, 0.06); text-align: center; }
.pm-table td { padding: 8px 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.04); text-align: center; font-weight: 700; color: rgba(255, 255, 255, 0.8); }
.pm-table tr:last-child td { border-bottom: 0; }
.pm-table .history-win { color: #53ba67; font-weight: 900; font-size: 0.86rem; }
.pm-table .history-loss { color: #e74c3c; font-weight: 900; font-size: 0.86rem; }

.result-mark.loss { color: #e74c3c; }
.pm-streak-box { margin: 4px auto 12px; width: max-content; max-width: 100%; display: inline-flex; align-items: center; gap: 7px; background: linear-gradient(135deg, rgba(255, 152, 0, 0.15), rgba(255, 87, 34, 0.05)); border: 1px solid rgba(255, 152, 0, 0.3); border-radius: 12px; padding: 6px 14px; color: rgba(255, 255, 255, 0.82); font-size: 0.75rem; font-weight: 700; }
.pm-streak-box[hidden] { display: none !important; }
.pm-streak-box i { color: #ff9800; }
.pm-streak-box b { color: #fff; font-size: 0.95rem; }
.result-word-box { margin: 0 0 14px; text-align: center; }
.result-word-box > span { color: rgba(255, 255, 255, 0.45); font-size: 0.67rem; font-weight: 800; text-transform: uppercase; }
.answer-word { margin: 7px 0 0; color: var(--correct-color); font-size: 2rem; font-weight: 800; }
.answer-word.loss { color: #e74c3c; }
.result-matrix { display: flex; flex-direction: column; align-items: center; gap: 5px; margin-bottom: 14px; }
.result-matrix-row { display: flex; direction: rtl; gap: 5px; }
.pm-matrix-tile { width: 36px; height: 36px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.95rem; color: #fff; }
.pm-matrix-tile.correct { background: var(--correct-color); }
.pm-matrix-tile.present { background: var(--present-color); }
.pm-matrix-tile.absent { background: #2a2a2c; color: rgba(255, 255, 255, 0.4); }
.result-actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 10px; }

body.light {
  --bg-color: #f8fafc;
  --bg-gradient: linear-gradient(180deg, #eef1f5 0%, #fff 100%);
  --surface-color: rgba(255, 255, 255, 0.95);
  --text-color: #111827;
  --muted-color: #64748b;
  --border-color: rgba(0, 0, 0, 0.1);
  --border-active: rgba(0, 0, 0, 0.22);
  --key-bg: rgba(0, 0, 0, 0.06);
  --key-text: #111827;
  --header-border: rgba(0, 0, 0, 0.08);
}
body.light header { background: rgba(255, 255, 255, 0.92); }
body.light .wl-brand-text, body.light .tile { color: #111827; }
body.light .hdr-btn:not(.home) { background: rgba(0, 0, 0, 0.04); border-color: rgba(0, 0, 0, 0.08); color: #111827; }
body.light .difficulty-menu { background: rgba(255, 255, 255, 0.99); border-color: rgba(0, 0, 0, 0.1); }
body.light .difficulty-option { color: #111827; }
body.light .tile { border-color: rgba(0, 0, 0, 0.15); }
body.light .tile.note-exact, body.light .tile.note-present, body.light .tile.note-absent,
body.light .key.mark-exact, body.light .key.mark-present, body.light .key.mark-absent { color: #fff; }
body.light .score.empty { color: rgba(0, 0, 0, 0.3); }
body.light .pm-overlay { background: rgba(15, 23, 42, 0.42); }
body.light .premium-glass { background: linear-gradient(145deg, #fff, #f1f4f7); color: #111827; border-color: rgba(15, 23, 42, 0.11); box-shadow: 0 24px 55px rgba(15, 23, 42, 0.22); }
body.light .pm-title { color: #111827; }
body.light .pm-subtitle, body.light .help-note, body.light .stats-main span, body.light .stat-grid span, body.light .result-word-box > span { color: #64748b; }
body.light .pm-floating-icon, body.light .pm-stat-box, body.light .pm-btn-secondary, body.light .pm-inset { background: rgba(15, 23, 42, 0.045); border-color: rgba(15, 23, 42, 0.1); color: #111827; box-shadow: inset 0 2px 8px rgba(15, 23, 42, 0.06); }
body.light .pm-close { background: rgba(15, 23, 42, 0.04); border-color: rgba(15, 23, 42, 0.1); color: #64748b; }
body.light .history-head { border-bottom-color: rgba(15, 23, 42, 0.1); }
body.light .history-head span, body.light .history-head i, body.light .no-attempts { color: #64748b; }
body.light .pm-table th { color: #64748b; border-bottom-color: rgba(15, 23, 42, 0.1); }
body.light .pm-table td { color: #111827; border-bottom-color: rgba(15, 23, 42, 0.08); }
body.light .stats-result-state span { background: rgba(15, 23, 42, 0.04); border-color: rgba(15, 23, 42, 0.1); }
body.light .pm-streak-box { color: #475569; background: rgba(255, 152, 0, 0.08); }
body.light .pm-streak-box b { color: #111827; }
body.light .pm-matrix-tile.absent { background: #787c7e; color: #fff; }

@media (hover: hover) and (pointer: fine) {
  .hdr-btn:hover { border-color: var(--border-active); transform: scale(1.05); }
  .key:hover { background: var(--border-active); }
  .difficulty-option:hover { background: rgba(255, 255, 255, 0.07); }
  body.light .difficulty-option:hover { background: rgba(0, 0, 0, 0.05); }
}

@media (min-width: 640px) {
  .hdr-btn { width: 44px; height: 44px; font-size: 1.05rem; border-radius: 13px; }
}

@media (max-width: 480px) {
  header { padding: 9px 10px; }
  .key { height: clamp(38px, 5.5vh, 50px); min-width: clamp(24px, 5vw, 34px); font-size: clamp(0.8rem, 2.8vw, 1rem); margin: 0 1px; padding: 0 1px; }
  .key.enter { font-size: clamp(0.65rem, 2.2vw, 0.8rem); }
  .key.wide { min-width: 50px; }
  .keyboard-row { gap: 2px; margin-bottom: 5px; }
  .game-wrapper { padding-inline: 6px; }
  .premium-glass { padding: 28px 17px 20px; border-radius: 23px; }
}

@media (max-width: 400px) {
  .hdr-btn { width: 34px; height: 34px; font-size: 0.82rem; border-radius: 10px; }
  .hdr-btn.diff { min-width: 58px; padding: 0 7px; font-size: 0.7rem; }
  .compact-hide { display: none; }
  .compact-menu-action { display: flex; }
  .wl-brand { gap: 6px; padding: 4px 5px; }
  .wl-grid-icon { width: 26px; height: 26px; }
  .wl-brand-text { font-size: 18px; }
  .difficulty-menu { width: 164px; }
  .stat-grid { gap: 5px; }
  .stat-grid span { font-size: 0.59rem; }
  .pm-matrix-tile { width: 30px; height: 30px; font-size: 0.82rem; }
}

@media (max-width: 340px) {
  :root { --tile-size: clamp(26px, min(5.15dvh, 11.1vw), 45px); }
  .wl-grid-icon { width: 24px; height: 24px; }
  .wl-brand-text { font-size: 17px; }
  .score-group { grid-template-columns: repeat(3, calc(var(--tile-size) * 0.58)); }
}

@media (max-height: 620px) {
  :root { --tile-size: clamp(23px, 4.75dvh, 34px); }
  header { padding-block: 6px; }
  .keyboard-row { margin-bottom: 3px; }
  .key { height: clamp(31px, 6.5dvh, 39px); }
}

@media (max-height: 700px) {
  #statsModal .premium-glass { padding: 18px 14px 14px; }
  #statsModal .pm-floating-icon { width: 42px; height: 42px; margin-bottom: 7px; font-size: 1.1rem; border-radius: 11px; }
  #statsModal .pm-title { font-size: 1.15rem; margin-block: 2px 4px; }
  #statsModal .pm-subtitle { margin-bottom: 7px; font-size: 0.68rem; }
  #statsModal .stats-main { width: 58%; padding: 7px; margin-bottom: 6px; }
  #statsModal .stats-main b { font-size: 1.8rem; }
  #statsModal .stat-grid { margin-bottom: 7px; }
  #statsModal .stat-grid .pm-stat-box { min-height: 57px; padding: 5px 3px; gap: 3px; }
  #statsModal .stat-grid b { font-size: 1.05rem; }
  #statsModal .history-head { padding-block: 7px; }
  #statsModal .history-scroll { max-height: 150px; padding-block: 5px; }
  #statsModal .pm-table th, #statsModal .pm-table td { padding-block: 5px; }
  #resultModal .premium-glass { padding: 18px 14px 14px; }
  #resultModal .pm-floating-icon { width: 42px; height: 42px; margin-bottom: 6px; border-radius: 11px; font-size: 1.1rem; }
  #resultModal .pm-title { margin-block: 2px 5px; font-size: 1.18rem; }
  #resultModal .pm-subtitle { margin-bottom: 8px; font-size: 0.7rem; }
  #resultModal .pm-streak-box { margin-block: 2px 7px; padding: 4px 10px; }
  #resultModal .result-word-box { margin-bottom: 8px; padding: 8px; border-radius: 13px; }
  #resultModal .answer-word { margin-top: 3px; font-size: 1.55rem; }
  #resultModal .result-matrix { gap: 3px; margin-bottom: 8px; }
  #resultModal .result-matrix-row { gap: 3px; }
  #resultModal .pm-matrix-tile { width: 24px; height: 24px; border-radius: 5px; font-size: 0.72rem; }
  #resultModal .pm-btn-primary, #resultModal .pm-btn-secondary { min-height: 40px; padding: 8px 5px; font-size: 0.74rem; }
}

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

@keyframes tile-pop { 50% { transform: scale(1.12); } }
@keyframes tile-flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.shake { animation: shake 0.45s ease; }
