:root {
  --banner-height: 50px;

  --game-width: 728px;

  --gap: 6px; /* KEEP px (board math depends on it) */

  --game-header-padding: 1.25rem;
  --game-status-padding: 1.5rem;

  --header-text-height: clamp(48px, 10vw, 72px);

  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 0.75rem;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;

  --stack-gap: 0.75rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  font-family: sans-serif;
  height: 100%;
  margin: 0;
  overflow: hidden; /* Prevent scrolling */
}

body.resizing .game-tile {
  transition: none !important;
}

/* Archive */
.archive {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.archive-header h2 {
  font-size: 1.5rem;
  margin: 0;
}

.archive-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;

  width: 100%;
  flex: 0 0 auto; /* IMPORTANT: prevents flex stretching weirdness */
}

.archive-row {
  align-items: center;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  padding: 1rem;
  text-align: left;
  transition:
    background 0.15s ease,
    transform 0.15s ease;
  width: 100%;
  min-width: 0;

  /* 🟢 FIX 1: Enforces a matching uniform height, but lets text expand if needed */
  min-height: 4.75rem;
  flex: 0 0 auto;
}

.archive-row:hover {
  background: #f9fafb;
}

.archive-row:active {
  transform: scale(0.98);
}

.archive-row-left {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.archive-row-title {
  font-size: 1rem;
  font-weight: 700;
}

.archive-row-date {
  color: #6b7280;
  font-size: 0.875rem;
}

.archive-row-right {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-end;

  gap: 0.25rem;
  height: 100%;
}

.archive-row-score {
  font-size: 1rem;
  font-weight: 800;
  line-height: 1; /* Stops extra font canvas padding from breaking alignment */
}

.archive-row-stars {
  display: flex;
  align-items: center;
}

.archive-row-stars,
.archive-row-status {
  color: #6b7280;
  font-size: 0.8125rem;
}

.archive-row-stats-row {
  display: flex;

  /* 🟢 FIX: Aligns text elements precisely along their natural text baselines */
  align-items: baseline;

  /* Creates clean horizontal whitespace separation between stars and score text */
  gap: 0.5rem;
  margin-bottom: 0.125rem;
}

.archive-scroll {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 0.75rem;
  min-height: 0;

  overflow-y: auto;
  padding: 1rem;

  width: 100%;
  max-width: var(--game-width);
  margin: 0 auto;
}

/* Banner */
.banner {
  align-items: center;
  background: #ffffff;
  display: flex;
  height: var(--banner-height);
  justify-content: center;
  left: 0;
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 3000;
}

/* Game Actions */
.game-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 0;
}

.game-action-button {
  align-items: center;
  border-radius: 999px;
  border: 1px solid #e5e7eb;
  background: white;
  cursor: pointer;
  display: flex;
  height: clamp(2rem, 8.2vw, 2.5rem);
  justify-content: center;
  transition:
    transform 0.15s ease,
    background 0.15s ease;
  width: clamp(2rem, 8.2vw, 2.5rem);
  -webkit-tap-highlight-color: transparent;
}

.game-action-button .game-icon {
  width: 80%;
  height: 80%;
}

.game-action-button:hover {
  background: #f3f4f6;
}

.game-action-button:active {
  transform: scale(0.92);
}

/* Game Area */
.game-area {
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  max-width: var(--game-width);
  /*overflow: visible;*/
  position: relative;
  width: 100%;

  height: 100%;

  overflow: hidden !important;
}

/* Game Container */
.game-container {
  display: flex;
  height: calc(100vh - var(--banner-height));
  margin-top: var(--banner-height);
  overflow: hidden;
  width: 100vw;
}

/* Game Board */
.game-board {
  aspect-ratio: 1 / 1;
  background-color: #ffffff;
  display: block;
  gap: 0;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  overflow: hidden;
  padding: 6px;
  pointer-events: auto;
  position: relative;
  user-select: none;
}

.game-board-block {
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
  display: inline-flex; /*flex;*/
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: 12px;

  min-height: 0;
  min-width: 0;
  max-height: 100%;
  max-width: 100%;

  flex-shrink: 0;
}

