/* ==========================================================================
   1. Variables & Base Styles
   ========================================================================== */

:root {
  /* Colors */
  --bg-primary: #1e1e1e;
  --bg-secondary: #2d2d2d;
  --bg-tertiary: #383838;
  --bg-active: #424242;
  --bg-dark: #262626;
  --bg-hover: #333333;
  --bg-button-secondary: #404040;

  --text-primary: #e0e0e0;
  --text-secondary: #bdbdbd;
  --text-muted: #757575;

  --accent-primary: #ffc107;
  --accent-hover: #ffca28;

  --error: #ff5252;
  --success: #69f0ae;
  --success-hover: #4caf50;

  --border-color: #404040;

  /* Radii */
  --radius-lg: 10px;
  --radius-md: 8px;
  --radius-sm: 5px;

  /* Shadow */
  --shadow-main: 0 4px 20px rgba(0, 0, 0, 0.3);
  --shadow-toast: 0 4px 12px rgba(0, 0, 0, 0.5);
}

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

html,
body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

h1 {
  color: var(--accent-primary);
  margin-bottom: 30px;
}

h2 {
  margin-top: 12px;
  margin-bottom: 12px;
  color: var(--accent-primary);
}

h3 {
  color: var(--accent-primary);
  font-size: 1.1em;
}

/* ==========================================================================
   2. Layout & Navigation
   ========================================================================== */

#app-container {
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

#logged-in-view {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

#main-content {
  flex-grow: 1;
  padding: 20px;
  display: flex;
  overflow-y: auto;
  min-width: 0; /* Prevents flex children from overflowing */
}

#main-content > * {
  margin: auto;
  width: 100%;
}

/* Sidebar & Toggles */
.sidebar {
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  padding: 48px 15px 15px 20px;
  transition:
    transform 0.3s ease,
    margin-left 0.3s ease;
}

.sidebar.left {
  width: 300px;
  flex-shrink: 0;
  z-index: 100;
}

.sidebar.right {
  position: fixed;
  top: 0;
  right: 0;
  width: 250px;
  height: 100%;
  z-index: 120;
  transform: translateX(100%);
  border-left: 2px solid var(--accent-primary);
}

.sidebar-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.sidebar-toggle-label {
  position: fixed;
  top: 15px;
  z-index: 150;
}

.sidebar-toggle-label.left {
  left: 15px;
}
.sidebar-toggle-label.right {
  right: 15px;
}

/* Sidebar Logic Controls */
#sidebar-toggle-check:checked ~ #sidebar-toggle-label {
  left: 15px;
}
#options-toggle-check:checked ~ .sidebar.right {
  transform: translateX(0);
}

#sidebar-toggle-check:checked ~ #logged-in-view .sidebar.left {
  transform: translateX(-100%);
  margin-left: -300px;
}

/* SVG Toggle Animations */
.sidebar-toggle-label .line {
  fill: none;
  stroke: var(--accent-primary);
  stroke-width: 3;
  stroke-linecap: round;
  transition:
    transform 0.3s ease,
    d 0.3s ease;
}

/* Left Sidebar Icon States (Caret -> Hamburger) */
#sidebar-toggle-check:not(:checked) ~ #sidebar-toggle-label .line.top {
  d: path("M 18 8 L 10 15");
}
#sidebar-toggle-check:not(:checked) ~ #sidebar-toggle-label .line.middle {
  d: path("M 10 15 L 10 15");
}
#sidebar-toggle-check:not(:checked) ~ #sidebar-toggle-label .line.bottom {
  d: path("M 18 22 L 10 15");
}

#sidebar-toggle-check:checked ~ #sidebar-toggle-label .line.top {
  d: path("M 5 8 L 25 8");
}
#sidebar-toggle-check:checked ~ #sidebar-toggle-label .line.middle {
  d: path("M 5 15 L 25 15");
}
#sidebar-toggle-check:checked ~ #sidebar-toggle-label .line.bottom {
  d: path("M 5 22 L 25 22");
}

