:root {
  /* Page scale set by public/js/pageScale.js (CSS zoom on <html>; 1 on phones and large screens).
     Under CSS zoom, vh/vw shrink with the page, so viewport sizes go through these units instead. */
  --app-zoom: 1;
  --app-vh: calc(1vh / var(--app-zoom));
  --app-vw: calc(1vw / var(--app-zoom));
  --app-dvh: var(--app-vh);
  --bg-page: #ffffff;
  --bg-card: #ffffff;
  --bg-subtle: #f5f9ff;
  --navy-1: #0a1f44;
  --navy-2: #123066;
  --navy-heading: #0a1f44;
  --btn-blue: #1d6ae5;
  --btn-blue-dark: #1554ba;
  --hover-cyan: #00bcd4;
  --hover-cyan-bright: #00d4f0;
  --text-main: #17253d;
  --text-muted: #52637d;
  --border-light: #d7e3f4;
  --border-navy: #1c3f7a;
  --success: #12995a;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow-sm: 0 4px 14px rgba(10, 31, 68, 0.07);
  --shadow-md: 0 10px 28px rgba(10, 31, 68, 0.13);
  --shadow-lg: 0 18px 44px rgba(10, 31, 68, 0.22);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

@supports (height: 1dvh) {
  :root {
    --app-dvh: calc(1dvh / var(--app-zoom));
  }
}

:root[data-theme="dark"] {
  --bg-page: #0b1326;
  --bg-card: #121e3a;
  --bg-subtle: #18284c;
  --navy-1: #0d182e;
  --navy-2: #152445;
  --navy-heading: #38bdf8;
  --btn-blue: #2563eb;
  --btn-blue-dark: #1d4ed8;
  --hover-cyan: #00bcd4;
  --hover-cyan-bright: #38bdf8;
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --border-light: #2b4478;
  --border-navy: #38bdf8;
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.7);
}

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

html {
  overflow-x: hidden;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.55;
  min-height: calc(100 * var(--app-vh));
  max-width: 100%;
}

body {
  overflow-x: hidden;
}

#app-shell {
  min-height: calc(100 * var(--app-vh));
  display: flex;
  flex-direction: column;
  background-color: var(--bg-page);
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overflow-x: clip;
}

h1,
h2,
h3,
h4,
h5 {
  color: var(--navy-heading);
  margin-top: 0;
  font-weight: 700;
}

a {
  color: var(--btn-blue);
  text-decoration: none;
  transition: color 0.18s ease, background-color 0.18s ease, border-color 0.18s ease;
}

a:hover {
  color: var(--hover-cyan);
}

.bar-container {
  max-width: 100%;
  margin: 0;
  padding: 0 24px;
  width: 100%;
}

/* =========================================================
   THANH NGANG SỐ 1 (Top Bar 1 - Xanh Navy - Thon Gọn)
   ========================================================= */
.top-bar-1 {
  background-color: var(--navy-1);
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 2px 8px rgba(10, 31, 68, 0.18);
  position: sticky;
  top: 0;
  z-index: 90;
}

.bar-1-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  gap: 12px;
}

.header-left-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-shrink: 0;
}

.mobile-menu-toggle {
  display: none;
  appearance: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.16s ease, border-color 0.16s ease;
}

.mobile-menu-toggle:hover,
.mobile-menu-toggle:focus-visible {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.45);
  outline: none;
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #ffffff;
  font-size: 1.26rem;
  font-weight: 500;
  letter-spacing: 0.2px;
  flex-shrink: 0;
  user-select: none;
  -webkit-user-select: none;
  text-decoration: none;
  outline: none;
}

.brand-logo:hover,
.brand-logo:focus,
.brand-logo:focus-visible,
.brand-logo:active {
  color: #ffffff;
  font-weight: 500;
  text-decoration: none;
  outline: none;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.settings-menu-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.settings-trigger-btn {
  appearance: none;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: none;
  outline: none;
}

.settings-trigger-btn:hover,
.settings-trigger-btn:focus-visible,
.settings-trigger-btn.active {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.24);
  box-shadow: none;
  outline: none;
}

.settings-gear-icon {
  display: block;
  pointer-events: none;
}

.settings-dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 230px;
  background: #ffffff;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 160;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: userDropdownFadeIn 0.15s ease-out;
}

.settings-dropdown-menu.hidden {
  display: none !important;
}

.settings-dropdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-dropdown-label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
}

.theme-switcher,
.lang-switcher {
  display: inline-flex;
  align-items: center;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.theme-btn,
.lang-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.2px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: none;
  outline: none;
}

.theme-btn:hover,
.theme-btn:focus-visible,
.lang-btn:hover,
.lang-btn:focus-visible {
  background-color: transparent;
  color: var(--text-main);
  box-shadow: none;
  outline: none;
}

.theme-btn.active,
.theme-btn.active:hover,
.theme-btn.active:focus-visible,
.lang-btn.active,
.lang-btn.active:hover,
.lang-btn.active:focus-visible {
  background-color: var(--btn-blue);
  color: #ffffff;
  box-shadow: none;
}

.auth-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-menu-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.user-menu-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.84rem;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.25;
  box-shadow: none;
}

.user-menu-btn:hover,
.user-menu-btn:focus-visible,
.user-menu-btn.active {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.24);
  box-shadow: none;
  outline: none;
}

.user-dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 190px;
  background: #ffffff;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 28px rgba(10, 31, 68, 0.2);
  z-index: 150;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 5px 0;
  animation: userDropdownFadeIn 0.15s ease-out;
}

.user-dropdown-menu.hidden {
  display: none !important;
}

@keyframes userDropdownFadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.user-dropdown-item {
  appearance: none;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: block;
  box-shadow: none;
}

.user-dropdown-item:hover,
.user-dropdown-item:focus-visible {
  background-color: transparent;
  color: var(--text-main);
  outline: none;
}

.user-dropdown-item.user-dropdown-item-danger {
  color: #c5221f;
  border-top: 1px solid var(--border-light);
  margin-top: 4px;
  padding-top: 10px;
}

.user-dropdown-item.user-dropdown-item-danger:hover,
.user-dropdown-item.user-dropdown-item-danger:focus-visible {
  background-color: transparent;
  color: #c5221f;
}

.profile-modal-box {
  max-width: 460px;
  width: 92%;
}

.profile-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.profile-header-strip {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1.5px solid var(--border-light);
}

.profile-avatar-initials {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--navy-1), var(--btn-blue));
  color: #ffffff;
  font-size: 1.25rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
  flex-shrink: 0;
  box-shadow: 0 3px 8px rgba(10, 31, 68, 0.2);
}

.profile-header-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}

.profile-fullname {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--navy-1);
  margin: 0;
  word-break: break-word;
}

.profile-role-tag {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.profile-role-admin {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.profile-role-user {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
}

.profile-details-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  background: #f8fafc;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

.profile-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.profile-label {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
}

.profile-value {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-main);
  word-break: break-all;
}

.profile-rating-highlight {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--navy-1);
}

.profile-status-badge {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  color: #15803d;
}

.profile-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

/* =========================================================
   USER PROFILE SUBPAGE (#/profile)
   ========================================================= */
.profile-page-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 24px;
  align-items: start;
  max-width: 100%;
  margin: 0;
}

/* The wide column may shrink below its content (long names, tables) instead of
   pushing the page wider than the screen */
.profile-page-grid {
  grid-template-columns: 340px minmax(0, 1fr);
}

.profile-page-grid > * {
  min-width: 0;
}

.profile-hero-card {
  text-align: center;
  padding: 28px 20px 22px;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.profile-avatar-large {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--navy-1), var(--btn-blue));
  color: #ffffff;
  font-size: 1.85rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
  margin: 0 auto 14px;
  box-shadow: 0 4px 14px rgba(10, 31, 68, 0.22);
}

.profile-hero-name {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--navy-1);
  margin: 0 0 4px;
  word-break: break-word;
}

.profile-hero-username {
  font-size: 0.88rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 12px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.profile-hero-tags {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.profile-hero-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 14px;
}

.profile-status-pill {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: #dcfce7;
  color: #15803d;
  border: 1px solid #bbf7d0;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.profile-stat-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.profile-stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
}

.profile-stat-label {
  color: var(--text-muted);
  font-weight: 600;
}

.profile-stat-value {
  font-weight: 700;
  color: var(--text-main);
  text-align: right;
  word-break: break-all;
}

.profile-stat-value.highlight {
  color: var(--btn-blue);
  font-size: 1.05rem;
  font-weight: 800;
}

:root[data-theme="dark"] .profile-hero-name {
  color: #ffffff;
}

:root[data-theme="dark"] .profile-hero-username {
  color: #94a3b8;
}

:root[data-theme="dark"] .profile-status-pill {
  background: rgba(34, 197, 94, 0.18);
  color: #4ade80;
  border-color: rgba(34, 197, 94, 0.3);
}

:root[data-theme="dark"] .profile-stat-box {
  background: #0f1c2e;
  border-color: rgba(255, 255, 255, 0.1);
}

:root[data-theme="dark"] .profile-stat-value.highlight {
  color: var(--hover-cyan-bright);
}

.user-badge {
  color: #ffffff;
  font-weight: 600;
  font-size: 0.84rem;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.1);
}

/* =========================================================
   MAIN NAVIGATION BAR (Same Row as Logo - Slim & Compact)
   ========================================================= */
.main-nav-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: flex-start;
  margin: 0 12px;
}

.nav-col-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: #ffffff;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: 0.1px;
  min-height: 38px;
  padding: 7px 15px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: none;
}

.nav-col-btn:hover,
.nav-col-btn:focus-visible {
  background-color: transparent;
  color: #ffffff;
  border-color: transparent;
  transform: none;
  box-shadow: none;
  outline: none;
}

.nav-col-btn.active,
.nav-col-btn.active:hover,
.nav-col-btn.active:focus-visible {
  background-color: var(--btn-blue);
  color: #ffffff;
  border-color: transparent;
  box-shadow: none;
}

.home-welcome-banner {
  max-width: 820px;
  margin: 48px auto;
  padding: 36px 32px;
  text-align: center;
  background: #ffffff;
  border: 1.5px solid var(--border-light);
  border-top: 6px solid var(--navy-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.home-welcome-banner h1 {
  font-size: 1.85rem;
  color: var(--navy-heading);
  margin-bottom: 12px;
}

.home-welcome-lead {
  font-size: 1.03rem;
  color: var(--text-main);
  margin: 0 auto 14px;
  max-width: 680px;
}

.home-welcome-hint {
  display: inline-block;
  margin: 6px 0 0;
  padding: 9px 18px;
  border-radius: 99px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  color: var(--navy-heading);
  font-size: 0.92rem;
  font-weight: 600;
}

/* =========================================================
   NÚT BẤM (Không glow, không đổi màu khi hover)
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background-color: var(--btn-blue);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: none;
  text-decoration: none;
  line-height: 1.2;
  white-space: nowrap;
  vertical-align: middle;
}

.btn:hover,
.btn:focus-visible {
  background-color: var(--btn-blue);
  color: #ffffff;
  border-color: transparent;
  box-shadow: none;
  transform: none;
  outline: none;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-sm {
  padding: 7px 13px;
  font-size: 0.86rem;
}

.btn-lg {
  padding: 13px 22px;
  font-size: 1.03rem;
  font-weight: 700;
}

.btn-block {
  width: 100%;
}

.btn-outline,
.btn-outline:hover,
.btn-outline:focus-visible {
  background-color: #ffffff;
  color: var(--btn-blue);
  border: 1.5px solid var(--btn-blue);
  box-shadow: none;
}

.btn-auth,
.btn-auth:hover,
.btn-auth:focus-visible {
  padding: 5px 12px;
  font-size: 0.84rem;
  border-radius: 5px;
  background-color: var(--btn-blue);
  color: #ffffff;
  box-shadow: none;
}

.btn-auth-register,
.btn-auth-register:hover,
.btn-auth-register:focus-visible {
  border: 1px solid rgba(255, 255, 255, 0.35);
}

/* =========================================================
   KHU VỰC CHÍNH & BỐ CỤC 4 CỘT TRANG CHỦ
   ========================================================= */
.main-container {
  flex: 1;
  max-width: 100%;
  width: 100%;
  margin: 0;
  padding: 24px 24px 44px;
  background-color: var(--bg-page);
}

.hero-banner {
  background: #ffffff;
  border: 1.5px solid var(--border-light);
  border-left: 6px solid var(--navy-1);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  box-shadow: var(--shadow-sm);
}

.hero-banner h1 {
  font-size: 1.55rem;
  margin-bottom: 6px;
  color: var(--navy-heading);
}

.hero-banner p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.96rem;
}

.four-columns-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
  align-items: stretch;
}

.feature-column-card {
  background: #ffffff;
  border: 1.5px solid var(--border-light);
  border-top: 5px solid var(--navy-1);
  border-radius: var(--radius-md);
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.feature-column-card:hover {
  border-color: var(--hover-cyan);
  border-top-color: var(--hover-cyan);
  box-shadow: var(--shadow-md);
  transform: translateY(-3px);
}

.col-badge,
.popup-badge {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--navy-1);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  padding: 3px 10px;
  border-radius: 99px;
  margin-bottom: 10px;
}

.col-icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--bg-subtle);
  color: var(--navy-1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  margin-bottom: 14px;
  border: 1px solid var(--border-light);
}

.column-title {
  font-size: 1.32rem;
  color: var(--navy-heading);
  margin-bottom: 8px;
}

.column-desc {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin-bottom: 16px;
}

.column-sublist {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.column-sublist li {
  font-size: 0.88rem;
  color: var(--text-main);
  padding: 7px 10px;
  border-radius: 7px;
  background: var(--bg-subtle);
  border: 1px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.column-sublist li:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}

/* =========================================================
   HỘP THÔNG BÁO NHỎ (Popup Modal)
   ========================================================= */
.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 31, 68, 0.52);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.hidden,
.popup-overlay.hidden,
.user-dropdown-menu.hidden,
.settings-dropdown-menu.hidden {
  display: none !important;
}

.popup-box,
.popup-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  border-top: 6px solid var(--navy-1);
  max-width: 520px;
  width: 100%;
  /* never taller than the visible screen: long popups scroll so their buttons stay reachable */
  max-height: calc(100 * var(--app-dvh) - 32px);
  overflow-y: auto;
  padding: 22px 24px 24px;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.18s ease-out;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.popup-header,
.popup-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1.5px solid var(--border-light);
}

.popup-title,
.popup-card-title {
  font-size: 1.25rem;
  color: var(--navy-heading);
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.popup-subtitle {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 0 0 16px;
}

.popup-subtitle:empty {
  display: none;
  margin: 0;
}

.popup-close-btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--btn-blue);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: none;
}

.popup-close-btn:hover,
.popup-close-btn:focus-visible {
  background: var(--btn-blue);
  color: #ffffff;
  transform: none;
  box-shadow: none;
  outline: none;
}

.admin-modal-box {
  max-width: 580px;
  max-height: calc(88 * var(--app-vh));
  overflow-y: auto;
}

.admin-modal-box.admin-modal-box-wide {
  max-width: 820px;
}

/* Admin library (kho giáo trình / bài tập) */
.library-manage-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 16px;
}

.library-section-switch,
.library-toolbar-actions,
.library-row-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.library-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1.5px solid var(--border-light);
}

.library-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 0;
}

.library-crumb {
  border: none;
  background: none;
  padding: 2px 4px;
  font: inherit;
  font-weight: 600;
  color: var(--btn-blue);
  cursor: pointer;
  border-radius: 4px;
  overflow-wrap: anywhere;
  text-align: left;
}

.library-crumb:hover,
.library-crumb:focus-visible {
  text-decoration: underline;
  outline: none;
}

.library-crumb:last-child {
  color: var(--navy-heading);
}

.library-crumb-sep {
  color: var(--text-muted);
}

.library-list {
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
  overflow: visible;
}

.library-picker-root .library-list {
  max-height: calc(46 * var(--app-vh));
  overflow-y: auto;
}

.library-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
}

.library-row:first-child {
  border-top-left-radius: calc(var(--radius-sm) - 2px);
  border-top-right-radius: calc(var(--radius-sm) - 2px);
}

.library-row:last-child {
  border-bottom: none;
  border-bottom-left-radius: calc(var(--radius-sm) - 2px);
  border-bottom-right-radius: calc(var(--radius-sm) - 2px);
}

.library-row:hover {
  background: var(--bg-subtle);
}

.library-row-folder {
  flex-wrap: nowrap;
  position: relative;
}

.library-row-folder.menu-open {
  background: var(--bg-subtle);
  z-index: 30;
}

.library-folder-menu-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  margin-left: auto;
}

.library-folder-menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  box-shadow: none;
}

.library-folder-menu-btn:hover,
.library-folder-menu-btn:focus-visible,
.library-folder-menu-btn.active {
  background: var(--bg-card, #ffffff);
  border-color: var(--border-light);
  color: var(--btn-blue);
  outline: none;
}

.library-folder-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 140px;
  background: var(--bg-card, #ffffff);
  border: 1.5px solid var(--border-light);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(10, 31, 68, 0.16);
  z-index: 120;
  display: flex;
  flex-direction: column;
  padding: 4px;
  animation: userDropdownFadeIn 0.14s ease-out;
}

.library-folder-menu.hidden {
  display: none !important;
}

.library-folder-menu.drop-up {
  top: auto;
  bottom: calc(100% + 4px);
}

.library-folder-menu-item {
  appearance: none;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  border-radius: 6px;
  transition: background-color 0.12s ease, color 0.12s ease;
  box-shadow: none;
  white-space: nowrap;
}

.library-folder-menu-item:hover,
.library-folder-menu-item:focus-visible {
  background-color: var(--bg-subtle);
  color: var(--btn-blue);
  outline: none;
}

.library-folder-menu-item-danger {
  color: #dc2626 !important;
}

.library-folder-menu-item-danger:hover,
.library-folder-menu-item-danger:focus-visible {
  background-color: rgba(239, 68, 68, 0.1) !important;
  color: #b91c1c !important;
}

:root[data-theme="dark"] .library-folder-menu-btn:hover,
:root[data-theme="dark"] .library-folder-menu-btn:focus-visible,
:root[data-theme="dark"] .library-folder-menu-btn.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: #3b82f6;
  color: #60a5fa;
}

:root[data-theme="dark"] .library-folder-menu {
  background: #1e293b;
  border-color: var(--border-light);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
}

:root[data-theme="dark"] .library-folder-menu-item {
  color: #f1f5f9;
}

:root[data-theme="dark"] .library-folder-menu-item:hover,
:root[data-theme="dark"] .library-folder-menu-item:focus-visible {
  background-color: rgba(255, 255, 255, 0.08);
  color: #60a5fa;
}

:root[data-theme="dark"] .library-folder-menu-item-danger {
  color: #f87171 !important;
}

:root[data-theme="dark"] .library-folder-menu-item-danger:hover,
:root[data-theme="dark"] .library-folder-menu-item-danger:focus-visible {
  background-color: rgba(239, 68, 68, 0.18) !important;
  color: #fca5a5 !important;
}

.library-row-main {
  flex: 1 1 220px;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  border: none;
  background: none;
  font: inherit;
  color: var(--text-main);
  text-align: left;
}

button.library-row-main,
label.library-row-main {
  cursor: pointer;
}

.library-row-icon {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--text-muted);
}

.library-row-icon.library-icon-folder {
  color: var(--btn-blue);
}

.library-row-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.library-row-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.library-row-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.library-pick-checkbox {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
}

.library-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

.library-pick-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

/* Title popup shown after picking files to upload; sits above the library picker popup. */
.library-title-overlay {
  z-index: 260;
}

.library-title-file {
  margin: -2px 0 8px;
  color: var(--text-muted);
  font-size: 0.86rem;
  word-break: break-all;
}

.library-pick-count {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1.5px solid var(--border-light);
}

.admin-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-danger-outline,
.btn-danger-outline:hover,
.btn-danger-outline:focus-visible {
  background-color: #ffffff;
  color: var(--danger);
  border: 1.5px solid var(--danger);
  box-shadow: none;
}

.popup-grid-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.popup-btn-full {
  grid-column: span 2;
}

.popup-options-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.popup-levels-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.popup-option-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1.5px solid transparent;
  background-color: var(--btn-blue);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.96rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: none;
}

.popup-option-btn:hover,
.popup-option-btn:focus-visible {
  background-color: var(--btn-blue);
  color: #ffffff;
  border-color: transparent;
  transform: none;
  box-shadow: none;
  outline: none;
}

.popup-option-btn.popup-btn-all,
.popup-option-btn.popup-btn-all:hover,
.popup-option-btn.popup-btn-all:focus-visible {
  background-color: var(--navy-1);
  color: #ffffff;
  border-color: transparent;
  box-shadow: none;
}

/* =========================================================
   CÁC TRANG NHỎ (Sub-pages Layout, Cards, Breadcrumb)
   ========================================================= */
.page-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 16px;
  margin-bottom: 22px;
  border-bottom: 2px solid var(--border-light);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.page-title {
  font-size: 1.55rem;
  color: var(--navy-heading);
  margin: 0;
}

.card {
  background: #ffffff;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: 1.15rem;
  color: var(--navy-heading);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* =========================================================
   BÀN CỜ CHESSGROUND & GIAO DIỆN THI ĐẤU / PHÂN TÍCH
   ========================================================= */
.chess-workspace {
  --cg-side-w: clamp(320px, calc(27 * var(--app-vw)), 440px);
  --cg-avail-w: calc(100 * var(--app-vw) - 112px - var(--cg-side-w));
  /* --cg-fit-h is measured by boardFit.js so strips + board + controls fill the viewport height exactly */
  --cg-board-size: clamp(300px, min(var(--cg-avail-w), var(--cg-fit-h, calc(100 * var(--app-vh) - 135px))), 960px);
  display: grid;
  grid-template-columns: auto minmax(320px, 1fr);
  gap: 24px;
  align-items: start;
}

/* Wide screens: equal side tracks keep the board column exactly centered on the page */
@media (min-width: 1200px) {
  .chess-workspace:not(#sim-workspace) {
    /* room for two >=320px side tracks + 2 gaps + page padding + coordinates + scrollbar */
    --cg-avail-w: calc(100 * var(--app-vw) - 800px);
    grid-template-columns: minmax(0, 1fr) auto minmax(320px, 1fr);
  }
  .chess-workspace:not(#sim-workspace) > .board-column {
    grid-column: 2;
    grid-row: 1;
  }
  .chess-workspace:not(#sim-workspace) > .side-panel {
    grid-column: 3;
    grid-row: 1;
    min-width: 0;
  }
}

.board-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.board-with-eval {
  display: flex;
  gap: 10px;
  align-items: stretch;
  position: relative;
  overflow: visible;
  margin-bottom: var(--cg-coord-size, 24px);
  margin-right: var(--cg-coord-size, 24px);
}

.board-with-eval .cg-board-frame {
  margin-bottom: 0;
  margin-right: 0;
}

.eval-bar-wrap {
  width: 26px;
  border-radius: 6px;
  background: #1f2937;
  border: 1.5px solid var(--navy-1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 460px;
}

.eval-bar-black {
  background: #1e293b;
  width: 100%;
  transition: height 0.3s ease;
}

.eval-bar-white {
  background: #f8fafc;
  width: 100%;
  flex: 1;
}

.eval-bar-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  text-align: center;
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--navy-1);
  background: rgba(255, 255, 255, 0.88);
  padding: 2px 1px;
}

:root {
  --cg-frame-color: #3d495f;
  --cg-frame-edge: #566282;
  --cg-square-light: #e9eaed;
  --cg-square-dark: #7b90bc;
}

/* Board look: white / blue squares inside a slate-navy frame that carries the coordinates
   (rank numbers in the left band, file letters in the bottom band). Overrides the vendor
   brown theme, which build-vendor.mjs copies in unchanged. */
cg-board {
  background-color: var(--cg-square-light);
  background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA4IDgiPjxyZWN0IHdpZHRoPSI4IiBoZWlnaHQ9IjgiIGZpbGw9IiNlOWVhZWQiLz48cGF0aCBmaWxsPSIjN2I5MGJjIiBzaGFwZS1yZW5kZXJpbmc9ImNyaXNwRWRnZXMiIGQ9Ik0xIDBoMXYxaC0xek0zIDBoMXYxaC0xek01IDBoMXYxaC0xek03IDBoMXYxaC0xek0wIDFoMXYxaC0xek0yIDFoMXYxaC0xek00IDFoMXYxaC0xek02IDFoMXYxaC0xek0xIDJoMXYxaC0xek0zIDJoMXYxaC0xek01IDJoMXYxaC0xek03IDJoMXYxaC0xek0wIDNoMXYxaC0xek0yIDNoMXYxaC0xek00IDNoMXYxaC0xek02IDNoMXYxaC0xek0xIDRoMXYxaC0xek0zIDRoMXYxaC0xek01IDRoMXYxaC0xek03IDRoMXYxaC0xek0wIDVoMXYxaC0xek0yIDVoMXYxaC0xek00IDVoMXYxaC0xek02IDVoMXYxaC0xek0xIDZoMXYxaC0xek0zIDZoMXYxaC0xek01IDZoMXYxaC0xek03IDZoMXYxaC0xek0wIDdoMXYxaC0xek0yIDdoMXYxaC0xek00IDdoMXYxaC0xek02IDdoMXYxaC0xeiIvPjxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0iIzFjMjc0MCIgc3Ryb2tlLW9wYWNpdHk9Ii4zOCIgc3Ryb2tlLXdpZHRoPSIxIiB2ZWN0b3ItZWZmZWN0PSJub24tc2NhbGluZy1zdHJva2UiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIgZD0iTTEgMHY4TTAgMWg4TTIgMHY4TTAgMmg4TTMgMHY4TTAgM2g4TTQgMHY4TTAgNGg4TTUgMHY4TTAgNWg4TTYgMHY4TTAgNmg4TTcgMHY4TTAgN2g4Ii8+PC9zdmc+');
}

/* The frame box holds the top band, the left band and the board. Its right and bottom bands are
   painted by ::before into the --cg-coord-size gutter that the margins reserve, so the frame is
   the same thickness on all four sides. */
.cg-board-frame,
.sim-manual-board-frame {
  padding: var(--cg-coord-size) 0 0 var(--cg-coord-size);
  overflow: visible;
  position: relative;
  isolation: isolate;
  margin-bottom: var(--cg-coord-size);
  margin-right: var(--cg-coord-size);
}

.cg-board-frame::before,
.sim-manual-board-frame::before {
  content: '';
  position: absolute;
  inset: 0 calc(-1 * var(--cg-coord-size)) calc(-1 * var(--cg-coord-size)) 0;
  z-index: -1;
  background: var(--cg-frame-color);
  border-radius: 4px;
  box-shadow: inset 0 0 0 2px var(--cg-frame-edge), var(--shadow-md);
  pointer-events: none;
}

.cg-board-frame {
  --cg-coord-size: 24px;
  width: var(--cg-board-size, 496px);
  height: var(--cg-board-size, 496px);
}

.cg-board-frame .cg-wrap {
  width: 100%;
  height: 100%;
  overflow: visible;
  position: relative;
}

.cg-board-frame .cg-wrap cg-container {
  overflow: visible;
}

.cg-board-frame .cg-wrap > cg-container {
  width: 100% !important;
  height: 100% !important;
}

.cg-board-frame cg-board {
  border-radius: 0;
  overflow: hidden;
}

.cg-board-frame .cg-wrap coords,
.cg-wrap coords {
  position: absolute;
  display: flex;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  z-index: 3;
}

.cg-board-frame .cg-wrap coords.ranks,
.cg-wrap coords.ranks {
  top: 0;
  right: auto;
  left: calc(-1 * var(--cg-coord-size, 24px));
  flex-flow: column-reverse;
  height: 100%;
  width: var(--cg-coord-size, 24px);
}

.cg-board-frame .cg-wrap coords.ranks.black,
.cg-wrap coords.ranks.black {
  flex-flow: column;
}

.cg-board-frame .cg-wrap coords.ranks coord,
.cg-wrap coords.ranks coord {
  height: 12.5%;
  flex: 0 0 12.5%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transform: none;
  color: #ffffff;
  text-shadow: none;
}

.cg-board-frame .cg-wrap coords.files,
.cg-wrap coords.files {
  bottom: calc(-1 * var(--cg-coord-size, 24px));
  left: 0;
  flex-flow: row;
  width: 100%;
  height: var(--cg-coord-size, 24px);
  text-transform: uppercase;
}

.cg-board-frame .cg-wrap coords.files.black,
.cg-wrap coords.files.black {
  flex-flow: row-reverse;
}

.cg-board-frame .cg-wrap coords.files coord,
.cg-wrap coords.files coord {
  width: 12.5%;
  flex: 0 0 12.5%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: #ffffff;
  text-shadow: none;
}

.cg-board-frame .cg-wrap coords coord,
.cg-wrap coords coord,
.cg-board-frame .cg-wrap coords coord.coord-light,
.cg-wrap coords coord.coord-light,
.cg-board-frame .cg-wrap coords coord.coord-dark,
.cg-wrap coords coord.coord-dark {
  color: #ffffff;
  text-shadow: none;
}

/* The evaluation bar runs the full height of the frame, bottom band included. */
.board-with-eval > .eval-bar-wrap {
  margin-bottom: calc(-1 * var(--an-coord-w, var(--cg-coord-size, 24px)));
}

/* Strips and control cards are as wide as the whole frame (board + both side bands). */
.player-strip {
  width: calc(var(--cg-board-size, 496px) + var(--cg-coord-size, 24px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  background: var(--bg-subtle);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
}

.teacher-demo-controls-card {
  width: calc(var(--cg-board-size, 496px) + var(--cg-coord-size, 24px));
  padding: 14px;
}

/* Whose turn it is: the mover's card gets a thick blue ring, a tinted background, a blue clock and a
   "To move" tab, while the waiting player's card fades back, so the turn reads at a glance. */
.player-strip {
  position: relative;
  transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s, opacity 0.2s;
}

.player-strip.active-turn {
  border-color: var(--btn-blue);
  background: #dbeafe;
  box-shadow: 0 0 0 3px rgba(29, 106, 229, 0.35), 0 6px 18px rgba(29, 106, 229, 0.22);
}

.player-strip.active-turn .player-info {
  color: var(--btn-blue-dark);
}

/* the side marker is a king picture, so the glow follows its outline instead of a box ring */
.player-strip.active-turn .color-dot {
  filter: drop-shadow(0 0 3px rgba(29, 106, 229, 0.9));
  animation: turn-dot-pulse 1.6s ease-in-out infinite;
}

.player-strip.active-turn .clock-box:not(.low-time) {
  background: var(--btn-blue);
  color: #ffffff;
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px var(--btn-blue);
}

/* Inline pill at the start of the row: the strips sit right against the board's coordinate band,
   so a tab sticking out of the card would cover the file letters. */
.player-strip.active-turn::before {
  content: 'Đến lượt';
  flex: none;
  margin-right: 10px;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--btn-blue);
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.6;
  white-space: nowrap;
  pointer-events: none;
}

:root[lang='en'] .player-strip.active-turn::before {
  content: 'To move';
}

/* Wide play layouts put the player cards in their own column, clear of the board: there the pill
   becomes a tab on the card's top edge. */
@media (min-width: 1200px) {
  .play-workspace > .board-column > .player-strip.active-turn::before,
  #sim-workspace > .board-column > .player-strip.active-turn::before {
    position: absolute;
    top: -11px;
    left: 12px;
    margin: 0;
  }
}

.board-column:has(> .player-strip.active-turn) > .player-strip:not(.active-turn) {
  opacity: 0.68;
}

@keyframes turn-dot-pulse {
  0%,
  100% {
    filter: drop-shadow(0 0 3px rgba(29, 106, 229, 0.9));
  }
  50% {
    filter: drop-shadow(0 0 7px rgba(29, 106, 229, 0.55));
  }
}

@media (prefers-reduced-motion: reduce) {
  .player-strip.active-turn .color-dot {
    animation: none;
  }
}

.player-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--navy-heading);
  min-width: 0;
  flex: 1 1 auto;
}

.player-info > span:not(.color-dot):not(.player-ping-badge) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--navy-1);
  display: inline-block;
  flex-shrink: 0;
}

.color-dot.white {
  background: #ffffff;
}

.color-dot.black {
  background: #111827;
}

/* In a player tag the side is shown by a king of that colour in front of the name. */
.player-info .color-dot {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 0;
  background: center / contain no-repeat;
}

.player-info .color-dot.white {
  background-image: url('/assets/pieces/wK.svg');
}

.player-info .color-dot.black {
  background-image: url('/assets/pieces/bK.svg');
}

.clock-box {
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.18rem;
  font-weight: 800;
  padding: 4px 12px;
  border-radius: 6px;
  background: var(--navy-1);
  color: #ffffff;
  min-width: 82px;
  text-align: center;
}

.clock-box.low-time {
  background: var(--danger);
}

/* Biên bản nước đi */
.moves-table-wrap {
  max-height: 230px;
  overflow-y: auto;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: #ffffff;
}