.game-board-container {
  align-items: flex-start; /* Position game-board-block at top */
  display: flex;
  flex-grow: 1; /* Fill the available height */
  justify-content: center;
  min-height: 0;
  /*padding-top: 0;*/
  padding: 0 16px;

  /*flex: 1 1 auto;*/
}

.game-board-background {
  aspect-ratio: 1 / 1;
  bottom: 6px;
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  inset: 0;
  left: 6px;
  pointer-events: none;
  position: absolute;
  right: 6px;
  top: 6px;
  z-index: 0;
}

.game-board-cell {
  align-items: center;
  background-color: #ffffff; /* clean white */
  border: 1px solid #d1d5db; /* subtle grid outline */
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: center;
}

.game-board-star {
  aspect-ratio: 1;
  background-color: #d1d5db;

  clip-path: polygon(
    50% 0%,
    61% 35%,
    98% 35%,
    68% 57%,
    79% 91%,
    50% 70%,
    21% 91%,
    32% 57%,
    2% 35%,
    39% 35%
  );

  opacity: 0.8;
  width: 52%;
}

.game-board-star-awarded {
  animation: starPop 500ms ease-out;
  background-color: #facc15;
}

@keyframes starPop {
  0% {
    transform: scale(1);
    opacity: 0.8;
  }

  30% {
    transform: scale(1.8);
    opacity: 1;
    filter: drop-shadow(0 0 12px #facc15);
  }

  100% {
    transform: scale(1);
    opacity: 1;
    filter: drop-shadow(0 0 0 transparent);
  }
}

.game-board-star-bonus {
  background-color: #facc15;
}

/* Game End */
.game-end-button.disabled {
  cursor: not-allowed;
  filter: grayscale(1);
  opacity: 0.5;
  pointer-events: none;
}

.game-end-dialog {
  background: white;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-align: center;
  width: clamp(18.75rem, 90vw, 25rem);
}

.game-end-dialog h3 {
  font-size: clamp(1.2rem, 4vw, 1.5rem);
  font-weight: 800;
}

.game-end-dialog-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 1rem;
  gap: 0.75rem;
}

.game-end-dialog-actions button {
  padding: clamp(0.75rem, 3vw, 1rem); /* Match Share button padding */
  border-radius: var(--radius-md);
  border: 1px solid #e5e7eb;
  background: white;
  cursor: pointer;
  flex: 1;
  font-weight: 600; /* Match Share button weight */
  font-family: inherit;
  transition: background 0.15s ease;
}

/* Make the 'End Game' (danger) button look like a primary action */
.game-end-dialog-actions .danger {
  background: #ef4444;
  color: white;
  border: none;
}

.game-end-dialog-actions button:not(.danger):hover {
  background: #f9fafb;
}

.game-end-overlay {
  align-items: center;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  inset: 0;
  justify-content: center;
  position: fixed;
  z-index: 2000;
}