/* Right Sidebar Icon States (Wand -> Caret) */
#options-toggle-check:not(:checked) ~ #options-toggle-label .line.top {
  d: path("M 17 10 L 23 10");
}
#options-toggle-check:not(:checked) ~ #options-toggle-label .line.middle {
  d: path("M 20 7 L 20 13");
}
#options-toggle-check:not(:checked) ~ #options-toggle-label .line.bottom {
  d: path("M 8 22 L 15 15");
}

#options-toggle-check:checked ~ #options-toggle-label .line.top {
  d: path("M 12 8 L 20 15");
}
#options-toggle-check:checked ~ #options-toggle-label .line.middle {
  d: path("M 20 15 L 20 15");
}
#options-toggle-check:checked ~ #options-toggle-label .line.bottom {
  d: path("M 12 22 L 20 15");
}

.info-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  background-color: var(--success);
  border-radius: 50%;
  border: 2px solid var(--bg-button-secondary);
  user-select: none;
}

/* ==========================================================================
   3. Forms & Buttons
   ========================================================================== */

button {
  padding: 10px 15px;
  border: none;
  background-color: var(--accent-primary);
  color: var(--bg-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1em;
  font-weight: bold;
  transition:
    background-color 0.3s,
    transform 0.1s;
}

button:hover {
  background-color: var(--accent-hover);
}
button:active {
  transform: scale(0.98);
}
button:disabled {
  background-color: var(--bg-button-secondary);
  color: var(--text-muted);
  cursor: not-allowed;
}

.icon-button {
  width: 32px;
  height: 32px;
  padding: 5px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg-button-secondary);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition:
    background-color 0.3s,
    color 0.3s;
  box-sizing: border-box;
}

.icon-button:hover {
  background: var(--bg-active);
  color: var(--accent-primary);
}

.icon-button:disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

.icon-button svg {
  width: 100%;
  height: 100%;
}

.btn-accent {
  background: var(--accent-primary);
  color: var(--bg-primary);
}

.btn-accent:hover {
  background: color-mix(in srgb, var(--accent-primary), black 15%);
  color: var(--bg-primary);
}

.btn-danger {
  background-color: var(--error);
  color: #fff;
}

.btn-danger:hover {
  background-color: color-mix(in srgb, var(--error), black 30%);
  color: #fff;
}

.btn-secondary {
  background-color: var(--bg-button-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--bg-active);
  color: var(--text-primary);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 2em;
  color: var(--text-secondary);
}

.subtle-link {
  color: var(--accent-primary);
  text-decoration: none;
  font-size: 0.9em;
}

#generic-modal-body {
  max-height: 70vh;
  overflow-y: auto;
  white-space: pre-wrap;
}

.sidebar-nav-btn {
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  text-align: left;
  padding: 10px 15px;
  border: 1px solid transparent;
  width: 100%;
}

.sidebar-nav-btn:hover {
  background-color: var(--bg-active);
  color: var(--accent-primary);
}

.sidebar-nav-btn.active {
  border-left: 3px solid var(--accent-primary);
  color: var(--accent-primary);
  background-color: var(--bg-active);
}

#user-button {
  width: 100%;
  text-align: left;
  background: var(--bg-button-secondary);
  color: var(--text-secondary);
  padding: 10px 15px;
  border: 1px solid transparent;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

#user-button:hover {
  background-color: var(--bg-active);
  color: var(--accent-primary);
}

#forfeit-button,
#logout-button {
  position: fixed;
  bottom: 15px;
  right: 15px;
  z-index: 100;
}

/* Inputs & Form Groups */
input[type="text"],
input[type="password"],
input[type="email"],
select {
  padding: 10px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-size: 1em;
  width: 100%;
  box-sizing: border-box;
}

input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background-color: var(--bg-tertiary);
  border: 2px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  transition:
    background-color 0.2s,
    border-color 0.2s;
}

input[type="checkbox"]:checked {
  background-color: var(--accent-primary);
  border-color: var(--accent-primary);
}

