/* SQORDY Core Stylesheet */

html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: black;
  color: white;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
}

:root {
  --header-h: clamp(40px, 4.5vh, 48px);
  --max-game-w: min(640px, 94vw);
  
  /* Grid cell sizing scales fluidly to guarantee fitting within 100vh */
  --cell-size: min(
    calc((100vh - var(--header-h) - 240px) / 5.3),
    calc((min(var(--max-game-w), 94vw) - 32px) / 5),
    calc(46vh / 5),
    84px
  );
  --cell-size-safe: max(var(--cell-size), 32px);
  
  /* Keyboard height scales dynamically */
  --key-h: min(
    calc((20vh - 10px) / 3),
    calc((100vh - var(--header-h) - (var(--cell-size-safe) * 5.2) - 80px) / 3),
    54px
  );
  --key-h-safe: max(var(--key-h), 36px);
}

@supports (height: 100dvh) {
  :root {
    --cell-size: min(
      calc((100dvh - var(--header-h) - 240px) / 5.3),
      calc((min(var(--max-game-w), 94vw) - 32px) / 5),
      calc(46dvh / 5),
      84px
    );
    --key-h: min(
      calc((20dvh - 10px) / 3),
      calc((100dvh - var(--header-h) - (var(--cell-size-safe) * 5.2) - 80px) / 3),
      54px
    );
    --key-h-safe: max(var(--key-h), 36px);
  }
}

/* Desktop Monitor Screen Enhancements */
@media (min-width: 600px) and (min-height: 650px) {
  :root {
    --max-game-w: min(660px, 90vw);
    --cell-size: min(
      calc((100vh - var(--header-h) - 240px) / 5.3),
      calc((min(660px, 90vw) - 40px) / 5),
      84px
    );
    --cell-size-safe: max(var(--cell-size), 38px);
    --key-h: min(54px, calc(18vh / 3));
    --key-h-safe: max(var(--key-h), 38px);
  }
}

@supports (height: 100dvh) {
  @media (min-width: 600px) and (min-height: 650px) {
    :root {
      --cell-size: min(
        calc((100dvh - var(--header-h) - 240px) / 5.3),
        calc((min(660px, 90vw) - 40px) / 5),
        84px
      );
      --key-h: min(54px, calc(18dvh / 3));
      --key-h-safe: max(var(--key-h), 38px);
    }
  }
}

/* Header */
.header {
  height: var(--header-h);
  min-height: 40px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: black;
  padding: 0 8px;
  width: 100%;
  max-width: var(--max-game-w);
  margin: 0 auto;
  border-bottom: 1px solid #222;
  box-sizing: border-box;
}

.header h1 {
  font-size: clamp(15px, 3.8vw, 22px);
  margin: 0;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0.5px;
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: auto;
  white-space: nowrap;
  transition: text-shadow 0.25s ease-out;
}

.header h1:hover, .sqordy-title:hover {
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.7), 0 0 2px #ffffff;
}

.tm-symbol {
  font-size: 0.4em;
  line-height: 1;
  vertical-align: top;
  margin-left: 2px;
  position: relative;
  top: -0.45em;
  font-weight: 600;
  color: #aaa;
}

.button-container {
  display: flex;
  gap: clamp(3px, 1vw, 6px);
  align-items: center;
  margin-left: auto;
  z-index: 2;
}

button.question-mark, button.info-icon, button.calendar-btn, .header-home-btn {
  width: clamp(28px, 3.8vh, 32px);
  height: clamp(28px, 3.8vh, 32px);
  min-width: 26px;
  min-height: 26px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgb(35, 35, 35);
  color: white;
  font-size: 14px;
  font-weight: bold;
  border-radius: 6px;
  border: 1px solid #444;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
  line-height: 1;
  box-shadow: none;
  text-decoration: none;
  box-sizing: border-box;
}

.header-home-btn {
  position: relative;
  z-index: 2;
}