/* Game Icon */
.game-icon {
  fill: none;
  height: 90%;
  width: 90%;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

/* Game Footer */
.game-footer {
  align-items: center;
  display: flex;
  height: 54px;
  justify-content: center;
}

/* Game Header */
.game-header {
  align-items: center;
  border-bottom: 1px solid #e5e7eb;
  display: grid;
  grid-template-columns: auto 1fr auto;
  margin-bottom: 1.25rem;
  margin-top: var(--space-2);
  max-width: var(--game-width);
  padding-bottom: 0.2rem;
  padding-left: var(--game-header-padding);
  padding-right: var(--game-header-padding);
  position: relative;
  width: 100%;

  top: 0;
  z-index: 10;
  background: white;
}

.game-header-button {
  align-items: center;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  height: clamp(2rem, 8.2vw, 2.5rem);
  justify-content: center;
  padding: 0;
  width: clamp(2rem, 8.2vw, 2.5rem);
  -webkit-tap-highlight-color: transparent;
}

.game-header-left {
  justify-content: flex-start;
}

.game-header-right {
  justify-content: flex-right;
  justify-content: flex-end;
}

.game-header-title {
  display: flex;
  flex-direction: column;
  /*height: var(--header-text-height);*/
  justify-content: center;
  justify-self: center;
  text-align: center;
}

.game-header-title h1 {
  font-size: clamp(1.3rem, 6vw, 1.625rem);
  font-weight: 900;
  line-height: 1;
  margin: 0;
  text-transform: uppercase;
}

.game-header-title h2 {
  color: #858688;
  font-size: clamp(0.7rem, 2.2vw, 0.875rem);
  font-weight: 700;
  letter-spacing: 1px;
  line-height: 1.1;
  opacity: 0.6;
  margin: 0;
  text-transform: uppercase;
}

/* Game Over */
body.game-over-active .game-board-container {
  flex-shrink: 0; /* Precents board collapse on height extension */
  flex-grow: 0;
}

body.game-over-active .game-footer {
  display: none;
}

/*
body.game-over-active .game-container {
  overflow-y: auto;
  scroll-behavior: auto;
}*/

body.game-over-active .game-scroll {
  overscroll-behavior: contain;
  overflow-y: auto;
}

body.game-over-active .game-over-section {
  opacity: 1;
  transform: translateY(0);
}

/* 3. The Game Over area itself */
.game-over {
  background: white;
  align-items: center;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 1rem 0 1rem 0;
  transition: opacity 0.8s ease-in-out;
  width: 100%;
}

.game-over-feedback {
  background-color: #edeff1;
  padding: 1rem clamp(1rem, 5vw, 2rem);
}

.game-over-feedback h2 {
  color: #111827;
  font-size: clamp(1.5rem, 8vw, 2.5rem);
  font-weight: 900;
  letter-spacing: 0.1em;
  line-height: 1.1;
  margin: 0 auto;
  padding: 0;
  text-transform: uppercase;
}

.game-over-feedback h3 {
  color: #6b7280; /* Subtle grey */
  font-size: clamp(0.9rem, 2.5vw, 1.2rem);
  font-weight: 500;
  line-height: 1.4;
  margin: 0 auto;
  padding: 0;
}

.game-over-section {
  text-align: center;
  border-bottom: 1px solid #e5e7eb;
  width: 100%;
}

.game-over-share {
  background: white;
  padding: 1rem 1.5rem;
}

.game-over-share .game-over-share-copy-btn {
  background: #111827; /* Dark Slate to match Tile Chi theme */
  border: none;
  border-radius: var(--radius-md);
  color: white;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 1rem 2rem;
  transition:
    transform 0.1s ease,
    background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.game-over-share-copy-btn:active {
  transform: scale(0.98);
  background: #374151;
}

.game-over-stars {
  padding: 1rem clamp(1rem, 5vw, 2rem);
}

.game-over-stars-number {
  font-size: clamp(1.5rem, 8vw, 2.5rem);
  font-weight: 900;
}

.game-over-stars-slash {
  font-size: clamp(1.5rem, 8vw, 2.5rem);
  font-weight: 700;
}

.game-over-stars-total {
  font-size: clamp(1.5rem, 8vw, 2.5rem);
  font-weight: 900;
}

.game-over-stars-icon {
  font-size: clamp(1.5rem, 8vw, 2.5rem);
  margin-bottom: 0.5rem;
}

.game-scroll {
  flex: 1;
  min-height: 0;
  overflow: hidden; /* default = no scroll */
  display: flex;
  flex-direction: column;
}

/* Views */
#archiveView,
#gameView {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.view-hidden {
  display: none !important;
}

/* Game Share */
.game-share-preview {
  background: #f9fafb;
  border-radius: var(--radius-md);
  font-family: monospace;
  font-size: clamp(0.75rem, 2.5vw, 0.85rem);
  padding: 1rem;
  white-space: pre;
}

.game-share-copy-btn {
  background: #111827;
  border: none;
  border-radius: var(--radius-md);
  color: white;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  padding: 1rem;
  transition:
    transform 0.1s ease,
    background 0.2s ease;
  width: 100%;
}

/* Game Status */
.game-current-word {
  align-items: center;
  color: #111827;
  display: flex;
  font-size: clamp(1.5rem, 5.5vw, 2.25rem);
  font-weight: 700;
  gap: 0.5rem;
  height: clamp(1.5rem, 5.5vw, 2.25rem);
  justify-content: center;
  letter-spacing: 2px;
  line-height: 1;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  overflow: hidden;
  position: relative;
  white-space: nowrap;
  will-change: contents;
}

.game-current-word.is-game-over {
  color: #111827; /* Deep Slate - Neutral & Professional */
  font-size: clamp(1.4rem, 5vw, 2.4rem);
  font-weight: 800;
  letter-spacing: clamp(0.15rem, 0.5vw, 0.4rem);
  overflow: visible;
  text-transform: uppercase;
}

.game-current-word-score-pop {
  color: #16a34a;
  font-size: clamp(1.2rem, 5vw, 2rem);
  font-weight: 900;
  left: 0;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  top: 0;
  transform: translate(-50%, -50%) scale(0.8);
  z-index: 9999;
}

.game-current-word-score-pop.show {
  animation: popScore 2000ms ease-out forwards;
}

@keyframes popScore {
  0% {
    transform: translate(-50%, -50%) scale(0.7);
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  60% {
    transform: translate(-50%, -50%) scale(1.4);
  }
  100% {
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 0;
  }
}

/*.game-found-words-overlay {
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  inset: 0;
  justify-content: center;
  position: fixed;
  z-index: 1000;
}

.game-found-words-overlay.hidden {
  display: none;
}*/

.game-found-words-panel {
  background: white;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  /*left: 50%;*/
  position: absolute;
  /*transform: translateX(-50%);*/
  width: min(360px, 90vw);
  max-height: 70vh;
  overflow: hidden;
}

.game-found-words-panel-header {
  align-items: center;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  font-weight: 700;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
}

.game-found-words-panel-header button {
  border: none;
  cursor: pointer;
  background: transparent;
  font-size: 18px;
}

.game-found-words-panel-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  max-height: 100%;
  overflow-y: auto;
  padding: var(--space-3);
}

.game-found-words-panel-list span {
  background: #f3f4f6;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.8125rem;
  padding: var(--space-1) var(--space-2);
  word-break: break-word;
}

.game-recent-words {
  display: flex;
  gap: var(--space-2);
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  white-space: nowrap;
}

.game-recent-words::-webkit-scrollbar {
  display: none; /* Chrome */
}

.game-recent-words span {
  animation: popIn 0.15s ease;
  background: #f3f4f6;
  border-radius: var(--radius-sm);
  font-size: clamp(0.8rem, 2.5vw, 1rem);
  font-weight: 600;
  padding: var(--space-1) var(--space-2);
}

@keyframes popIn {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.game-score {
  font-size: clamp(1.1rem, 3.5vw, 1.6rem);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.game-status {
  align-items: center;
  display: grid;
  grid-template-columns: auto 1fr auto;
  /*margin-bottom: var(--space-2);*/
  margin-bottom: 18px; /* same as game-board top padding */
  max-width: var(--game-width);
  width: 100%;
}

.game-status-left {
  justify-content: flex-start;
  padding-left: var(--game-status-padding);
}

.game-status-right {
  justify-self: end;
  padding-right: var(--game-status-padding);
}

/* Hidden */
.hidden {
  display: none;
}

/* Sidebar */
.game-sidebar {
  display: none;
}

/* Game Tile */
.game-tile {
  align-items: center;
  background-color: #edeff1;
  border: 2px solid #cbd5e1;
  border-radius: var(--radius-sm);
  display: flex;
  font-size: clamp(0.75rem, 5vw, 2.2rem);
  font-weight: 700;
  height: calc((100% - (4 * var(--gap))) / 5);
  justify-content: center;
  left: 0;
  position: absolute;
  text-transform: uppercase;
  top: 0;
  transition: transform 0.2s ease;
  width: calc((100% - (4 * var(--gap))) / 5);
  z-index: 1;
}

.game-tile * {
  pointer-events: none; /* Letters/content won't interfere with dragging */
}

.game-tile.active {
  background-color: #60a5fa;
  color: white;
  transform: scale(1.1);
  z-index: 2;
}

.game-tile.invalid {
  background: #fca5a5;
  border-color: #ef4444;
}

.game-tile.valid {
  background: #86efac;
  border-color: #22c55e;
}

.game-selection-letter {
  position: absolute;
  transform: translate(-50%, -50%);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.game-selection-letters-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

/* Menu */
.menu-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  padding: 1rem;
}

.menu-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 0.5rem 0;
}

.menu-footer {
  border-top: 1px solid #e5e7eb;
  margin-top: auto;
  padding: 1rem;
}

.menu-header {
  align-items: center;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  font-weight: 700;
  justify-content: space-between;
  padding: 1rem;
}

.menu-header button {
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
}

.menu-item {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  display: block;
  padding: 1rem 1.25rem;
  text-align: left;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s ease;
  width: 100%;
}

.menu-item:hover {
  background: #f3f4f6;
}

.menu-item:active {
  background: #e5e7eb;
}

.menu-list {
  display: flex;
  flex-direction: column;
}

.menu-overlay {
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  inset: 0;
  opacity: 1;
  pointer-events: none;
  position: absolute;
  transition: opacity 500ms ease;
  z-index: 2500;

  justify-content: flex-start;
}

.menu-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.menu-overlay.open .menu-panel {
  transform: translateX(0);
}

.menu-overlay.hidden {
  display: none;
}

.menu-panel {
  height: 100%;
  background: white;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 500ms ease;
  width: min(300px, 80%);
}

.menu-player-row {
  align-items: center;
  display: flex;
  font-size: clamp(0.75rem, 2vw, 1rem);
  gap: 0.6rem;
  padding: 0 0 0.5rem 0;
}

.menu-player-label,
.menu-player-id {
  line-height: 1;
}

.menu-player-id {
  background: #f3f4f6;
  border-radius: 4px;
  color: #4b5563;
  font-family: monospace;
  /* Keep the 1.1em multiplier so it optically matches the label height */
  font-size: 1.1em;
  font-weight: 700;
  flex-shrink: 1;
  overflow: hidden;
  padding: 0.2rem 0.5rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-player-label {
  color: #9ca3af;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
  letter-spacing: 0.05em;
}

.menu-user-email {
  font-weight: bold;
}

/* Overlay */
.overlay {
  align-items: center;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  inset: 0;
  justify-content: center;
  position: fixed;
  z-index: 2000;
}

.overlay.hidden {
  display: none;
}

.overlay-panel {
  background: white;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  max-height: 80vh;
  overflow: hidden;
  /*width: clamp(20rem, 90vw, 28rem);*/
  width: min(92vw, 360px);
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;

  padding: 1rem;
  border-bottom: 1px solid #e5e7eb;

  font-weight: 700;
}

.overlay-header button {
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
}

.overlay-content {
  padding: 1rem;
  overflow-x: hidden;
  overflow-y: auto;
}

.overlay--anchored {
  align-items: flex-start;
  justify-content: center;
}

/* Stats */
.stats-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stats-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
}

.stats-label {
  text-align: left;
  opacity: 0.6;
}

.stats-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

/* Desktop */
@media (min-width: 728px) {
  .game-footer {
    height: 90px;
  }
}

@media (min-width: 1050px) {
  .banner {
    display: none;
  }

  .game-area {
    flex-shrink: 0;
    width: var(--game-width); /* Game snaps to 728px */
  }

  .game-container {
    height: 100vh;
    margin-top: 0;
  }

  .game-sidebar {
    align-items: center;
    background-color: #edeff1;
    display: flex; /* Sidebars appear */
    flex: 1;
    justify-content: center;
    min-width: 160px;
  }
}