input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid var(--bg-primary);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.option-group {
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option-group label {
  font-size: 0.9em;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.int-picker {
  display: flex;
  gap: 6px;
}

.int-picker-btn {
  min-width: 36px;
  width: auto;
  padding: 0 10px;
  height: 36px;
  font-size: 1em;
  font-weight: bold;
  background: var(--bg-button-secondary);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition:
    background-color 0.2s,
    color 0.2s;
}

.int-picker-btn:hover {
  background: var(--bg-active);
  color: var(--text-primary);
}

.int-picker-btn.active {
  background: var(--accent-primary);
  color: var(--bg-primary);
}

.int-stepper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.int-stepper-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 1.3em;
  font-weight: bold;
  background: var(--bg-button-secondary);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
}

.int-stepper-value {
  min-width: 28px;
  text-align: center;
  font-size: 1.1em;
  font-weight: bold;
  color: var(--accent-primary);
}

.option-group input[type="color"] {
  width: 100%;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
}

/* ==========================================================================
   4. Components (Cards, Badges, Lists, Tables, Modals, Toasts)
   ========================================================================== */

/* Badges */
.status-badge {
  font-size: 0.7em;
  padding: 2px 6px;
  border-radius: 10px;
  text-transform: uppercase;
  font-weight: bold;
  margin-left: 8px;
  vertical-align: middle;
}

.status-badge.win {
  background-color: var(--success);
  color: var(--bg-primary);
}
.status-badge.lost {
  background-color: var(--error);
  color: #fff;
}
.status-badge.draw {
  background-color: var(--text-muted);
  color: var(--text-primary);
}
.status-badge.waiting {
  background-color: var(--accent-primary);
  color: var(--bg-primary);
}
.status-badge.playing {
  background-color: var(--bg-button-secondary);
  color: var(--text-secondary);
}

/* Stats Cards */
.stat-card {
  background: var(--bg-secondary);
  padding: 25px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  text-align: center;
  display: block;
}
.stat-label {
  display: block;
  color: var(--text-muted);
  font-size: 0.9em;
  margin-bottom: 10px;
}

.period-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.period-btn {
  padding: 6px;
  border-radius: var(--radius-sm, 6px);
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
}
.period-btn.active {
  background: var(--accent-primary);
  border: none;
  color: #000;
  font-weight: 600;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 20px;
}
.card-header h2 {
  margin: 0;
}
.card-subtitle {
  color: var(--accent-primary);
  font-weight: bold;
  font-size: 0.9rem;
}

.stat-value {
  display: block;
  color: var(--accent-primary);
  font-size: 2em;
  font-weight: bold;
}

/* Lists (Games, Invites) */
#active-game-list,
#finished-game-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
}

#active-game-list {
  flex-grow: 1;
}

#finished-game-list {
  max-height: 200px;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-dark);
}

.game-list-item {
  padding: 12px 15px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background-color 0.2s;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.game-list-item:hover {
  background-color: var(--bg-tertiary);
}
.game-list-item.active {
  background-color: var(--bg-active);
  font-weight: bold;
  border-left: 3px solid var(--accent-primary);
}
.game-list-item.your-turn {
  color: var(--success);
  font-weight: bold;
}
.game-list-item.ambiguous-turn {
  color: var(--accent-primary);
}

.game-list-item-info {
  flex-grow: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-list-item.unseen-complete {
  color: var(--accent-primary) !important;
  font-weight: bold;
  border-left: 3px solid var(--accent-primary);
}

.game-list-item.unseen-complete .status-badge {
  border: 1px solid var(--accent-primary);
  background: rgba(255, 193, 7, 0.1) !important;
  color: var(--accent-primary) !important;
}

.game-id {
  color: var(--text-muted);
  font-size: 0.8em;
  margin-left: 5px;
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
  width: 100%;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.rankings-table {
  width: 100%;
  min-width: 400px;
  border-collapse: collapse;
  border: none;
}

.rankings-table th,
.rankings-table td {
  padding: 15px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.rankings-table th {
  background: var(--bg-tertiary);
  color: var(--accent-primary);
  font-weight: bold;
}

.rankings-table tr:hover {
  background: var(--bg-hover);
}
.rankings-table tr:last-child td {
  border-bottom: none;
}

/* Modals */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  backdrop-filter: blur(5px);
}

.modal-content {
  background: var(--bg-secondary);
  padding: 30px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-main);
  border: 1px solid var(--border-color);
  width: 90%;
  max-width: 500px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
}

.modal-header h2 {
  margin: 0;
}

.modal-section h3 {
  margin-top: 0;
  margin-bottom: 15px;
  font-size: 1.1em;
  color: var(--text-secondary);
}

.modal-divider {
  height: 1px;
  background: var(--border-color);
  margin: 25px 0;
}

/* Toasts */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  position: relative;
  background: var(--bg-hover);
  color: #fff;
  padding: 12px 24px 12px 28px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-toast);
  overflow: hidden;
  animation:
    slideIn 0.3s ease,
    fadeOut 0.3s ease 2.7s forwards;
  min-width: 200px;
}