button.question-mark:hover, button.info-icon:hover, button.calendar-btn:hover, .header-home-btn:hover {
  background-color: whitesmoke;
  color: black;
}

button.question-mark:hover, button.info-icon:hover, button.calendar-btn:hover {
  background-color: whitesmoke;
  color: black;
}

/* Game Main Layout */
.sqordy4-game {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 0;
  margin: 0 auto;
  width: 100%;
  max-width: var(--max-game-w);
  box-sizing: border-box;
  padding: clamp(4px, 1vh, 12px) clamp(8px, 2vw, 16px) clamp(4px, 1vh, 12px);
  overflow: hidden;
}

/* Grid & Cells */
.grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 auto;
}

.row {
  display: flex;
  flex-direction: row;
  justify-content: center;
  margin: 0;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--cell-size-safe);
  width: var(--cell-size-safe);
  aspect-ratio: 1/1;
  background-color: rgb(75, 75, 75);
  color: white;
  border-radius: 4px;
  margin: clamp(1.5px, calc(var(--cell-size-safe) * 0.04), 3px);
  font-size: calc(var(--cell-size-safe) * 0.70);
  text-align: center;
  line-height: 1;
  font-weight: 800;
  box-shadow: 1.5px 1.5px 0px rgba(255, 255, 255, 0.2);
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, background-color 0.15s ease, box-shadow 0.18s ease;
  cursor: pointer;
}

.cell.pop {
  animation: cellPop 0.15s ease-in-out;
}

@keyframes cellPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.cell.win {
  background-color: rgb(23, 141, 43);
  color: white;
  box-shadow: 1.5px 1.5px 0px rgba(255, 255, 255, 0.45) !important;
}

.cell.highlighted-horizontally {
  background-color: #EAAB3D;
  color: white;
}

.cell.highlighted-vertically {
  background-color: #449e99;
  color: white;
}