.moves-grid {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) minmax(0, 1fr);
  font-size: 0.9rem;
}

.move-num-cell {
  padding: 6px 8px;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
  border-bottom: 1px solid #eef3fb;
}

.move-san-cell {
  padding: 6px 10px;
  border-bottom: 1px solid #eef3fb;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 500;
  transition: background-color 0.14s ease;
}

.move-san-cell:hover {
  background-color: var(--hover-cyan);
  color: var(--navy-1);
}

.move-san-cell.selected {
  background-color: var(--navy-1);
  color: #ffffff;
  font-weight: 700;
}

/* Nhãn phân loại nước đi khi Phân Tích */
.badge-judgment {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 700;
}

.j-best {
  background: #dcfce7;
  color: #15803d;
}
.j-good {
  background: #e0f2fe;
  color: #0369a1;
}
.j-inaccuracy {
  background: #fef9c3;
  color: #a16207;
}
.j-mistake {
  background: #ffedd5;
  color: #c2410c;
}
.j-blunder {
  background: #fee2e2;
  color: #b91c1c;
}

/* Form Elements */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-weight: 600;
  color: var(--navy-heading);
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.94rem;
  background: #ffffff;
  color: var(--text-main);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--hover-cyan);
  box-shadow: 0 0 0 3px rgba(0, 188, 212, 0.18);
}

/* Level Selector Pills (Căn Bản, Tốt, Mã, Tượng, Xe, Hậu, Vua) */
.levels-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.level-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 99px;
  border: none;
  background: var(--btn-blue);
  color: #ffffff;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: none;
}

.level-tab:hover,
.level-tab:focus-visible {
  background: var(--btn-blue);
  color: #ffffff;
  transform: none;
  box-shadow: none;
  outline: none;
}

.level-tab.active,
.level-tab.active:hover,
.level-tab.active:focus-visible {
  background: var(--navy-1);
  color: #ffffff;
  box-shadow: none;
}

/* Tables (Swiss Standings, Pairings) */
.data-table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.91rem;
}

.data-table th {
  background: var(--navy-1);
  color: #ffffff;
  text-align: left;
  padding: 11px 12px;
  font-weight: 700;
  white-space: nowrap;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}

.data-table tr:hover td {
  background: #f0fbff;
}

/* QR Box */
.qr-display-box {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  border: 2px solid var(--navy-1);
  border-radius: var(--radius-md);
  background: #ffffff;
}

.qr-display-box svg,
.qr-display-box img {
  width: 210px;
  height: 210px;
  display: block;
}

/* Promotion Modal: a large piece picture above each piece name */
.promo-box {
  max-width: 440px;
  text-align: center;
}

.promo-choices {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.promo-piece-btn,
.promo-piece-btn:hover,
.promo-piece-btn:focus-visible {
  padding: 10px 6px 12px;
  border-radius: 10px;
  border: 2px solid var(--border-light);
  background: var(--btn-blue);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 700;
  color: #ffffff;
  box-shadow: none;
  outline: none;
}

.promo-piece-img {
  width: 100%;
  max-width: 72px;
  aspect-ratio: 1;
  display: block;
  padding: 4px;
  border-radius: 8px;
  background: #f0d9b5;
  pointer-events: none;
  user-select: none;
}

.promo-piece-label {
  line-height: 1.2;
  overflow-wrap: anywhere;
}

/* Analysis Workspace & Side-by-Side Summary */
.analysis-workspace {
  --an-eval-w: 24px;
  --an-gap: 8px;
  --an-coord-w: 24px;
  --an-side-w: clamp(330px, calc(28 * var(--app-vw)), 460px);
  --an-avail-w: calc(100 * var(--app-vw) - 88px - var(--an-eval-w) - var(--an-gap) - var(--an-coord-w) - var(--an-side-w));
  --an-board-size: clamp(300px, min(var(--an-avail-w), var(--cg-fit-h, calc(100 * var(--app-vh) - 155px))), 920px);
}

.analysis-workspace .board-column {
  align-items: center;
}

@media (min-width: 1200px) {
  .analysis-workspace {
    --an-avail-w: calc(100 * var(--app-vw) - 800px - var(--an-eval-w) - var(--an-gap));
  }
}

.analysis-workspace .board-with-eval {
  display: flex;
  gap: var(--an-gap);
  align-items: stretch;
  justify-content: center;
  width: auto;
}

.analysis-workspace .cg-board-frame {
  width: var(--an-board-size);
  height: var(--an-board-size);
}

.analysis-workspace .eval-bar-wrap {
  width: var(--an-eval-w);
  min-height: var(--an-board-size);
}

.analysis-workspace .player-strip,
.analysis-workspace .analysis-nav-controls {
  width: calc(var(--an-board-size) + var(--an-eval-w) + var(--an-gap) + var(--an-coord-w, 24px));
  max-width: 100%;
  box-sizing: border-box;
}

.analysis-player-strip {
  min-height: 42px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.analysis-player-strip #btn-an-flip {
  padding: 3px 10px;
  font-size: 0.8rem;
  line-height: 1.2;
}

.analysis-player-strip #an-turn-indicator {
  padding: 3px 8px;
  font-size: 0.78rem;
}

.analysis-nav-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  justify-content: center;
}

.analysis-nav-controls .btn {
  width: 100%;
  justify-content: center;
  padding: 7px 6px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.analysis-summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.analysis-summary-header .card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.analysis-summary-header #recent-games-select {
  width: auto;
  max-width: 100%;
  padding: 6px 10px;
  font-size: 0.82rem;
}

.side-stat-box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 6px;
}

.side-stat-box-header strong {
  font-size: 0.92rem;
  color: var(--text-main);
}

.analysis-stat-items {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 5px;
}

.analysis-stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 5px;
  font-size: 0.8rem;
  color: var(--text-main);
}

.analysis-stat-item strong {
  font-weight: 700;
  margin-left: 6px;
}

.analysis-stat-item-blunder {
  grid-column: span 2;
  color: #dc2626;
  border-color: rgba(239, 68, 68, 0.28);
  background: rgba(239, 68, 68, 0.05);
}

.analysis-tab-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.analysis-tab-bar .btn {
  width: 100%;
  justify-content: center;
  padding: 9px 12px;
  font-weight: 600;
}

.analysis-panel-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 0 0 12px;
  line-height: 1.45;
}

.analysis-mistake-filter-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.analysis-mistake-filter-bar .btn {
  width: 100%;
  justify-content: center;
  padding: 7px 8px;
  font-size: 0.82rem;
  font-weight: 600;
}

.analysis-mistake-helper-btns {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.analysis-mistake-helper-btns .btn {
  width: 100%;
  justify-content: center;
  padding: 7px 6px;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}

.analysis-mistakes-scroll {
  max-height: 250px;
  overflow-y: auto;
  padding-right: 2px;
}

.analysis-moves-table-wrap {
  max-height: 290px;
}

.dual-stats-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

/* With the board centered the analysis side column can be narrow: stack the two summary boxes */
.analysis-side-panel {
  container-type: inline-size;
}

@container (max-width: 460px) {
  .dual-stats-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.side-stat-box {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-light);
  background: var(--bg-subtle);
}

.eval-chart-box {
  width: 100%;
  height: 110px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #1e293b;
  margin-bottom: 14px;
  cursor: pointer;
}

.mistake-item-card {
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-light);
  margin-bottom: 9px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.mistake-item-card:hover {
  border-color: var(--hover-cyan);
  background: #f0fcff;
}

.mistake-item-card.active-mistake {
  border-color: var(--navy-1);
  border-left: 5px solid var(--btn-blue);
  background: #edf5ff;
}

.mistake-item-card.solved-mistake {
  border-color: var(--success);
  background: #f0fdf4;
}

/* Banners & Alerts */
.status-banner {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border-left: 4px solid var(--btn-blue);
  margin-bottom: 14px;
  font-size: 0.93rem;
}

.status-banner.success {
  background: #ecfdf5;
  border-left-color: var(--success);
  color: #065f46;
}

.status-banner.warning {
  background: #fffbeb;
  border-left-color: var(--warning);
  color: #92400e;
}

.status-banner.danger {
  background: #fef2f2;
  border-left-color: var(--danger);
  color: #991b1b;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast-item {
  background: var(--navy-1);
  color: #ffffff;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--hover-cyan);
  box-shadow: var(--shadow-md);
  font-size: 0.9rem;
  font-weight: 600;
  animation: popIn 0.18s ease-out;
}

/* Footer */
.site-footer {
  background: var(--navy-1);
  color: #dbeafe;
  padding: 18px 0;
  font-size: 0.88rem;
  margin-top: auto;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.footer-links {
  display: flex;
  gap: 16px;
}

.footer-links a {
  color: #ffffff;
}

.footer-links a:hover {
  color: var(--hover-cyan-bright);
}

/* =========================================================
   DARK THEME COMPONENT OVERRIDES
   ========================================================= */
:root[data-theme="dark"] .card,
:root[data-theme="dark"] .popup-box,
:root[data-theme="dark"] .popup-card,
:root[data-theme="dark"] .home-welcome-banner,
:root[data-theme="dark"] .hero-banner,
:root[data-theme="dark"] .feature-column-card,
:root[data-theme="dark"] .admin-toolbar {
  background-color: var(--bg-card);
  border-color: var(--border-light);
}

:root[data-theme="dark"] .home-welcome-banner {
  border-top-color: var(--border-navy);
}

:root[data-theme="dark"] .feature-column-card {
  border-top-color: var(--btn-blue);
}

:root[data-theme="dark"] .feature-column-card:hover {
  border-color: var(--hover-cyan);
  border-top-color: var(--hover-cyan);
}

:root[data-theme="dark"] .btn-outline,
:root[data-theme="dark"] .btn-outline:hover,
:root[data-theme="dark"] .btn-outline:focus-visible {
  background-color: transparent;
  color: #93c5fd;
  border-color: #3b82f6;
  box-shadow: none;
}

:root[data-theme="dark"] .btn-danger-outline,
:root[data-theme="dark"] .btn-danger-outline:hover,
:root[data-theme="dark"] .btn-danger-outline:focus-visible {
  background-color: transparent;
  color: #f87171;
  border-color: #ef4444;
  box-shadow: none;
}

:root[data-theme="dark"] .form-input,
:root[data-theme="dark"] .form-select,
:root[data-theme="dark"] .form-textarea {
  background-color: var(--bg-subtle);
  color: var(--text-main);
  border-color: var(--border-light);
}

:root[data-theme="dark"] .form-input:focus,
:root[data-theme="dark"] .form-select:focus,
:root[data-theme="dark"] .form-textarea:focus {
  border-color: var(--hover-cyan);
  box-shadow: 0 0 0 3px rgba(0, 188, 212, 0.25);
}

:root[data-theme="dark"] .moves-table-wrap {
  background-color: var(--bg-card);
  border-color: var(--border-light);
}

:root[data-theme="dark"] .move-num-cell {
  background-color: var(--bg-subtle);
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-light);
}

:root[data-theme="dark"] .move-san-cell {
  color: var(--text-main);
  border-bottom: 1px solid var(--border-light);
}

:root[data-theme="dark"] .move-san-cell:hover {
  background-color: var(--hover-cyan);
  color: var(--navy-1);
}

:root[data-theme="dark"] .move-san-cell.selected {
  background-color: var(--btn-blue);
  color: #ffffff;
}

:root[data-theme="dark"] .data-table th {
  background-color: var(--navy-2);
  color: #ffffff;
}

:root[data-theme="dark"] .data-table td {
  border-bottom-color: var(--border-light);
  color: var(--text-main);
}

:root[data-theme="dark"] .data-table tr:hover td {
  background-color: var(--bg-subtle);
}

:root[data-theme="dark"] .player-strip {
  background-color: var(--bg-subtle);
  border-color: var(--border-light);
}

:root[data-theme="dark"] .player-strip.active-turn {
  background-color: rgba(37, 99, 235, 0.32);
  border-color: var(--border-navy);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.4), 0 6px 18px rgba(37, 99, 235, 0.3);
}

:root[data-theme="dark"] .player-strip.active-turn .player-info {
  color: #e0f2fe;
}

:root[data-theme="dark"] .player-strip.active-turn .clock-box:not(.low-time) {
  background-color: #0369a1;
  color: #ffffff;
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px #38bdf8;
}

:root[data-theme="dark"] .player-strip.active-turn::before {
  background: #0284c7;
}

:root[data-theme="dark"] .color-dot {
  border-color: var(--border-light);
}

/* a black king on the dark theme's navy strip needs a light halo to stay visible */
:root[data-theme="dark"] .player-info .color-dot.black {
  filter: drop-shadow(0 0 1.5px rgba(255, 255, 255, 0.85));
}

/* keep that halo under the turn glow */
:root[data-theme="dark"] .player-strip.active-turn .player-info .color-dot.black {
  animation-name: turn-dot-pulse-halo;
}

@keyframes turn-dot-pulse-halo {
  0%,
  100% {
    filter: drop-shadow(0 0 1.5px rgba(255, 255, 255, 0.85)) drop-shadow(0 0 3px rgba(56, 189, 248, 0.9));
  }
  50% {
    filter: drop-shadow(0 0 1.5px rgba(255, 255, 255, 0.85)) drop-shadow(0 0 7px rgba(56, 189, 248, 0.55));
  }
}

:root[data-theme="dark"] .mistake-item-card {
  background-color: var(--bg-card);
  border-color: var(--border-light);
}

:root[data-theme="dark"] .mistake-item-card:hover {
  background-color: var(--bg-subtle);
  border-color: var(--hover-cyan);
}

:root[data-theme="dark"] .mistake-item-card.active-mistake {
  background-color: rgba(37, 99, 235, 0.22);
  border-color: var(--border-navy);
}

:root[data-theme="dark"] .mistake-item-card.solved-mistake {
  background-color: rgba(18, 153, 90, 0.18);
  border-color: var(--success);
}

:root[data-theme="dark"] .side-stat-box {
  background-color: var(--bg-subtle);
  border-color: var(--border-light);
}

:root[data-theme="dark"] .analysis-stat-item {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-light);
  color: var(--text-main);
}

:root[data-theme="dark"] .analysis-stat-item-blunder {
  color: #f87171;
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.3);
}

:root[data-theme="dark"] .status-banner {
  background-color: var(--bg-subtle);
  color: var(--text-main);
  border-left-color: var(--btn-blue);
}

:root[data-theme="dark"] .status-banner.success {
  background-color: rgba(18, 153, 90, 0.18);
  border-left-color: var(--success);
  color: #6ee7b7;
}

:root[data-theme="dark"] .status-banner.warning {
  background-color: rgba(217, 119, 6, 0.18);
  border-left-color: var(--warning);
  color: #fcd34d;
}

:root[data-theme="dark"] .status-banner.danger {
  background-color: rgba(220, 38, 38, 0.18);
  border-left-color: var(--danger);
  color: #fca5a5;
}

:root[data-theme="dark"] .j-best {
  background: rgba(34, 197, 94, 0.22);
  color: #4ade80;
}

:root[data-theme="dark"] .j-good {
  background: rgba(56, 189, 248, 0.22);
  color: #38bdf8;
}

:root[data-theme="dark"] .j-inaccuracy {
  background: rgba(234, 179, 8, 0.22);
  color: #fde047;
}

:root[data-theme="dark"] .j-mistake {
  background: rgba(249, 115, 22, 0.22);
  color: #fb923c;
}

:root[data-theme="dark"] .j-blunder {
  background: rgba(239, 68, 68, 0.22);
  color: #f87171;
}

:root[data-theme="dark"] .eval-bar-label {
  color: #0b1326;
}

:root[data-theme="dark"] .popup-box,
:root[data-theme="dark"] .popup-card {
  border-top-color: var(--border-navy);
}

:root[data-theme="dark"] .page-header-bar {
  border-bottom-color: var(--border-light);
}

:root[data-theme="dark"] .site-footer {
  background-color: var(--navy-1);
  border-top: 1px solid var(--border-light);
}

:root[data-theme="dark"] .popup-option-btn.popup-btn-all,
:root[data-theme="dark"] .popup-option-btn.popup-btn-all:hover,
:root[data-theme="dark"] .popup-option-btn.popup-btn-all:focus-visible {
  background-color: var(--navy-2);
  color: #ffffff;
  border-color: var(--border-navy);
  box-shadow: none;
}

:root[data-theme="dark"] .user-dropdown-menu,
:root[data-theme="dark"] .settings-dropdown-menu {
  background: #14233a;
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}

:root[data-theme="dark"] .user-dropdown-item,
:root[data-theme="dark"] .user-dropdown-item:hover,
:root[data-theme="dark"] .user-dropdown-item:focus-visible {
  background-color: transparent;
  color: #e2e8f0;
}

:root[data-theme="dark"] .user-dropdown-item.user-dropdown-item-danger,
:root[data-theme="dark"] .user-dropdown-item.user-dropdown-item-danger:hover,
:root[data-theme="dark"] .user-dropdown-item.user-dropdown-item-danger:focus-visible {
  background-color: transparent;
  color: #f87171;
  border-top-color: rgba(255, 255, 255, 0.12);
}

:root[data-theme="dark"] .profile-fullname {
  color: #ffffff;
}

:root[data-theme="dark"] .profile-rating-highlight {
  color: var(--hover-cyan-bright);
}

:root[data-theme="dark"] .profile-details-grid {
  background: #0f1c2e;
  border-color: rgba(255, 255, 255, 0.1);
}

:root[data-theme="dark"] .profile-header-strip {
  border-bottom-color: rgba(255, 255, 255, 0.12);
}

:root[data-theme="dark"] .profile-role-admin {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.35);
}

:root[data-theme="dark"] .profile-role-user {
  background: rgba(56, 189, 248, 0.18);
  color: #7dd3fc;
  border-color: rgba(56, 189, 248, 0.3);
}

:root[data-theme="dark"] .profile-status-badge {
  color: #4ade80;
}

/* =========================================================
   CURRICULUM LESSON TIERS (TIER 1: LIST, TIER 2: DETAIL)
   ========================================================= */
.lesson-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
  margin-top: 14px;
}

.lesson-select-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-top: 4px solid var(--navy-1);
  border-radius: var(--radius-md);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  cursor: pointer;
}

.lesson-select-card:hover {
  border-color: var(--hover-cyan);
  border-top-color: var(--hover-cyan);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.lesson-badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #ffffff;
  background: var(--navy-1);
  padding: 3px 12px;
  border-radius: 99px;
}

.exercise-type-badge {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  padding: 2px 8px;
  border-radius: 99px;
}

.lesson-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.lesson-card-title {
  font-size: 1.15rem;
  color: var(--navy-heading);
  margin: 0 0 8px;
  line-height: 1.4;
  font-weight: 700;
  overflow-wrap: break-word;
  word-break: break-word;
}

.lesson-points-count {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--btn-blue);
  margin-bottom: 10px;
}

.lesson-card-preview {
  margin: 0 0 16px;
  padding-left: 18px;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.lesson-card-preview li {
  margin-bottom: 4px;
}

.lesson-card-footer {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.exercise-admin-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.exercise-admin-actions .btn {
  width: 100%;
  justify-content: center;
}

.exercise-chapter-card {
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.exercise-chapter-header {
  border-bottom: 1.5px solid var(--border-light);
}

.exercise-chapter-header .col-badge {
  margin: 0 !important;
  margin-bottom: 0 !important;
  vertical-align: middle;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.exercise-chapter-header h3 {
  margin: 0 !important;
  display: inline-flex;
  align-items: center;
  line-height: 1.3;
  vertical-align: middle;
}

.lesson-points-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 14px 0;
}

.lesson-point-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px 16px;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--navy-1);
  transition: transform 0.15s ease;
}

.lesson-point-item:hover {
  transform: translateX(2px);
}

.lesson-point-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--navy-1);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.lesson-point-text {
  font-size: 0.94rem;
  line-height: 1.55;
  color: var(--text-main);
  flex: 1;
}

.lesson-nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}

:root[data-theme="dark"] .lesson-select-card {
  background: var(--bg-card);
  border-color: var(--border-light);
  border-top-color: var(--hover-cyan);
}

:root[data-theme="dark"] .lesson-select-card:hover {
  border-color: var(--hover-cyan-bright);
  border-top-color: var(--hover-cyan-bright);
}

:root[data-theme="dark"] .lesson-badge {
  background: var(--navy-2);
  color: var(--hover-cyan);
  border: 1px solid var(--border-navy);
}

:root[data-theme="dark"] .exercise-type-badge {
  background: var(--navy-2);
  color: var(--text-muted);
  border-color: var(--border-light);
}

:root[data-theme="dark"] .lesson-point-item {
  background: var(--bg-subtle);
  border-left-color: var(--hover-cyan);
}

:root[data-theme="dark"] .lesson-point-num {
  background: var(--btn-blue);
  color: #ffffff;
}

/* Responsive */
@media (max-width: 1100px) {
  .four-columns-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 960px) {
  .chess-workspace {
    grid-template-columns: minmax(0, 1fr);
    justify-items: stretch;
    gap: 16px;
  }
  .chess-workspace > .side-panel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .board-column {
    width: 100%;
    align-items: stretch;
  }
  .cg-board-frame {
    width: calc(100% - var(--cg-coord-size, 24px));
    height: auto;
    aspect-ratio: 1 / 1;
    margin-bottom: var(--cg-coord-size, 24px);
    margin-right: var(--cg-coord-size, 24px);
  }
  .player-strip,
  .teacher-demo-controls-card {
    width: 100%;
    max-width: 100%;
    margin-right: 0;
  }
  .analysis-workspace .board-with-eval {
    width: calc(100% - var(--an-coord-w, 24px));
    margin-right: var(--an-coord-w, 24px);
    margin-bottom: var(--an-coord-w, 24px);
    justify-content: flex-start;
  }
  .analysis-workspace .cg-board-frame {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    height: auto;
    aspect-ratio: 1 / 1;
  }
  .analysis-workspace .eval-bar-wrap {
    flex: 0 0 var(--an-eval-w, 24px);
    width: var(--an-eval-w, 24px);
    min-height: 0;
  }
  .analysis-workspace .player-strip,
  .analysis-workspace .analysis-nav-controls {
    width: 100%;
    max-width: 100%;
    margin-right: 0;
  }
  .bar-1-inner {
    flex-wrap: wrap;
    padding-top: 8px;
    padding-bottom: 8px;
    min-height: auto;
  }
  .main-nav-bar {
    order: 3;
    flex: 0 0 100%;
    width: 100%;
    margin: 6px 0 0 0;
    justify-content: space-between;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding-top: 6px;
    gap: 3px;
  }
  .nav-col-btn {
    padding: 5px 8px;
    font-size: 0.82rem;
    min-height: 30px;
    flex: 1;
    justify-content: center;
  }
}

@media (max-width: 820px) {
  .profile-page-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .main-nav-bar {
    display: none;
  }
  .four-columns-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .hero-banner {
    flex-direction: column;
    align-items: flex-start;
  }
  .popup-levels-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .dual-stats-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .lesson-cards-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }
  .lesson-nav-bar {
    flex-direction: column;
    align-items: stretch;
  }
}

/* =========================================================================
   USERS DIRECTORY PAGE (#/users)
   ========================================================================= */
.users-card {
  padding: 0;
}

.users-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}

.users-card-title {
  margin: 6px 0 6px;
  font-size: 1.35rem;
  color: var(--navy-heading);
}

.users-card-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.users-count-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 10px 20px;
  min-width: 110px;
}

.users-count-num {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--btn-blue);
  line-height: 1.1;
}

.users-count-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-top: 2px;
}

.users-table-wrap {
  width: 100%;
  overflow-x: auto;
  min-height: auto;
  padding-bottom: 0;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  background-color: var(--bg-card);
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.94rem;
  table-layout: fixed;
}

.users-table thead th {
  background-color: var(--navy-2);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 13px 16px;
  border-bottom: 2px solid var(--navy-1);
  white-space: nowrap;
  vertical-align: middle;
}

.users-table tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-main);
  vertical-align: middle;
  overflow-wrap: break-word;
  word-break: break-word;
}

.users-table tbody tr:last-child td {
  border-bottom: none;
}

.users-table tbody tr:hover td {
  background-color: var(--bg-subtle);
}

.users-table tbody tr.users-row-current td {
  background-color: rgba(21, 101, 192, 0.06);
}

.users-col-rank {
  width: 80px;
  text-align: center !important;
  vertical-align: middle;
}

.users-col-username {
  vertical-align: middle;
}

.users-col-fullname {
  vertical-align: middle;
}

.users-col-role {
  vertical-align: middle;
}

.users-col-status {
  vertical-align: middle;
}

.users-col-games {
  vertical-align: middle;
  text-align: right !important;
  white-space: nowrap;
}

.users-col-elo {
  width: 84px;
  text-align: center !important;
  vertical-align: middle;
  white-space: nowrap;
}

.users-col-elo .users-elo-pill {
  padding: 2px 8px;
}

.users-col-action {
  width: 120px;
  text-align: right !important;
  vertical-align: middle;
}

.user-cell-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  vertical-align: middle;
  line-height: 1.4;
  min-height: 28px;
  max-width: 100%;
}

.user-cell-wrap strong {
  vertical-align: middle;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.users-rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  background-color: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  vertical-align: middle;
}

.users-rank-badge.rank-top-1 {
  background-color: var(--navy-1);
  color: #ffffff;
  border-color: var(--navy-1);
}

.users-rank-badge.rank-top-2 {
  background-color: var(--btn-blue);
  color: #ffffff;
  border-color: var(--btn-blue);
}

.users-rank-badge.rank-top-3 {
  background-color: #0284c7;
  color: #ffffff;
  border-color: #0284c7;
}

.user-you-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  background-color: rgba(21, 101, 192, 0.14);
  color: var(--btn-blue);
  vertical-align: middle;
  line-height: 1.2;
}

.user-list-fullname {
  color: var(--text-main);
  font-weight: 500;
  vertical-align: middle;
}

.user-list-empty {
  color: var(--text-muted);
  opacity: 0.65;
  vertical-align: middle;
}

.users-rating-games-wrap {
  flex-wrap: wrap;
  gap: 6px;
}

.users-elo-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  vertical-align: middle;
  white-space: nowrap;
}

.users-elo-pill.rated {
  background-color: rgba(16, 185, 129, 0.14);
  color: #047857;
  border: 1px solid rgba(16, 185, 129, 0.34);
}

.users-elo-pill.unrated {
  background-color: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  font-weight: 500;
}

/* still playing the first rated games (initial rating period): "3/5" */
.users-elo-pill.provisional {
  background-color: rgba(217, 119, 6, 0.12);
  color: var(--warning);
  border: 1px dashed var(--warning);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

:root[data-theme="dark"] .users-elo-pill.rated {
  background-color: rgba(16, 185, 129, 0.22);
  color: #6ee7b7;
  border-color: rgba(52, 211, 153, 0.42);
}

.users-games-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: 999px;
  background-color: rgba(21, 101, 192, 0.1);
  color: var(--navy-heading);
  font-size: 0.86rem;
  vertical-align: middle;
  border: 1px solid rgba(21, 101, 192, 0.22);
}

.user-admin-protected-tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  background-color: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-light);
}

.users-action-wrap {
  position: relative;
  display: inline-flex;
  justify-content: flex-end;
}

.users-action-gear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1.5px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0;
  box-shadow: none;
}

.users-action-gear-btn:hover,
.users-action-gear-btn:focus-visible,
.users-action-gear-btn.active {
  color: var(--btn-blue);
  border-color: var(--btn-blue);
  background: var(--bg-subtle);
  outline: none;
}

.users-action-gear-icon {
  display: block;
  pointer-events: none;
  transition: transform 0.2s ease;
}

.users-action-gear-btn.active .users-action-gear-icon {
  transform: rotate(45deg);
}

.users-action-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 195px;
  background: #ffffff;
  border: 1.5px solid var(--border-light);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(10, 31, 68, 0.18);
  z-index: 120;
  display: flex;
  flex-direction: column;
  padding: 5px 0;
  animation: userDropdownFadeIn 0.15s ease-out;
}

.users-action-dropdown.hidden {
  display: none !important;
}

.users-action-dropdown.drop-up {
  top: auto;
  bottom: calc(100% + 4px);
}

.users-action-item {
  appearance: none;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  transition: background-color 0.12s ease;
  box-shadow: none;
}

.users-action-item:hover,
.users-action-item:focus-visible {
  background-color: var(--bg-subtle);
  outline: none;
}

.users-action-item-icon {
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
}

.users-action-item-danger {
  color: #dc2626 !important;
  border-top: 1px solid var(--border-light);
  margin-top: 3px;
  padding-top: 8px;
}

.users-action-item-danger:hover,
.users-action-item-danger:focus-visible {
  background-color: rgba(239, 68, 68, 0.08) !important;
  color: #b91c1c !important;
}

.users-pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 0;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
}

.users-pagination-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.users-page-btn {
  min-width: 34px;
  justify-content: center;
}

.users-pagination-select-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.users-pagination-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.users-page-select {
  width: auto;
  min-width: 170px;
  padding: 6px 10px;
  font-size: 0.88rem;
}

.btn-danger,
.btn-danger:hover,
.btn-danger:focus-visible {
  background-color: #dc2626;
  color: #ffffff;
  border: 1px solid #dc2626;
  box-shadow: none;
}

:root[data-theme="dark"] .users-table tbody tr.users-row-current td {
  background-color: rgba(37, 99, 235, 0.16);
}

:root[data-theme="dark"] .users-games-pill {
  background-color: rgba(56, 189, 248, 0.14);
  color: #e2e8f0;
  border-color: rgba(56, 189, 248, 0.3);
}

:root[data-theme="dark"] .user-you-badge {
  background-color: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
}

/* User Management & Classes Styles */
.stat-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 10px;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

/* Class Management Grid & Card Layout */
.classes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  align-items: stretch;
}

.class-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  display: flex;
  flex-direction: column;
  justify-content: center;
  cursor: pointer;
  position: relative;
  text-align: left;
}

.class-card:hover {
  border-color: var(--primary);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
  transform: translateY(-2px);
}

.class-card:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.class-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
}

.class-card-icon-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.class-card-avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.class-card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.class-card-members-badge {
  background: rgba(16, 185, 129, 0.15);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 3px 9px;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  white-space: nowrap;
}

.class-card-desc {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.class-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-subtle);
  border-radius: 8px;
  margin-bottom: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.class-card-hint {
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: transform 0.15s ease;
}

.class-card:hover .class-card-hint {
  transform: translateX(3px);
}

.class-card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
  flex-wrap: wrap;
}

.class-members-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}

.class-members-search-wrap input:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn-reports-large {
  width: 100%;
  padding: 18px 20px;
  border-radius: 12px;
  border: 2px solid #f59e0b;
  background: rgba(245, 158, 11, 0.08);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  transition: all 0.2s ease;
  text-align: left;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
  font-family: inherit;
  flex-wrap: wrap;
}

.btn-reports-large:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.15);
  background: rgba(245, 158, 11, 0.12);
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

:root[data-theme="dark"] .class-card {
  background: var(--bg-card);
  border-color: var(--border-light);
}

:root[data-theme="dark"] .class-card:hover {
  border-color: var(--primary);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}

:root[data-theme="dark"] .class-card-avatar {
  background: rgba(37, 99, 235, 0.2);
  color: #60a5fa;
}

:root[data-theme="dark"] .class-card-members-badge {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.4);
}

:root[data-theme="dark"] .class-card-meta {
  background: rgba(255, 255, 255, 0.04);
}

/* =========================================================
   ADMIN SYSTEM MANAGEMENT 2-COLUMN SPLIT LAYOUT
   Left: User Management
   Right: Statistics (top) & Issue Reports (bottom)
   ========================================================= */
.system-manage-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  width: 100%;
}