.toast::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background-color: var(--accent-primary);
  transform-origin: bottom;
  animation: shrinkHeight 3s linear forwards;
}

.toast.success::before {
  background-color: var(--success);
}

.toast.error::before {
  background-color: var(--error);
}
.accentuated {
  color: var(--accent-primary);
}

.rotate-icon {
  width: 100%;
  height: 100%;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.rotate-icon.vertical {
  transform: rotate(90deg);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes shrinkHeight {
  from {
    transform: scaleY(1);
  }
  to {
    transform: scaleY(0);
  }
}

/* ==========================================================================
   5. View Specific Styles (Auth, Social, Stats)
   ========================================================================== */

/* Loading View */
#loading-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  z-index: 2000;
}

.loader {
  width: 48px;
  height: 48px;
  border: 5px solid var(--bg-tertiary);
  border-bottom-color: var(--accent-primary);
  border-radius: 50%;
  display: inline-block;
  box-sizing: border-box;
  animation: rotation 1s linear infinite;
}

@keyframes rotation {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Auth View */
#auth-view {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

#auth-form {
  background: var(--bg-secondary);
  padding: 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-main);
  text-align: center;
  width: 90%;
  max-width: 400px;
  border: 1px solid var(--border-color);
}

#auth-form input {
  margin-bottom: 15px;
}

#auth-buttons {
  display: flex;
  gap: 10px;
}

/* Social & Invites */
#invites-container {
  padding: 0 20px 10px 20px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 10px;
}

#invites-container h3 {
  margin: 0 0 10px 0;
}

#invite-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.invite-item {
  background-color: var(--bg-tertiary);
  padding: 10px;
  margin-bottom: 5px;
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9em;
}

.invite-join-btn {
  padding: 5px 10px;
  font-size: 0.8em;
  background-color: var(--success);
  color: var(--bg-primary);
}

.invite-join-btn:hover {
  background-color: var(--success-hover);
}

/* Home / Stats View */
#stats-view {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

#rankings-section {
  margin-top: 40px;
  display: flex;
  flex-direction: column;
  gap: 40px;
}

#global-history-section {
  margin-top: 40px;
  padding: 25px;
}

#global-history-section h2 {
  margin-bottom: 20px;
}

#global-history-container {
  height: 300px;
  width: 100%;
  position: relative;
}

#global-history-legend {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  justify-content: center;
}

#summary-stats-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
}

.home-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 15px;
  margin-top: 50px;
  width: 100%;
}

.home-stats .stat-card {
  background: var(--bg-tertiary);
  padding: 15px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  text-align: center;
  transition:
    transform 0.2s,
    background-color 0.2s;
}

.home-stats .stat-card:hover {
  transform: translateY(-3px);
  background-color: var(--bg-active);
}

.home-view-container {
  margin-top: 30px;
  background: var(--bg-secondary);
  padding: 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  width: 100%;
  box-sizing: border-box;
}