.cell.highlighted-both {
  background-image: linear-gradient(to bottom right, #449e99 0%, #449e99 50%, #EAAB3D 50%, #EAAB3D 100%);
  color: white;
}

.cell.highlighted {
  background-color: white !important;
  background-image: none !important;
  color: black !important;
}

/* Informative Retro Shadows on Plain Unsolved Cells (Thinner 1.5px 2D bottom-right offset) */
.cell.shadow-row-hint:not(.win):not(.highlighted-horizontally):not(.highlighted-vertically):not(.highlighted-both) {
  box-shadow: 1.5px 1.5px 0px #EAAB3D !important;
}

.cell.shadow-col-hint:not(.win):not(.highlighted-horizontally):not(.highlighted-vertically):not(.highlighted-both) {
  box-shadow: 1.5px 1.5px 0px #449e99 !important;
}

.cell.shadow-both-hint:not(.win):not(.highlighted-horizontally):not(.highlighted-vertically):not(.highlighted-both) {
  box-shadow: 1.5px 1.5px 0px #EAAB3D, 3px 3px 0px #449e99 !important;
}

/* Clue spaces and solved cells (orange, blue, split, green) have crisp white shadow */
.cell.win,
.cell.highlighted-horizontally,
.cell.highlighted-vertically,
.cell.highlighted-both {
  box-shadow: 1.5px 1.5px 0px rgba(255, 255, 255, 0.5) !important;
}

/* Retain hint color with prominent active border when selected */
.cell.highlighted.highlighted-horizontally {
  background-color: #EAAB3D !important;
  color: white !important;
  box-shadow: 0 0 0 3px #ffffff, 0 0 14px rgba(234, 171, 61, 0.9) !important;
}

.cell.highlighted.highlighted-vertically {
  background-color: #449e99 !important;
  color: white !important;
  box-shadow: 0 0 0 3px #ffffff, 0 0 14px rgba(68, 158, 153, 0.9) !important;
}

.cell.highlighted.highlighted-both {
  background-image: linear-gradient(to bottom right, #449e99 0%, #449e99 50%, #EAAB3D 50%, #EAAB3D 100%) !important;
  color: white !important;
  box-shadow: 0 0 0 3px #ffffff, 0 0 14px rgba(255, 255, 255, 0.95) !important;
}

/* Dynamic In-Game Row & Column Hint Highlighting */
.cell.row-hint-active {
  box-shadow: inset 0 0 0 3px #EAAB3D, 0 0 10px rgba(234, 171, 61, 0.7) !important;
  background-color: rgba(234, 171, 61, 0.35) !important;
}

.cell.col-hint-active {
  box-shadow: inset 0 0 0 3px #449e99, 0 0 10px rgba(68, 158, 153, 0.7) !important;
  background-color: rgba(68, 158, 153, 0.35) !important;
}

.cell.row-hint-active.col-hint-active {
  box-shadow: inset 0 0 0 3px #ffffff, 0 0 12px rgba(255, 255, 255, 0.9) !important;
  background-image: linear-gradient(to bottom right, rgba(68, 158, 153, 0.45) 0%, rgba(68, 158, 153, 0.45) 50%, rgba(234, 171, 61, 0.45) 50%, rgba(234, 171, 61, 0.45) 100%) !important;
}

/* Protected Locked Green Cells - Must NEVER be overridden by clue highlights */
.cell.win,
.cell.win.row-hint-active,
.cell.win.col-hint-active,
.cell.win.shadow-row-hint,
.cell.win.shadow-col-hint,
.cell.win.shadow-both-hint {
  background-color: #2b7a3a !important;
  background-image: none !important;
  border-color: #4caf50 !important;
  color: #ffffff !important;
  box-shadow: none !important;
}

/* Flash Animations when a hint is triggered */
@keyframes rowHintFlash {
  0% {
    background-color: #EAAB3D;
    color: #ffffff;
    transform: scale(1.12);
    box-shadow: 0 0 18px rgba(234, 171, 61, 1), inset 0 0 0 2px #ffffff;
    z-index: 10;
  }
  45% {
    background-color: #f3be65;
    color: #ffffff;
    transform: scale(1.06);
    box-shadow: 0 0 12px rgba(234, 171, 61, 0.85);
    z-index: 10;
  }
  100% {
    transform: scale(1);
  }
}

@keyframes colHintFlash {
  0% {
    background-color: #449e99;
    color: #ffffff;
    transform: scale(1.12);
    box-shadow: 0 0 18px rgba(68, 158, 153, 1), inset 0 0 0 2px #ffffff;
    z-index: 10;
  }
  45% {
    background-color: #61b8b3;
    color: #ffffff;
    transform: scale(1.06);
    box-shadow: 0 0 12px rgba(68, 158, 153, 0.85);
    z-index: 10;
  }
  100% {
    transform: scale(1);
  }
}

@keyframes bothHintFlash {
  0% {
    background-image: linear-gradient(to bottom right, #449e99 0%, #449e99 50%, #EAAB3D 50%, #EAAB3D 100%);
    color: #ffffff;
    transform: scale(1.14);
    box-shadow: 0 0 20px rgba(255, 255, 255, 1), inset 0 0 0 3px #ffffff;
    z-index: 10;
  }
  45% {
    background-image: linear-gradient(to bottom right, #61b8b3 0%, #61b8b3 50%, #f3be65 50%, #f3be65 100%);
    color: #ffffff;
    transform: scale(1.07);
    box-shadow: 0 0 14px rgba(255, 255, 255, 0.9);
    z-index: 10;
  }
  100% {
    transform: scale(1);
  }
}

.cell.flash-row-hint {
  animation: rowHintFlash 0.5s ease-out !important;
  z-index: 5;
}

.cell.flash-col-hint {
  animation: colHintFlash 0.5s ease-out !important;
  z-index: 5;
}

.cell.flash-both-hint {
  animation: bothHintFlash 0.5s ease-out !important;
  z-index: 5;
}

/* Fast Sequential White-to-Green Flash Animation for Solved Order */
@keyframes winFlash {
  0% {
    background-color: #ffffff;
    color: #000000;
    transform: scale(1.16);
    box-shadow: 0 0 16px rgba(255, 255, 255, 0.95);
  }
  60% {
    background-color: #ffffff;
    color: #000000;
    transform: scale(1.08);
  }
  100% {
    background-color: rgb(23, 141, 43);
    color: #ffffff;
    transform: scale(1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  }
}

.cell.win-flash {
  animation: winFlash 0.35s ease-out forwards;
}

/* Counter */
.counter {
  font-size: calc(var(--cell-size-safe) * 0.44);
  text-align: center;
  height: calc(var(--cell-size-safe) * 0.82);
  width: calc(var(--cell-size-safe) * 0.82);
  aspect-ratio: 1/1;
  font-family: Arial, sans-serif;
  line-height: calc(var(--cell-size-safe) * 0.82);
  margin: clamp(4px, 1.2vh, 14px) auto;
  background-image: linear-gradient(to top, rgb(23, 141, 43) 0%, rgb(23, 141, 43) 100%, black 100%, black 100%);
  border: 2px solid white;
  color: white;
  border-radius: clamp(4px, calc(var(--cell-size-safe) * 0.12), 8px);
  display: block;
}

/* Keyboard */
.keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 auto;
  width: 100%;
  max-width: var(--max-game-w);
  padding: 0 4px;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

.keyboard .row {
  display: flex;
  justify-content: center;
  width: 100%;
  margin: 1.5px 0;
}

.key {
  flex: 1;
  max-width: clamp(34px, calc(var(--max-game-w) / 10), 46px);
  height: var(--key-h-safe);
  background-color: rgb(110, 110, 110);
  color: #111;
  border-radius: 4px;
  margin: clamp(1px, 0.2vw, 2px);
  font-weight: 700;
  font-size: calc(var(--key-h-safe) * 0.46);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 1.5px 1.5px 0px rgba(255, 255, 255, 0.16);
  transition: transform 0.08s ease, background-color 0.15s ease, box-shadow 0.08s ease;
  box-sizing: border-box;
}

.key:active {
  transform: translate(1px, 1px);
  box-shadow: none;
}

.key.backspace {
  flex: 1.5;
  max-width: clamp(54px, calc(var(--max-game-w) / 6.5), 72px);
  font-size: calc(var(--key-h-safe) * 0.48);
  padding: 0 2px;
}

.key.incorrect {
  background-color: black;
  color: black;
  box-shadow: inset 0 0 0 2px rgb(100, 100, 100); 
}

.key.highlighted-vertically {
  background-color: #449e99 !important;
  color: white !important;
}

.key.highlighted-horizontally {
  background-color: #EAAB3D !important;
  color: white !important;
}

.key.highlighted-both {
  background-image: linear-gradient(to bottom right, #449e99 0%, #449e99 50%, #EAAB3D 50%, #EAAB3D 100%) !important;
  color: white !important;
}

/* Footer */
.footer {
  background-color: transparent;
  padding: 2px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 auto;
  font-size: 11px;
  width: 100%;
  max-width: var(--max-game-w);
  box-sizing: border-box;
  color: #888;
  height: 20px;
  min-height: 20px;
}

.left-section {
  flex: 1;
  text-align: left;
}

.left-section p {
  text-decoration: none;
  color: rgb(120, 120, 120);
  margin: 0;
  font-size: 11px;
}

.right-section {
  flex: 1;
  text-align: right;
}

.right-section a {
  text-decoration: none;
  color: rgb(120, 120, 120);
  font-size: 11px;
}

.right-section a:hover {
  text-decoration: underline;
}

/* Modal Windows */
#popup-win, #popup-lose, #popup-help, #popup-window, #popup-info {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 9999 !important;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  padding: 12px;
}

#popup-calendar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10001 !important;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  padding: 12px;
}

.popup-container {
  background-color: #1a1a1a;
  border: 1px solid #383838;
  padding: clamp(24px, 3.5vh, 36px) clamp(22px, 3.5vw, 36px);
  border-radius: 16px;
  max-width: clamp(520px, 65vw, 650px);
  width: 100%;
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  overflow-x: hidden;
  text-align: center;
  position: relative;
  box-shadow: 0 18px 50px rgba(0,0,0,0.95);
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
}

.popup-title {
  margin-top: 0;
  margin-bottom: 14px;
  font-size: clamp(24px, 3.6vh, 30px);
  font-weight: 800;
  color: #fff;
  line-height: 1.2;
}

.popup-container p {
  font-size: clamp(14px, 2vh, 16px);
  line-height: 1.6;
  margin: 10px 0;
  font-weight: normal;
  color: #e0e0e0;
  text-align: left;
}

.popup-container h2 {
  font-size: clamp(16px, 2.2vh, 20px);
  line-height: 1.4;
  margin: 18px 0 8px 0;
  color: #fff;
  font-weight: 700;
  text-align: left;
}

.popup-subtitle {
  font-size: clamp(16px, 2.2vh, 18px);
  color: #eee;
  margin: 8px 0;
  font-weight: 600;
}

.icon-container {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 6px 0;
  padding: 10px 0;
  border-bottom: 1px solid #2e2e2e;
}

.icon-container:first-of-type {
  border-top: 1px solid #2e2e2e;
  margin-top: 12px;
}

.icon {
  width: clamp(34px, 4.5vh, 42px);
  height: clamp(34px, 4.5vh, 42px);
  min-width: clamp(34px, 4.5vh, 42px);
  min-height: clamp(34px, 4.5vh, 42px);
  flex-shrink: 0;
  border-radius: 8px;
  margin: 0;
}

.explanation {
  font-size: clamp(14px, 2vh, 16px) !important;
  line-height: 1.5 !important;
  text-align: left !important;
  flex: 1;
  margin: 0 !important;
  color: #e0e0e0 !important;
  font-weight: 500 !important;
}

.exit-help, .exit-info, .exit-win, .exit-lose, .exit-calendar {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  background-color: #2c2c2c;
  color: #eee;
  border: 1px solid #555;
  border-radius: 50%;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  transition: all 0.15s ease;
  box-shadow: none;
  z-index: 100;
}

.exit-help:hover, .exit-info:hover, .exit-win:hover, .exit-lose:hover, .exit-calendar:hover {
  background-color: #444;
  color: #fff;
}

button svg {
  pointer-events: none;
}

#shareBtn {
  position: absolute;
  top: 12px;
  right: 48px;
  width: 28px;
  height: 28px;
  background-color: #2c2c2c;
  color: white;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  z-index: 10;
}

#shareBtn:hover {
  background-color: #444;
}

.calendar-btn-modal {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 28px;
  height: 28px;
  background-color: #2c2c2c;
  color: white;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  z-index: 10;
  transition: all 0.15s ease;
}

.calendar-btn-modal:hover {
  background-color: #444;
}

#win-leaderboard-btn {
  left: 46px;
}

/* Challenge Banner */
.challenge-banner {
  background-color: #1a2233;
  border-bottom: 1px solid #2563eb;
  color: #93c5fd;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: var(--max-game-w);
  margin: 0 auto;
  box-sizing: border-box;
}

.close-challenge-btn {
  background: none;
  border: none;
  color: #93c5fd;
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.close-challenge-btn:hover {
  color: #fff;
}

/* Head-to-Head Comparison Card */
.h2h-result-box {
  background-color: #141414;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 8px 12px;
  margin: 8px auto;
  width: 90%;
  max-width: 300px;
  box-sizing: border-box;
}

.h2h-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #888;
  font-weight: 700;
  margin-bottom: 6px;
}

.h2h-comparison {
  display: flex;
  align-items: center;
  justify-content: space-around;
  margin-bottom: 6px;
}

.h2h-side {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.h2h-label {
  font-size: 11px;
  color: #aaa;
  margin-bottom: 2px;
}

.h2h-score {
  font-size: 15px;
  font-weight: 800;
  color: #fff;
}

.h2h-time {
  font-size: 11px;
  color: #777;
}

.h2h-vs {
  font-size: 11px;
  font-weight: 800;
  color: #555;
}

.h2h-verdict {
  font-size: 12px;
  font-weight: 800;
  color: #4ade80;
  letter-spacing: 0.5px;
  padding-top: 5px;
  border-top: 1px solid #222;
}

.h2h-verdict.lose {
  color: #f87171;
}

.h2h-verdict.tie {
  color: #fbbf24;
}

/* Order / Letters Toggle in Win Modal */
.toggle-container {
  margin: 8px auto;
  display: flex;
  justify-content: center;
}

.toggle-btn {
  background-color: #2a2a2a;
  color: white;
  border: 1px solid #555;
  border-radius: 6px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toggle-btn:hover {
  background-color: #444;
}

.toggle-btn.toggle-btn-active {
  background-color: #1b9e3e;
  border-color: #1b9e3e;
  color: white;
}

/* Grid in Win / Reveal / Lose Popups */
.grid-answer, .grid-win, .grid-lose {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 6px auto;
}

.grid-answer .cell {
  height: clamp(28px, 3.8vh, 36px);
  width: clamp(28px, 3.8vh, 36px);
  line-height: clamp(28px, 3.8vh, 36px);
  font-size: clamp(14px, 2.0vh, 18px);
  margin: 1.5px;
  background-color: rgb(65, 65, 65);
  color: white;
  border-radius: 5px;
  cursor: default;
  box-shadow: none;
}

.grid-win .cell {
  height: clamp(28px, 3.8vh, 36px);
  width: clamp(28px, 3.8vh, 36px);
  line-height: clamp(28px, 3.8vh, 36px);
  font-size: clamp(15px, 2.2vh, 19px);
  margin: 1.5px;
  background-color: rgb(23, 141, 43);
  color: white;
  border-radius: 5px;
  cursor: default;
  box-shadow: none;
}

.grid-lose .cell {
  height: clamp(28px, 3.8vh, 36px);
  width: clamp(28px, 3.8vh, 36px);
  line-height: clamp(28px, 3.8vh, 36px);
  font-size: clamp(15px, 2.2vh, 19px);
  margin: 1.5px;
  background-color: rgb(180, 40, 40);
  color: white;
  border-radius: 5px;
  cursor: default;
  box-shadow: none;
}

/* Archive Calendar Modal Styles */
.calendar-popup-container {
  max-width: 380px;
  width: 95vw;
  padding: 18px 16px;
  border-radius: 14px;
  background-color: #1a1a1a;
  border: 1px solid #333;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.9);
}

.cal-stats-strip {
  display: flex;
  justify-content: space-around;
  background-color: #242424;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 8px 6px;
  margin: 8px 0 12px 0;
}

.cal-stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cal-stat-value {
  font-size: 16px;
  font-weight: 800;
  color: #fff;
}

.cal-stat-label {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.cal-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 4px;
}

.cal-month-title {
  font-size: 15px;
  font-weight: 700;
  color: #eee;
}

.cal-nav-btn {
  background-color: #282828;
  border: 1px solid #444;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cal-nav-btn:hover:not(:disabled) {
  background-color: #444;
}

.cal-nav-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: #777;
  margin-bottom: 6px;
}

.cal-days-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 12px;
}

.cal-day {
  aspect-ratio: 1/1;
  min-height: 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
  padding: 0;
  position: relative;
  background-color: transparent;
  color: #fff;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.cal-day small {
  font-size: 8px;
  line-height: 1;
  position: static;
  transform: none;
  margin-top: 1px;
}

.cal-day:hover:not(.cal-disabled) {
  transform: scale(1.08);
  filter: brightness(1.15);
}

.cal-day.cal-avail {
  background-color: #2b2b2b;
  border-color: #3d3d3d;
  color: #eee;
}

.cal-day.cal-avail:hover {
  border-color: #449e99;
  background-color: #333;
}

.cal-day.cal-won {
  background-color: #1b9e3e;
  border-color: #23b749;
  color: #ffffff;
  box-shadow: 0 1px 4px rgba(27, 158, 62, 0.4);
}

.cal-day.cal-lost {
  background-color: #c9302c;
  border-color: #d9534f;
  color: #ffffff;
  box-shadow: 0 1px 4px rgba(201, 48, 44, 0.4);
}

.cal-day.cal-in-progress {
  background-color: #2b2b2b;
  border-color: #EAAB3D;
  color: #EAAB3D;
}

.cal-day.today {
  outline: 2px solid #EAAB3D;
  outline-offset: -1px;
}

.cal-day.cal-disabled {
  color: #444;
  background-color: transparent;
  cursor: default;
}

.cal-legend {
  display: flex;
  justify-content: center;
  gap: 12px;
  font-size: 11px;
  color: #888;
  padding-top: 8px;
  border-top: 1px solid #292929;
}

.cal-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.cal-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.cal-dot-won { background-color: #1b9e3e; }
.cal-dot-lost { background-color: #c9302c; }
.cal-dot-avail { background-color: #3d3d3d; border: 1px solid #666; }
.cal-dot-today { background-color: #EAAB3D; }

/* Data Management in Info Modal */
.data-management-box {
  margin-top: 15px;
  padding: 12px;
  background-color: #222;
  border-radius: 8px;
  border: 1px solid #333;
  text-align: left;
}

.data-management-box h2 {
  margin-top: 0;
  margin-bottom: 6px;
  font-size: 14px;
}

.data-btn-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.btn-data-action {
  background-color: #449e99;
  color: white;
  border: none;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.2s ease;
  width: 100%;
  text-align: center;
}

.btn-data-action:hover {
  opacity: 0.9;
}

.btn-data-danger {
  background-color: #c9302c;
  color: white;
  border: none;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.2s ease;
  width: 100%;
  text-align: center;
}

.btn-data-danger:hover {
  opacity: 0.9;
}

/* Toast Notification */
#toast-notification {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background-color: rgba(25, 25, 25, 0.96);
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.7);
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#toast-notification.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==========================================================================
   Global Leaderboard Modal & Components
   ========================================================================== */

#popup-leaderboard {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10001 !important;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  padding: 12px;
}

.leaderboard-popup-container {
  max-width: 480px;
  padding: 24px 20px;
}

.exit-leaderboard {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: #888;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 4px;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.exit-leaderboard:hover {
  color: #fff;
  background-color: #333;
}

.leaderboard-date-sub {
  font-size: 13px;
  color: #EAAB3D;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-top: -8px;
  margin-bottom: 16px;
  text-transform: uppercase;
}

/* Loading State */
.leaderboard-loading {
  padding: 36px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: #aaa;
  font-size: 14px;
}

.leaderboard-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #333;
  border-top-color: #EAAB3D;
  border-radius: 50%;
  animation: lb-spin 0.8s linear infinite;
}

@keyframes lb-spin {
  to { transform: rotate(360deg); }
}

/* Threshold State (< 10 entries) */
.leaderboard-threshold-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 12px 6px;
}

.threshold-icon-wrap {
  width: 64px;
  height: 64px;
  background: radial-gradient(circle, rgba(234, 171, 61, 0.2) 0%, rgba(0, 0, 0, 0) 70%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.threshold-title {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  margin: 0 0 8px 0;
}

.threshold-desc {
  font-size: 13px !important;
  color: #aaa !important;
  text-align: center !important;
  line-height: 1.5 !important;
  max-width: 340px;
  margin: 0 auto 16px auto !important;
}

.threshold-progress-bar {
  width: 100%;
  max-width: 300px;
  height: 8px;
  background-color: #2a2a2a;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.threshold-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #EAAB3D, #f39c12);
  border-radius: 4px;
  transition: width 0.4s ease;
}

.threshold-count-badge {
  font-size: 12px;
  font-weight: 700;
  color: #EAAB3D;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

.btn-demo-toggle {
  background: #252525;
  color: #888;
  border: 1px solid #3a3a3a;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-top: 10px;
}

.btn-demo-toggle:hover {
  background: #333;
  color: #fff;
  border-color: #555;
}

/* Active Leaderboard Table */
.leaderboard-active-view {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.user-standings-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, rgba(68, 158, 153, 0.25) 0%, rgba(26, 26, 26, 0.9) 100%);
  border: 1px solid #449e99;
  border-radius: 10px;
  padding: 10px 14px;
}

.user-card-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-card-rank {
  font-size: 16px;
  font-weight: 800;
  color: #449e99;
  background: rgba(68, 158, 153, 0.2);
  padding: 2px 8px;
  border-radius: 6px;
}

.user-card-name {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}

.user-card-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  font-weight: 700;
}

.user-card-score {
  color: #EAAB3D;
}

.user-card-time {
  color: #bbb;
}

.lb-table-wrapper {
  max-height: 48vh;
  max-height: 48dvh;
  overflow-y: auto;
  border-radius: 8px;
  border: 1px solid #2e2e2e;
  background-color: #151515;
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.lb-table thead {
  position: sticky;
  top: 0;
  background-color: #202020;
  z-index: 1;
  border-bottom: 1px solid #333;
}

.lb-table th {
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.lb-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #222;
  color: #ddd;
}

.lb-row:hover {
  background-color: #222;
}

.lb-row-you {
  background-color: rgba(68, 158, 153, 0.15);
  font-weight: 700;
}

.lb-row-you td {
  color: #fff;
}

.lb-col-rank {
  width: 40px;
  text-align: center;
}

.lb-col-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-col-score {
  text-align: right;
  color: #EAAB3D;
  font-weight: 700;
  width: 65px;
}

.lb-col-time {
  text-align: right;
  color: #aaa;
  width: 55px;
}

.rank-badge {
  display: inline-block;
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
  background-color: #2a2a2a;
  color: #aaa;
}

.rank-gold {
  background: linear-gradient(135deg, #f39c12, #d68910);
  color: #000;
  box-shadow: 0 0 8px rgba(243, 156, 18, 0.5);
}

.rank-silver {
  background: linear-gradient(135deg, #d5d8dc, #aeb6bf);
  color: #000;
}

.rank-bronze {
  background: linear-gradient(135deg, #e59866, #ba4a00);
  color: #fff;
}

.you-tag {
  font-size: 9px;
  font-weight: 800;
  background-color: #449e99;
  color: #000;
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 4px;
  vertical-align: middle;
}

.lb-footer-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  color: #888;
  padding-top: 4px;
}

/* Player Name Editor */
.player-name-editor {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  color: #aaa;
}

.player-name-input-group {
  display: flex;
  gap: 4px;
}

.player-name-input-group input {
  background-color: #222;
  border: 1px solid #444;
  border-radius: 5px;
  color: #fff;
  padding: 4px 8px;
  font-size: 12px;
  width: 110px;
  outline: none;
}

.player-name-input-group input:focus {
  border-color: #EAAB3D;
}

.btn-save-name {
  background-color: #383838;
  border: 1px solid #555;
  color: #fff;
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.btn-save-name:hover {
  background-color: #449e99;
  border-color: #449e99;
}