.system-manage-col-left {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.system-manage-col-right {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.system-manage-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}

.system-manage-stats-grid .stat-card {
  padding: 14px 16px;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

@media (max-width: 1100px) {
  .system-manage-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* =========================================================
   MANAGE USERS ACTION OPTIONS POPOVER / DROPDOWN
   ========================================================= */
.manage-user-row {
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.manage-user-row:hover {
  background-color: var(--bg-subtle);
}

.manage-user-row:focus-visible {
  outline: 2px solid var(--btn-blue, #2563eb);
  outline-offset: -2px;
  background-color: var(--bg-subtle);
}

.manage-user-row.options-active {
  background-color: var(--bg-subtle) !important;
}

.manage-user-options-popover {
  position: fixed;
  min-width: 195px;
  max-width: min(260px, calc(100 * var(--app-vw) - 24px));
  max-height: calc(100 * var(--app-vh) - 24px);
  overflow-y: auto;
  background: var(--bg-card, #ffffff);
  border: 1.5px solid var(--border-light, #e2e8f0);
  border-radius: 10px;
  box-shadow: 0 10px 25px -4px rgba(10, 31, 68, 0.18), 0 4px 10px -2px rgba(10, 31, 68, 0.08);
  z-index: 1050;
  display: flex;
  flex-direction: column;
  padding: 6px;
  animation: userDropdownFadeIn 0.14s ease-out;
}

.manage-user-options-header {
  padding: 6px 10px 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.manage-user-options-header span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.manage-user-options-item {
  appearance: none;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  border-radius: 6px;
  transition: background-color 0.12s ease, color 0.12s ease;
  box-shadow: none;
}

.manage-user-options-item:hover:not(:disabled),
.manage-user-options-item:focus-visible:not(:disabled) {
  background-color: var(--bg-subtle);
  color: var(--btn-blue, #2563eb);
  outline: none;
}

.manage-user-options-item-danger {
  color: #dc2626 !important;
}

.manage-user-options-item-danger:hover:not(:disabled),
.manage-user-options-item-danger:focus-visible:not(:disabled) {
  background-color: rgba(239, 68, 68, 0.1) !important;
  color: #b91c1c !important;
}

.manage-user-options-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

:root[data-theme="dark"] .manage-user-row:hover,
:root[data-theme="dark"] .manage-user-row.options-active {
  background-color: rgba(255, 255, 255, 0.06) !important;
}

:root[data-theme="dark"] .manage-user-options-popover {
  background: #1e293b;
  border-color: #334155;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
}

:root[data-theme="dark"] .manage-user-options-header {
  color: #94a3b8;
  border-bottom-color: #334155;
}

:root[data-theme="dark"] .manage-user-options-item {
  color: #f1f5f9;
}

:root[data-theme="dark"] .manage-user-options-item:hover:not(:disabled),
:root[data-theme="dark"] .manage-user-options-item:focus-visible:not(:disabled) {
  background-color: rgba(255, 255, 255, 0.08);
  color: #60a5fa;
}

:root[data-theme="dark"] .manage-user-options-item-danger {
  color: #f87171 !important;
}

:root[data-theme="dark"] .manage-user-options-item-danger:hover:not(:disabled),
:root[data-theme="dark"] .manage-user-options-item-danger:focus-visible:not(:disabled) {
  background-color: rgba(239, 68, 68, 0.18) !important;
  color: #fca5a5 !important;
}

/* =========================================================================
   COMPREHENSIVE DARK THEME HIGH-CONTRAST FIXES
   ========================================================================= */
:root[data-theme="dark"] .col-badge,
:root[data-theme="dark"] .popup-badge {
  color: #38bdf8;
  background-color: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.38);
}

:root[data-theme="dark"] .col-icon-wrap {
  color: #38bdf8;
  background-color: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.38);
}

:root[data-theme="dark"] .breadcrumb a {
  color: #7dd3fc;
}

:root[data-theme="dark"] .breadcrumb a:hover {
  color: var(--hover-cyan-bright);
}

:root[data-theme="dark"] .breadcrumb strong {
  color: #f8fafc;
}

:root[data-theme="dark"] .level-tab,
:root[data-theme="dark"] .level-tab:hover,
:root[data-theme="dark"] .level-tab:focus-visible {
  background-color: var(--bg-subtle);
  color: #e2e8f0;
  border: 1px solid var(--border-light);
  box-shadow: none;
}

:root[data-theme="dark"] .level-tab.active,
:root[data-theme="dark"] .level-tab.active:hover,
:root[data-theme="dark"] .level-tab.active:focus-visible {
  background-color: var(--btn-blue);
  color: #ffffff;
  border: 1px solid var(--btn-blue);
  font-weight: 800;
  box-shadow: none;
}

:root[data-theme="dark"] .clock-box {
  background-color: #091224;
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.38);
}

:root[data-theme="dark"] .clock-box.low-time {
  background-color: var(--danger);
  color: #ffffff;
  border-color: #f87171;
}

:root[data-theme="dark"] .home-welcome-hint {
  background-color: rgba(56, 189, 248, 0.14);
  color: #7dd3fc;
  border-color: rgba(56, 189, 248, 0.35);
}

:root[data-theme="dark"] .lesson-points-count {
  color: #38bdf8;
}

:root[data-theme="dark"] .exercise-type-badge {
  background-color: rgba(56, 189, 248, 0.14);
  color: #bae6fd;
  border-color: rgba(56, 189, 248, 0.32);
}

:root[data-theme="dark"] .users-count-num {
  color: #38bdf8;
}

:root[data-theme="dark"] .users-count-label {
  color: #cbd5e1;
}

:root[data-theme="dark"] .users-rank-badge {
  background-color: var(--bg-subtle);
  color: #e2e8f0;
  border-color: var(--border-light);
}

:root[data-theme="dark"] .users-rank-badge.rank-top-1 {
  background-color: #38bdf8;
  color: #0a1f44;
  border-color: #7dd3fc;
  font-weight: 800;
}

:root[data-theme="dark"] .users-rank-badge.rank-top-2 {
  background-color: #2563eb;
  color: #ffffff;
  border-color: #60a5fa;
}

:root[data-theme="dark"] .users-rank-badge.rank-top-3 {
  background-color: #0284c7;
  color: #ffffff;
  border-color: #38bdf8;
}

:root[data-theme="dark"] .user-admin-protected-tag {
  background-color: rgba(56, 189, 248, 0.14);
  color: #7dd3fc;
  border-color: rgba(56, 189, 248, 0.32);
}

:root[data-theme="dark"] .users-action-gear-btn {
  background: var(--bg-subtle);
  border-color: var(--border-light);
  color: var(--text-muted);
}

:root[data-theme="dark"] .users-action-gear-btn:hover,
:root[data-theme="dark"] .users-action-gear-btn.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: #3b82f6;
  color: #60a5fa;
}

:root[data-theme="dark"] .users-action-dropdown {
  background: #1e293b;
  border-color: var(--border-light);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
}

:root[data-theme="dark"] .users-action-item {
  color: #f1f5f9;
}

:root[data-theme="dark"] .users-action-item:hover,
:root[data-theme="dark"] .users-action-item:focus-visible {
  background-color: rgba(255, 255, 255, 0.08);
}

:root[data-theme="dark"] .users-action-item-danger {
  color: #f87171 !important;
  border-top-color: var(--border-light);
}

:root[data-theme="dark"] .users-action-item-danger:hover,
:root[data-theme="dark"] .users-action-item-danger:focus-visible {
  background-color: rgba(239, 68, 68, 0.18) !important;
  color: #fca5a5 !important;
}

:root[data-theme="dark"] .form-input::placeholder,
:root[data-theme="dark"] .form-textarea::placeholder {
  color: #94a3b8;
  opacity: 1;
}

/* =========================================================================
   LEVEL SELECTION GRID (#/curriculum & #/exercises)
   ========================================================================= */
.level-choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 20px;
  margin-top: 8px;
}

.level-choice-card {
  background-color: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-top: 5px solid var(--navy-1);
  border-radius: var(--radius-md);
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.level-choice-card:hover {
  border-color: var(--hover-cyan);
  border-top-color: var(--hover-cyan);
  box-shadow: var(--shadow-md);
  transform: translateY(-3px);
}

.level-choice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.level-choice-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
}

.level-choice-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background-color: var(--navy-1, #0a1f44);
  background-image: linear-gradient(135deg, var(--navy-1, #0a1f44) 0%, var(--navy-2, #123066) 100%);
  border: 1px solid rgba(10, 31, 68, 0.16);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 6px;
  box-shadow: 0 2px 6px rgba(10, 31, 68, 0.14);
}

.level-choice-icon.sm {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  padding: 4px;
}

.level-choice-icon img,
.level-choice-icon svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.level-tab-icon {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: var(--navy-1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 3px;
}

.level-tab-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

:root[data-theme="dark"] .level-choice-icon {
  background-color: #16376b;
  background-image: linear-gradient(135deg, #16376b 0%, #0e7490 100%);
  border-color: rgba(56, 189, 248, 0.38);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

@keyframes hdcSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.btn-refresh-users.is-loading svg {
  animation: hdcSpin 0.8s linear infinite;
}

.level-choice-title {
  font-size: 1.32rem;
  font-weight: 800;
  color: var(--navy-heading);
  margin: 0;
  line-height: 1.3;
  flex: 1 1 auto;
  min-width: 0;
  word-break: break-word;
  overflow-wrap: break-word;
}

.level-choice-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.level-choice-actions .btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
}

.level-choice-desc {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.55;
}

:root[data-theme="dark"] .level-choice-card {
  background-color: var(--bg-card);
  border-color: var(--border-light);
  border-top-color: var(--hover-cyan);
}

:root[data-theme="dark"] .level-choice-card:hover {
  border-color: var(--hover-cyan-bright);
  border-top-color: var(--hover-cyan-bright);
}

/* Levels of a class as a numbered list (#/curriculum & #/exercises): one row per level, in the
   order set by the admin (move up / move down buttons). */
.level-choice-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.level-choice-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 18px;
  background-color: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-left: 5px solid var(--navy-1);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.level-choice-row:hover {
  border-color: var(--hover-cyan);
  border-left-color: var(--hover-cyan);
  box-shadow: var(--shadow-md);
}

.level-row-index {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  color: var(--navy-heading);
  font-weight: 800;
  font-size: 0.9rem;
}

.level-row-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.level-choice-row .level-choice-header {
  margin-bottom: 0;
}

.level-choice-row .level-choice-title {
  font-size: 1.12rem;
}

.level-row-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.level-row-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.level-row-open {
  text-decoration: none;
  white-space: normal;
  text-align: center;
}

.level-choice-actions .move-level-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

:root[data-theme="dark"] .level-choice-row {
  background-color: var(--bg-card);
  border-color: var(--border-light);
  border-left-color: var(--hover-cyan);
}

:root[data-theme="dark"] .level-choice-row:hover {
  border-color: var(--hover-cyan-bright);
}

@media (max-width: 640px) {
  .level-choice-row {
    padding: 12px;
    gap: 10px;
  }
  .level-row-index {
    width: 26px;
    height: 26px;
    font-size: 0.82rem;
  }
  /* admin buttons drop under the title so the level name keeps its width */
  .level-choice-row .level-choice-header {
    flex-wrap: wrap;
  }
  .level-row-open {
    flex: 1 1 100%;
  }
}

/* Class-Scoped List & Expandable Levels Panel (#/curriculum & #/exercises) */
.curriculum-class-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.curriculum-class-item {
  background-color: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius, 12px);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.curriculum-class-item:hover {
  border-color: var(--hover-cyan);
}

.curriculum-class-item.expanded {
  border-color: var(--hover-cyan);
  box-shadow: var(--shadow-md);
}

.curriculum-class-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.16s ease;
}

.curriculum-class-row:hover,
.curriculum-class-row:focus-visible {
  background-color: rgba(0, 151, 167, 0.05);
  outline: none;
}

.curriculum-class-item.expanded .curriculum-class-row {
  background-color: rgba(0, 151, 167, 0.06);
}

.curriculum-class-row-main {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1 1 auto;
}

.curriculum-class-avatar {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background-color: rgba(0, 151, 167, 0.12);
  color: var(--hover-cyan);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.curriculum-class-info {
  min-width: 0;
  flex: 1 1 auto;
}

.curriculum-class-name {
  font-size: 1.12rem;
  font-weight: 800;
  color: var(--navy-heading);
  margin: 0;
  line-height: 1.3;
  word-break: break-word;
  overflow-wrap: break-word;
}

.curriculum-class-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 4px 0 0;
  line-height: 1.45;
  word-break: break-word;
}

.curriculum-class-meta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.curriculum-class-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-main);
  background-color: rgba(15, 23, 42, 0.05);
  border: 1px solid var(--border-light);
  white-space: nowrap;
}

.curriculum-class-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  transition: border-color 0.18s ease, color 0.18s ease, background-color 0.18s ease;
}

.curriculum-class-item.expanded .curriculum-class-chevron {
  color: var(--hover-cyan);
  border-color: var(--hover-cyan);
  background-color: rgba(0, 151, 167, 0.08);
}

.curriculum-class-levels-panel {
  border-top: 1px solid var(--border-light);
  padding: 18px 20px 20px;
  background-color: rgba(248, 250, 252, 0.72);
}

.curriculum-class-levels-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.curriculum-class-levels-label {
  font-size: 0.94rem;
  color: var(--navy-heading);
  font-weight: 600;
}

:root[data-theme="dark"] .curriculum-class-item {
  background-color: var(--bg-card);
  border-color: var(--border-light);
}

:root[data-theme="dark"] .curriculum-class-item.expanded,
:root[data-theme="dark"] .curriculum-class-item:hover {
  border-color: var(--hover-cyan-bright);
}

:root[data-theme="dark"] .curriculum-class-row:hover,
:root[data-theme="dark"] .curriculum-class-row:focus-visible,
:root[data-theme="dark"] .curriculum-class-item.expanded .curriculum-class-row {
  background-color: rgba(0, 188, 212, 0.08);
}

:root[data-theme="dark"] .curriculum-class-badge {
  background-color: rgba(255, 255, 255, 0.06);
  border-color: var(--border-light);
}

:root[data-theme="dark"] .curriculum-class-levels-panel {
  background-color: rgba(15, 23, 42, 0.42);
  border-top-color: var(--border-light);
}

/* =========================================================================
   WORD & PDF CURRICULUM DOCUMENT MANAGER & VIEWER
   ========================================================================= */
.curriculum-docs-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.curriculum-docs-hint {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.18s ease;
}

.btn-icon svg {
  display: block;
}

.doc-type-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.doc-type-badge.pdf {
  background-color: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
}

.doc-type-badge.word {
  background-color: #dbeafe;
  color: #1d4ed8;
  border: 1px solid #93c5fd;
}

:root[data-theme="dark"] .doc-type-badge.pdf {
  background-color: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.4);
}

:root[data-theme="dark"] .doc-type-badge.word {
  background-color: rgba(59, 130, 246, 0.22);
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.45);
}

/* Word (.docx / .doc) content rendered inside the book reader */

.docx-empty-msg {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.94rem;
}

.docx-p {
  margin: 0 0 10px;
  font-size: 0.96rem;
  line-height: 1.68;
  color: var(--text-main);
}

.docx-align-center {
  text-align: center;
}

.docx-align-right {
  text-align: right;
}

.docx-align-justify {
  text-align: justify;
}

.docx-heading-1 {
  font-size: 1.24rem;
  font-weight: 800;
  margin: 14px 0 10px;
  color: var(--navy-heading);
}

.docx-heading-2 {
  font-size: 1.02rem;
  font-weight: 700;
  margin: 10px 0 8px;
  color: var(--navy-heading);
}

.docx-heading-3,
.docx-heading-4 {
  font-size: 0.98rem;
  font-weight: 700;
  margin: 8px 0 6px;
  color: var(--navy-heading);
}

.docx-list-item {
  padding-left: 6px;
}

.docx-list-lvl-1 {
  padding-left: 22px;
}

.docx-list-lvl-2 {
  padding-left: 38px;
}

.docx-list-lvl-3,
.docx-list-lvl-4 {
  padding-left: 52px;
}

.docx-list-marker {
  display: inline-block;
  min-width: 22px;
  color: var(--navy-heading);
}

.docx-tab {
  display: inline-block;
  min-width: 24px;
}

.docx-tab-blank {
  display: inline-block;
  min-width: 54px;
  border-bottom: 1px solid currentColor;
  text-decoration: none;
}

.docx-link {
  color: var(--btn-blue);
  text-decoration: underline;
}

.docx-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 14px 0;
}

.docx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.docx-table th,
.docx-table td {
  border: 1px solid var(--border-light);
  padding: 8px 10px;
  vertical-align: top;
  text-align: left;
}

.docx-table th {
  background-color: var(--bg-subtle);
  color: var(--navy-heading);
  font-weight: 700;
}

.docx-embedded-img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 8px 0;
  display: inline-block;
}

/* =========================================================================
   HOMEPAGE BLOGS SECTION (ADMIN CREATE/EDIT/DELETE, TEXT + LINKS + IMAGES)
   ========================================================================= */
.home-blogs-section {
  max-width: 100%;
  width: 100%;
  margin: 4px 0 0;
}

.home-blogs-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--border-light);
}

.home-blogs-title {
  font-size: 1.45rem;
  margin: 4px 0 4px;
  color: var(--navy-heading);
}

.home-blogs-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.home-blogs-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.blog-empty-card {
  padding: 28px 20px;
  text-align: center;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1.5px dashed var(--border-light);
  border-radius: var(--radius-md);
  font-size: 0.94rem;
}

.blog-post-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-left: 5px solid var(--navy-1);
  border-radius: var(--radius-md);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
}

:root[data-theme="dark"] .blog-post-card {
  border-left-color: var(--btn-blue);
}

.blog-post-header,
.blog-post-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.blog-post-title {
  font-size: 1.24rem;
  margin: 0 0 6px;
  color: var(--navy-heading);
  word-break: break-word;
}

.blog-post-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.blog-author-badge {
  font-weight: 700;
  color: var(--btn-blue);
}

:root[data-theme="dark"] .blog-author-badge {
  color: #38bdf8;
}

.blog-admin-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.blog-post-content {
  font-size: 0.96rem;
  line-height: 1.65;
  color: var(--text-main);
  word-break: break-word;
}

.blog-paragraph {
  margin: 0 0 10px;
}

.blog-paragraph:last-child {
  margin-bottom: 0;
}

.blog-inline-link {
  color: var(--btn-blue);
  font-weight: 600;
  text-decoration: underline;
  word-break: break-all;
}

:root[data-theme="dark"] .blog-inline-link {
  color: #38bdf8;
}

.blog-post-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.blog-attached-link,
.blog-ext-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  color: var(--btn-blue);
  font-size: 0.86rem;
  font-weight: 600;
  word-break: break-all;
}

:root[data-theme="dark"] .blog-attached-link,
:root[data-theme="dark"] .blog-ext-link {
  color: #7dd3fc;
}

.blog-post-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.blog-post-images.single-img {
  grid-template-columns: minmax(0, 1fr);
}

/* Several images: equal 4:3 tiles, so a tall picture no longer stretches its neighbours
   and leaves empty space under them (a click still opens the full image) */
.blog-post-images.multi-img .blog-img-link {
  aspect-ratio: 4 / 3;
  max-height: none;
}

.blog-post-images.multi-img .blog-post-image {
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: cover;
}

.blog-post-img-link,
.blog-img-link {
  display: block;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-light);
  background: var(--bg-subtle);
  max-height: 460px;
}

.blog-post-img,
.blog-post-image {
  width: 100%;
  max-height: 450px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.blog-editor-modal-card {
  max-width: 680px;
  width: 95%;
  max-height: calc(90 * var(--app-vh));
  overflow-y: auto;
}

.blog-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.blog-helper-box {
  margin-top: 10px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
}

.blog-helper-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.blog-links-preview-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.blog-preview-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  font-size: 0.84rem;
}

.blog-chip-remove {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--danger);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0 4px;
}

.blog-images-editor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

/* "Nothing added yet" note of the blog / slideshow editors: one full-width line,
   never squeezed into a single image column */
.blog-empty-hint {
  grid-column: 1 / -1;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-light);
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.blog-editor-img-item,
.blog-draft-img-card {
  position: relative;
  min-width: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-light);
  aspect-ratio: 4 / 3;
  background: var(--bg-subtle);
}

.blog-editor-img-item img,
.blog-draft-img-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.blog-img-remove,
.blog-draft-img-card .blog-draft-img-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  min-width: 0;
  min-height: 0;
  border-radius: 50%;
  border: none;
  background: rgba(220, 38, 38, 0.9);
  color: #ffffff;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* =========================================================================
   FRIEND MULTIPLAYER ROOM CODE & QR SCANNER UI
   ========================================================================= */
.friend-hub-shell {
  max-width: 1080px;
  margin: 16px auto;
  width: 100%;
}

.restricted-student-shell {
  max-width: 680px;
  margin: 28px auto;
  width: 100%;
}

.ai-setup-card {
  max-width: 720px;
  margin: 16px auto;
  padding: 26px;
}

/* Play vs computer: one horizontal row of numbered difficulty buttons (1 = easiest). */
/* Difficulty picker: a full-width bar showing the current level; clicking it opens the list below */
.ai-level-select {
  position: relative;
}

.ai-level-select-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 8px 14px 8px 8px;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--navy-heading);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ai-level-select-bar:hover,
.ai-level-select-bar:focus-visible,
.ai-level-select.is-open .ai-level-select-bar {
  border-color: var(--btn-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
  outline: none;
}

.ai-level-badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--btn-blue);
  color: #ffffff;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.ai-level-caption {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.95rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.ai-level-chevron {
  flex: 0 0 auto;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.ai-level-select.is-open .ai-level-chevron {
  transform: rotate(180deg);
}

.ai-level-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 6px;
  max-height: 340px;
  overflow-y: auto;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  box-shadow: var(--shadow-md);
}

.ai-level-list[hidden] {
  display: none;
}

.ai-level-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px 6px 6px;
  border-radius: 8px;
  color: var(--text-main);
  cursor: pointer;
}

.ai-level-option .ai-level-badge {
  width: 30px;
  height: 30px;
  background: var(--bg-subtle);
  color: var(--navy-heading);
}

.ai-level-option:hover,
.ai-level-option:focus-visible {
  background: var(--bg-subtle);
  outline: none;
}

.ai-level-option.is-selected {
  background: rgba(37, 99, 235, 0.1);
}

.ai-level-option.is-selected .ai-level-badge {
  background: var(--btn-blue);
  color: #ffffff;
}

.ai-level-option-name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.ai-level-option-elo {
  flex: 0 0 auto;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.color-choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.preset-time-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.friend-time-inputs-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.users-search-field-wrap {
  flex: 1 1 240px;
  min-width: 0;
}

.level-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.level-summary-main {
  flex: 1 1 240px;
  min-width: 0;
}

.level-summary-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.room-invite-qr-row {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.room-invite-qr-details {
  flex: 1 1 200px;
  min-width: 0;
}

.friend-hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  gap: 22px;
}

.friend-hub-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 26px 24px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-light);
  background: var(--bg-card);
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.friend-hub-card:hover {
  transform: translateY(-2px);
  border-color: var(--btn-blue);
}

.friend-hub-icon-wrap {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.friend-hub-icon-wrap.join {
  background: rgba(29, 106, 229, 0.12);
  color: var(--btn-blue);
}

.friend-hub-icon-wrap.create {
  background: rgba(16, 185, 129, 0.12);
  color: #10b981;
}

.friend-hub-icon-wrap.local {
  background: rgba(139, 92, 246, 0.14);
  color: #7c3aed;
}

.local-hub-badge {
  background: #ede9fe;
  color: #6d28d9;
}

:root[data-theme='dark'] .local-hub-badge {
  background: rgba(139, 92, 246, 0.22);
  color: #c4b5fd;
}

/* "Same device" setup popup: who plays (player 1 = signed-in user, player 2 = account or guest) */
.local-setup-players {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.local-setup-player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-subtle);
  border: 1.5px solid var(--border-light);
  border-radius: 8px;
  color: var(--navy-heading);
}

.local-setup-player-tag {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
}

.local-setup-opponent {
  flex-direction: column;
  align-items: stretch;
}

.local-opponent-login {
  display: grid;
  gap: 8px;
}

.local-opponent-switch {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.local-opponent-switch-link,
.local-opponent-switch-link:hover {
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-weight: 700;
  color: var(--btn-blue);
  text-decoration: underline;
  cursor: pointer;
}

.local-opponent-note {
  margin: 6px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.local-opponent-verified {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(16, 185, 129, 0.1);
  border: 1.5px solid rgba(16, 185, 129, 0.45);
}

.local-opponent-verified > div {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.local-opponent-verified span:not(.local-opponent-check) {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.local-opponent-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  background: #10b981;
  color: #ffffff;
  font-weight: 800;
}

/* Same-device game page */
.local-guest-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  vertical-align: middle;
}

.local-auto-flip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 12px;
  font-size: 0.88rem;
  color: var(--navy-heading);
  cursor: pointer;
}

.local-auto-flip input {
  width: 16px;
  height: 16px;
  flex: none;
  accent-color: var(--btn-blue);
}

.local-confirm-message {
  margin: 6px 0 18px;
  color: var(--text-muted);
  line-height: 1.5;
}

.local-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.friend-join-card {
  border-left: 5px solid var(--btn-blue);
}

.friend-join-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.friend-code-input {
  font-weight: 600;
  letter-spacing: 0.4px;
}

.friend-join-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.friend-join-actions .btn {
  flex: 1;
  min-width: 135px;
}

.room-code-highlight-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1.5px solid var(--border-light);
}

.room-code-label {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-right: 6px;
}

.room-code-value {
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--navy-heading);
  letter-spacing: 1.5px;
  background: var(--bg-card);
  padding: 2px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
}

.qr-scanner-video-wrap {
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 280px;
  background: #091224;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1.5px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-scanner-video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Enforce no glowing effect on any button across the entire app */
button,
.btn,
.nav-col-btn,
.popup-option-btn,
.popup-close-btn,
.level-tab,
.theme-btn,
.lang-btn,
.user-menu-btn,
.settings-trigger-btn,
.promo-piece-btn {
  box-shadow: none !important;
}

/* =========================================================================
   MOBILE UI OPTIMIZATION
   ========================================================================= */
@media (max-width: 768px) {
  :root {
    --mobile-gutter: 12px;
  }

  .bar-container {
    padding: 0 var(--mobile-gutter);
  }

  .bar-1-inner {
    flex-wrap: nowrap;
    min-height: 52px;
    padding-top: 6px;
    padding-bottom: 6px;
    gap: 8px;
  }

  .mobile-menu-toggle {
    display: inline-flex;
  }

  .main-container {
    padding: 14px var(--mobile-gutter) 28px;
  }

  .brand-logo {
    font-size: 0.98rem;
    gap: 6px;
  }

  .brand-chess-icon {
    width: 19px;
    height: 19px;
  }

  .header-right-controls {
    gap: 6px;
  }

  .auth-controls {
    gap: 5px;
  }

  .btn-auth {
    padding: 5px 8px;
    font-size: 0.76rem;
    border-radius: 6px;
  }

  .user-menu-btn {
    padding: 4px 8px;
    font-size: 0.78rem;
    max-width: 155px;
  }

  .user-menu-name {
    max-width: 96px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .settings-trigger-btn {
    width: 30px;
    height: 30px;
  }

  .settings-dropdown-menu {
    right: 0;
    min-width: 210px;
  }

  .main-nav-bar {
    display: none;
  }

  .home-welcome-banner {
    margin: 6px auto 16px;
    padding: 16px 14px;
    border-radius: 12px;
  }

  .home-welcome-badge {
    font-size: 0.7rem;
    padding: 3px 10px;
    margin-bottom: 8px;
  }

  .home-welcome-banner h1 {
    font-size: 1.22rem;
    margin-bottom: 6px;
  }

  .home-welcome-lead {
    font-size: 0.88rem;
    line-height: 1.5;
    margin-bottom: 10px;
  }

  .home-welcome-hint {
    font-size: 0.79rem;
    padding: 7px 11px;
    border-radius: 10px;
    line-height: 1.4;
  }

  .home-blogs-header {
    margin-bottom: 12px;
    padding-bottom: 10px;
    gap: 10px;
  }

  .home-blogs-title {
    font-size: 1.2rem;
  }

  .home-blogs-subtitle {
    font-size: 0.85rem;
  }

  .home-blogs-list {
    gap: 12px;
  }

  .page-header-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 14px;
    padding-bottom: 10px;
  }

  .page-title {
    font-size: 1.18rem;
  }

  .card:not(.users-card),
  .ai-setup-card,
  .friend-hub-card {
    padding: 14px 12px !important;
    border-radius: 10px;
  }

  .users-card {
    padding: 0 !important;
  }

  .class-card {
    padding: 14px 12px !important;
  }

  .class-card-actions {
    gap: 6px;
    justify-content: flex-start;
  }

  .btn-reports-large {
    padding: 14px 12px !important;
    gap: 10px !important;
  }

  .classes-grid,
  .level-choice-grid,
  .friend-hub-grid,
  .lesson-cards-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .level-choice-card {
    padding: 16px 14px;
    gap: 12px;
  }

  .level-choice-header {
    gap: 8px;
    margin-bottom: 6px;
  }

  .level-choice-title-group {
    gap: 8px;
  }

  .level-choice-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    padding: 5px;
  }

  .level-choice-title {
    font-size: 1.14rem;
    margin: 0;
  }

  .level-choice-actions .btn-icon {
    width: 30px;
    height: 30px;
  }

  .level-choice-desc {
    font-size: 0.86rem;
  }

  .curriculum-class-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px;
  }

  .curriculum-class-row.curriculum-class-row-compact {
    flex-direction: row;
    align-items: center;
  }

  .curriculum-class-meta {
    justify-content: space-between;
    width: 100%;
  }

  .curriculum-class-row.curriculum-class-row-compact .curriculum-class-meta {
    width: auto;
    justify-content: flex-end;
  }

  .curriculum-class-chevron {
    margin-left: auto;
  }

  .curriculum-class-levels-panel {
    padding: 14px;
  }

  .lesson-select-card {
    padding: 15px 14px;
  }

  .lesson-card-title {
    font-size: 1.04rem;
  }

  .chess-workspace {
    --cg-coord-size: 22px;
    gap: 12px;
  }

  .board-column {
    width: 100%;
    gap: 8px;
  }

  .board-with-eval {
    gap: 6px;
    margin-bottom: var(--cg-coord-size, 22px);
    margin-right: var(--cg-coord-size, 22px);
  }

  .eval-bar-wrap {
    width: 16px;
    min-height: 0;
  }

  .cg-board-frame {
    --cg-coord-size: 22px;
    width: calc(100% - var(--cg-coord-size));
    height: auto;
    aspect-ratio: 1 / 1;
    margin-bottom: var(--cg-coord-size);
    margin-right: var(--cg-coord-size);
  }

  .player-strip {
    width: 100%;
    max-width: 100%;
    padding: 7px 10px;
    font-size: 0.85rem;
    gap: 8px;
    margin-right: 0;
  }

  /* Refined Mobile Analysis Workspace (Neat, balanced, perfectly aligned) */
  .analysis-workspace {
    --an-eval-w: 16px;
    --an-gap: 6px;
    --an-coord-w: 22px;
    gap: 14px;
  }

  .analysis-workspace .board-with-eval {
    width: calc(100% - var(--an-coord-w, 22px));
    margin-right: var(--an-coord-w, 22px);
    margin-bottom: var(--an-coord-w, 22px);
  }

  .analysis-workspace .eval-bar-wrap {
    flex: 0 0 var(--an-eval-w, 16px);
    width: var(--an-eval-w, 16px);
    min-height: 0;
  }

  .analysis-workspace .player-strip,
  .analysis-workspace .analysis-nav-controls {
    width: 100%;
    max-width: 100%;
    margin-right: 0;
  }

  .analysis-workspace .card {
    padding: 14px 12px;
  }

  .analysis-workspace .board-column {
    width: 100%;
    align-items: stretch;
  }

  .analysis-summary-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .analysis-summary-header #recent-games-select {
    width: 100% !important;
  }

  .analysis-mistake-helper-btns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .player-info {
    gap: 7px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .clock-box {
    font-size: 0.96rem;
    padding: 3px 8px;
    width: 72px;
  }

  .qr-display-box {
    padding: 10px;
    margin: 0 auto;
  }

  .qr-display-box svg,
  .qr-display-box img {
    width: 156px;
    height: 156px;
  }

  .popup-box,
  .popup-card {
    padding: 16px 14px;
    width: 95%;
    max-height: calc(90 * var(--app-vh));
    overflow-y: auto;
  }

  .popup-grid-options {
    grid-template-columns: minmax(0, 1fr);
  }

  .popup-btn-full {
    grid-column: span 1;
  }

  .blog-post-card {
    padding: 14px 13px;
  }

  .blog-post-title {
    font-size: 1.1rem;
  }

  .blog-post-content {
    font-size: 0.91rem;
  }

  .blog-helper-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .docx-p {
    font-size: 0.91rem;
    line-height: 1.6;
  }

  .docx-heading-1 {
    font-size: 1.1rem;
  }

  .docx-heading-2 {
    font-size: 0.96rem;
  }

  .users-card-header {
    margin-bottom: 14px;
    padding-bottom: 12px;
    gap: 10px;
  }

  .users-card-title {
    font-size: 1.16rem;
  }

  .users-count-box {
    padding: 8px 14px;
    min-width: 90px;
  }

  .users-count-num {
    font-size: 1.25rem;
  }

  .users-table thead th,
  .users-table tbody td {
    padding: 8px 6px;
    font-size: 0.78rem;
  }

  .users-table thead th {
    white-space: normal;
    line-height: 1.25;
  }

  .users-col-rank {
    width: 42px;
    padding-left: 6px !important;
    padding-right: 4px !important;
  }

  .users-rank-badge {
    width: 24px;
    height: 24px;
    font-size: 0.76rem;
  }

  .users-games-pill {
    padding: 3px 7px;
    font-size: 0.75rem;
    white-space: nowrap;
  }

  .data-table th,
  .data-table td {
    padding: 8px 8px;
    font-size: 0.8rem;
  }

  .data-table td:first-child {
    white-space: nowrap;
  }

  #add-player-form {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .site-footer {
    padding: 14px 0;
    font-size: 0.82rem;
  }

  .footer-inner {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
  }
}