.home-view-container h3 {
  margin-top: 0;
  margin-bottom: 15px;
  color: var(--text-primary);
}

.game-ranks-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.game-rank-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease;
}

.game-rank-item:hover {
  border-color: var(--text-muted);
}

/* The signed-in player's own row in a leaderboard */
.game-rank-item.is-me {
  border-color: var(--accent-primary);
  background: rgba(255, 193, 7, 0.1);
}

.game-rank-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

/* Circular rank-position badge (daily leaderboard) */
.game-rank-pos {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-dark);
  color: var(--text-secondary);
  font-weight: bold;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.rank-1 .game-rank-pos {
  background: linear-gradient(135deg, #ffd34d, #e0a200);
  color: #4a3500;
}
.rank-2 .game-rank-pos {
  background: linear-gradient(135deg, #e4e4e4, #b0b0b0);
  color: #333333;
}
.rank-3 .game-rank-pos {
  background: linear-gradient(135deg, #e0925a, #b06a30);
  color: #3a1d00;
}

.game-rank-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: bold;
  color: var(--accent-primary);
}

.game-rank-you {
  flex-shrink: 0;
  background: var(--accent-primary);
  color: var(--bg-primary);
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 0.65rem;
  font-weight: bold;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.game-rank-badge {
  flex-shrink: 0;
  background: var(--accent-primary);
  color: var(--bg-primary);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.8em;
  font-weight: bold;
}

.game-rank-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 0.9em;
  color: var(--text-secondary);
}

.game-rank-detail {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.game-rank-score {
  font-weight: bold;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* Compact win/loss/draw chips (Your Rankings) */
.rank-chip {
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 0.82em;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: var(--bg-dark);
  color: var(--text-secondary);
}
.rank-chip-win {
  background: rgba(105, 240, 174, 0.16);
  color: var(--success);
}
.rank-chip-loss {
  background: rgba(255, 82, 82, 0.16);
  color: var(--error);
}
.rank-chip-draw {
  background: var(--bg-dark);
  color: var(--text-muted);
}

/* Push Notifications UI */
.push-status-card {
  background: var(--bg-tertiary);
  padding: 15px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  flex-wrap: wrap;
}

.push-status-info {
  flex: 1 1 200px;
}

#push-status-text {
  font-weight: bold;
  display: block;
  margin-bottom: 4px;
}

.push-status-desc {
  margin: 0;
  font-size: 0.85em;
  color: var(--text-muted);
}

.push-actions {
  display: flex;
  gap: 10px;
}

.push-btn {
  padding: 8px 12px;
  font-size: 0.85em;
  white-space: nowrap;
}

#push-toggle-btn.enabled {
  background-color: var(--bg-button-secondary);
  color: var(--text-secondary);
}

#test-push-btn {
  background-color: var(--bg-button-secondary);
  color: var(--text-primary);
}

#user-info {
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-action-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.sidebar-action-row > :first-child {
  flex: 1;
  min-width: 0;
}

.sidebar-action-row > :last-child {
  flex-shrink: 0;
}

#daily-challenge-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.play-daily-btn.daily-joined::after {
  content: " ✓";
  opacity: 0.8;
}

#finished-games-container {
  margin-top: auto;
  border-top: 1px solid var(--border-color);
}

#finished-games-header {
  padding: 15px;
  background-color: var(--bg-secondary);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: bold;
  color: var(--text-secondary);
  user-select: none;
}

#finished-games-header:hover {
  background-color: var(--bg-tertiary);
  color: var(--accent-primary);
}

.finished-unseen-badge {
  background-color: var(--error);
  color: #fff;
  font-size: 0.75rem;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 12px;
  margin-left: 8px;
  display: inline-block;
  vertical-align: middle;
  line-height: 1;
}

.finished-unseen-badge.hidden {
  display: none !important;
}

#load-more-finished {
  width: 100%;
  padding: 10px;
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  font-size: 0.9em;
  border-top: 1px solid var(--border-color);
  font-weight: bold;
}

#load-more-finished:hover:not(:disabled) {
  background-color: var(--bg-active);
  color: var(--accent-primary);
}