@media (max-width: 480px) {
  :root {
    --mobile-gutter: 10px;
  }

  .bar-container {
    padding: 0 var(--mobile-gutter);
  }

  .main-container {
    padding: 12px var(--mobile-gutter) 24px;
  }

  .card:not(.users-card),
  .ai-setup-card,
  .friend-hub-card {
    padding: 12px 10px !important;
  }

  .class-card {
    padding: 12px 10px !important;
  }

  .class-card-actions {
    gap: 6px;
    justify-content: stretch;
  }

  .class-card-actions .btn {
    flex: 1 1 calc(50% - 6px);
    text-align: center;
    justify-content: center;
  }

  .btn-reports-large {
    padding: 12px 10px !important;
    gap: 8px !important;
  }

  .brand-logo {
    font-size: 0.92rem;
  }

  .nav-col-btn {
    font-size: 0.73rem;
    padding: 5px 4px;
    min-height: 28px;
  }

  .cg-board-frame {
    --cg-coord-size: 18px;
    width: calc(100% - var(--cg-coord-size));
    height: auto;
    aspect-ratio: 1 / 1;
    margin-bottom: var(--cg-coord-size);
    margin-right: var(--cg-coord-size);
  }

  .board-with-eval {
    margin-bottom: var(--cg-coord-size, 18px);
    margin-right: var(--cg-coord-size, 18px);
  }

  .eval-bar-wrap {
    min-height: 0;
  }

  .player-strip {
    width: 100%;
    max-width: 100%;
    margin-right: 0;
  }

  .cg-board-frame .cg-wrap coords,
  .cg-wrap coords {
    font-size: 12px;
  }

  .analysis-workspace {
    --an-eval-w: 14px;
    --an-gap: 5px;
    --an-coord-w: 18px;
    gap: 12px;
  }

  .analysis-workspace .board-with-eval {
    width: calc(100% - var(--an-coord-w, 18px));
    margin-right: var(--an-coord-w, 18px);
    margin-bottom: var(--an-coord-w, 18px);
    gap: var(--an-gap);
  }

  .analysis-workspace .eval-bar-wrap {
    flex: 0 0 var(--an-eval-w, 14px);
    width: var(--an-eval-w, 14px);
    min-height: 0;
  }

  .analysis-workspace .player-strip,
  .analysis-workspace .analysis-nav-controls {
    width: 100%;
    max-width: 100%;
    margin-right: 0;
  }

  .analysis-player-strip {
    min-height: 38px;
    padding: 5px 8px;
    font-size: 0.78rem;
  }

  .analysis-player-strip #btn-an-flip {
    padding: 2px 7px;
    font-size: 0.75rem;
  }

  .analysis-player-strip #an-turn-indicator {
    padding: 2px 6px;
    font-size: 0.75rem;
  }

  .moves-grid {
    grid-template-columns: 38px minmax(0, 1fr) minmax(0, 1fr);
    font-size: 0.82rem;
  }

  .move-san-cell {
    padding: 5px 6px;
  }

  .analysis-workspace .player-strip {
    padding: 6px 8px;
    font-size: 0.78rem;
  }

  .analysis-nav-controls {
    gap: 5px;
  }

  .analysis-nav-controls .btn {
    font-size: 0.76rem;
    padding: 6px 2px;
  }

  .analysis-mistake-filter-bar {
    gap: 5px;
  }

  .analysis-mistake-filter-bar .btn {
    font-size: 0.76rem;
    padding: 6px 4px;
  }

  .analysis-mistake-helper-btns .btn {
    font-size: 0.78rem;
    padding: 7px 4px;
  }

  .side-stat-box {
    padding: 10px 10px;
  }

  .analysis-stat-item {
    font-size: 0.76rem;
    padding: 3px 6px;
  }

  #ai-setup-color-grid,
  #color-pick-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 6px !important;
  }

  #ai-setup-color-grid .btn,
  #color-pick-grid .btn {
    padding: 8px 6px !important;
    font-size: 0.76rem !important;
  }
}

/* =========================================================================
   FRIEND ROOM LIVE PING, CONNECTION STATUS & 30S DISCONNECT COUNTDOWN
   ========================================================================= */
.player-ping-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
  margin-left: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid transparent;
}

.player-ping-badge.ping-good {
  background: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}

.player-ping-badge.ping-fair {
  background: #fffbeb;
  color: #b45309;
  border-color: #fde68a;
}

.player-ping-badge.ping-poor {
  background: #fff1f2;
  color: #be123c;
  border-color: #fecdd3;
}

.player-ping-badge.ping-offline {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #fca5a5;
  animation: pulseDisconnectBadge 1.2s infinite ease-in-out;
}

@keyframes pulseDisconnectBadge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.ping-signal-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 10px;
}

.ping-signal-bars i {
  display: inline-block;
  width: 2.5px;
  border-radius: 1px;
  background: currentColor;
}

.ping-signal-bars i:nth-child(1) { height: 4px; }
.ping-signal-bars i:nth-child(2) { height: 7px; }
.ping-signal-bars i:nth-child(3) { height: 10px; }

.ping-signal-bars.fair i:nth-child(3) { opacity: 0.3; }
.ping-signal-bars.poor i:nth-child(2),
.ping-signal-bars.poor i:nth-child(3) { opacity: 0.3; }
.ping-signal-bars.offline i { opacity: 0.35; }

.room-connection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 9px 12px;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  font-size: 0.82rem;
}

.conn-bar-main {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  color: var(--navy-heading);
}

.conn-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.conn-status-dot.online {
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.conn-status-dot.fair,
.conn-status-dot.waiting {
  background: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

.conn-status-dot.poor,
.conn-status-dot.offline {
  background: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25);
}

.conn-bar-metrics {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.conn-metric-pill {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.77rem;
}

.disconnect-countdown-banner {
  padding: 12px 14px;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  background: #fef2f2;
  border: 1.5px solid #f87171;
  border-left: 5px solid #dc2626;
  color: #991b1b;
}

.disconnect-banner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.disconnect-warn-title {
  font-weight: 800;
  font-size: 0.92rem;
  color: #991b1b;
}

.disconnect-timer-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #dc2626;
  color: #ffffff;
  font-weight: 800;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.disconnect-banner-sub {
  font-size: 0.83rem;
  line-height: 1.4;
  color: #7f1d1d;
  margin-bottom: 8px;
}

.disconnect-progress-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #fecaca;
  overflow: hidden;
}

.disconnect-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #ef4444, #dc2626);
  border-radius: 999px;
  transition: width 0.22s linear;
}

:root[data-theme="dark"] .player-ping-badge.ping-good {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.35);
}

:root[data-theme="dark"] .player-ping-badge.ping-fair {
  background: rgba(245, 158, 11, 0.16);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.35);
}

:root[data-theme="dark"] .player-ping-badge.ping-poor,
:root[data-theme="dark"] .player-ping-badge.ping-offline {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.4);
}

:root[data-theme="dark"] .disconnect-countdown-banner {
  background: rgba(127, 29, 29, 0.32);
  border-color: rgba(248, 113, 113, 0.55);
  border-left-color: #ef4444;
  color: #fecaca;
}

:root[data-theme="dark"] .disconnect-warn-title {
  color: #fca5a5;
}

:root[data-theme="dark"] .disconnect-banner-sub {
  color: #fecaca;
}

:root[data-theme="dark"] .disconnect-progress-track {
  background: rgba(254, 202, 202, 0.2);
}

/* =========================================================================
   MATCH HISTORY & STOCKFISH GAME ANALYSIS STYLES
   ========================================================================= */
.history-page-container {
  max-width: 100%;
  width: 100%;
  margin: 0;
  padding: 24px 0 48px;
}

.history-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.history-page-title {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--navy-heading);
  display: flex;
  align-items: center;
  gap: 10px;
}

.history-page-subtitle {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-muted);
  max-width: 650px;
}

.history-header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* History 2-Column Layout (List on Left, Filters on Right) */
.history-content-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.history-list-pane {
  flex: 1 1 0%;
  min-width: 0;
}

.history-filter-sidebar {
  width: 300px;
  flex-shrink: 0;
  position: sticky;
  top: 80px;
}

@media (max-width: 860px) {
  .history-content-layout {
    flex-direction: column-reverse;
  }
  .history-filter-sidebar {
    width: 100%;
    position: static;
  }
}

.history-filter-panel {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.history-filter-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--navy-heading);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

.history-filter-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-filter-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.history-filter-vertical {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-filter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
  text-align: left;
}

.history-filter-item:hover {
  border-color: var(--btn-blue);
  color: var(--btn-blue);
}

.history-filter-item.active {
  background: var(--btn-blue);
  border-color: var(--btn-blue);
  color: #ffffff;
}

.history-filter-item .filter-item-count {
  font-size: 0.76rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.08);
  font-weight: 600;
}

.history-filter-item.active .filter-item-count {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

/* History Stats Mini Section in Filter Sidebar (Pie / Donut Chart) */
.history-stats-section {
  padding-top: 10px;
  border-top: 1px solid var(--border-light);
}

.history-chart-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 8px 0 4px;
}

.history-chart-svg-wrap {
  width: 140px;
  height: 140px;
}

.history-pie-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.pie-slice {
  transition: stroke-dasharray 0.3s ease, stroke-dashoffset 0.3s ease;
}

.history-chart-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.history-legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
}

.legend-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
  flex-shrink: 0;
}

.dot-win {
  background-color: #10b981;
}

.dot-draw {
  background-color: #94a3b8;
}

.dot-loss {
  background-color: #ef4444;
}

.legend-label {
  color: var(--text-muted);
  flex: 1;
}

.legend-val {
  font-weight: 600;
  color: var(--navy-heading);
}

/* History Vertical List (Top to Bottom) */
.history-list-vertical {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-list-item {
  display: flex;
  align-items: center;
  padding: 12px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.history-list-item:hover {
  border-color: var(--btn-blue);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.history-item-row,
.history-item-main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.95rem;
  color: var(--text-main);
  width: 100%;
}

.history-outcome-badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.history-outcome-badge.outcome-win {
  background: rgba(34, 197, 94, 0.14);
  color: #15803d;
  border: 1px solid rgba(34, 197, 94, 0.35);
}

:root[data-theme="dark"] .history-outcome-badge.outcome-win {
  background: rgba(34, 197, 94, 0.22);
  color: #4ade80;
  border-color: rgba(34, 197, 94, 0.45);
}

.history-outcome-badge.outcome-loss {
  background: rgba(239, 68, 68, 0.14);
  color: #b91c1c;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

:root[data-theme="dark"] .history-outcome-badge.outcome-loss {
  background: rgba(239, 68, 68, 0.22);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.45);
}

.history-outcome-badge.outcome-draw {
  background: rgba(148, 163, 184, 0.16);
  color: #475569;
  border: 1px solid rgba(148, 163, 184, 0.35);
}

:root[data-theme="dark"] .history-outcome-badge.outcome-draw {
  background: rgba(148, 163, 184, 0.22);
  color: #cbd5e1;
  border-color: rgba(148, 163, 184, 0.45);
}

.history-item-sep {
  color: var(--text-muted);
  font-weight: 600;
  user-select: none;
}

.history-item-opponent {
  font-weight: 600;
  color: var(--navy-heading);
}

.history-item-datetime {
  color: var(--text-muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

@media (max-width: 680px) {
  .history-list-item {
    padding: 10px 14px;
  }
  .history-item-row,
  .history-item-main {
    gap: 8px;
    font-size: 0.88rem;
  }
}

.btn-primary-highlight {
  background: linear-gradient(135deg, #1d6ae5 0%, #00bcd4 100%);
  color: #ffffff !important;
  border: none;
  box-shadow: 0 3px 10px rgba(0, 188, 212, 0.3);
  font-weight: 600;
  transition: all 0.2s ease;
  cursor: pointer;
}

.btn-primary-highlight:hover {
  background: linear-gradient(135deg, #1554ba 0%, #00acc1 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0, 188, 212, 0.45);
}

.btn-view-analysis {
  background: var(--btn-blue);
  color: #ffffff !important;
  font-weight: 600;
  cursor: pointer;
}

.btn-view-analysis:hover {
  background: var(--btn-blue-dark);
}

.btn-delete-game {
  padding: 6px 12px;
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.3);
  cursor: pointer;
}

.btn-delete-game:hover {
  background: rgba(220, 38, 38, 0.1);
  border-color: var(--danger);
}

/* Empty State & Loading */
.history-empty-state {
  text-align: center;
  padding: 48px 24px;
  background: var(--bg-card);
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-lg);
}

.history-empty-state h3 {
  margin: 0 0 8px;
  font-size: 1.3rem;
  color: var(--navy-heading);
}

.history-empty-state p {
  color: var(--text-muted);
  max-width: 480px;
  margin: 0 auto 16px;
  line-height: 1.6;
}

.history-empty-state h3:last-child,
.history-empty-state p:last-child {
  margin-bottom: 0;
}

.history-loading-box {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.spinner-inline {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}

.ai-game-over-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* King in check: a stronger red mark than the vendor theme so it stands out on the blue squares */
cg-board square.check {
  background: radial-gradient(
    ellipse at center,
    rgba(255, 0, 0, 1) 0%,
    rgba(231, 0, 0, 1) 30%,
    rgba(200, 0, 0, 0.45) 70%,
    rgba(158, 0, 0, 0) 100%
  );
  box-shadow: inset 0 0 0 3px rgba(220, 38, 38, 0.9);
}

/* Selected piece: a warm gold square with a ring (the vendor dark green barely shows on the blue
   squares), and the piece itself lifted and lit with a glow so it stands apart from the rest.
   chessHelper.js adds .cg-selected-piece to the piece on the selected square. The lift uses the
   `translate` property, which adds to chessground's inline transform; `scale` would also multiply
   that positioning translate and throw the piece off its square. */
cg-board square.selected {
  background-color: rgba(255, 204, 0, 0.55);
  box-shadow: inset 0 0 0 3px rgba(234, 140, 0, 0.95);
}

.cg-wrap piece.cg-selected-piece {
  z-index: 3;
  translate: 0 -5%;
  filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 6px rgba(255, 176, 0, 0.95))
    drop-shadow(0 5px 4px rgba(0, 0, 0, 0.4));
}

/* while dragging the piece already follows the pointer; keep the glow but skip the lift */
cg-board piece.dragging.cg-selected-piece {
  translate: none;
}

/* AI Setup Time Preset Grid */
.ai-setup-time-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

/* minutes / increment inputs shown for the "custom time" preset */
.ai-setup-custom-time {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.ai-setup-custom-time[hidden] {
  display: none;
}

.ai-setup-custom-time .form-group {
  margin-bottom: 0;
}

.ai-setup-time-grid .time-btn-full {
  grid-column: 1 / -1;
  padding: 10px 8px;
}

@media (max-width: 640px) {
  .ai-setup-time-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Admin Created Credentials Panel */
.created-credentials-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.created-cred-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.created-cred-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--border-light);
  background: var(--bg-subtle, #f8fafc);
}

.created-cred-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.created-cred-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

.created-cred-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--navy-heading);
  word-break: break-all;
}

.created-cred-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg-subtle, #f8fafc);
  border: 1px solid var(--border-light);
  font-size: 0.86rem;
  color: var(--text-main);
}

.btn-copy-cred {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-copy-cred[data-copied="true"] {
  border-color: #10b981;
  color: #059669;
  background: rgba(16, 185, 129, 0.1);
}

:root[data-theme="dark"] .created-cred-row,
:root[data-theme="dark"] .created-cred-meta {
  background: rgba(15, 23, 42, 0.65);
  border-color: var(--border-light);
}

:root[data-theme="dark"] .btn-copy-cred[data-copied="true"] {
  color: #34d399;
  border-color: #34d399;
}

/* =========================================================
   MOBILE NAVIGATION DRAWER & BACKDROP
   ========================================================= */
body.mobile-nav-open {
  overflow: hidden;
}

.mobile-nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 22, 46, 0.52);
  backdrop-filter: blur(2px);
  z-index: 990;
  transition: opacity 0.2s ease;
}

.mobile-nav-backdrop.hidden {
  display: none;
}

.mobile-nav-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(310px, calc(84 * var(--app-vw)));
  background: var(--bg-card, #ffffff);
  color: var(--text-main);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 34px rgba(10, 31, 68, 0.28);
  border-right: 1px solid var(--border-light);
  transform: translateX(0);
  transition: transform 0.22s ease;
}

.mobile-nav-drawer.hidden {
  display: none;
  transform: translateX(-100%);
}

.mobile-nav-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--navy-1);
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.mobile-nav-drawer-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.mobile-nav-close-btn {
  appearance: none;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.mobile-nav-close-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

.mobile-nav-list {
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  gap: 6px;
  overflow-y: auto;
  flex: 1;
}

.mobile-nav-btn {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-main);
  font-size: 0.96rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.mobile-nav-btn.hidden {
  display: none !important;
}

.mobile-nav-btn:hover {
  background: var(--bg-subtle);
  color: var(--btn-blue);
}

.mobile-nav-btn.active {
  background: rgba(21, 101, 192, 0.12);
  border-color: rgba(21, 101, 192, 0.3);
  color: var(--btn-blue);
}

.mobile-nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: currentColor;
}

:root[data-theme="dark"] .mobile-nav-drawer {
  background: var(--bg-card);
  border-right-color: var(--border-light);
}

:root[data-theme="dark"] .mobile-nav-btn.active {
  background: rgba(96, 165, 250, 0.18);
  border-color: rgba(96, 165, 250, 0.38);
  color: #93c5fd;
}

/* =========================================================
   MOBILE ALIGNMENT & SYMMETRIC BALANCE ACROSS ALL VIEWS
   ========================================================= */
@media (max-width: 768px) {
  .friend-hub-shell,
  .restricted-student-shell,
  .ai-setup-card {
    margin: 0 auto !important;
  }

  .ai-setup-time-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .ai-setup-time-grid .time-btn-full {
    grid-column: 1 / -1;
  }

  .color-choice-grid .btn,
  .preset-time-grid .btn {
    min-height: 42px;
    padding: 8px 6px;
    font-size: 0.82rem;
    line-height: 1.25;
    white-space: normal;
    text-align: center;
    justify-content: center;
  }

  /* Prevent long single buttons or panels from stretching flex/grid tracks past mobile width */
  .chess-workspace,
  .chess-workspace .board-column,
  .chess-workspace .side-panel,
  .analysis-workspace,
  .analysis-workspace .board-column,
  .analysis-workspace .side-panel {
    min-width: 0;
    max-width: 100%;
    width: 100%;
    --cg-coord-size: 22px;
  }

  .analysis-workspace .analysis-nav-controls .btn,
  .analysis-workspace .analysis-mistake-helper-btns .btn,
  .analysis-workspace .analysis-mistake-filter-bar .btn,
  .manage-subtabs-bar .btn,
  .analysis-tab-bar .btn,
  .room-actions-grid .btn,
  .ai-match-actions-pair .btn,
  .ai-match-actions-quad .btn {
    white-space: normal;
    word-break: break-word;
    line-height: 1.25;
    min-width: 0;
  }

  /* Match player-strip and analysis controls to full visual [board + coords] width */
  .chess-workspace .player-strip,
  .chess-workspace .teacher-demo-controls-card,
  .analysis-workspace .analysis-player-strip,
  .analysis-workspace .analysis-nav-controls {
    width: 100%;
    max-width: 100%;
    margin-right: 0;
  }

  .analysis-workspace .analysis-nav-controls {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .analysis-workspace .analysis-nav-controls .btn {
    width: 100%;
    min-width: 0;
    justify-content: center;
    padding: 8px 6px;
  }

  .system-manage-stats-grid > .stat-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }

  .system-manage-stats-grid > .stat-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .manage-subtabs-bar,
  .analysis-tab-bar {
    display: flex;
    gap: 8px;
    width: 100%;
  }

  .manage-subtabs-bar .btn,
  .analysis-tab-bar .btn {
    flex: 1 1 0;
    justify-content: center;
    text-align: center;
    min-width: 0;
    padding: 9px 10px !important;
    font-size: 0.86rem;
  }

  .friend-hub-hero {
    margin-bottom: 18px !important;
  }

  .friend-hub-hero h2 {
    font-size: 1.4rem !important;
  }

  .popup-overlay {
    padding: 12px;
    align-items: center;
    justify-content: center;
  }

  .popup-box,
  .popup-card,
  .admin-modal-box {
    width: 100%;
    max-width: calc(100 * var(--app-vw) - 24px);
    max-height: calc(88 * var(--app-vh));
    overflow-y: auto;
    padding: 18px 14px;
    margin: 0 auto;
  }

  .popup-levels-grid > .popup-level-btn:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .users-pagination {
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 12px;
  }

  .settings-dropdown-menu {
    max-width: calc(100 * var(--app-vw) - 20px);
    right: 0;
  }
}

@media (max-width: 640px) {
  .home-blogs-header,
  .history-header-bar,
  .tournament-page-header,
  .users-card-header,
  .curriculum-docs-toolbar,
  .level-summary-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .home-blogs-header > button,
  .home-blogs-header > a,
  .users-card-header > .btn,
  .curriculum-docs-toolbar > .btn {
    width: 100%;
    justify-content: center;
  }

  .history-header-actions,
  .tournament-page-header > div:last-child {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
    gap: 8px;
    width: 100%;
  }

  .tournament-page-header > div:last-child:empty,
  .history-header-actions:empty {
    display: none;
  }

  .history-header-actions .btn,
  .tournament-page-header > div:last-child .btn {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .level-summary-side {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
  }

  .page-header-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .room-invite-qr-row {
    flex-direction: column;
    align-items: stretch;
  }

  .room-invite-qr-row .qr-display-box {
    margin: 0 auto;
  }

  .room-actions-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .room-actions-grid .btn,
  .ai-match-actions-pair .btn,
  .ai-match-actions-quad .btn {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .ai-match-actions-pair,
  .ai-match-actions-quad {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px !important;
  }
}

@media (max-width: 480px) {
  .header-left-group {
    gap: 6px;
  }

  .brand-logo {
    font-size: 1.02rem;
  }

  .top-bar-right {
    gap: 6px;
  }

  .auth-actions {
    gap: 5px;
  }

  .btn-auth {
    padding: 5px 8px;
    font-size: 0.76rem;
    white-space: nowrap;
  }

  .chess-workspace,
  .analysis-workspace {
    --cg-coord-size: 18px;
  }

  .chess-workspace .player-strip,
  .chess-workspace .teacher-demo-controls-card,
  .analysis-workspace .analysis-player-strip,
  .analysis-workspace .analysis-nav-controls {
    width: 100%;
    max-width: 100%;
    margin-right: 0;
  }

  .popup-overlay {
    padding: 10px;
  }

  .popup-box,
  .popup-card,
  .admin-modal-box {
    max-width: calc(100 * var(--app-vw) - 20px);
    padding: 16px 12px;
  }

  .popup-grid-options {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }
}

@media (max-width: 359px) {
  .color-choice-grid,
  .friend-time-inputs-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* =========================================================
   PROFILE ELO CARD & PLAY POPUP ADMIN OPTION
   ========================================================= */
.profile-elo-summary {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.profile-elo-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.profile-elo-label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-muted);
}

.profile-elo-value {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--navy-heading);
}

.profile-elo-submeta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

/* =========================================================
   SWISS TOURNAMENTS & MANAGEMENT PAGES
   ========================================================= */
.tournament-page {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.tournament-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.tournament-page-lead {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.94rem;
}

.tournament-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tournament-section-title {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--navy-heading);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.tournament-section-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.tournament-card-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tournament-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
}

.tournament-card-main {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.tournament-card-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: rgba(21, 101, 192, 0.1);
  color: var(--btn-blue);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tournament-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tournament-card-title-row,
.tournament-detail-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tournament-card-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--navy-heading);
}

.tournament-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}

.tournament-status-badge.status-registration {
  background: rgba(16, 185, 129, 0.14);
  color: #047857;
  border: 1px solid rgba(16, 185, 129, 0.34);
}

.tournament-status-badge.status-active {
  background: rgba(21, 101, 192, 0.12);
  color: var(--btn-blue);
  border: 1px solid rgba(21, 101, 192, 0.3);
}

.tournament-status-badge.status-completed {
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-light);
}

.tournament-joined-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  background: rgba(245, 158, 11, 0.14);
  color: #b45309;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.tournament-meta-row {
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.tournament-meta-item,
.tournament-meta-lock {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.tournament-roles-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 0.82rem;
}

.tournament-roles-label {
  color: var(--text-muted);
  font-weight: 600;
}

.tournament-role-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-light);
}

.tournament-card-desc {
  margin: 2px 0 0;
  font-size: 0.88rem;
  color: var(--text-main);
  line-height: 1.5;
}

.tournament-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.tournament-denied-note {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tournament-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border-radius: 10px;
  border: 1px dashed var(--border-light);
}

.tournament-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tournament-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.tournament-roles-checks {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.tournament-role-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-light);
  background: var(--bg-subtle);
  font-size: 0.88rem;
  cursor: pointer;
}

.tournament-form-field {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tournament-form-field textarea {
  resize: vertical;
  min-height: 84px;
}

.tournament-form-hint {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tournament-input-suffix {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tournament-input-suffix > span {
  flex-shrink: 0;
  font-size: 0.86rem;
  color: var(--text-muted);
  width: 72px;
}

.required-mark {
  color: #ef4444;
}

/* Shared layout helpers: card heading row, button rows and modal footers */
.card-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.card-head-note {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.btn-group-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
}

.modal-actions .btn {
  min-width: 112px;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #047857;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  animation: live-dot-pulse 1.6s ease-in-out infinite;
}

@keyframes live-dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* Swiss stage bracket: rounds as columns, score groups as boxes, elbow connectors between groups */
.swiss-bracket {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 44px;
  overflow-x: auto;
  padding: 2px 2px 8px;
}

.bracket-links {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 0;
  pointer-events: none;
  overflow: visible;
}

.ss-link {
  fill: none;
  stroke: var(--btn-blue);
  stroke-width: 1.75;
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.bracket-links marker path {
  fill: var(--btn-blue);
}

.swiss-bracket.has-focus .ss-link {
  opacity: 0.12;
}

.swiss-bracket.has-focus .ss-link.is-focused {
  opacity: 1;
  stroke-width: 2.5;
}

.ss-column {
  position: relative;
  z-index: 1;
  flex: 1 0 236px;
  max-width: 300px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ss-column-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 6px 10px;
  border: 1.5px solid var(--border-light);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--navy-heading);
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
}

button.ss-column-head {
  cursor: pointer;
}

.ss-column.is-selected .ss-column-head {
  border-color: var(--btn-blue);
}

.ss-column-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
}

.ss-column.is-pending {
  opacity: 0.65;
}

.ss-placeholder {
  padding: 22px 10px;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
  border: 1.5px dashed var(--border-light);
  border-radius: 8px;
}

.ss-group {
  border: 1.5px solid var(--btn-blue);
  border-radius: 6px;
  background: var(--bg-card);
  overflow: hidden;
}

.ss-group-head {
  padding: 4px 10px;
  background: var(--btn-blue);
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.02em;
}

.ss-group-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
}

.ss-summary {
  border-color: var(--border-light);
}

.ss-summary .ss-group-head {
  background: var(--bg-subtle);
  color: var(--navy-heading);
  border-bottom: 1px solid var(--border-light);
}

.ss-summary.is-top {
  border-color: #10b981;
}

.ss-summary.is-top .ss-group-head {
  background: #10b981;
  color: #ffffff;
}

.ss-chips {
  flex-direction: row;
  flex-wrap: wrap;
}

.ss-match {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  color: inherit;
  text-decoration: none;
  border-radius: 6px;
}

a.ss-match:hover .ss-board {
  background: var(--btn-blue);
  color: #ffffff;
}

.ss-board {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
}

.ss-match.is-live .ss-board {
  background: #10b981;
  color: #ffffff;
  animation: live-dot-pulse 1.6s ease-in-out infinite;
}

.ss-vs {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
}

.ss-name {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 0;
  padding: 4px 8px;
  border: 1.5px solid var(--btn-blue);
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--navy-heading);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
}

.ss-name-full,
.ss-name-handle {
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ss-name-handle {
  font-size: 0.68rem;
  font-weight: 500;
  opacity: 0.75;
}

.ss-chips .ss-name {
  flex: 1 1 calc(50% - 6px);
}

.ss-name.is-win {
  background: var(--btn-blue);
  color: #ffffff;
}

.ss-name.is-draw {
  background: rgba(245, 158, 11, 0.18);
  border-color: #f59e0b;
  color: #92400e;
}

.ss-name.is-loss {
  border-color: var(--border-light);
  color: var(--text-muted);
}

.ss-name.is-bye {
  border-style: dashed;
  border-color: var(--border-light);
  color: var(--text-muted);
  font-style: italic;
}

.ss-name.is-mine {
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.55) !important;
}

.ss-name.is-focused {
  outline: 2px solid #f59e0b;
  outline-offset: 1px;
}

:root[data-theme="dark"] .ss-name.is-draw {
  color: #fcd34d;
}

.bracket-legend {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.bracket-legend > span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-chip {
  display: inline-block;
  width: 18px;
  height: 10px;
  border-radius: 999px;
  border: 1.5px solid var(--btn-blue);
}

.legend-chip.is-win { background: var(--btn-blue); }
.legend-chip.is-draw { background: rgba(245, 158, 11, 0.3); border-color: #f59e0b; }
.legend-chip.is-loss { border-color: var(--border-light); }

@media (max-width: 600px) {
  .tournament-form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .swiss-bracket {
    gap: 32px;
  }
  .ss-column {
    flex-basis: 220px;
  }
  .modal-actions .btn {
    flex: 1;
  }
}

.pairings-table {
  width: 100%;
}

.pairing-row-mine td {
  background: rgba(21, 101, 192, 0.06);
}

.pairing-actions,
.pairing-result-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.pairing-room-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}

.pairing-room-chip.chip-live {
  background: rgba(16, 185, 129, 0.14);
  color: #047857;
}

.pairing-room-chip.chip-finished {
  background: rgba(21, 101, 192, 0.12);
  color: var(--btn-blue);
}

.pairing-room-chip.chip-arbiter {
  background: rgba(124, 58, 237, 0.12);
  color: #6d28d9;
}

:root[data-theme="dark"] .pairing-room-chip.chip-arbiter {
  color: #c4b5fd;
}

.pairing-room-chip.chip-waiting {
  background: rgba(245, 158, 11, 0.15);
  color: #b45309;
}

.rating-delta {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
}

.rating-delta-up {
  background: rgba(16, 185, 129, 0.15);
  color: #047857;
}

.rating-delta-down {
  background: rgba(239, 68, 68, 0.14);
  color: #b91c1c;
}

.rating-delta-zero {
  background: var(--bg-subtle);
  color: var(--text-muted);
}

:root[data-theme="dark"] .tournament-status-badge.status-registration,
:root[data-theme="dark"] .rating-delta-up,
:root[data-theme="dark"] .pairing-room-chip.chip-live {
  color: #6ee7b7;
}

:root[data-theme="dark"] .rating-delta-down {
  color: #fca5a5;
}

:root[data-theme="dark"] .tournament-joined-badge,
:root[data-theme="dark"] .pairing-room-chip.chip-waiting {
  color: #fcd34d;
}

/* Mobile Enhancements for Tables, Cards, Tournaments & Modals */
@media (max-width: 768px) {
  .tournament-card {
    flex-direction: column;
    padding: 14px 12px;
  }
  .tournament-card-actions {
    width: 100%;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 8px;
  }
  .tournament-card-actions .btn {
    width: 100%;
    padding-left: 8px;
    padding-right: 8px;
  }
  .tournament-form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .users-table-wrap,
  .data-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .users-table {
    min-width: 560px;
  }
  .users-elo-pill,
  .users-games-pill {
    padding: 2px 7px;
    font-size: 0.74rem;
  }
  .system-manage-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .btn-auth {
    padding: 4px 7px;
    font-size: 0.73rem;
  }
  .user-menu-btn {
    max-width: 122px;
  }
  .user-menu-name {
    max-width: 72px;
  }
  .system-manage-stats-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* =========================================================
   PROFILE TABS, ABOUT & RATING CHART
   ========================================================= */
.profile-tabs {
  display: flex;
  width: fit-content;
  gap: 4px;
  padding: 4px;
  margin: 0 0 16px auto;
  border-radius: 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  max-width: 100%;
}

.profile-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}

.profile-tab:hover {
  color: var(--text-main);
}

.profile-tab.active {
  background: var(--btn-blue);
  color: #ffffff;
}

.profile-tab:focus-visible {
  outline: 2px solid var(--hover-cyan);
  outline-offset: 2px;
}

.profile-main-col {
  min-width: 0;
}

.profile-bio-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text-main);
}

.profile-empty-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.rating-chart {
  --chart-line: #1d6ae5;
  position: relative;
  width: 100%;
}

:root[data-theme="dark"] .rating-chart {
  --chart-line: #38bdf8;
}

.rating-chart-svg {
  display: block;
  max-width: 100%;
  touch-action: pan-y;
}

.rating-chart-grid {
  stroke: var(--border-light);
  stroke-width: 1;
}

.rating-chart-tick {
  fill: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.rating-chart-line {
  fill: none;
  stroke: var(--chart-line);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.rating-chart-end,
.rating-chart-focus {
  fill: var(--chart-line);
  stroke: var(--bg-card);
  stroke-width: 2;
}

.rating-chart-end-label {
  fill: var(--text-main);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.rating-chart-crosshair {
  stroke: var(--text-muted);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.rating-chart-tooltip {
  position: absolute;
  pointer-events: none;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-md);
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: nowrap;
  z-index: 2;
}

.rating-chart-tooltip-value {
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 700;
}

.rating-chart-tooltip-value span {
  color: var(--text-muted);
  font-weight: 600;
}

@media (max-width: 480px) {
  .profile-tabs {
    width: 100%;
  }
  .profile-tab {
    flex: 1;
    padding: 8px 10px;
  }
}

/* Profile: match history tab and sign-out card */
.profile-history-host .history-page-container {
  padding: 0;
}

.profile-history-host .history-header-bar {
  display: none;
}

@media (max-width: 1180px) {
  .profile-history-host .history-content-layout {
    flex-direction: column-reverse;
  }
  .profile-history-host .history-filter-sidebar {
    width: 100%;
    position: static;
  }
}

.profile-logout-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

@media (max-width: 480px) {
  .profile-tab {
    font-size: 0.82rem;
    padding: 8px 6px;
    white-space: normal;
    line-height: 1.25;
  }
}

.user-profile-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s ease;
}

.user-profile-link:hover,
.user-profile-link:focus-visible {
  color: var(--btn-blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

:root[data-theme="dark"] .user-profile-link:hover,
:root[data-theme="dark"] .user-profile-link:focus-visible {
  color: var(--hover-cyan-bright);
}

.muted-username-link {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* =========================================================
   CHESS GAME SIMULATION PAGE (#/play/simulate)
   ========================================================= */
.sim-page-shell {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sim-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.sim-page-title {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--navy-heading);
}

.sim-page-subtitle {
  margin: 4px 0 0;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.sim-options-list,
.sim-options-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sim-option-list-item {
  border: 1.5px solid var(--border-light);
  border-radius: 12px;
  background: var(--bg-card);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.sim-option-list-item:hover {
  border-color: var(--btn-blue);
}

.sim-option-list-item.active {
  border-color: var(--btn-blue);
  box-shadow: var(--shadow-md);
}

:root[data-theme="dark"] .sim-option-list-item:hover,
:root[data-theme="dark"] .sim-option-list-item.active {
  border-color: var(--hover-cyan-bright);
}

.sim-option-card,
.sim-option-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border-radius: 0;
  border: none;
  background: transparent;
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
  transition: background-color 0.16s ease;
}

.sim-option-card:hover,
.sim-option-card:focus-visible,
.sim-option-row:hover,
.sim-option-row:focus-visible {
  background: var(--bg-subtle);
  outline: none;
}

.sim-option-card.active,
.sim-option-row.active {
  background: rgba(21, 101, 192, 0.08);
}

:root[data-theme="dark"] .sim-option-card.active,
:root[data-theme="dark"] .sim-option-row.active {
  background: rgba(56, 189, 248, 0.14);
}

.sim-option-row-main {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1 1 auto;
}

.sim-option-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(21, 101, 192, 0.1);
  color: var(--btn-blue);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

:root[data-theme="dark"] .sim-option-icon {
  background: rgba(56, 189, 248, 0.15);
  color: var(--hover-cyan-bright);
}

.sim-option-card.active .sim-option-icon,
.sim-option-row.active .sim-option-icon {
  background: var(--btn-blue);
  color: #ffffff;
}

.sim-option-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1 1 auto;
}

.sim-option-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sim-option-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--navy-1);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  padding: 2px 8px;
  border-radius: 99px;
  white-space: nowrap;
  flex-shrink: 0;
}

.sim-option-card.active .sim-option-badge {
  color: var(--btn-blue);
  border-color: rgba(21, 101, 192, 0.35);
  background: rgba(21, 101, 192, 0.1);
}

:root[data-theme="dark"] .sim-option-badge {
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.32);
}

.sim-option-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy-heading);
  line-height: 1.3;
}

.sim-option-desc {
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.sim-option-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  flex-shrink: 0;
  transition: border-color 0.16s ease, color 0.16s ease, background-color 0.16s ease;
}

.sim-option-card.active .sim-option-chevron,
.sim-option-row.active .sim-option-chevron {
  color: var(--btn-blue);
  border-color: var(--btn-blue);
  background: rgba(21, 101, 192, 0.08);
}

:root[data-theme="dark"] .sim-option-card.active .sim-option-chevron,
:root[data-theme="dark"] .sim-option-row.active .sim-option-chevron {
  color: var(--hover-cyan-bright);
  border-color: var(--hover-cyan-bright);
  background: rgba(56, 189, 248, 0.15);
}

.sim-popup-card {
  max-width: 600px;
  width: 100%;
  max-height: calc(100 * var(--app-vh) - 32px);
  overflow-y: auto;
}

.sim-popup-card.sim-popup-manual {
  max-width: min(960px, calc(100 * var(--app-vw) - 32px));
  padding: 22px 24px 24px;
  /* Avoid CSS transform animations (e.g. popIn scale) on the manual board modal
     so Chessground never caches a scaled/shifted getBoundingClientRect(). */
  animation: simManualFadeIn 0.16s ease-out;
}

@keyframes simManualFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.sim-modal-body {
  display: flex;
  flex-direction: column;
}

.sim-modal-panel {
  display: flex;
  flex-direction: column;
}

.sim-modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.sim-config-card {
  padding: 20px;
}

.sim-config-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.sim-config-title {
  margin: 6px 0 4px;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--navy-heading);
}

.sim-config-desc {
  margin: 0 0 14px;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.sim-turn-choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.sim-turn-choice-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border-light);
  background: var(--bg-subtle);
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.25;
  cursor: pointer;
  user-select: none;
}

.sim-turn-choice-label input[type="radio"] {
  accent-color: var(--btn-blue);
  width: 16px;
  height: 16px;
  margin: 0;
  flex-shrink: 0;
}

.sim-turn-choice-label.active {
  border-color: var(--btn-blue);
  background: rgba(21, 101, 192, 0.1);
  color: var(--navy-heading);
}

:root[data-theme="dark"] .sim-turn-choice-label.active {
  border-color: var(--hover-cyan-bright);
  background: rgba(56, 189, 248, 0.16);
}

#sim-panel-manual {
  --sim-manual-coord-size: 20px;
  --sim-manual-board-size: clamp(260px, min(calc(42 * var(--app-vw)), calc(100 * var(--app-vh) - 430px)), 440px);
  --sim-manual-col-w: calc(var(--sim-manual-board-size) + var(--sim-manual-coord-size));
}

.sim-manual-editor-layout {
  display: grid;
  grid-template-columns: var(--sim-manual-col-w) minmax(0, 1fr);
  gap: 24px;
  align-items: stretch;
}

.sim-manual-editor-wrap {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.sim-spare-palette {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
  padding: 6px;
  border-radius: 10px;
  background: var(--bg-subtle);
  border: 1.5px solid var(--border-light);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.sim-spare-piece {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 44px;
  padding: 4px;
  border-radius: 8px;
  border: 1.5px solid transparent;
  background: var(--bg-card);
  cursor: grab;
  touch-action: none;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.sim-spare-piece:hover {
  border-color: var(--btn-blue);
  transform: translateY(-1px);
}

.sim-spare-piece:active {
  cursor: grabbing;
}

.sim-spare-piece.active {
  border-color: var(--btn-blue);
  background: rgba(21, 101, 192, 0.14);
  box-shadow: 0 0 0 2px rgba(21, 101, 192, 0.22);
}

:root[data-theme="dark"] .sim-spare-piece.active {
  border-color: var(--hover-cyan-bright);
  background: rgba(56, 189, 248, 0.18);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.26);
}

.sim-spare-piece img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.sim-manual-board-frame {
  --cg-coord-size: var(--sim-manual-coord-size, 20px);
  width: calc(100% - var(--cg-coord-size));
  height: auto;
  aspect-ratio: 1 / 1;
  touch-action: none;
}

.sim-manual-board-frame .cg-wrap {
  width: 100%;
  height: 100%;
  overflow: visible;
  position: relative;
  touch-action: none;
}

.sim-manual-board-frame .cg-wrap cg-container {
  width: 100% !important;
  height: 100% !important;
  overflow: visible;
}

.sim-manual-board-frame cg-board {
  border-radius: 0;
  overflow: hidden;
}

.sim-manual-board-frame.trash-active cg-board {
  cursor: not-allowed;
}

.sim-manual-toolbar {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
}

.sim-manual-toolbar .btn {
  width: 100%;
  min-height: 36px;
  padding: 6px 6px;
  font-size: 0.79rem;
  line-height: 1.2;
  text-align: center;
  white-space: normal;
  justify-content: center;
}

.sim-manual-toolbar .sim-toolbar-tool {
  grid-column: span 3;
}

.sim-manual-toolbar .sim-toolbar-preset {
  grid-column: span 2;
}

#btn-sim-tool-trash.active {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.sim-manual-side-controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 18px;
  border-radius: 12px;
  background: var(--bg-subtle);
  border: 1.5px solid var(--border-light);
}

.sim-manual-guide {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  font-size: 0.85rem;
  line-height: 1.48;
  color: var(--text-muted);
}

.sim-manual-control-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sim-manual-control-block .form-label {
  margin-bottom: 0;
}

.sim-manual-side-controls .sim-turn-choice-label {
  padding: 10px 10px;
  font-size: 0.88rem;
}

.sim-turn-choice-label > span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.sim-manual-side-controls .sim-turn-choice-label:not(.active) {
  background: var(--bg-card);
}

.sim-manual-fen-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
}

.sim-manual-feedback {
  min-height: 18px;
  font-size: 0.84rem;
}

.sim-manual-start-actions {
  margin-top: auto;
  padding-top: 6px;
}

.sim-manual-start-btn {
  width: 100%;
  padding: 12px 18px;
  font-size: 0.96rem;
}

.main-container.sim-board-container {
  padding: 14px 24px;
}

.sim-page-shell.sim-board-shell {
  gap: 10px;
}

.sim-board-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.sim-board-shell .sim-board-topbar {
  margin-bottom: 0;
}

#sim-workspace {
  /* --cg-fit-h is measured by boardFit.js, as on the play pages, so the board fills the viewport */
  --cg-side-w: clamp(300px, calc(24 * var(--app-vw)), 344px);
  --cg-board-size: clamp(300px, min(var(--cg-avail-w), var(--cg-fit-h, calc(100 * var(--app-vh) - 206px))), 960px);
}

/* "Back to simulation options" is the first item of the board column: a left-aligned row above
   the board on tablet / mobile, and the top of the left track (above the player cards) on wide
   screens */
.sim-back-col {
  display: flex;
  justify-content: flex-start;
  align-self: stretch;
  min-width: 0;
}

.sim-back-btn {
  max-width: 100%;
  white-space: normal;
  text-align: left;
}

#sim-workspace .board-column {
  gap: 8px;
}

@media (min-width: 961px) {
  #sim-workspace {
    grid-template-columns: auto minmax(300px, 1fr);
  }
  #sim-workspace > .side-panel {
    width: 100%;
    max-width: 344px;
    justify-self: start;
    min-width: 0;
  }
  #sim-workspace > .side-panel > .card {
    padding: 16px 18px;
  }
  #sim-workspace > .side-panel .card-title {
    font-size: 1.05rem;
  }
}

@media (min-width: 961px) and (max-width: 1199px) {
  #sim-workspace {
    --cg-avail-w: calc(100 * var(--app-vw) - 520px);
  }
}

/* Wide screens: same three tracks as the play pages — back button + player cards | board |
   controls. The equal 1fr side tracks keep the board centered; the board column spans the first
   two tracks through a subgrid so boardFit.js measures a column holding just the board. */
@media (min-width: 1200px) {
  #sim-workspace {
    --cg-strip-w: 260px;
    /* same sizing as the play pages: two >=280px side tracks + 2 gaps + page padding +
       coordinates + scrollbar */
    --cg-avail-w: calc(100 * var(--app-vw) - 700px);
    grid-template-columns: minmax(0, 1fr) auto minmax(280px, 1fr);
  }
  #sim-workspace > .board-column {
    grid-column: 1 / span 2;
    grid-row: 1;
    display: grid;
    grid-template-columns: subgrid;
    grid-template-rows: auto auto 1fr;
    row-gap: 12px;
    /* match the workspace gap, otherwise the subgrid shifts the board off the centre track */
    column-gap: 24px;
    align-items: start;
  }
  #sim-workspace > .side-panel {
    grid-column: 3;
    grid-row: 1;
  }
  #sim-workspace > .board-column > .cg-board-frame {
    grid-column: 2;
    grid-row: 1 / span 3;
  }
  #sim-workspace > .board-column > .sim-back-col {
    grid-column: 1;
    grid-row: 1;
    justify-self: end;
    width: 100%;
    max-width: var(--cg-strip-w);
  }
  #sim-workspace > .board-column > .sim-back-col .sim-back-btn {
    width: 100%;
    justify-content: flex-start;
  }
  #sim-workspace > .board-column > .player-strip {
    grid-column: 1;
    justify-self: end;
    width: 100%;
    max-width: var(--cg-strip-w);
    margin-right: 0;
    padding: 14px;
  }
  #sim-workspace > .board-column > #sim-top-strip {
    grid-row: 2;
    align-self: start;
  }
  #sim-workspace > .board-column > #sim-bottom-strip {
    grid-row: 3;
    align-self: end;
    /* line up with the bottom edge of the board, not of the coordinate band below it */
    margin-bottom: var(--cg-coord-size, 24px);
  }
  #sim-workspace > .board-column > .player-strip .player-info > span:not(.color-dot) {
    white-space: normal;
    overflow-wrap: anywhere;
  }
  /* the bottom-left mascot would cover the bottom player card in the left track */
  body:has(#sim-workspace) .welcome-mascot {
    display: none;
  }
}

.sim-playmode-switch {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}

.sim-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.sim-hint-section {
  margin-bottom: 14px;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  overflow: hidden;
}

.sim-hint-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  background: transparent;
  border: 0;
  color: var(--navy-heading);
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  text-align: left;
}

.sim-hint-toggle:hover,
.sim-hint-toggle:focus-visible,
.sim-hint-toggle.open {
  background-color: #eff6ff;
}

.sim-hint-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.sim-hint-chevron {
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.sim-hint-toggle.open .sim-hint-chevron {
  transform: rotate(180deg);
}

.sim-hint-panel {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border-light);
}

.sim-hint-note {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-muted, #64748b);
}

/* "Show hint arrows" row at the top of the hint panel */
.sim-hint-arrows-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.sim-hint-arrows-label {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-main);
}

.sim-switch {
  position: relative;
  flex-shrink: 0;
  width: 42px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #cbd5e1;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.sim-switch.on {
  background: var(--btn-blue);
}

.sim-switch:focus-visible {
  outline: 2px solid var(--hover-cyan);
  outline-offset: 2px;
}

.sim-switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(10, 31, 68, 0.3);
  transition: transform 0.15s ease;
}

.sim-switch.on .sim-switch-knob {
  transform: translateX(18px);
}

:root[data-theme="dark"] .sim-switch:not(.on) {
  background: #475569;
}

.sim-hint-lines {
  border: 1px solid var(--border-light);
  border-radius: 8px;
  overflow: hidden;
  font-size: 0.86rem;
}

.sim-hint-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 8px;
  line-height: 1.6;
  cursor: pointer;
}

.sim-hint-line + .sim-hint-line {
  border-top: 1px solid var(--border-light);
}

.sim-hint-line:hover {
  background: #eff6ff;
}

.sim-hint-eval {
  flex: 0 0 42px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--navy-heading);
}

.sim-hint-line.best .sim-hint-eval {
  color: #15803d;
}

.sim-hint-pv {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 2px;
  min-width: 0;
}

.sim-hint-num {
  margin-left: 4px;
  color: var(--text-muted);
}

.sim-hint-san {
  padding: 0 3px;
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.sim-hint-san.first {
  font-weight: 700;
}

.sim-hint-san:hover,
.sim-hint-san:focus-visible {
  color: #2563eb;
  background: rgba(59, 130, 246, 0.14);
}

:root[data-theme="dark"] .sim-hint-toggle:hover,
:root[data-theme="dark"] .sim-hint-toggle:focus-visible,
:root[data-theme="dark"] .sim-hint-toggle.open,
:root[data-theme="dark"] .sim-hint-line:hover {
  background-color: rgba(59, 130, 246, 0.16);
}

:root[data-theme="dark"] .sim-hint-line.best .sim-hint-eval {
  color: #4ade80;
}

:root[data-theme="dark"] .sim-hint-san:hover,
:root[data-theme="dark"] .sim-hint-san:focus-visible {
  color: #93c5fd;
}

.sim-fen-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sim-action-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.sim-action-icon-btn:not(:disabled):hover,
.sim-action-icon-btn:not(:disabled):focus-visible {
  background-color: #eff6ff;
}

:root[data-theme="dark"] .sim-action-icon-btn:not(:disabled):hover,
:root[data-theme="dark"] .sim-action-icon-btn:not(:disabled):focus-visible {
  background-color: rgba(59, 130, 246, 0.16);
}

@media (max-width: 860px) {
  #sim-panel-manual {
    --sim-manual-coord-size: 18px;
  }
  .sim-popup-card.sim-popup-manual {
    max-width: min(620px, calc(100 * var(--app-vw) - 24px));
  }
  .sim-manual-editor-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }
  .sim-manual-editor-wrap {
    width: min(480px, 100%);
    margin: 0 auto;
  }
  .sim-manual-side-controls {
    padding: 14px;
    gap: 12px;
  }
}

@media (max-width: 768px) {
  .main-container.sim-board-container {
    padding: 12px var(--mobile-gutter) 20px;
  }
  .sim-page-title {
    font-size: 1.32rem;
  }
  .sim-option-row {
    padding: 12px 14px;
    gap: 10px;
  }
  .sim-option-icon {
    width: 38px;
    height: 38px;
  }
  .sim-popup-card,
  .sim-popup-card.sim-popup-manual {
    padding: 16px 14px 18px;
    max-height: calc(100 * var(--app-vh) - 20px);
  }
}

@media (max-width: 520px) {
  .sim-popup-card,
  .sim-popup-card.sim-popup-manual {
    padding: 14px 12px 16px;
    max-height: calc(100 * var(--app-vh) - 16px);
  }
  .sim-turn-choice-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .sim-manual-side-controls .sim-turn-choice-label {
    white-space: normal;
  }
  .sim-spare-piece {
    height: 38px;
  }
  .sim-manual-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .sim-manual-toolbar .sim-toolbar-tool,
  .sim-manual-toolbar .sim-toolbar-preset {
    grid-column: auto;
  }
  .sim-manual-toolbar .sim-toolbar-preset:last-child {
    grid-column: 1 / -1;
  }
}

/* Welcome mascot: greets a new / returning visitor in the bottom-left corner */
.welcome-mascot {
  position: fixed;
  left: 12px;
  bottom: 0;
  z-index: 180;
  display: flex;
  flex-direction: row-reverse;
  align-items: flex-end;
  gap: 4px;
  max-width: calc(100 * var(--app-vw) - 24px);
  pointer-events: none;
  animation: welcomeMascotIn 0.35s ease-out;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.welcome-mascot-leaving {
  opacity: 0;
  transform: translateY(12px);
}

.welcome-mascot-bubble {
  position: relative;
  pointer-events: auto;
  max-width: 260px;
  margin-bottom: 70px;
  min-width: 0;
  padding: 12px 30px 12px 14px;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 4px;
  box-shadow: var(--shadow-md);
}

.welcome-mascot-text {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.5;
}

.welcome-mascot-close {
  position: absolute;
  top: 2px;
  right: 4px;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}

.welcome-mascot-close:hover {
  color: var(--text-main);
}

.welcome-mascot-figure {
  flex: 0 0 auto;
  display: block;
  height: 190px;
  width: auto;
  filter: drop-shadow(0 6px 10px rgba(10, 31, 68, 0.28));
  pointer-events: none;
  user-select: none;
}

/* Toasts sit bottom-right above the hotline button */
.toast-container {
  bottom: 80px;
}

@keyframes welcomeMascotIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 480px) {
  .welcome-mascot-figure {
    height: 140px;
  }
  .toast-container {
    bottom: 64px;
  }
  .welcome-mascot-bubble {
    max-width: none;
    flex: 1 1 auto;
    min-width: 0;
  }
}

/* Piece icon that names the side to move inside status messages */
.turn-side-icon {
  display: inline-block;
  width: 2.2em;
  height: 2.2em;
  margin: -0.5em 0.35em -0.5em 0.1em;
  padding: 2px;
  vertical-align: middle;
  background: #e8eef8;
  border: 1px solid var(--border-light);
  border-radius: 7px;
}

/* =========================================================
   DONATE LETTER ("LỜI NGỎ")
   ========================================================= */
.popup-box.popup-box--donate {
  max-width: 680px;
  max-height: calc(100 * var(--app-dvh) - 32px);
  display: flex;
  flex-direction: column;
}

.popup-box.popup-box--donate #popup-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
  padding-right: 4px;
}

.donate-letter {
  --letter-navy: #1e3a8a;
  --letter-gold: #b7791f;
  --letter-red: #be3a4a;
  --letter-check: #2f855a;
  --letter-footer-bg: #eef3f8;
  color: var(--text-main);
  font-size: 0.95rem;
  line-height: 1.6;
  text-align: left;
}

:root[data-theme="dark"] .donate-letter {
  --letter-navy: #7fb2ff;
  --letter-gold: #f2b84b;
  --letter-red: #f58b98;
  --letter-check: #5fd39a;
  --letter-footer-bg: rgba(255, 255, 255, 0.05);
}

.donate-letter p {
  margin: 0 0 12px;
}

.donate-letter-title {
  margin: 0;
  text-align: center;
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--letter-navy);
}

.donate-letter-tagline {
  margin-top: 4px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--letter-gold);
}

.donate-letter-divider {
  width: 140px;
  margin: 8px auto 18px;
  border-bottom: 1.5px solid var(--text-muted);
}

.donate-letter-gold {
  color: var(--letter-gold);
}

.donate-letter-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0 8px;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.2px;
}

.donate-letter-heading--blue {
  color: var(--letter-navy);
}

.donate-letter-heading--blue span {
  color: #2b6cb0;
}

.donate-letter-heading--red {
  color: var(--letter-red);
}

.donate-letter-heading--gold {
  color: var(--letter-gold);
}

.donate-letter-subheading {
  margin: 4px 0 6px;
  font-weight: 700;
  color: var(--letter-navy);
}

.donate-letter-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0 0 0 4px;
  font-size: 0.9rem;
}

.donate-letter-list li {
  position: relative;
  padding-left: 22px;
  margin-bottom: 4px;
}

.donate-letter-list li::before {
  content: '✓';
  position: absolute;
  left: 2px;
  top: 0;
  font-weight: 700;
  color: var(--letter-check);
}

.donate-letter-footer {
  margin-top: 18px;
  padding: 12px 16px;
  text-align: center;
  background: var(--letter-footer-bg);
  border-top: 2px solid var(--letter-gold);
  border-bottom: 1px solid var(--border-light);
}

.donate-letter-footer-name {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--letter-navy);
}

.donate-letter-footer-motto {
  margin-top: 2px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--letter-gold);
}

@media (max-width: 480px) {
  .donate-letter-title {
    font-size: 1.55rem;
  }
}

/* =========================================================
   MANAGE: STAT CARDS ALIGNED (numbers on one line)
   ========================================================= */
.system-manage-stats-grid > .stat-card {
  display: flex;
  flex-direction: column;
}

.system-manage-stats-grid > .stat-card > div:first-child {
  line-height: 1.35;
  min-height: 2.7em;
}

@media (max-width: 480px) {
  .system-manage-stats-grid > .stat-card > div:first-child {
    min-height: 0;
  }
}

/* =========================================================
   HOME QUICK LINKS (Thi đấu / Học)
   ========================================================= */
.home-quick-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 4px 0 22px;
}

.home-quick-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  padding: 16px 18px;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-main);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.home-quick-btn:hover,
.home-quick-btn:focus-visible {
  transform: translateY(-2px);
  border-color: var(--btn-blue);
  box-shadow: var(--shadow-md);
  outline: none;
}

.home-quick-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--btn-blue);
}

.home-quick-btn--learn .home-quick-icon {
  background: #0f9d6b;
}

.home-quick-icon img {
  width: 36px;
  height: 36px;
}

.home-quick-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.home-quick-label {
  font-size: 1.08rem;
  font-weight: 800;
  color: var(--navy-heading);
}

.home-quick-desc {
  margin-top: 2px;
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.4;
}

@media (max-width: 720px) {
  .home-quick-links {
    gap: 10px;
  }
  .home-quick-btn {
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px 8px;
    text-align: center;
  }
  .home-quick-text {
    align-items: center;
  }
  .home-quick-icon {
    width: 42px;
    height: 42px;
  }
  .home-quick-icon img {
    width: 24px;
    height: 24px;
  }
  .home-quick-label {
    font-size: 0.95rem;
  }
  .home-quick-desc {
    display: none;
  }
}

/* =========================================================
   HOMEPAGE LAYOUT: main column + compact lists on the right
   ========================================================= */
.home-layout {
  /* Spans the full page width (edge to edge, inside the page padding): the quick buttons,
     the cover image and the blog share the main column, and the lists sit right beside
     them with the same gap everywhere. */
  --home-gap: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 25%);
  grid-template-rows: auto auto 1fr;
  grid-template-areas:
    "quick side"
    "slider side"
    "blogs side";
  column-gap: var(--home-gap);
  align-items: start;
  width: 100%;
  max-width: none;
  margin: 0;
}

.home-layout > .home-quick-links {
  grid-area: quick;
  gap: var(--home-gap);
  margin: 0 0 var(--home-gap);
}

.home-layout > .home-slider {
  grid-area: slider;
  max-width: none;
  margin: 0 0 var(--home-gap);
}

.home-layout > .home-blogs-section {
  grid-area: blogs;
  margin: 0;
}

.home-layout .home-blogs-list {
  gap: var(--home-gap);
}

.home-side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: var(--home-gap);
  min-width: 0;
}

/* "Blog" / "Sự kiện" switch: phones only (see the 760px rules below) */
.home-mobile-tabs {
  display: none;
}

.home-side-card {
  min-width: 0;
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.home-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1.5px solid var(--border-light);
  background: var(--bg-subtle);
}

.home-side-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--navy-heading);
}

.home-side-more {
  flex-shrink: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--btn-blue);
  text-decoration: none;
  white-space: nowrap;
}

:root[data-theme="dark"] .home-side-more,
:root[data-theme="dark"] .home-side-more-row,
:root[data-theme="dark"] .home-side-empty a {
  color: var(--hover-cyan-bright);
}

.home-side-more:hover,
.home-side-more:focus-visible {
  text-decoration: underline;
}

.home-side-body {
  padding: 6px;
}

.home-side-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.home-side-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  text-decoration: none;
}

a.home-side-row:hover,
a.home-side-row:focus-visible {
  background: var(--bg-subtle);
  outline: none;
}

.home-side-row.is-current {
  background: var(--bg-subtle);
}

.home-side-row-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.home-side-row-name {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-side-row-name a {
  color: inherit;
  text-decoration: none;
}

.home-side-row-name a:hover,
.home-side-row-name a:focus-visible {
  text-decoration: underline;
}

.home-side-row-meta {
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-side-row-tag {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-light);
  background: var(--bg-subtle);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.home-side-row-tag:empty {
  display: none;
}

.home-side-row--rank .users-rank-badge {
  flex-shrink: 0;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  font-size: 0.78rem;
}

.home-side-row--rank .users-elo-pill {
  flex-shrink: 0;
  padding: 2px 9px;
  font-size: 0.78rem;
}

.home-side-more-row {
  display: block;
  padding: 6px 8px 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--btn-blue);
  text-decoration: none;
}

.home-side-more-row:hover,
.home-side-more-row:focus-visible {
  text-decoration: underline;
}

.home-side-empty {
  padding: 12px 8px;
  font-size: 0.85rem;
  line-height: 1.45;
  text-align: center;
  color: var(--text-muted);
}

.home-side-empty a {
  font-weight: 600;
  color: var(--btn-blue);
}

/* Narrower screens: the lists drop under the cover image, above the blog */
@media (max-width: 1100px) {
  .home-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas:
      "quick"
      "slider"
      "greet"
      "side"
      "blogs";
  }
  /* the greeting card (moved here by app.js) sits on its own row above the lists / tabs */
  .home-layout > .home-greeting-card {
    grid-area: greet;
    margin: 0 0 var(--home-gap);
  }
  .home-side {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
    margin: 0 0 var(--home-gap);
  }
}

@media (max-width: 760px) {
  .home-layout {
    --home-gap: 12px;
    grid-template-areas:
      "quick"
      "slider"
      "greet"
      "tabs"
      "side"
      "blogs";
  }
  .home-side {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Under the cover image: two tabs, one of the two blocks visible at a time */
  .home-mobile-tabs {
    grid-area: tabs;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    padding: 4px;
    margin: 0 0 var(--home-gap);
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--bg-subtle);
  }
  .home-mobile-tab {
    min-width: 0;
    min-height: 42px;
    padding: 8px 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
  }
  .home-mobile-tab.is-active {
    background: var(--btn-blue);
    color: #ffffff;
    box-shadow: var(--shadow-sm);
  }
  .home-mobile-tab:focus-visible {
    outline: 2px solid var(--btn-blue);
    outline-offset: 2px;
  }
  .home-layout[data-home-tab="blog"] > .home-side,
  .home-layout[data-home-tab="events"] > .home-blogs-section {
    display: none;
  }
}

/* =========================================================
   PLAY VS AI: level buttons never overflow
   ========================================================= */
.color-choice-grid .btn,
.ai-setup-time-grid .btn {
  min-width: 0;
  white-space: normal;
  line-height: 1.3;
}

/* =========================================================
   SITE FOOTER
   ========================================================= */
.site-footer {
  margin-top: auto;
  background: var(--navy-1);
  color: #cbd5e1;
  font-size: 0.92rem;
}

.site-footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px 48px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 24px;
}

.site-footer-logo {
  font-size: 1.35rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: 0.3px;
}

.site-footer-motto {
  margin: 8px 0 0;
  color: #f2b84b;
  font-weight: 600;
  line-height: 1.5;
}

.site-footer-title {
  margin: 0 0 12px;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #ffffff;
}

.site-footer-phone {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.site-footer-phone svg {
  flex-shrink: 0;
  color: #f2b84b;
}

.site-footer-phone strong {
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.site-footer-phone:hover,
.site-footer-phone:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--hover-cyan-bright);
  outline: none;
}

.site-footer-bottom {
  padding: 14px 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
  font-size: 0.82rem;
  color: #94a3b8;
}

:root[data-theme="dark"] .site-footer {
  background: #070e1d;
  border-top: 1px solid var(--border-light);
}

@media (max-width: 720px) {
  .site-footer-inner {
    gap: 20px;
    padding: 24px 16px 18px;
  }
}

/* Board pages are fitted to the viewport height: no footer there. */
#app-shell:has(.chess-workspace) .site-footer {
  display: none;
}

/* =========================================================
   HOMEPAGE SLIDESHOW
   ========================================================= */
.home-slider {
  /* Ảnh bìa nhỏ gọn hơn khung trang, căn giữa; vẫn giữ tỉ lệ 2:1 */
  width: 100%;
  max-width: 820px;
  margin: 0 auto 18px;
}

.home-slider-viewport {
  position: relative;
  width: 100%;
  /* Khung theo tỉ lệ ảnh bìa chuẩn (~1776 x 887, tức 2:1). Ảnh khác tỉ lệ được
     giữ nguyên và chèn viền đen (letterbox) thay vì bị cắt. */
  aspect-ratio: 2 / 1;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  touch-action: pan-y;
}

/* The outline is an overlay, not a border: a real border would shrink the inside of the
   frame away from 2:1 and leave hairline black bars beside a 2:1 image. */
.home-slider-viewport::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--border-light);
  border-radius: inherit;
  pointer-events: none;
}

.home-slide {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

.home-slide.is-active {
  opacity: 1;
  visibility: visible;
}

.home-slide img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  background: #000;
  display: block;
  user-select: none;
}

.home-slide-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 36px 20px 34px;
  background: linear-gradient(to top, rgba(5, 14, 32, 0.82), rgba(5, 14, 32, 0));
  color: #ffffff;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  overflow-wrap: anywhere;
}

.home-slider-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(5, 14, 32, 0.5);
  color: #ffffff;
  cursor: pointer;
  transition: background 0.15s ease;
}