#load-more-finished:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Ended Games & Recap */
.recap-container {
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-color);
  animation: modalScaleUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalScaleUp {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.recap-header {
  padding: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  position: relative;
  background-color: var(--bg-secondary);
}

.recap-header::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
}

.recap-header.outcome-win {
  border-bottom: 2px solid var(--success);
}

.recap-header.outcome-lost {
  border-bottom: 2px solid var(--error);
}

.recap-header.outcome-draw {
  border-bottom: 2px solid var(--text-muted);
}

.recap-header-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.recap-badge {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 12px;
  margin-left: 0;
  vertical-align: middle;
}

.recap-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
}

.recap-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg-secondary);
}

.recap-section-title {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.recap-players-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recap-player-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.95rem;
}

.recap-player-row.me {
  color: var(--accent-primary);
  font-weight: bold;
}

.recap-footer {
  padding: 20px 24px;
  background-color: var(--bg-dark);
  border-top: 1px solid var(--border-color);
}

.recap-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.recap-page-indicator {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ==========================================================================
   6. Game UI - Generic & Global Scaling
   ========================================================================== */

.main-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 800px;
}

#game-header {
  text-align: center;
  width: 100%;
}
#game-title {
  color: var(--accent-primary);
  margin: 0;
}
#status {
  font-size: 1.2em;
  font-weight: bold;
}

#game-container {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 10px;
  box-sizing: border-box;
}

#game-actions {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 20px;
  width: 100%;
}

.action-group {
  display: flex;
  gap: 5px;
}
.action-group.wrap {
  flex-wrap: wrap;
}
.action-group.wrap > * {
  flex: 1 1 auto;
  min-width: 120px;
}

/* Autocomplete input */
.action-group.wrap > .input-with-autocomplete {
  position: relative;
  display: flex;
  flex: 1 1 100%;
}

.input-with-autocomplete input {
  width: 100%;
}

.autocomplete-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
  list-style: none;
  padding: 0;
  margin: 0;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.autocomplete-suggestions li {
  padding: 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
}

.autocomplete-suggestions li:last-child {
  border-bottom: none;
}

.autocomplete-suggestions li:hover,
.autocomplete-suggestions li.active {
  background-color: var(--bg-tertiary);
}

/* Shared Board Styles */
.game-board {
  display: grid;
  gap: 8px;
  background-color: var(--border-color);
  padding: 8px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-main);
  width: 100%; /* Responsive width */
  aspect-ratio: 1 / 1; /* Keep it square */
  box-sizing: border-box;
}

.cell {
  background-color: var(--bg-tertiary);
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
  cursor: default;
  user-select: none;
  border-radius: var(--radius-sm);
  transition:
    background-color 0.2s,
    transform 0.1s;
  width: 100%;
  height: 100%;
}

.cell.clickable {
  cursor: pointer;
}
.cell.clickable:hover {
  background-color: var(--bg-active);
  transform: scale(1.02);
}

.game-info {
  display: flex;
  gap: 20px;
  background-color: var(--bg-secondary);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  font-size: 1.1em;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}
.game-info div {
  display: flex;
  align-items: center;
}

/* ==========================================================================
   8. Utilities
   ========================================================================== */

.hidden,
.logged-in-only.hidden {
  display: none !important;
}

#auth-view:not(.hidden) ~ * .logged-in-only,
#auth-view:not(.hidden) ~ .logged-in-only {
  display: none !important;
}

#auth-view:not(.hidden) ~ #sidebar-toggle-label {
  display: none !important;
}

/* Mobile Sidebar Fixes */
@media (max-width: 600px) {
  .sidebar.left {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 100vw;
    z-index: 120;
    margin-left: 0;
    box-shadow: var(--shadow-main);
  }

  #sidebar-toggle-check:checked ~ #logged-in-view .sidebar.left {
    transform: translateX(-100%);
    margin-left: 0;
  }

  #main-content {
    padding: 10px;
  }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--bg-active);
}