.home-slider-arrow:hover,
.home-slider-arrow:focus-visible {
  background: rgba(5, 14, 32, 0.82);
  outline: none;
}

.home-slider-arrow--prev {
  left: 12px;
}

.home-slider-arrow--next {
  right: 12px;
}

.home-slider-dots {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  max-width: calc(100% - 24px);
}

.home-slider-dot {
  width: 10px;
  height: 10px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: background 0.15s ease, width 0.15s ease;
}

.home-slider-dot.is-active {
  width: 24px;
  border-radius: 6px;
  background: #ffffff;
}

.home-slider-manage {
  position: absolute;
  top: 12px;
  right: 12px;
  box-shadow: var(--shadow-md);
}

.home-slider-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 22px 16px;
  border: 1.5px dashed var(--border-light);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  text-align: center;
}

.home-slider-empty .home-slider-manage {
  position: static;
  box-shadow: none;
}

/* Slide manager (admin modal) */
.home-slides-hint {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.home-slides-count {
  margin-left: auto;
  align-self: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
}

.home-slides-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(46 * var(--app-vh));
  overflow-y: auto;
}

.home-slides-row {
  display: grid;
  grid-template-columns: 24px 112px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.home-slides-order {
  font-weight: 800;
  color: var(--text-muted);
  text-align: center;
}

.home-slides-thumb {
  width: 112px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--navy-1);
}

.home-slides-actions {
  display: flex;
  gap: 6px;
}

.home-slides-actions .btn {
  padding: 6px 8px;
}

@media (max-width: 720px) {
  .home-slider-viewport {
    border-radius: var(--radius-md);
  }
  .home-slider-arrow {
    width: 34px;
    height: 34px;
  }
  .home-slider-arrow--prev {
    left: 6px;
  }
  .home-slider-arrow--next {
    right: 6px;
  }
  .home-slide-caption {
    padding: 28px 12px 30px;
    font-size: 0.9rem;
  }
  .home-slides-row {
    grid-template-columns: 24px 84px minmax(0, 1fr);
  }
  .home-slides-thumb {
    width: 84px;
    height: 40px;
  }
  .home-slides-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}

@media (prefers-reduced-motion: reduce) {
  .home-slide {
    transition: none;
  }
}

/* =========================================================
   LAYOUT & OVERFLOW FIXES (whole-site pass)
   Rules found by walking every page at phone / tablet / desktop
   widths in both languages. Kept together at the end of the file
   so they win over the older per-page rules they correct.
   ========================================================= */

/* Analysis: the evaluation ("+0.1", "M12") is wider than the narrow bar it sits in,
   so it is written along the bar instead of across it */
.eval-bar-label {
  left: 50%;
  right: auto;
  bottom: 4px;
  transform: translateX(-50%);
  writing-mode: vertical-rl;
  padding: 3px 0;
  border-radius: 3px;
  font-size: 0.62rem;
  line-height: 1.15;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

/* Homepage slideshow on phones: the caption stays clear of the arrows */
@media (max-width: 720px) {
  .home-slider-arrow {
    top: 40%;
    width: 30px;
    height: 30px;
  }
  .home-slide-caption {
    padding: 22px 12px 24px;
    font-size: 0.82rem;
    line-height: 1.35;
  }
}

/* Leaderboard: four short columns fit a phone screen, no sideways scrolling */
@media (max-width: 768px) {
  .users-card .users-table {
    min-width: 0;
  }
  .users-card .users-table th.users-col-rank,
  .users-card .users-table td.users-col-rank {
    width: 50px !important;
    padding-left: 4px !important;
    padding-right: 4px !important;
  }
  .users-card .users-table .users-col-elo {
    width: 58px;
  }
  .users-card .users-table th.users-col-games {
    width: 82px !important;
  }
}

/* Top bar on phones: show the user's name instead of a cut-off "Xin chào ..." */
@media (max-width: 768px) {
  .user-menu-greeting {
    display: none;
  }
}

/* Usernames in the user tables: shorten with "..." inside their column instead of
   running over the next column */
.user-cell-wrap > .user-profile-link {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-cell-wrap > .user-you-badge {
  flex-shrink: 0;
}

.users-table td.users-col-username,
.users-table td.users-col-fullname {
  overflow: hidden;
}

/* Level page on phones: the summary card is only as tall as its text
   (its 240px basis is a width on desktop but became a height once stacked) */
@media (max-width: 640px) {
  .level-summary-main {
    flex: 0 0 auto;
  }
}

/* Phones: a long label on a full-width or dialog button wraps onto a second line
   instead of leaving its button */
@media (max-width: 600px) {
  .btn-block,
  .modal-actions .btn,
  .tournament-card-actions .btn {
    white-space: normal;
    text-align: center;
  }
  .modal-actions .btn {
    flex: 1 1 auto;
    min-width: 0;
  }
}

/* Class cards: the class name may use two lines instead of being cut to a few letters */
.class-card-title {
  white-space: normal;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.3;
}

.class-card-header {
  align-items: flex-start;
}

/* Tournament pairings / standings: many columns, so on small screens they scroll sideways
   with comfortable column widths instead of squeezing names into one word per line */
@media (max-width: 900px) {
  .data-table.pairings-table,
  .data-table.standings-table {
    width: max-content;
    min-width: 100%;
  }
  .data-table.pairings-table td,
  .data-table.standings-table td {
    max-width: 230px;
  }
}

/* Tournament registration list: the @username sits under the player's name,
   so the table fits a phone without sideways scrolling */
.tp-player-cell .tp-player-handle {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.tp-player-cell strong {
  overflow-wrap: anywhere;
}

/* Analysis "learn from mistakes" buttons: four share a narrow side panel, so a longer
   label ("Nước tối ưu") wraps inside its button instead of spilling over the edge */
.analysis-mistake-helper-btns .btn {
  white-space: normal;
  text-align: center;
  line-height: 1.2;
  min-width: 0;
}

/* Class members dialog: the "Xóa khỏi lớp" button wraps inside its narrow column */
.users-table .users-col-action .btn {
  white-space: normal;
  text-align: center;
}

/* Game result notice: congratulates the winner / encourages the loser when a game ends */
.game-result-card {
  max-width: 420px;
  text-align: center;
  border-top-color: var(--btn-blue);
}

.game-result-card[data-outcome="win"] {
  border-top-color: var(--success);
}

.game-result-figure {
  display: block;
  height: 120px;
  width: auto;
  margin: 0 auto 10px;
  user-select: none;
}

/* the loss clip is square: a bit larger than the mascot so it reads well */
.game-result-video {
  height: 150px;
  width: 150px;
  object-fit: contain;
  border-radius: var(--radius-md);
  pointer-events: none;
}

.game-result-title {
  margin: 0 0 8px;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--navy-heading);
  overflow-wrap: anywhere;
}

.game-result-card[data-outcome="win"] .game-result-title {
  color: var(--success);
}

.game-result-message {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
}

.game-result-detail {
  margin: 0 0 16px;
  font-size: 0.88rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.game-result-detail:empty {
  display: none;
}

.game-result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.game-result-actions .btn {
  flex: 1 1 120px;
  white-space: normal;
}

:root[data-theme="dark"] .game-result-actions .btn-outline {
  background-color: transparent;
  color: var(--hover-cyan-bright);
  border-color: var(--hover-cyan-bright);
}

/* =========================================================================
   CURRICULUM BOOKSHELF: each curriculum file is a book standing on a wooden shelf
   ========================================================================= */
.curriculum-bookshelf {
  --shelf-row: 196px;
  --shelf-plank: 18px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  column-gap: 3px;
  min-height: var(--shelf-row);
  margin-top: 10px;
  padding: 0 18px;
  border: 12px solid #7a4a21;
  border-radius: 10px;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.22), var(--shadow-md);
  /* one tile per shelf row: shadow under the plank above, then the plank the books stand on */
  background:
    linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.38) 0,
        rgba(0, 0, 0, 0) 16px,
        rgba(0, 0, 0, 0) calc(100% - var(--shelf-plank)),
        #c08a52 calc(100% - var(--shelf-plank)),
        #a06c38 calc(100% - 5px),
        #6d4420 100%
      )
      0 0 / 100% var(--shelf-row) repeat-y,
    linear-gradient(90deg, #5a3819, #6b4423 50%, #5a3819);
}

/* Each book stands upright with only its spine showing */
.shelf-book-slot {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: var(--shelf-row);
  padding-bottom: var(--shelf-plank);
}

.shelf-book {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  width: var(--book-width, 40px);
  height: var(--book-height, 150px);
  padding: 0 0 12px;
  border: none;
  border-radius: 3px 3px 2px 2px;
  /* rounded spine: light down the middle, darker towards both edges */
  background:
    linear-gradient(
      90deg,
      rgba(0, 0, 0, 0.42) 0,
      rgba(0, 0, 0, 0.08) 18%,
      rgba(255, 255, 255, 0.2) 42%,
      rgba(255, 255, 255, 0.06) 60%,
      rgba(0, 0, 0, 0.18) 82%,
      rgba(0, 0, 0, 0.45) 100%
    ),
    var(--book-color, #1f3f7a);
  box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.45);
  color: #fdf6e3;
  font-family: inherit;
  cursor: pointer;
  transform-origin: bottom center;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

/* gold bands near the top of the spine */
.shelf-book-band {
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #8a6a1e, #e8c96b 45%, #8a6a1e);
  opacity: 0.85;
}

.shelf-book-band:first-child {
  top: 14px;
}

.shelf-book-band:nth-child(2) {
  top: 21px;
}

/* admin: edit the spine title, a small button at the foot of the spine */
.shelf-book-edit {
  position: absolute;
  bottom: calc(var(--shelf-plank) + 6px);
  left: 50%;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1.5px solid #ffffff;
  border-radius: 50%;
  background: var(--btn-blue);
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  transform: translateX(-50%);
}

.shelf-book-edit:focus-visible {
  outline: 2px solid #ffe08a;
  outline-offset: 2px;
}

.book-title-file {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

/* the title printed down the spine, between the gold bands and the foot of the book;
   a long title wraps onto a second line, anything longer is cut (the tooltip shows it whole) */
.shelf-book-spine-title {
  position: absolute;
  top: 30px;
  bottom: 10px;
  left: 50%;
  max-width: 2.3em;
  overflow: hidden;
  writing-mode: vertical-rl;
  text-align: center;
  overflow-wrap: anywhere;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.15;
  color: #fdf6e3;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.55);
  transform: translateX(-50%);
  pointer-events: none;
}

/* leave room for the admin's edit button at the foot of the spine */
.shelf-book-slot.has-admin-tools .shelf-book-spine-title {
  bottom: 34px;
}

.shelf-book:hover,
.shelf-book:focus-visible {
  transform: translateY(-10px);
  box-shadow: 3px 8px 12px rgba(0, 0, 0, 0.55);
}

.shelf-book:focus-visible {
  outline: 2px solid #ffe08a;
  outline-offset: 2px;
}

.shelf-book-delete {
  position: absolute;
  /* over the gold bands at the head of the spine, leaving the spine free for the title */
  top: calc(100% - var(--shelf-plank) - var(--book-height, 150px) + 4px);
  left: 50%;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1.5px solid #ffffff;
  border-radius: 50%;
  background: var(--danger);
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  transform: translateX(-50%);
}

.shelf-book-delete svg {
  width: 12px;
  height: 12px;
}

/* the book title, shown beside the mouse pointer */
.shelf-book-tooltip {
  position: fixed;
  z-index: 185;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 260px;
  padding: 7px 11px;
  border-radius: 8px;
  background: var(--navy-1);
  color: #ffffff;
  box-shadow: var(--shadow-md);
  pointer-events: none;
}

:root[data-theme="dark"] .shelf-book-tooltip {
  border: 1px solid var(--border-light);
}

.shelf-book-tooltip-title {
  font-size: 0.88rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.shelf-book-tooltip-meta {
  font-size: 0.74rem;
  color: #cbd5e1;
}

.shelf-book-tooltip-meta:empty {
  display: none;
}

@media (max-width: 520px) {
  .curriculum-bookshelf {
    --shelf-row: 176px;
    padding: 0 10px;
    border-width: 9px;
  }
  .shelf-book {
    width: calc(var(--book-width, 40px) - 4px);
    height: calc(var(--book-height, 150px) - 16px);
  }
  .shelf-book-delete {
    top: calc(100% - var(--shelf-plank) - var(--book-height, 150px) + 20px);
  }
  .shelf-book-spine-title {
    font-size: 11px;
  }
}

/* =========================================================================
   BOOK READER: full-screen open book, two pages side by side
   ========================================================================= */
body.book-reader-open {
  overflow: hidden;
}

.book-reader {
  position: fixed;
  inset: 0;
  z-index: 190;
  display: flex;
  flex-direction: column;
  background: #1b2233;
  color: #f1f5f9;
}

.book-reader-bar,
.book-reader-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: #0d1424;
}

.book-reader-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.book-reader-title {
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-reader-tools {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.book-reader-tool,
.book-reader-step,
.book-reader-side {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid rgba(241, 245, 249, 0.35);
  background: rgba(241, 245, 249, 0.08);
  color: #f1f5f9;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.book-reader-tool {
  min-width: 36px;
  height: 36px;
  padding: 0 9px;
  border-radius: 8px;
}

.book-reader-close {
  background: var(--btn-blue);
  border-color: var(--btn-blue);
}

.book-reader-step {
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  white-space: nowrap;
}

.book-reader-tool:hover,
.book-reader-step:hover:not(:disabled),
.book-reader-side:hover:not(:disabled) {
  background: rgba(241, 245, 249, 0.2);
  color: #ffffff;
}

.book-reader-close:hover {
  background: var(--btn-blue-dark);
}

.book-reader-tool:focus-visible,
.book-reader-step:focus-visible,
.book-reader-side:focus-visible {
  outline: 2px solid var(--hover-cyan-bright);
  outline-offset: 2px;
}

.book-reader-step:disabled,
.book-reader-side:disabled {
  opacity: 0.3;
  cursor: default;
}

.book-reader-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 64px;
  overflow: hidden;
  touch-action: pan-y;
}

.book-reader-side {
  position: absolute;
  top: 50%;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  transform: translateY(-50%);
}

.book-reader-side.prev {
  left: 10px;
}

.book-reader-side.next {
  right: 10px;
}

.book-reader-status {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: min(90%, 460px);
  padding: 12px 18px;
  border-radius: 10px;
  background: rgba(13, 20, 36, 0.9);
  font-size: 0.94rem;
  text-align: center;
  transform: translate(-50%, -50%);
}

.book-reader-status.is-error {
  color: #fecaca;
}

.book-reader-book {
  position: relative;
  display: flex;
  align-items: stretch;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.55));
}

.book-reader.is-busy .book-reader-book {
  opacity: 0.6;
}

.book-page {
  position: relative;
  flex: 0 0 auto;
  background: #ffffff;
}

.book-page canvas {
  display: block;
}

.book-page-blank {
  background: #f1ede2;
}

/* shading towards the spine, where the two pages meet */
.book-reader-book[data-pages="2"] .book-page::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.book-reader-book[data-pages="2"] .book-page:first-child::after {
  background: linear-gradient(to left, rgba(0, 0, 0, 0.22), rgba(0, 0, 0, 0.05) 5%, rgba(0, 0, 0, 0) 14%);
}

.book-reader-book[data-pages="2"] .book-page:last-child::after {
  background: linear-gradient(to right, rgba(0, 0, 0, 0.22), rgba(0, 0, 0, 0.05) 5%, rgba(0, 0, 0, 0) 14%);
}

/* Word documents: one sheet of paper holding page-sized text columns */
.book-sheet {
  position: relative;
  padding: 30px 34px;
  background: #fffdf7;
  /* the text keeps the light palette on paper, whatever the site theme is */
  --text-main: #17253d;
  --text-muted: #52637d;
  --navy-heading: #0a1f44;
  --border-light: #d7e3f4;
  --bg-subtle: #f1f5fb;
  --bg-card: #ffffff;
  --btn-blue: #1d6ae5;
  color: #17253d;
}

.book-reader-book[data-pages="2"] .book-sheet::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(50% - 34px);
  width: 68px;
  background: linear-gradient(
    to right,
    rgba(0, 0, 0, 0),
    rgba(0, 0, 0, 0.07) 40%,
    rgba(0, 0, 0, 0.2) 50%,
    rgba(0, 0, 0, 0.07) 60%,
    rgba(0, 0, 0, 0)
  );
  pointer-events: none;
}

.book-flow-window {
  overflow: hidden;
}

.book-flow {
  height: 100%;
  column-fill: auto;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.book-flow img {
  max-width: 100%;
  max-height: var(--book-page-height, 100%);
  height: auto;
  object-fit: contain;
  break-inside: avoid;
}

.book-flow .docx-heading-1,
.book-flow .docx-heading-2,
.book-flow .docx-heading-3,
.book-flow .docx-heading-4 {
  break-after: avoid;
}

.book-flow .docx-table tr {
  break-inside: avoid;
}

/* a page break in the Word file starts a new page of the book */
.book-flow .docx-page-break {
  break-before: column;
  height: 0;
  margin: 0;
  border: none;
}

.book-flow-end {
  display: block;
  width: 1px;
  height: 1px;
}

.book-reader-book.turn-next {
  animation: bookTurnNext 0.26s ease-out;
}

.book-reader-book.turn-prev {
  animation: bookTurnPrev 0.26s ease-out;
}

@keyframes bookTurnNext {
  from {
    opacity: 0.35;
    transform: translateX(22px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes bookTurnPrev {
  from {
    opacity: 0.35;
    transform: translateX(-22px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.book-reader-progress {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 0;
}

.book-reader-pageinfo {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.book-reader-slider {
  flex: 0 1 260px;
  min-width: 60px;
  accent-color: var(--hover-cyan);
}

@media (max-width: 759px) {
  .book-reader-stage {
    padding: 10px 8px;
  }
  .book-reader-side,
  .book-reader-close span,
  .book-reader-step span {
    display: none;
  }
  .book-reader-bar,
  .book-reader-foot {
    padding: 8px 10px;
  }
  .book-sheet {
    padding: 20px 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .shelf-book {
    transition: none;
  }
  .book-reader-book.turn-next,
  .book-reader-book.turn-prev {
    animation: none;
  }
}

/* Floating hotline: phone icon + number pinned to the bottom-right corner,
   opposite the welcome mascot on the left */
.floating-phone {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 175;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px 6px 6px;
  border-radius: 999px;
  background: var(--navy-1);
  color: #ffffff;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: 0.4px;
  box-shadow: 0 6px 18px rgba(10, 31, 68, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.floating-phone:hover,
.floating-phone:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 10px 22px rgba(10, 31, 68, 0.36);
  outline: none;
}

.floating-phone-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #f2b84b;
  color: var(--navy-1);
  flex-shrink: 0;
  animation: floatingPhoneRing 1.6s ease-in-out infinite;
}

.floating-phone-icon::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid #f2b84b;
  animation: floatingPhonePulse 1.6s ease-out infinite;
}

.floating-phone-number {
  white-space: nowrap;
  font-size: 0.98rem;
}

@keyframes floatingPhoneRing {
  0%, 60%, 100% { transform: rotate(0); }
  10%, 30% { transform: rotate(-14deg); }
  20%, 40% { transform: rotate(14deg); }
}

@keyframes floatingPhonePulse {
  from { transform: scale(1); opacity: 0.8; }
  to { transform: scale(1.6); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .floating-phone-icon,
  .floating-phone-icon::after {
    animation: none;
  }
}

@media (max-width: 480px) {
  .floating-phone {
    right: 10px;
    bottom: 10px;
    gap: 8px;
    padding: 4px 12px 4px 4px;
  }
  .floating-phone-icon {
    width: 34px;
    height: 34px;
  }
  .floating-phone-number {
    font-size: 0.88rem;
  }
}

/* Play pages (vs computer, vs friend, tournament game) on wide screens: three tracks — player
   cards | board | controls. The two side tracks are equal (1fr) so the board sits exactly in the
   middle of the page, like the simultaneous-play page. The board column spans the first two tracks
   through a subgrid, so boardFit.js still measures one column box, which now holds just the board
   (no strips above/below it), and the board grows to the full viewport height. */
@media (min-width: 1200px) {
  .chess-workspace.play-workspace:not(#sim-workspace) {
    /* player cards fill the left track (up to this width) */
    --cg-strip-w: 380px;
    /* two >=280px side tracks + 2 gaps + page padding + coordinates + scrollbar */
    --cg-avail-w: calc(100 * var(--app-vw) - 700px);
    grid-template-columns: minmax(0, 1fr) auto minmax(280px, 1fr);
  }
  .chess-workspace.play-workspace:not(#sim-workspace) > .board-column {
    grid-column: 1 / span 2;
    grid-row: 1;
    display: grid;
    grid-template-columns: subgrid;
    grid-template-rows: 1fr 1fr;
    row-gap: 0;
    align-items: start;
  }
  .chess-workspace.play-workspace:not(#sim-workspace) > .side-panel {
    grid-column: 3;
    grid-row: 1;
    min-width: 0;
  }
  .play-workspace > .board-column > .cg-board-frame {
    grid-column: 2;
    grid-row: 1 / span 2;
  }
  .play-workspace > .board-column > .player-strip {
    grid-column: 1;
    justify-self: end;
    width: 100%;
    max-width: var(--cg-strip-w);
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 14px;
  }
  .play-workspace > .board-column > .player-strip:first-child {
    grid-row: 1;
    align-self: start;
  }
  .play-workspace > .board-column > .player-strip:last-child {
    grid-row: 2;
    align-self: end;
    /* line up with the bottom edge of the board, not of the coordinate band below it */
    margin-bottom: var(--cg-coord-size, 24px);
  }
  .play-workspace > .board-column > .player-strip .player-info {
    flex-wrap: wrap;
    row-gap: 6px;
  }
  .play-workspace > .board-column > .player-strip .player-info > span:not(.color-dot):not(.player-ping-badge):not(.illegal-move-badge) {
    flex: 1 1 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .play-workspace > .board-column > .player-strip .clock-box {
    align-self: stretch;
    text-align: center;
    font-size: 1.6rem;
    padding: 8px 10px;
  }
  /* the technical-error notice sits in the card track, halfway between the two player cards */
  .play-workspace > .board-column > .illegal-move-center-notice {
    position: static;
    inset: auto;
    z-index: auto;
    grid-column: 1;
    grid-row: 1 / span 2;
    align-self: center;
    justify-self: end;
    width: 100%;
    max-width: var(--cg-strip-w);
    padding: 0;
  }
  .play-workspace > .board-column > .illegal-move-center-notice .illegal-move-center-card {
    width: 100%;
  }
}

/* On a wide play page the left track holds the player cards; the bottom-left mascot would cover
   the player's clock there, so it steps aside while a game board is on screen. */
@media (min-width: 1200px) {
  body:has(.play-workspace) .welcome-mascot {
    display: none;
  }
}

/* =========================================================================
   Play pages: left-edge notice (fast-move warning / illegal-move error)
   and the per-player technical-error badge
   ========================================================================= */
.play-side-notice {
  position: fixed;
  left: 16px;
  top: 50%;
  z-index: 320;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: min(320px, calc(100 * var(--app-vw) - 32px));
  padding: 14px 14px 14px 16px;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-light);
  border-left: 5px solid var(--warning);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transform: translate(-24px, -50%);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.play-side-notice.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(0, -50%);
}

.play-side-notice[data-tone='danger'] {
  border-left-color: var(--danger);
}

.play-side-notice-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--warning);
  color: #ffffff;
  font-weight: 800;
  font-size: 1rem;
}

.play-side-notice[data-tone='danger'] .play-side-notice-icon {
  background: var(--danger);
}

.play-side-notice-body {
  flex: 1;
  min-width: 0;
}

.play-side-notice-title {
  display: block;
  margin-bottom: 4px;
  color: var(--navy-heading);
  font-size: 0.98rem;
}

.play-side-notice[data-tone='danger'] .play-side-notice-title {
  color: var(--danger);
}

/* the fast-move reminder slogan is the point of the notice, so it reads larger than the title */
.play-side-notice[data-tone='warning'] .play-side-notice-message {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text-main);
}

.play-side-notice-message {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.play-side-notice-close {
  flex-shrink: 0;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.3rem;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}

/* Fast-move reminder: a big picture of the girl pointing at the player, standing out of the
   top of the card, replaces the round icon. */
.play-side-notice[data-tone='warning'] {
  align-items: flex-end;
  width: min(316px, calc(100 * var(--app-vw) - 32px));
  padding: 14px 14px 14px 8px;
}

.play-side-notice[data-tone='warning'] .play-side-notice-icon {
  width: auto;
  height: 200px;
  margin: -78px 0 -14px 0;
  border-radius: 0;
  background: none;
}

.play-side-notice[data-tone='warning'] .play-side-notice-icon img {
  height: 100%;
  width: auto;
  display: block;
  filter: drop-shadow(0 6px 10px rgba(10, 31, 68, 0.22));
}

.play-side-notice[data-tone='warning'] .play-side-notice-body {
  align-self: center;
}

.play-side-notice[data-tone='warning'] .play-side-notice-close {
  align-self: flex-start;
}

/* Placed by JS right against the left edge of the board (left/top set inline). */
.play-side-notice.is-beside-board {
  transform: translate(-16px, -50%);
}

.play-side-notice.is-beside-board.is-visible {
  transform: translate(0, -50%);
}

/* Phones: the board fills the width, so the notice drops in from the top-left instead. */
@media (max-width: 720px) {
  .play-side-notice {
    top: 76px;
    transform: translate(-24px, 0);
  }

  .play-side-notice.is-visible {
    transform: translate(0, 0);
  }
}

.illegal-move-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  margin-left: 6px;
  border-radius: 999px;
  border: 1px solid var(--danger);
  color: var(--danger);
  background: rgba(220, 38, 38, 0.08);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  flex-shrink: 0;
}

.illegal-move-badge[hidden] {
  display: none;
}

/* =========================================================================
   Play pages: technical-error notice in the middle of the screen (wide play layouts put it
   between the player cards instead, see above). It stays for --illegal-hold-ms while the wrong
   move is held on the board, the bar counting it down.
   ========================================================================= */
.illegal-move-center-notice {
  position: fixed;
  inset: 0;
  z-index: 330;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  pointer-events: none;
}

.illegal-move-center-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(380px, 100%);
  padding: 22px 22px 26px;
  text-align: center;
  background: var(--bg-card);
  color: var(--text-main);
  border: 2px solid var(--danger);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  animation: illegal-move-pop 0.22s ease-out;
}

.illegal-move-center-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin-bottom: 4px;
  border-radius: 50%;
  background: var(--danger);
  color: #ffffff;
  font-size: 1.6rem;
  font-weight: 800;
}

.illegal-move-center-title {
  color: var(--danger);
  font-size: 1.2rem;
}

.illegal-move-center-message {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
}

.illegal-move-center-hint {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.illegal-move-center-hint:empty {
  display: none;
}

.illegal-move-center-timer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 5px;
  background: rgba(220, 38, 38, 0.15);
}

.illegal-move-center-timer > span {
  display: block;
  height: 100%;
  background: var(--danger);
  transform-origin: left center;
  animation: illegal-move-countdown var(--illegal-hold-ms, 3000ms) linear forwards;
}

@keyframes illegal-move-pop {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes illegal-move-countdown {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .illegal-move-center-card {
    animation: none;
  }
}

/* Clock standing still while the technical-error notice is shown */
.clock-box.clock-paused {
  position: relative;
  opacity: 0.6;
  outline: 2px dashed var(--danger);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------------
   Add / edit level popup: how-to-add choice, default level picker, icon library
   --------------------------------------------------------------------------- */
.level-modal-class-note {
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  font-size: 0.88rem;
  color: var(--text-main);
}

.level-add-intro {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.level-add-choice {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.level-add-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 16px;
  text-align: left;
  font: inherit;
  color: var(--text-main);
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.level-add-option:hover,
.level-add-option:focus-visible {
  border-color: var(--btn-blue);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
  outline: none;
}

.level-add-option strong {
  font-size: 1rem;
  color: var(--navy-heading);
}

.level-add-option > span:last-child {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.level-add-option-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  color: #ffffff;
  background-image: linear-gradient(135deg, var(--navy-1) 0%, var(--btn-blue) 100%);
}

.level-template-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(calc(52 * var(--app-vh)), 440px);
  overflow-y: auto;
  padding-right: 2px;
}

.level-template-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  cursor: pointer;
}

.level-template-row:has(input:checked) {
  border-color: var(--btn-blue);
  background: var(--bg-subtle);
}

.level-template-row.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.level-template-row input {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--btn-blue);
}

.level-template-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.level-template-text strong {
  color: var(--text-main);
  font-size: 0.95rem;
}

.level-template-text span {
  color: var(--text-muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 16px;
}

.level-icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 8px;
  max-height: 248px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.level-icon-picker-status {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 6px;
}

.level-icon-tile {
  position: relative;
}

.level-icon-option {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px 6px;
  font: inherit;
  color: var(--text-main);
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.level-icon-option:hover,
.level-icon-option:focus-visible {
  border-color: var(--hover-cyan);
  outline: none;
}

.level-icon-tile.is-selected .level-icon-option {
  border-color: var(--btn-blue);
  box-shadow: 0 0 0 2px var(--btn-blue);
}

.level-icon-option-label {
  max-width: 100%;
  font-size: 0.72rem;
  line-height: 1.2;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-icon-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 0.9rem;
  line-height: 1;
  color: #ffffff;
  background: var(--danger);
  border: 2px solid var(--bg-card);
  border-radius: 50%;
  cursor: pointer;
}

.level-icon-picker-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.level-icon-picker-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

@media (max-width: 560px) {
  .level-add-choice {
    grid-template-columns: 1fr;
  }

  .level-icon-grid {
    grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  }
}

/* Play vs computer setup: levels 1-4 as a row of buttons, harder levels in the list below */
.ai-level-quick {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.ai-level-quick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding: 10px 6px;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--navy-heading);
  font: inherit;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.ai-level-quick-btn .ai-level-badge {
  width: 32px;
  height: 32px;
  background: var(--bg-subtle);
  color: var(--navy-heading);
}

.ai-level-quick-btn:hover,
.ai-level-quick-btn:focus-visible {
  border-color: var(--btn-blue);
  outline: none;
}

.ai-level-quick-btn.is-selected {
  border-color: var(--btn-blue);
  background: rgba(37, 99, 235, 0.1);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.ai-level-quick-btn.is-selected .ai-level-badge {
  background: var(--btn-blue);
  color: #ffffff;
}

.ai-level-quick-name {
  max-width: 100%;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.ai-level-quick-elo {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* nothing from the list is picked yet: a muted prompt instead of a level */
.ai-level-select.is-placeholder .ai-level-select-bar {
  color: var(--text-muted);
}

.ai-level-select.is-placeholder .ai-level-select-bar > .ai-level-badge {
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.ai-level-select.is-placeholder .ai-level-caption {
  font-weight: 600;
}

@media (max-width: 560px) {
  .ai-level-quick {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Match cards (play vs computer, friend / tournament room): icon-only action buttons.
   The label is the tooltip (title) and the accessible name. */
.match-icon-actions {
  /* every visible button gets an equal column, together they span the card */
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.ai-game-over-box .match-icon-actions {
  margin: 0;
}

.ai-game-over-box {
  margin-bottom: 14px;
}

.match-icon-actions .btn.btn-icon {
  width: 100%;
}

.btn.btn-icon {
  width: 42px;
  height: 42px;
  padding: 0;
  flex: 0 0 auto;
}

/* Match cards: same title style, info as an aligned label / value list */
.side-panel .match-card-title {
  margin: 0 0 12px;
  padding-bottom: 10px;
  font-size: 1.08rem;
  border-bottom: 1px solid var(--border-light);
}

.match-info-list {
  display: grid;
  gap: 0;
  margin: 0;
  font-size: 0.9rem;
}

.match-info-list > div {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--border-light);
}

.match-info-list > div:last-child {
  border-bottom: 0;
}

.match-info-list dt {
  color: var(--text-muted);
  font-weight: 600;
}

.match-info-list dd {
  margin: 0;
  color: var(--text-main);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.btn.btn-icon svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.btn.btn-icon.btn-icon-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 55%, transparent);
}

.btn.btn-icon.btn-icon-danger:hover,
.btn.btn-icon.btn-icon-danger:focus-visible {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}

/* Homepage greeting card (above "Giải đấu sắp diễn ra"): greeting by time of day, clock, date */
.home-greeting-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  color: #ffffff;
  border-color: transparent;
  background-image: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
}

.home-greeting-card[data-period='sun'] {
  background-image: linear-gradient(135deg, #0ea5e9 0%, #1d6ae5 100%);
}

.home-greeting-card[data-period='sunset'] {
  background-image: linear-gradient(135deg, #f97316 0%, #db2777 100%);
}

.home-greeting-card[data-period='moon'] {
  background-image: linear-gradient(135deg, #1e3a8a 0%, #0a1f44 100%);
}

.home-greeting-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
}

.home-greeting-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.home-greeting-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  line-height: 1.3;
  color: #ffffff;
  overflow-wrap: anywhere;
}

.home-greeting-time {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.home-greeting-date {
  font-size: 0.86rem;
  opacity: 0.92;
}

/* Result notice: display only, a bar counts down to the summary page */
.game-result-next {
  margin: 10px 0 8px;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.game-result-timer {
  display: block;
  height: 5px;
  border-radius: 999px;
  background: var(--bg-subtle);
  overflow: hidden;
}

.game-result-timer > span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--btn-blue);
  transform-origin: left center;
  animation: game-result-countdown var(--result-notice-ms, 15000ms) linear forwards;
}

.game-result-card[data-outcome='loss'] .game-result-timer > span {
  background: var(--warning);
}

@keyframes game-result-countdown {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

/* ---------------------------------------------------------------------------
   Game summary page (after the result notice). While it is shown, the game underneath is hidden
   but stays in the page, so live room updates keep working.
   --------------------------------------------------------------------------- */
:has(> .game-summary-page) > :not(.game-summary-page) {
  display: none !important;
}

.game-summary-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

.game-summary-hero {
  text-align: center;
  padding: 24px 20px;
  border-radius: var(--radius-lg);
  color: #ffffff;
  background-image: linear-gradient(135deg, var(--navy-1) 0%, var(--btn-blue) 100%);
  box-shadow: var(--shadow-md);
}

.game-summary-hero[data-outcome='win'] {
  background-image: linear-gradient(135deg, #0f766e 0%, #12995a 100%);
}

.game-summary-hero[data-outcome='loss'] {
  background-image: linear-gradient(135deg, #7c2d12 0%, #d97706 100%);
}

.game-summary-kicker {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.game-summary-title {
  margin: 10px 0 4px;
  font-size: 1.7rem;
  color: #ffffff;
}

.game-summary-result {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.game-summary-reason {
  margin: 6px 0 0;
  opacity: 0.95;
}

.game-summary-meta {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.game-summary-meta > span {
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 0.85rem;
}

/* Winner certificate on the summary of a game vs a friend; the name sits in the frame of the image. */
.game-summary-certificate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.winner-certificate {
  position: relative;
  container-type: inline-size;
  width: 100%;
  max-width: 760px;
  margin: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  line-height: 0;
}

.winner-certificate img {
  display: block;
  width: 100%;
  height: auto;
}

.winner-certificate-name {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3%;
  box-sizing: border-box;
  line-height: 1.15;
}

.winner-certificate-name span {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: var(--name-scale, 3.6cqw);
  font-weight: 800;
  color: #b3121f;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

.game-summary-players {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.game-summary-player {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.game-summary-player.is-you {
  border-color: var(--btn-blue);
}

.game-summary-player-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.game-summary-player .color-dot,
.game-summary-table .color-dot {
  border: 0;
  border-radius: 0;
  background: center / contain no-repeat;
  flex-shrink: 0;
}

.game-summary-player .color-dot {
  width: 34px;
  height: 34px;
}

.game-summary-table .color-dot {
  width: 22px;
  height: 22px;
  margin-right: 6px;
  vertical-align: middle;
}

.game-summary-page .color-dot.white {
  background-image: url('/assets/pieces/wK.svg');
}

.game-summary-page .color-dot.black {
  background-image: url('/assets/pieces/bK.svg');
}

.game-summary-player-name {
  min-width: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--navy-heading);
  overflow-wrap: anywhere;
}

.game-summary-you {
  margin-left: auto;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--btn-blue);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
}

.game-summary-rating {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}

.game-summary-rating-before {
  color: var(--text-muted);
  font-size: 1.05rem;
}

.game-summary-rating-arrow {
  color: var(--text-muted);
}

.game-summary-rating-after {
  font-size: 1.6rem;
  color: var(--navy-heading);
}

.game-summary-delta {
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.95rem;
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.game-summary-delta.is-up {
  background: rgba(18, 153, 90, 0.14);
  color: var(--success);
}

.game-summary-delta.is-down {
  background: rgba(220, 38, 38, 0.12);
  color: var(--danger);
}

.game-summary-coeffs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.game-summary-coeffs > div {
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  text-align: center;
}

.game-summary-coeffs dt {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.game-summary-coeffs dd {
  margin: 2px 0 0;
  font-weight: 800;
  color: var(--text-main);
}

.game-summary-provisional {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(217, 119, 6, 0.12);
  color: var(--warning);
  font-size: 0.86rem;
  font-weight: 600;
}

.game-summary-unrated {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 0.9rem;
}

.game-summary-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.game-summary-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  text-align: center;
}

.game-summary-tile span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.game-summary-tile strong {
  font-size: 1.35rem;
  color: var(--navy-heading);
  font-variant-numeric: tabular-nums;
}

.game-summary-table-wrap {
  overflow-x: auto;
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
}

.game-summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.game-summary-table th,
.game-summary-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.game-summary-table thead th {
  background: var(--bg-subtle);
  color: var(--navy-heading);
}

.game-summary-table tbody th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
}

.game-summary-table tbody tr:last-child th,
.game-summary-table tbody tr:last-child td {
  border-bottom: 0;
}

.game-summary-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.game-summary-actions .btn {
  min-height: 46px;
}

@media (max-width: 640px) {
  .game-summary-players {
    grid-template-columns: 1fr;
  }

  .game-summary-title {
    font-size: 1.35rem;
  }

  .game-summary-result {
    font-size: 1.8rem;
  }
}

/* =========================================================
   GIÁO TRÌNH / BÀI TẬP: TRANG CHỌN & BÀI TẬP MIỄN PHÍ (learnPage.js)
   Free exercises = every stage of lichess.org/learn
   ========================================================= */
:root {
  --learn-orange: #f57c00;
  --learn-gold: #f5b400;
  --learn-ongoing-1: #2f80ed;
  --learn-ongoing-2: #1554ba;
  --learn-done-1: #1fb36b;
  --learn-done-2: #12804b;
  --learn-future-1: #8f9bb3;
  --learn-future-2: #66738f;
}

/* ---------- #/curriculum & #/exercises: choose free content or your classes ---------- */
.learn-hub-page {
  max-width: 1000px;
  margin: 0 auto;
}

.learn-hub-title {
  margin: 0 0 4px;
  font-size: 1.6rem;
  color: var(--navy-heading);
}

.learn-hub-subtitle {
  margin: 0 0 22px;
  color: var(--text-muted);
}

.learn-hub-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.learn-hub-grid--single {
  grid-template-columns: minmax(0, 520px);
}

/* #/learn for students: Curriculum, Exercises, Online learning */
.learn-hub-grid--three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 1100px) {
  .learn-hub-grid--three .learn-hub-card {
    flex-direction: column;
  }
}

.learn-hub-card {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  padding: 24px 22px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-top: 5px solid var(--learn-orange);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  color: var(--text-main);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.learn-hub-card--classes {
  border-top-color: var(--navy-1);
}

.learn-hub-card:hover,
.learn-hub-card:focus-visible {
  color: var(--text-main);
  border-color: var(--hover-cyan);
  box-shadow: var(--shadow-md);
  transform: translateY(-3px);
}

.learn-hub-card-icon {
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  background: linear-gradient(135deg, #ff9b2f, var(--learn-orange));
}

.learn-hub-card--classes .learn-hub-card-icon {
  background: linear-gradient(135deg, var(--navy-2), var(--navy-1));
}

.learn-hub-card--online {
  border-top-color: var(--success);
}

.learn-hub-card--online .learn-hub-card-icon,
.learn-coming-soon-icon.learn-coming-soon-icon--online {
  color: #ffffff;
  background: linear-gradient(135deg, #22b573, var(--success));
}

.learn-coming-soon-icon--online svg {
  width: 52px;
  height: 52px;
}

.learn-hub-card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.learn-hub-card-badge {
  align-self: flex-start;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--navy-1);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  padding: 2px 10px;
  border-radius: 99px;
}

.learn-hub-card-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--navy-heading);
}

.learn-hub-card-desc {
  color: var(--text-muted);
  font-size: 0.93rem;
}

.learn-hub-card-cta {
  margin-top: 6px;
  font-weight: 700;
  color: var(--btn-blue);
}

/* ---------- #/curriculum/free: coming soon ---------- */
.learn-coming-soon-page {
  max-width: 640px;
  margin: 0 auto;
}

.learn-back-btn {
  margin-bottom: 16px;
}

.learn-coming-soon-card {
  text-align: center;
  padding: 40px 28px;
}

.learn-coming-soon-icon {
  width: 96px;
  height: 96px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: var(--learn-orange);
  display: flex;
  align-items: center;
  justify-content: center;
}

.learn-coming-soon-icon img {
  width: 60px;
  height: 60px;
}

.learn-coming-soon-title {
  margin: 0 0 6px;
  font-size: 1.5rem;
}

.learn-coming-soon-badge {
  display: inline-block;
  margin: 0 0 14px;
  padding: 4px 14px;
  border-radius: 99px;
  font-weight: 700;
  color: #ffffff;
  background: var(--learn-orange);
}

.learn-coming-soon-text {
  max-width: 460px;
  margin: 0 auto 22px;
  color: var(--text-muted);
  line-height: 1.65;
}

/* ---------- #/exercises/free: map of the stages ---------- */
.learn-map-page {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 32px;
}

.learn-map-side {
  position: sticky;
  top: 16px;
  align-self: start;
}

.learn-map-side-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.learn-helm {
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--navy-2), var(--navy-1));
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.learn-helm img {
  width: 44px;
  height: 44px;
}

.learn-helm--sm {
  width: 34px;
  height: 34px;
  border-radius: 8px;
}

.learn-helm--sm img {
  width: 24px;
  height: 24px;
}

.learn-map-title {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.15;
}

.learn-map-tagline {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 1.05rem;
}

.learn-overall-progress-text {
  font-weight: 600;
  margin-bottom: 6px;
}

.learn-overall-progress-bar {
  height: 10px;
  border-radius: 99px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  overflow: hidden;
}

.learn-overall-progress-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--learn-done-1), var(--learn-done-2));
  transition: width 0.6s ease;
}

.learn-reset-btn {
  margin-top: 16px;
}

.learn-categ-title {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.learn-categ-stages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  margin: 14px 0 32px;
}

.learn-stage-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 88px;
  padding: 10px 3.2em 10px 12px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  color: var(--text-main);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.learn-stage-card:hover,
.learn-stage-card:focus-visible {
  color: var(--text-main);
  transform: scale(1.02);
  box-shadow: var(--shadow-md);
}

.learn-stage-card.ongoing {
  border-color: var(--learn-ongoing-1);
  animation: learn-attention 2.4s ease-in-out infinite;
}

@keyframes learn-attention {
  50% {
    box-shadow: 0 0 0 4px rgba(47, 128, 237, 0.22), var(--shadow-md);
  }
}

.learn-stage-card-img,
.learn-side-stage-img,
.learn-table-title-img {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: linear-gradient(130deg, var(--learn-future-1), var(--learn-future-2));
}

.learn-stage-card-img {
  width: 62px;
  height: 62px;
}

.learn-stage-card-img img {
  width: 44px;
  height: 44px;
}

.learn-stage-card.ongoing .learn-stage-card-img,
.learn-side-stage.active .learn-side-stage-img {
  background: linear-gradient(130deg, var(--learn-ongoing-1), var(--learn-ongoing-2));
}

.learn-stage-card.done .learn-stage-card-img,
.learn-side-stage.done .learn-side-stage-img {
  background: linear-gradient(130deg, var(--learn-done-1), var(--learn-done-2));
}

.learn-stage-card-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.learn-stage-card-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--navy-heading);
  line-height: 1.2;
}

.learn-stage-card-subtitle {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.3;
}

.learn-ribbon {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 1px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.5;
}

.learn-ribbon--ongoing {
  color: #ffffff;
  background: var(--learn-ongoing-1);
}

.learn-ribbon--done {
  background: rgba(18, 153, 90, 0.12);
  border: 1px solid rgba(18, 153, 90, 0.3);
  padding: 2px 6px;
}

.learn-star-icon {
  width: 1.15em;
  height: 1.15em;
  fill: var(--learn-gold);
  stroke: #c98700;
  stroke-width: 2;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

/* ---------- #/exercises/free/:stage: playing a stage ---------- */
.learn-side-map {
  display: none;
}

@media (min-width: 1200px) {
  .learn-side-map {
    grid-column: 1;
    grid-row: 1;
    justify-self: end;
    width: 100%;
  }
}

/* the stage list next to the board: a box for the menu and one per category (as on lichess) */
.learn-side-map {
  flex-direction: column;
  gap: 10px;
  user-select: none;
}

@media (min-width: 1200px) {
  .learn-side-map {
    display: flex;
    max-width: 270px;
  }
}

.learn-side-box {
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.learn-side-back {
  display: flex;
  align-items: stretch;
  min-height: 56px;
  color: var(--navy-heading);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.learn-side-back:hover {
  color: var(--navy-heading);
  border-color: var(--hover-cyan);
  box-shadow: var(--shadow-md);
}

.learn-side-back-img {
  flex: 0 0 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy-2), var(--navy-1));
}

.learn-side-back-img img {
  width: 34px;
  height: 34px;
}

.learn-side-back-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 6px 12px;
  min-width: 0;
}

.learn-side-back-title {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.2;
}

.learn-side-back-progress {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.learn-side-categ-title {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 46px;
  padding: 0 12px 0 14px;
  border: 0;
  background: transparent;
  text-align: left;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--navy-heading);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.learn-side-categ-title:hover {
  background: rgba(29, 106, 229, 0.1);
}

.learn-side-categ-name {
  flex: 1 1 auto;
  min-width: 0;
}

.learn-side-categ-count {
  flex: 0 0 auto;
  padding: 1px 8px;
  border-radius: 99px;
  font-size: 0.74rem;
  letter-spacing: 0;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
}

.learn-side-categ-chevron {
  flex: 0 0 auto;
  transition: transform 0.2s ease;
}

.learn-side-categ.active .learn-side-categ-title {
  cursor: default;
  color: #ffffff;
  background: linear-gradient(130deg, var(--learn-ongoing-1), var(--learn-ongoing-2));
}

.learn-side-categ.active .learn-side-categ-count {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.35);
}

.learn-side-categ.active .learn-side-categ-chevron {
  transform: rotate(180deg);
}

.learn-side-categ-stages {
  display: none;
}

.learn-side-categ.active .learn-side-categ-stages {
  display: block;
}

.learn-side-stage {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  padding-right: 12px;
  border-top: 1px solid var(--border-light);
  color: var(--text-main);
  font-weight: 600;
  transition: background-color 0.15s ease;
}

.learn-side-stage:hover {
  color: var(--text-main);
  background: rgba(29, 106, 229, 0.08);
}

.learn-side-stage.active {
  color: var(--navy-heading);
  background: rgba(29, 106, 229, 0.12);
  box-shadow: inset -3px 0 0 var(--btn-blue);
}

.learn-side-stage-img {
  flex: 0 0 50px;
  width: 50px;
  height: 50px;
  border-radius: 0;
  background: linear-gradient(130deg, var(--learn-future-1), var(--learn-future-2));
}

.learn-side-stage.future .learn-side-stage-img img {
  opacity: 0.8;
}

.learn-side-stage-img img {
  width: 32px;
  height: 32px;
}

.learn-side-stage-title {
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.25;
}

.learn-side-stage-mark {
  flex: 0 0 auto;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

.learn-side-stage-mark--done {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: #ffffff;
  background: var(--success);
}

.learn-table {
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1.5px solid var(--border-light);
  background: var(--bg-card);
}

.learn-table-title {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(130deg, var(--learn-ongoing-1), var(--learn-ongoing-2));
  color: #ffffff;
}

.learn-table-title-img {
  width: 68px;
  height: 68px;
  background: transparent;
}

.learn-table-title-img img {
  width: 60px;
  height: 60px;
}

.learn-table-title-text h2 {
  margin: 0;
  font-size: 1.7rem;
  line-height: 1.15;
  color: #ffffff;
}

.learn-table-title-text p {
  margin: 4px 0 0;
  opacity: 0.9;
}

.learn-goal {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  padding: 18px;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--text-main);
}

.learn-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 136px;
  padding: 16px;
  border: 0;
  font-family: inherit;
  color: #ffffff;
  cursor: pointer;
  transition: filter 0.18s ease;
}

.learn-result:hover {
  filter: brightness(1.08);
}

.learn-result--completed {
  background: var(--success);
}

.learn-result--failed {
  background: var(--danger);
}

.learn-result-title {
  font-size: 1.6rem;
  font-weight: 800;
  animation: learn-text-glow 1s 1;
}

.learn-result-btn {
  padding: 5px 16px;
  border-radius: var(--radius-sm);
  background: #ffffff;
  font-size: 1.3rem;
  font-weight: 800;
  text-transform: uppercase;
  box-shadow: 0 0 5px 5px rgba(255, 255, 255, 0.45);
  animation: learn-shadow-glow 1s infinite;
}

.learn-result--failed .learn-result-btn {
  color: var(--danger);
}

.learn-result--completed .learn-result-btn {
  color: var(--success);
}

.learn-result-stars {
  display: inline-flex;
  gap: 6px;
  font-size: 1.7rem;
}

.learn-result-stars .learn-star-icon {
  stroke: #ffffff;
  animation: learn-text-glow 1s 1;
}

@keyframes learn-shadow-glow {
  50% {
    box-shadow: 0 0 10px 10px rgba(255, 255, 255, 0.5);
    transform: scale(1.05);
  }
}

@keyframes learn-text-glow {
  50% {
    text-shadow: 0 0 10px #ffffff;
    transform: scale(1.05);
  }
}

.learn-progress {
  display: flex;
  border-top: 1.5px solid var(--border-light);
}

.learn-progress-level {
  flex: 1 1 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 3em;
  font-weight: 700;
  color: var(--text-main);
  background: var(--bg-subtle);
  border-left: 1px solid var(--border-light);
  opacity: 0.85;
  transition: opacity 0.15s ease;
}

.learn-progress-level:first-child {
  border-left: 0;
}

.learn-progress-level:hover {
  opacity: 1;
  color: var(--text-main);
}

.learn-progress-level.done {
  color: #ffffff;
  background: var(--success);
}

.learn-progress-level.active {
  opacity: 1;
  color: #ffffff;
  background: var(--btn-blue);
}

.learn-progress-stars {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 0.72rem;
}

.learn-progress-stars .learn-star-icon {
  stroke: #ffffff;
}

/* board: targets are enemy pawns on the board (so pieces stop there), drawn as chess pieces instead
   (learnEngine.js makeAppleShape): a glowing black piece to capture, or a faded piece to place */
.learn-run-page.apples .cg-wrap piece.pawn.black {
  background-image: none !important;
}

.learn-run-page .learn-apple {
  filter: drop-shadow(0 0 3px rgba(255, 196, 0, 0.95)) drop-shadow(0 0 1px rgba(255, 160, 0, 0.9));
  animation:
    0.6s ease-in-out 0s 1 forwards learn-apple-appear,
    1.7s ease-in-out 0.7s infinite none learn-soft-grow;
}

.learn-run-page .learn-apple--ghost {
  filter: none;
}

/* on the image: the appear animation ends on the group's full opacity */
.learn-run-page .learn-apple--ghost image {
  opacity: 0.45;
}

@keyframes learn-apple-appear {
  0% {
    opacity: 0.5;
    scale: 0;
    rotate: -360deg;
  }

  100% {
    opacity: 1;
    scale: 1;
    rotate: 0deg;
  }
}

@keyframes learn-soft-grow {
  50% {
    scale: 1.08;
  }
}

@keyframes learn-rank-glow {
  50% {
    background-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 0 40px rgba(255, 255, 255, 0.7);
  }
}

.learn-run-page.highlight-2nd-rank cg-board::after,
.learn-run-page.highlight-5th-rank cg-board::after {
  content: '';
  position: absolute;
  left: 0;
  width: 100%;
  height: 12.5%;
  bottom: 12.5%;
  z-index: 1;
  pointer-events: none;
  background-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.2);
  animation: 1s learn-rank-glow ease-in-out infinite;
}

.learn-run-page.highlight-5th-rank cg-board::after {
  bottom: auto;
  top: 37.5%;
}

.learn-run-page.piece-values cg-board piece::before {
  position: absolute;
  top: 6%;
  right: 6%;
  color: #ffffff;
  text-shadow: 0 0 9px #000000, 0 0 4px #000000;
  font-size: clamp(14px, 2.6vw, 28px);
  font-weight: 800;
  line-height: 1;
}

.learn-run-page.piece-values cg-board piece.queen::before {
  content: '9';
}

.learn-run-page.piece-values cg-board piece.rook::before {
  content: '5';
}

.learn-run-page.piece-values cg-board piece.bishop::before,
.learn-run-page.piece-values cg-board piece.knight::before {
  content: '3';
}

.learn-run-page.piece-values cg-board piece.pawn::before {
  content: '1';
}

/* pawn promotion: the four pieces stacked on the promotion file, over the board */
.learn-promotion {
  position: absolute;
  top: var(--cg-coord-size, 24px);
  left: var(--cg-coord-size, 24px);
  right: 0;
  bottom: 0;
  z-index: 30;
  background: rgba(10, 31, 68, 0.45);
}

.learn-promotion[hidden] {
  display: none;
}

.learn-promotion-square {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(#ffffff 25%, #b0b8c8 80%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition: border-radius 0.15s ease, background 0.15s ease;
}

.learn-promotion-square:hover {
  border-radius: 0;
  background: radial-gradient(#ffffff 25%, #f5b400 100%);
}

.learn-promotion-square img {
  width: 100%;
  height: 100%;
  transform: scale(0.82);
  transition: transform 0.15s ease;
}

.learn-promotion-square:hover img {
  transform: scale(1);
}

.learn-promotion-explanation {
  position: absolute;
  top: 25%;
  left: 25%;
  width: 50%;
  min-height: 50%;
  padding: 18px 20px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-main);
  box-shadow: var(--shadow-lg);
  pointer-events: none;
}

.learn-promotion-explanation h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
}

.learn-promotion-explanation p {
  margin: 8px 0 0;
}

/* stage start / stage complete screens */
.learn-screen-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  padding: 16px;
  overflow: auto;
  background: rgba(5, 12, 28, 0.7);
  cursor: pointer;
}

.learn-screen {
  margin: auto;
  width: 360px;
  max-width: 100%;
  padding: 34px 0 22px;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text-main);
  text-align: center;
  box-shadow: var(--shadow-lg);
  cursor: default;
}

.learn-screen > * {
  animation: learn-slide-in 1s cubic-bezier(0.37, 0.82, 0.2, 1) both;
}

.learn-screen > :nth-child(2) {
  animation-duration: 1.5s;
}

.learn-screen > :nth-child(3) {
  animation-duration: 2s;
}

.learn-screen > :nth-child(4) {
  animation-duration: 2.5s;
}

.learn-screen > :nth-child(5) {
  animation-duration: 3s;
}

@keyframes learn-slide-in {
  0% {
    opacity: 0;
    filter: blur(15px);
  }

  100% {
    opacity: 1;
    filter: blur(0);
  }
}

.learn-screen h1 {
  margin: 0 18px 20px;
  font-size: 1.45rem;
  color: var(--navy-heading);
}

.learn-screen p {
  margin: 0 0 18px;
  padding: 0 12%;
  line-height: 1.6;
}

.learn-screen-round {
  display: flex;
  width: 220px;
  height: 220px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: var(--learn-orange);
}

.learn-screen-round img {
  width: 160px;
  height: 160px;
  margin: auto;
}

.learn-screen-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
}

.learn-screen-stars {
  margin-bottom: 16px;
}

.learn-screen-star-wrap {
  position: relative;
  display: inline-block;
  width: 55px;
  height: 55px;
  margin: 0 5px;
}

.learn-screen-star-wrap::before {
  content: '';
  position: absolute;
  top: 5px;
  left: 5px;
  width: 45px;
  height: 45px;
  background: url('/assets/learn/free/star.svg') center / contain no-repeat;
  filter: saturate(0);
  opacity: 0.2;
}

.learn-screen-star {
  position: absolute;
  inset: 0;
  background: url('/assets/learn/free/star.svg') center / contain no-repeat;
  opacity: 0;
  animation: learn-star-appear 2.5s ease-in-out 0.1s forwards;
}

.learn-screen-star-wrap:nth-child(2) .learn-screen-star {
  animation-delay: 0.8s;
}

.learn-screen-star-wrap:nth-child(3) .learn-screen-star {
  animation-delay: 1.6s;
}

@keyframes learn-star-appear {
  0% {
    opacity: 0.5;
    transform: scale(0) rotate(-360deg);
  }

  85% {
    opacity: 1;
    transform: scale(1.3) rotate(10deg);
  }

  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

.learn-screen-score {
  display: block;
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.85rem;
  color: var(--warning);
}

.learn-screen-score span {
  font-family: monospace;
  font-size: 1.05rem;
  font-weight: 700;
}

.learn-run-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.learn-run-tools .btn {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.learn-tool-icon {
  width: 1.05em;
  height: 1.05em;
  flex: 0 0 auto;
}

.learn-loading-card {
  max-width: 560px;
  margin: 24px auto;
  text-align: center;
  color: var(--text-muted);
}

@media (min-width: 1200px) {
  .page-back-row.learn-run-back {
    display: none;
  }
}

@media (max-width: 860px) {
  .learn-map-page {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
  }

  .learn-map-side {
    position: static;
  }

  .learn-hub-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .learn-categ-stages {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .learn-hub-card {
    padding: 18px 16px;
    gap: 14px;
  }

  .learn-hub-card-icon {
    width: 48px;
    height: 48px;
  }

  .learn-table-title-text h2 {
    font-size: 1.4rem;
  }

  .learn-promotion-explanation {
    top: 12%;
    left: 8%;
    width: 84%;
    min-height: 0;
    padding: 12px 14px;
    font-size: 0.88rem;
  }
}

:root[data-theme="dark"] .learn-hub-card-badge {
  color: var(--text-main);
}

:root[data-theme="dark"] .learn-ribbon--done {
  background: rgba(31, 179, 107, 0.16);
  border-color: rgba(31, 179, 107, 0.4);
}

:root[data-theme="dark"] .learn-screen-overlay {
  background: rgba(0, 0, 0, 0.72);
}

/* =========================================================
   TRANG LỚP HỌC: #/curriculum/classes/:id, #/exercises/classes/:id (classPage.js)
   laid out like the free exercises map
   ========================================================= */
.class-page-desc {
  margin: 0 0 14px;
  color: var(--text-muted);
  line-height: 1.55;
}

.class-page-stats {
  margin: 0 0 4px;
  font-weight: 600;
}

/* class page card: class name / "Bài tập cờ vua" (or "Giáo trình …") / levels · exercises */
.class-page-section {
  margin: 2px 0 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.class-page-side-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-top: 16px;
}

.class-page-empty {
  margin: 0;
}

.class-level-section {
  margin-bottom: 30px;
}

.class-level-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.class-level-badge {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(130deg, var(--learn-future-1), var(--learn-future-2));
}

.class-level-section.ongoing .class-level-badge {
  background: linear-gradient(130deg, var(--learn-ongoing-1), var(--learn-ongoing-2));
}

.class-level-section.done .class-level-badge {
  background: linear-gradient(130deg, var(--learn-done-1), var(--learn-done-2));
}

.class-level-badge img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.class-level-head-text {
  flex: 1 1 220px;
  min-width: 0;
}

.class-level-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.25;
  color: var(--navy-heading);
}

.class-level-index {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: 99px;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--navy-heading);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
}

.class-level-desc {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.class-level-count {
  flex: 0 0 auto;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
}

.class-level-section.done .class-level-count {
  color: var(--success);
  border-color: rgba(18, 153, 90, 0.35);
}

.class-level-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.class-level-items {
  margin: 12px 0 0;
}

.class-item-card.todo .learn-stage-card-img {
  background: linear-gradient(130deg, var(--learn-ongoing-1), var(--learn-ongoing-2));
}

.class-item-img--doc {
  background: linear-gradient(130deg, #ff9b2f, var(--learn-orange)) !important;
}

.class-item-question {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.class-item-done {
  color: #ffffff;
  background: var(--success);
  border-color: var(--success);
  padding: 3px 6px;
}

.class-level-empty {
  grid-column: 1 / -1;
  padding: 18px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.92rem;
  background: var(--bg-subtle);
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-md);
}

@media (max-width: 640px) {
  .class-level-actions {
    width: 100%;
  }

  .class-level-actions .level-row-open {
    margin-left: auto;
  }
}

:root[data-theme="dark"] .class-level-head {
  background: var(--bg-card);
}

a.curriculum-class-row,
a.curriculum-class-row:hover,
a.curriculum-class-row:focus-visible {
  color: var(--text-main);
  text-decoration: none;
}

/* =========================================================
   PAGE HEAD — one header for every page (public/js/pageHead.js)
   back pill above the title, left-aligned; actions on the right
   ========================================================= */
:root {
  --page-gap: 20px;
  --page-column-narrow: 760px;
  --page-column-medium: 1120px;
}

.page-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  margin: 0 0 var(--page-gap);
  text-align: left;
  align-self: stretch;
}

.page-head .page-header-bar {
  width: 100%;
  margin: 0;
  padding: 0 0 14px;
  border-bottom: 1px solid var(--border-light);
  align-items: flex-end;
  gap: 12px 20px;
}

.page-header-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1 1 320px;
}

.page-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  min-width: 0;
}

.page-title,
.page-head .page-title {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--navy-heading);
  overflow-wrap: anywhere;
}

.page-eyebrow {
  margin: 0;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--btn-blue);
}

.page-subtitle {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.page-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

/* the back pill */
.page-back,
.page-back:visited {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  max-width: 100%;
  padding: 0 14px 0 5px;
  border: 1px solid var(--border-light);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.page-back-icon {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: var(--navy-heading);
  background: var(--bg-subtle);
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.page-back-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-back:hover,
.page-back:focus-visible {
  color: var(--navy-heading);
  border-color: var(--hover-cyan);
  box-shadow: var(--shadow-md);
  text-decoration: none;
  outline: none;
}

.page-back:hover .page-back-icon,
.page-back:focus-visible .page-back-icon {
  color: #ffffff;
  background: var(--btn-blue);
  transform: translateX(-2px);
}

:root[data-theme="dark"] .page-back {
  background: var(--bg-card);
  color: var(--text-muted);
}

/* page widths: list pages use the full width; a page of choices or a form is one centred column
   whose header shares the column's left edge */
.page-column {
  width: 100%;
  max-width: var(--page-column-medium);
  margin: 0 auto;
}

.page-column--narrow {
  max-width: var(--page-column-narrow);
}

@media (max-width: 768px) {
  :root {
    --mobile-gutter: 16px;
    --page-gap: 16px;
  }

  .page-title,
  .page-head .page-title {
    font-size: 1.35rem;
  }

  .page-head .page-header-bar {
    flex-direction: column;
    align-items: stretch;
    padding-bottom: 12px;
  }

  .page-header-text {
    flex-basis: auto;
  }

  .page-header-actions > .btn {
    flex: 1 1 auto;
  }
}

@media (max-width: 480px) {
  :root {
    --mobile-gutter: 16px;
  }
}

/* a back pill on its own row (board pages: analysis, exercise, ...) */
.page-back-row {
  display: flex;
  align-items: center;
  margin: 0 0 14px;
}

button.page-back {
  font-family: inherit;
  cursor: pointer;
}

.donate-page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: 24px;
  align-items: start;
}


/* the left card of the free exercises map and of a class page */
.learn-side-card {
  padding: 18px;
}

.learn-side-card .learn-map-side-header {
  margin-bottom: 14px;
}

.learn-side-card .learn-map-title {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.2;
}

.learn-side-card .learn-helm {
  width: 52px;
  height: 52px;
  border-radius: 12px;
}

.learn-side-card .learn-helm img,
.learn-side-card .learn-helm svg {
  width: 32px;
  height: 32px;
}

.learn-side-card .learn-map-title {
  font-size: 1.08rem;
}

.learn-side-card .learn-map-tagline {
  font-size: 0.86rem;
}

/* =========================================================================
   #/news: chess news from public feeds (newsPage.js)
   ========================================================================= */
.news-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 16px;
}

.news-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
}

.news-tab {
  padding: 8px 18px;
  border-radius: 7px;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.news-tab:hover {
  color: var(--text-main);
}

.news-tab.active {
  background: var(--btn-blue);
  color: #ffffff;
}

.news-tab:focus-visible {
  outline: 2px solid var(--hover-cyan);
  outline-offset: 2px;
}

.news-status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.news-status-stale {
  color: var(--learn-orange, #f57c00);
}

.news-refresh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.news-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 24px;
  align-items: start;
}

.news-list {
  background: var(--bg-card);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.news-item {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 16px;
  padding: 16px 18px;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-light);
  transition: background-color 0.15s ease;
}

.news-item:last-child {
  border-bottom: 0;
}

.news-item:hover,
.news-item:focus-visible {
  background: var(--bg-subtle);
  color: var(--text-main);
}

.news-item:hover .news-item-title {
  color: var(--btn-blue);
}

.news-item-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.news-item-meta {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.news-item-title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--navy-heading);
  transition: color 0.15s ease;
}

.news-item-summary {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.news-item-open {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--btn-blue);
}

/* picture, or a tile with the source's initials under it while it loads / when there is none */
.news-thumb {
  position: relative;
  display: block;
  width: 132px;
  height: 88px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-subtle);
}

.news-thumb-tile {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--news-tile, #1d6ae5), color-mix(in srgb, var(--news-tile, #1d6ae5) 70%, #000));
  color: #ffffff;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.news-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* the lead story: its picture across the top, a larger headline */
.news-item--lead {
  grid-template-columns: minmax(0, 1fr);
  padding: 18px;
}

.news-thumb--lead {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 7;
  background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--border-light) 50%, var(--bg-subtle) 75%);
  background-size: 200% 100%;
  animation: news-shimmer 1.2s linear infinite;
}

.news-thumb--lead.has-image {
  animation: none;
}

.news-item--lead .news-item-title {
  font-size: 1.4rem;
  line-height: 1.3;
}

.news-item--lead .news-item-summary {
  -webkit-line-clamp: 3;
  font-size: 0.95rem;
}

.news-item--skeleton .news-thumb,
.news-item--skeleton .news-item-body > span {
  background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--border-light) 50%, var(--bg-subtle) 75%);
  background-size: 200% 100%;
  animation: news-shimmer 1.2s linear infinite;
  border-radius: 6px;
}

.news-item--skeleton .news-item-body > span {
  height: 14px;
}

.news-item--skeleton .news-item-body > span:nth-child(2) {
  height: 20px;
  width: 85%;
}

.news-item--skeleton .news-item-body > span:nth-child(3) {
  width: 60%;
}

@keyframes news-shimmer {
  to {
    background-position: -200% 0;
  }
}

.news-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

.news-aside {
  position: sticky;
  top: 16px;
}

.news-aside-card {
  padding: 18px;
}

.news-aside-title {
  margin: 0 0 10px;
  font-size: 1.05rem;
}

.news-sources {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
}

.news-sources li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.news-source-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success, #12995a);
  flex: 0 0 auto;
}

.news-source-dot.is-down {
  background: var(--danger, #dc2626);
}

.news-source-down {
  font-weight: 500;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.news-aside-note {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--text-muted);
}

@media (max-width: 960px) {
  .news-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .news-aside {
    position: static;
    order: 2;
  }
}

@media (max-width: 600px) {
  .news-item {
    grid-template-columns: 84px minmax(0, 1fr);
    gap: 12px;
    padding: 14px;
  }

  .news-thumb {
    width: 84px;
    height: 64px;
  }

  .news-thumb-tile {
    font-size: 1.1rem;
  }

  .news-item-title {
    font-size: 0.98rem;
  }

  .news-item--lead .news-item-title {
    font-size: 1.15rem;
  }

  .news-item-summary {
    display: none;
  }

  .news-item--lead .news-item-summary {
    display: -webkit-box;
  }
}

@media (prefers-reduced-motion: reduce) {
  .news-item--skeleton .news-thumb,
  .news-item--skeleton .news-item-body > span {
    animation: none;
  }
}

/* =========================================================================
   #/learn/online: classes with their live lesson, and the lessons to watch again
   (onlineLearning.js)
   ========================================================================= */
.online-class-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.online-class-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 18px;
}

.online-class-card.is-live {
  border-left: 4px solid #dc2626;
}

.online-class-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  flex-wrap: wrap;
}

.online-class-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 280px;
}

.online-class-icon {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  background: linear-gradient(135deg, var(--navy-2), var(--navy-1));
}

.online-class-name {
  margin: 0;
  font-size: 1.06rem;
}

.online-class-meta {
  margin: 2px 0 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.online-live {
  border-radius: var(--radius-sm, 8px);
  padding: 12px 14px;
  border: 1px solid var(--border-light);
  background: var(--bg-subtle);
}

.online-live.is-on {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  flex-wrap: wrap;
  border-color: rgba(220, 38, 38, 0.45);
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.07), rgba(220, 38, 38, 0.02));
}

.online-live-info {
  flex: 1 1 260px;
  min-width: 0;
}

.online-live.is-off {
  padding: 10px 14px;
}

.online-live.is-off p {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.online-live-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 2px 9px;
  border-radius: 99px;
  background: #dc2626;
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.online-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffffff;
  animation: online-live-pulse 1.4s ease-in-out infinite;
}

@keyframes online-live-pulse {
  50% {
    opacity: 0.35;
  }
}

.online-live-title {
  margin: 6px 0 2px;
  font-size: 1.02rem;
  color: var(--navy-heading);
}

.online-live-meta {
  margin: 0;
  font-size: 0.83rem;
  color: var(--text-muted);
}

.online-live-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.online-join-btn,
.online-start-form .btn,
.online-replay-actions .btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.online-join-btn {
  background: #16a34a;
  border-color: #16a34a;
}

.online-join-btn:hover {
  background: #15803d;
  border-color: #15803d;
}

.online-start-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.84rem;
  font-weight: 700;
}

.online-start-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.online-start-row .form-input {
  flex: 1 1 auto;
  min-width: 0;
}

.online-replays-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--radius-sm, 8px);
  border: 1px solid var(--border-light);
  background: var(--bg-subtle);
  color: var(--btn-blue);
  font-size: 0.84rem;
  font-weight: 600;
  flex: 0 1 auto;
}

.online-replays-link:hover {
  background: var(--bg-card);
  border-color: var(--btn-blue);
  color: var(--btn-blue-dark, var(--btn-blue));
}

.online-replays-link > span:first-of-type {
  flex: 1 1 auto;
}

.online-replays-count {
  min-width: 24px;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
}

@media (max-width: 700px) {
  .online-class-top {
    flex-direction: column;
    align-items: stretch;
  }

  .online-replays-link {
    width: 100%;
    justify-content: space-between;
  }

  .online-live.is-on {
    flex-direction: column;
    align-items: stretch;
  }

  .online-live-actions {
    width: 100%;
  }

  .online-live-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
}

.online-empty {
  padding: 32px 24px;
  text-align: center;
  color: var(--text-muted);
}

.online-player {
  padding: 0;
  overflow: hidden;
  margin-bottom: 20px;
}

.online-player-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000000;
}

.online-player-frame iframe,
.online-player-frame video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.online-player-link {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #ffffff;
}

.online-player-info {
  padding: 14px 18px;
}

.online-player-info h2 {
  margin: 0;
  font-size: 1.15rem;
}

.online-player-info p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.online-replay-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.online-replay {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-light);
}

.online-replay:last-child {
  border-bottom: 0;
}

.online-replay.is-playing {
  background: var(--bg-subtle);
}

.online-replay-main {
  flex: 1 1 260px;
  min-width: 0;
}

.online-replay-title {
  margin: 0;
  font-size: 1.02rem;
  color: var(--navy-heading);
}

.online-replay-meta {
  margin: 3px 0 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.online-replay-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.online-replay-none {
  font-size: 0.84rem;
  color: var(--text-muted);
}

.online-replay-form {
  flex: 1 1 100%;
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius-sm, 8px);
  background: var(--bg-subtle);
}

.online-replay-form label {
  display: grid;
  gap: 5px;
  font-size: 0.86rem;
  font-weight: 700;
}

.online-replay-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.online-replay-form-actions {
  display: flex;
  gap: 8px;
}

@media (max-width: 560px) {
  .online-start-row {
    flex-direction: column;
  }
}

/* =========================================================================
   #/learn/online/room/:id: the live lesson (liveRoom.js), a full-screen dark room
   ========================================================================= */
body.live-room-open {
  overflow: hidden;
}

body.live-room-open #top-bar-1,
body.live-room-open .site-footer,
body.live-room-open .welcome-mascot,
body.live-room-open .floating-phone {
  display: none !important;
}

/* in the room, notices go to the top right: at the bottom they would cover the controls and the
   host's end-lesson menu */
body.live-room-open .toast-container {
  top: 72px;
  bottom: auto;
}

.live-room {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  flex-direction: column;
  background: #0b1220;
  color: #e5e7eb;
  font-size: 0.95rem;
}

.live-room--message,
.live-room--prejoin {
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.live-loading {
  color: #cbd5e1;
}

.live-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: #0f172a;
  border-bottom: 1px solid #1e293b;
}

.live-top-left,
.live-top-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.live-top-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.live-title {
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-class {
  font-size: 0.8rem;
  color: #94a3b8;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 6px;
  background: #dc2626;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex: 0 0 auto;
}

.live-rec {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #fca5a5;
  font-weight: 700;
  font-size: 0.82rem;
}

.live-rec[hidden] {
  display: none;
}

.live-locked-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 6px;
  background: rgba(245, 158, 11, 0.16);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fbbf24;
  font-size: 0.78rem;
  font-weight: 700;
}

.live-locked-badge[hidden] {
  display: none;
}

.live-rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  animation: online-live-pulse 1.2s ease-in-out infinite;
}

.live-timer {
  font-variant-numeric: tabular-nums;
  color: #cbd5e1;
}

.live-count {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 6px;
  background: #1e293b;
  color: #e2e8f0;
  font-weight: 700;
}

.live-status {
  margin: 0;
  padding: 8px 16px;
  text-align: center;
  background: #854d0e;
  color: #ffffff;
  font-weight: 600;
}

.live-audio-unlock {
  border: 0;
  padding: 10px 16px;
  background: #1d4ed8;
  color: #ffffff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.live-audio-unlock[hidden],
.live-status[hidden] {
  display: none;
}

.live-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.live-body.has-panel {
  grid-template-columns: minmax(0, 1fr) 340px;
}

.live-stage {
  min-height: 0;
  min-width: 0;
  padding: 12px;
}

.live-grid {
  height: 100%;
  display: grid;
  gap: 10px;
  /* tile size worked out by liveRoom.js fitGallery(): the largest 16:9 tiles that fit */
  grid-template-columns: repeat(var(--live-cols, 1), var(--live-tile-w, minmax(0, 1fr)));
  grid-template-rows: repeat(var(--live-rows, 1), var(--live-tile-h, minmax(0, 1fr)));
  justify-content: center;
  align-content: center;
}

/* someone shares a screen: it fills the stage, everybody else lines up beside it */
.live-stage.has-screen .live-grid {
  grid-template-columns: minmax(0, 1fr) 220px;
  /* 16:9 tiles down the strip; the last row takes what is left so the screen spans the full height */
  grid-template-rows: repeat(var(--live-strip, 1), 124px) minmax(0, 1fr);
  grid-auto-rows: 124px;
  justify-content: stretch;
  align-content: stretch;
  overflow-y: auto;
}

.live-stage.has-screen .live-tile {
  grid-column: 2;
}

.live-stage.has-screen .live-tile.is-stage {
  grid-column: 1;
  grid-row: 1 / -1;
}

.live-tile {
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  border-radius: 12px;
  background: #1c2a44;
  outline: 3px solid transparent;
  outline-offset: -3px;
  transition: outline-color 0.15s ease;
}

.live-tile.is-speaking {
  outline-color: #22c55e;
}

.live-tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000000;
}

.live-tile.is-mirrored video {
  transform: scaleX(-1);
}

.live-tile.is-screen video {
  object-fit: contain;
}

.live-avatar {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: #1c2a44;
}

.live-avatar span {
  width: clamp(48px, 28%, 120px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #ffffff;
  font-weight: 800;
  font-size: clamp(1rem, 3vw, 2.2rem);
}

.live-tile.is-cam-off .live-avatar,
.live-prejoin-preview.is-cam-off .live-avatar {
  display: flex;
}

.live-tile-label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 600;
}

.live-tile-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-tile-mic {
  display: none;
  color: #f87171;
}

.live-tile.is-muted .live-tile-mic {
  display: inline-flex;
}

.live-tile-host {
  flex: 0 0 auto;
  padding: 0 6px;
  border-radius: 4px;
  background: #2563eb;
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.live-tile-hand {
  position: absolute;
  top: 8px;
  right: 8px;
  display: none;
  padding: 6px;
  border-radius: 50%;
  background: #f59e0b;
  color: #ffffff;
  animation: live-hand-wave 1.2s ease-in-out infinite;
}

.live-tile.has-hand .live-tile-hand {
  display: inline-flex;
}

@keyframes live-hand-wave {
  50% {
    transform: rotate(-14deg);
  }
}

.live-tile.is-connecting:not(.is-self)::after {
  content: '';
  position: absolute;
  top: 10px;
  left: 10px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  animation: live-spin 0.9s linear infinite;
}

@keyframes live-spin {
  to {
    transform: rotate(360deg);
  }
}

.live-net {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex: 0 0 auto;
}

.live-net.is-good {
  color: #4ade80;
}

.live-net.is-fair {
  color: #fbbf24;
}

.live-net.is-poor,
.live-net.is-offline {
  color: #f87171;
}

.live-net.is-pending {
  color: #94a3b8;
}

.live-net-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 1.5px;
  height: 11px;
  flex: 0 0 auto;
}

.live-net-bars i {
  display: block;
  width: 2.5px;
  border-radius: 1px;
  background: currentColor;
  opacity: 0.28;
}

.live-net-bars i:nth-child(1) {
  height: 3px;
}

.live-net-bars i:nth-child(2) {
  height: 5.5px;
}

.live-net-bars i:nth-child(3) {
  height: 8px;
}

.live-net-bars i:nth-child(4) {
  height: 11px;
}

.live-net[data-bars='1'] .live-net-bars i:nth-child(1),
.live-net[data-bars='2'] .live-net-bars i:nth-child(-n + 2),
.live-net[data-bars='3'] .live-net-bars i:nth-child(-n + 3),
.live-net[data-bars='4'] .live-net-bars i {
  opacity: 1;
}

.live-tile-net {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  padding: 4px 7px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.live-tile.is-connecting:not(.is-self) .live-tile-net {
  left: 30px;
}

.live-tile-net .live-net-ms {
  color: #f8fafc;
}

.live-tile-net.is-fair .live-net-ms {
  color: #fde68a;
}

.live-tile-net.is-poor .live-net-ms,
.live-tile-net.is-offline .live-net-ms {
  color: #fca5a5;
}

.live-tile-net.is-pending .live-net-ms {
  color: #cbd5e1;
}

.live-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #111c33;
  border-left: 1px solid #1e293b;
}

.live-panel[hidden] {
  display: none;
}

.live-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #1e293b;
}

.live-panel-head h2 {
  margin: 0;
  font-size: 1rem;
  color: #ffffff;
}

.live-panel-close {
  border: 0;
  background: transparent;
  color: #cbd5e1;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

.live-panel-close:hover {
  background: #1e293b;
}

.live-chat-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.live-chat-empty {
  margin: auto;
  color: #94a3b8;
}

.live-chat-msg {
  max-width: 92%;
  padding: 8px 10px;
  border-radius: 10px;
  background: #1c2a44;
}

.live-chat-msg.is-mine {
  align-self: flex-end;
  background: #1d4ed8;
}

.live-chat-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #cbd5e1;
}

.live-chat-head time {
  margin-left: auto;
  color: #94a3b8;
}

.live-chat-msg p {
  margin: 3px 0 0;
  color: #ffffff;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.live-chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #1e293b;
}

.live-chat-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0b1220;
  color: #ffffff;
  font: inherit;
}

.live-chat-input:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 0;
}

.live-chat-send {
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  background: #2563eb;
  color: #ffffff;
  cursor: pointer;
}

.live-chat-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.live-chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.live-perms-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.live-perm-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.live-perm-heading {
  margin: 0 0 2px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #94a3b8;
}

.live-perm-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 8px;
  background: #172540;
  border: 1px solid #1e293b;
  cursor: pointer;
}

.live-perm-row:hover {
  background: #1c2d4d;
}

.live-perm-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.live-perm-text strong {
  font-size: 0.86rem;
  font-weight: 600;
  color: #f8fafc;
}

.live-perm-sub {
  font-size: 0.75rem;
  color: #94a3b8;
}

.live-perm-switch {
  appearance: none;
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #334155;
  border: 1px solid #475569;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.live-perm-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.15s ease;
}

.live-perm-switch:checked {
  background: #2563eb;
  border-color: #3b82f6;
}

.live-perm-switch:checked::after {
  transform: translateX(16px);
}

.live-perm-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.live-kicked-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.live-kicked-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #172540;
  border: 1px solid #1e293b;
  font-size: 0.85rem;
  color: #e2e8f0;
}

.live-people {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
}

.live-person {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 8px;
  border-radius: 8px;
}

.live-person:hover {
  background: #1c2a44;
}

.live-person-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #2563eb;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 800;
  flex: 0 0 auto;
}

.live-person-name {
  flex: 1 1 auto;
  min-width: 0;
  color: #ffffff;
  overflow-wrap: anywhere;
}

.live-person-icons {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #94a3b8;
}

.live-person-icons .is-off {
  color: #f87171;
}

.live-person-hand {
  color: #f59e0b;
}

.live-person-net {
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.18);
  font-size: 0.7rem;
}

.live-person-net.is-good {
  border-color: rgba(74, 222, 128, 0.3);
}

.live-person-net.is-fair {
  border-color: rgba(251, 191, 36, 0.35);
}

.live-person-net.is-poor,
.live-person-net.is-offline {
  border-color: rgba(248, 113, 113, 0.35);
}

.live-person-actions {
  flex: 1 1 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-left: 42px;
}

.live-person-btn {
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 3px 9px;
  background: transparent;
  color: #e2e8f0;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.live-person-btn:hover {
  background: #1e293b;
}

.live-person-btn.is-danger {
  border-color: #7f1d1d;
  color: #fca5a5;
}

.live-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: #0f172a;
  border-top: 1px solid #1e293b;
  overflow-x: auto;
}

.live-ctrl-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.live-ctrl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 74px;
  padding: 6px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #e2e8f0;
  font: inherit;
  font-size: 0.74rem;
  cursor: pointer;
}

.live-ctrl:hover {
  background: #1e293b;
}

.live-ctrl:focus-visible {
  outline: 2px solid #3b82f6;
}

.live-ctrl.is-locked,
.live-ctrl:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.live-ctrl.is-locked:hover,
.live-ctrl:disabled:hover {
  background: transparent;
}

.live-ctrl-icon {
  position: relative;
  display: inline-flex;
}

.live-ctrl.is-off .live-ctrl-icon {
  color: #f87171;
}

.live-ctrl.is-active {
  background: #1e3a8a;
  color: #ffffff;
}

.live-ctrl.is-share .live-ctrl-icon {
  color: #4ade80;
}

.live-ctrl.is-record.is-active .live-ctrl-icon {
  color: #f87171;
}

.live-ctrl.is-danger {
  background: #dc2626;
  color: #ffffff;
}

.live-ctrl.is-danger:hover {
  background: #b91c1c;
}

.live-ctrl-badge {
  position: absolute;
  top: -6px;
  right: -10px;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 99px;
  background: #ef4444;
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}

.live-ctrl-label {
  white-space: nowrap;
}

.live-leave-wrap {
  position: relative;
}

.live-leave-menu {
  /* fixed to the window (placed by liveRoom.js above the button): the control bar's sideways
     scrolling would clip a menu sticking out of it */
  position: fixed;
  z-index: 6;
  right: 14px;
  bottom: 76px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 260px;
  padding: 8px;
  border-radius: 10px;
  background: #1e293b;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.live-leave-menu[hidden] {
  display: none;
}

.live-leave-option {
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  background: #334155;
  color: #ffffff;
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.live-leave-option.is-danger {
  background: #dc2626;
}

.live-over {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(11, 18, 32, 0.92);
}

.live-room--message .live-over {
  position: static;
  background: transparent;
}

.live-over[hidden] {
  display: none;
}

.live-over-card {
  max-width: 440px;
  padding: 28px 24px;
  border-radius: 14px;
  background: #111c33;
  text-align: center;
}

.live-over-text {
  margin: 0 0 18px;
  color: #ffffff;
  font-size: 1.05rem;
  font-weight: 600;
}

.live-over-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.live-over-actions .btn-outline {
  color: #ffffff;
  border-color: #475569;
}

/* before joining: camera preview and microphone / camera switches */
.live-prejoin {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 28px;
  align-items: center;
}

.live-prejoin-preview {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  overflow: hidden;
  background: #1c2a44;
}

.live-prejoin-preview video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.live-prejoin-class {
  margin: 0;
  color: #94a3b8;
  font-weight: 600;
}

.live-prejoin-title {
  margin: 4px 0 6px;
  color: #ffffff;
  font-size: 1.5rem;
}

.live-prejoin-meta {
  margin: 0 0 16px;
  color: #cbd5e1;
}

.live-prejoin-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.live-prejoin-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #ffffff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.live-prejoin-toggle.is-off {
  color: #fca5a5;
  border-color: #7f1d1d;
}

.live-join-btn {
  width: 100%;
  padding: 12px;
  font-size: 1.02rem;
  background: #16a34a;
  border-color: #16a34a;
}

.live-prejoin-back {
  display: inline-block;
  margin-top: 12px;
  color: #93c5fd;
}

@media (max-width: 900px) {
  .live-body.has-panel {
    grid-template-columns: minmax(0, 1fr);
  }

  .live-panel {
    position: absolute;
    inset: 0 0 64px 0;
    z-index: 4;
  }

  .live-stage.has-screen .live-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 3fr) auto;
    grid-auto-flow: column;
    grid-auto-columns: 140px;
    grid-auto-rows: auto;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .live-stage.has-screen .live-tile {
    grid-column: auto;
    grid-row: 2;
    aspect-ratio: 4 / 3;
  }

  .live-stage.has-screen .live-tile.is-stage {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .live-stage.has-screen .live-tile:not(.is-stage) .live-tile-net {
    top: 5px;
    left: 5px;
    padding: 2px 5px;
    font-size: 0.65rem;
  }

  .live-stage.has-screen .live-tile.is-connecting:not(.is-stage):not(.is-self) .live-tile-net {
    left: 26px;
  }

  .live-prejoin {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }

  .live-ctrl {
    min-width: 58px;
  }

  .live-ctrl-label {
    font-size: 0.66rem;
  }
}

@media (max-width: 600px) {
  .live-rec {
    font-size: 0;
    gap: 0;
  }

  .live-class,
  .live-timer {
    display: none;
  }

  .live-ctrl-label {
    display: none;
  }

  .live-ctrl {
    min-width: 44px;
  }
}

/* class management card: the teachers assigned to the class */
.class-card-teachers {
  margin-top: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #7c3aed;
}

/* =========================================================================
   UNIFIED BUTTONS & COMPACT LAYOUT REDESIGN (DESKTOP + MOBILE WEBVIEW)
   ========================================================================= */
:root {
  --btn-radius: 8px;
  --btn-h-sm: 32px;
  --btn-h: 38px;
  --btn-h-lg: 44px;
  --control-h: 38px;
  --card-radius: 12px;
  --card-pad: 18px;
}

button,
a,
.btn,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

button,
.btn,
.nav-col-btn,
.popup-option-btn,
.mobile-nav-btn,
.page-back,
.level-tab {
  touch-action: manipulation;
}

.btn {
  min-height: var(--btn-h);
  padding: 6px 14px;
  gap: 7px;
  border-radius: var(--btn-radius);
  border: 1.5px solid var(--btn-blue);
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.25;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.btn svg {
  flex-shrink: 0;
}

.btn:hover,
.btn:focus-visible {
  background-color: var(--btn-blue-dark);
  border-color: var(--btn-blue-dark);
  color: #ffffff;
}

.btn:focus-visible,
.popup-option-btn:focus-visible,
.popup-close-btn:focus-visible,
.nav-col-btn:focus-visible,
.user-menu-btn:focus-visible,
.settings-trigger-btn:focus-visible {
  outline: 2px solid var(--hover-cyan);
  outline-offset: 2px;
}

.btn-sm {
  min-height: var(--btn-h-sm);
  padding: 4px 11px;
  font-size: 0.82rem;
  gap: 6px;
  border-radius: 7px;
}

.btn-lg {
  min-height: var(--btn-h-lg);
  padding: 8px 18px;
  font-size: 0.96rem;
  border-radius: 9px;
}

.btn-outline:not(.btn-delete-game):not([data-copied='true']) {
  background-color: var(--bg-card);
  color: var(--btn-blue);
  border: 1.5px solid rgba(29, 106, 229, 0.45);
}

.btn-outline:not(.btn-delete-game):not([data-copied='true']):hover,
.btn-outline:not(.btn-delete-game):not([data-copied='true']):focus-visible {
  background-color: var(--bg-subtle);
  color: var(--btn-blue-dark);
  border-color: var(--btn-blue);
}

:root[data-theme='dark'] .btn-outline:not(.btn-delete-game):not([data-copied='true']) {
  background-color: transparent;
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.55);
}

:root[data-theme='dark'] .btn-outline:not(.btn-delete-game):not([data-copied='true']):hover,
:root[data-theme='dark'] .btn-outline:not(.btn-delete-game):not([data-copied='true']):focus-visible {
  background-color: rgba(37, 99, 235, 0.16);
  color: #bfdbfe;
  border-color: #60a5fa;
}

.btn-danger {
  background-color: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-danger:hover,
.btn-danger:focus-visible {
  background-color: #b91c1c;
  border-color: #b91c1c;
  color: #ffffff;
}

.btn-danger-outline {
  background-color: var(--bg-card);
  color: var(--danger);
  border: 1.5px solid rgba(220, 38, 38, 0.45);
}

.btn-danger-outline:hover,
.btn-danger-outline:focus-visible {
  background-color: rgba(220, 38, 38, 0.08);
  color: #b91c1c;
  border-color: var(--danger);
}

:root[data-theme='dark'] .btn-danger-outline {
  background-color: transparent;
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.55);
}

:root[data-theme='dark'] .btn-danger-outline:hover,
:root[data-theme='dark'] .btn-danger-outline:focus-visible {
  background-color: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
  border-color: #ef4444;
}

.btn-delete-game {
  background-color: var(--bg-card);
  color: var(--danger);
  border: 1.5px solid rgba(220, 38, 38, 0.4);
}

.btn-delete-game:hover,
.btn-delete-game:focus-visible {
  background-color: rgba(220, 38, 38, 0.1);
  color: #b91c1c;
  border-color: var(--danger);
}

.btn.btn-icon {
  min-height: var(--btn-h);
  width: var(--btn-h);
  height: var(--btn-h);
  padding: 0;
  border-radius: var(--btn-radius);
}

.btn.btn-sm.btn-icon {
  min-height: var(--btn-h-sm);
  width: var(--btn-h-sm);
  height: var(--btn-h-sm);
  padding: 0;
}

.match-icon-actions .btn.btn-icon {
  width: 100%;
  height: var(--btn-h);
}

.btn.online-join-btn,
.btn.live-join-btn {
  background-color: #16a34a;
  border-color: #16a34a;
  color: #ffffff;
}

.btn.online-join-btn:hover,
.btn.online-join-btn:focus-visible,
.btn.live-join-btn:hover,
.btn.live-join-btn:focus-visible {
  background-color: #15803d;
  border-color: #15803d;
  color: #ffffff;
}

.bar-container {
  padding: 0 20px;
}

.bar-1-inner {
  min-height: 52px;
  gap: 10px;
}

.nav-col-btn {
  min-height: 34px;
  padding: 5px 12px;
  border-radius: var(--btn-radius);
  font-size: 0.92rem;
  transition: background-color 0.15s ease;
}

.nav-col-btn:hover {
  background-color: rgba(255, 255, 255, 0.14);
}

.btn-auth,
.user-menu-btn,
.settings-trigger-btn {
  min-height: 34px;
  border-radius: var(--btn-radius);
}

.btn-auth {
  padding: 5px 12px;
  font-size: 0.84rem;
}

.user-menu-btn {
  padding: 5px 12px;
  font-size: 0.84rem;
}

.settings-trigger-btn {
  width: 34px;
  height: 34px;
}

.popup-option-btn {
  min-height: 42px;
  padding: 9px 14px;
  border-radius: var(--btn-radius);
  font-size: 0.9rem;
  transition: background-color 0.15s ease;
}

.popup-option-btn:hover,
.popup-option-btn:focus-visible {
  background-color: var(--btn-blue-dark);
}

.popup-close-btn {
  min-height: 32px;
  padding: 4px 12px;
  border-radius: 7px;
  font-size: 0.82rem;
  font-weight: 600;
}

.popup-close-btn:hover,
.popup-close-btn:focus-visible {
  background-color: var(--btn-blue-dark);
}

.level-tab {
  min-height: 34px;
  padding: 5px 14px;
  font-size: 0.86rem;
}

.news-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 5px 16px;
  font-size: 0.88rem;
}

.form-input,
.form-select {
  min-height: var(--control-h);
  padding: 7px 12px;
  border-radius: var(--btn-radius);
  font-size: 0.9rem;
}

.form-textarea {
  padding: 9px 12px;
  border-radius: var(--btn-radius);
  font-size: 0.9rem;
}

.main-container {
  padding: 18px 20px 36px;
}

.card:not(.users-card) {
  border-width: 1px;
  border-radius: var(--card-radius);
  padding: var(--card-pad);
  box-shadow: 0 2px 10px rgba(10, 31, 68, 0.05);
}

:root[data-theme='dark'] .card:not(.users-card) {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.home-welcome-banner,
.hero-banner,
.feature-column-card {
  border-radius: var(--card-radius);
  box-shadow: 0 2px 10px rgba(10, 31, 68, 0.05);
}

:root[data-theme='dark'] .home-welcome-banner,
:root[data-theme='dark'] .hero-banner,
:root[data-theme='dark'] .feature-column-card {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.page-head {
  gap: 10px;
  margin-bottom: 16px;
}

.page-head .page-header-bar {
  padding-bottom: 12px;
  gap: 10px 16px;
}

.page-title,
.page-head .page-title {
  font-size: 1.45rem;
}

.page-subtitle {
  font-size: 0.9rem;
}

.page-back {
  height: 32px;
  padding: 0 12px 0 4px;
  font-size: 0.84rem;
  box-shadow: none;
}

.page-header-actions {
  gap: 8px;
}

.popup-box,
.popup-card,
.admin-modal-box {
  border-width: 1px;
  border-radius: 14px;
  padding: 20px;
}

.admin-toolbar {
  padding: 10px 12px;
  border-width: 1px;
  border-radius: var(--card-radius);
  gap: 8px;
}

.admin-actions,
.btn-group-row {
  gap: 8px;
}

.data-table th,
.data-table td {
  padding: 9px 12px;
}

:root[data-theme='dark'] .online-class-card.is-live {
  border-left-color: #ef4444;
}

:root[data-theme='dark'] .online-replays-link {
  background: rgba(15, 23, 42, 0.45);
  color: #93c5fd;
}

:root[data-theme='dark'] .online-replays-link:hover {
  background: rgba(37, 99, 235, 0.14);
  border-color: #60a5fa;
  color: #bfdbfe;
}

:root[data-theme='dark'] .online-replays-count {
  background: var(--bg-card);
  color: #cbd5e1;
}

.live-controls {
  padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
}

.live-person-btn {
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 6px;
  font-weight: 600;
}

@media (max-width: 768px) {
  :root {
    --btn-h: 36px;
    --btn-h-sm: 32px;
    --btn-h-lg: 42px;
    --control-h: 36px;
    --card-pad: 14px;
  }

  .bar-container {
    padding: 0 12px;
  }

  .bar-1-inner {
    min-height: 48px;
    gap: 8px;
  }

  .mobile-menu-toggle,
  .settings-trigger-btn,
  .btn-auth,
  .user-menu-btn {
    min-height: 34px;
    height: 34px;
    border-radius: var(--btn-radius);
  }

  .mobile-menu-toggle,
  .settings-trigger-btn {
    width: 34px;
  }

  .main-container {
    padding: 14px 12px calc(24px + env(safe-area-inset-bottom, 0px));
  }

  .page-title,
  .page-head .page-title {
    font-size: 1.24rem;
  }

  .page-subtitle {
    font-size: 0.85rem;
  }

  .page-header-actions {
    width: 100%;
  }

  .btn:not(.btn-icon) {
    padding: 5px 12px;
    font-size: 0.84rem;
  }

  .btn-sm:not(.btn-icon) {
    padding: 4px 10px;
    font-size: 0.79rem;
  }

  .mobile-nav-btn {
    min-height: 42px;
    padding: 8px 12px;
    border-radius: 9px;
  }

  .site-footer-inner {
    padding: 20px 14px 14px;
    gap: 16px;
  }

  .site-footer-bottom {
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .live-top {
    padding: 8px 12px;
  }

  .live-controls {
    padding: 6px 10px max(8px, env(safe-area-inset-bottom, 0px));
    gap: 6px;
  }
}

@media (max-width: 480px) {
  .online-class-card {
    padding: 12px;
    gap: 10px;
  }

  .online-class-icon {
    width: 36px;
    height: 36px;
    border-radius: 9px;
  }

  .online-class-name {
    font-size: 1rem;
  }
}
