.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: var(--game-size);
  font-size: clamp(20px, calc(var(--game-size) * 0.08), 36px);
  margin-bottom: 20px;
  transition: opacity 0.2s ease-in-out;
}

.top-bar.tetris-mode {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 0;
}

#left-header {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
}

.top-bar.tetris-mode #left-header {
  display: contents;
}

.top-bar.tetris-mode #header-label {
  display: none;
}

.tetris-status-group {
  grid-column: 1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  justify-self: stretch;
  gap: 4px;
  min-width: 0;
  padding-left: 8px;
  padding-right: 20px;
  opacity: 0.78;
}

.top-bar.tetris-mode .score-stack {
  align-items: center;
  align-self: center;
  gap: 0;
}

/* Active tile for tetris mode */
.top-bar.tetris-mode #tetris-active-tile {
  --tetris-active-ring: rgba(62, 177, 92, 0.76);
  --tetris-active-glow-soft: rgba(62, 177, 92, 0.46);
  --tetris-active-ring-strong: rgba(62, 177, 92, 0.86);
  --tetris-active-glow-strong: rgba(62, 177, 92, 0.62);
  grid-column: 2;
  justify-self: center;
  margin: 0;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: clamp(50px, calc(var(--game-size) * 0.12), 64px);
  height: clamp(50px, calc(var(--game-size) * 0.12), 64px);
  font-family: Arial, sans-serif;
  font-weight: bold;
  font-size: clamp(30px, calc(var(--game-size) * 0.075), 42px);
  background-color: #16a34a;
  color: #ffffff;
  border-radius: 8px;
  box-shadow:
    inset 3px 3px 5px rgba(255, 255, 255, 1),
    inset -3px -3px 5px rgba(0, 0, 0, 0.15);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
  transition: box-shadow 0.2s ease-out, color 0.15s ease-out;
  flex-shrink: 0;
  align-self: center;
  animation: activeTileGlow 1.4s ease-in-out infinite alternate;
}

.top-bar.tetris-mode #tetris-active-tile.is-tone-green {
  --tetris-active-ring: rgba(62, 177, 92, 0.76);
  --tetris-active-glow-soft: rgba(62, 177, 92, 0.46);
  --tetris-active-ring-strong: rgba(62, 177, 92, 0.86);
  --tetris-active-glow-strong: rgba(62, 177, 92, 0.62);
  background-color: #16a34a;
  color: #ffffff;
}

.top-bar.tetris-mode #tetris-active-tile.is-tone-amber {
  --tetris-active-ring: rgba(225, 155, 28, 0.8);
  --tetris-active-glow-soft: rgba(225, 155, 28, 0.5);
  --tetris-active-ring-strong: rgba(237, 171, 43, 0.9);
  --tetris-active-glow-strong: rgba(237, 171, 43, 0.66);
  background-color: #d98b00;
  color: #ffffff;
}

.top-bar.tetris-mode #tetris-active-tile.is-tone-red {
  --tetris-active-ring: rgba(208, 48, 64, 0.84);
  --tetris-active-glow-soft: rgba(208, 48, 64, 0.56);
  --tetris-active-ring-strong: rgba(226, 66, 83, 0.94);
  --tetris-active-glow-strong: rgba(226, 66, 83, 0.74);
  background-color: #c41f2f;
  color: #ffffff;
  animation-duration: 0.72s;
}

@keyframes activeTileGlow {
  0% {
    box-shadow:
      inset 3px 3px 5px rgba(255, 255, 255, 1),
      inset -3px -3px 5px rgba(0, 0, 0, 0.15);
  }
  100% {
    box-shadow:
      inset 3px 3px 5px rgba(255, 255, 255, 1),
      inset -3px -3px 5px rgba(0, 0, 0, 0.15);
  }
}

#left-header .queue-container {
  align-self: flex-end;
}

.queue-container {
  display: none;
  align-items: center;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 4px;
  margin-left: 12px;
}

.top-bar.tetris-mode .queue-container {
  grid-column: 3;
  justify-self: start;
  display: flex;
  align-items: center;
  align-self: center;
  gap: 4px;
  margin-left: 10px;
  flex: none;
  min-width: 0;
  pointer-events: none;
}

.top-bar.tetris-mode #next-letter {
  width: clamp(46px, calc(var(--game-size) * 0.105), 58px);
  height: clamp(46px, calc(var(--game-size) * 0.105), 58px);
  font-size: clamp(27px, calc(var(--game-size) * 0.062), 35px);
  background-color: #dbe4ef;
  color: #24364d;
  opacity: 0.96;
  filter: none;
  cursor: default;
  box-shadow:
    inset 2px 2px 4px rgba(255, 255, 255, 0.72),
    inset -2px -2px 4px rgba(0, 0, 0, 0.14),
    1px 2px 3px rgba(0, 0, 0, 0.28);
}

.top-bar.tetris-mode #queue-1 {
  width: clamp(42px, calc(var(--game-size) * 0.095), 52px);
  height: clamp(42px, calc(var(--game-size) * 0.095), 52px);
  font-size: clamp(25px, calc(var(--game-size) * 0.056), 32px);
  background-color: #b8c7d9;
  color: #34475f;
  transform: none;
  opacity: 0.88;
  margin-left: 0;
}

.top-bar.tetris-mode #queue-2 {
  width: clamp(38px, calc(var(--game-size) * 0.085), 48px);
  height: clamp(38px, calc(var(--game-size) * 0.085), 48px);
  font-size: clamp(23px, calc(var(--game-size) * 0.05), 29px);
  background-color: #a7b7ca;
  color: #2d4057;
  transform: none;
  opacity: 0.8;
  margin-left: 0;
}

.top-bar.tetris-mode #score {
  min-width: clamp(39px, calc(var(--game-size) * 0.086), 46px);
  height: clamp(39px, calc(var(--game-size) * 0.086), 46px);
  padding: 0 7px;
  font-size: clamp(20px, calc(var(--game-size) * 0.051), 25px);
  box-shadow:
    inset 1px 1px 3px rgba(255, 255, 255, 0.2),
    inset -2px -2px 3px rgba(0, 0, 0, 0.24),
    1px 2px 3px rgba(0, 0, 0, 0.28);
}

.queue-container.is-active {
  display: flex;
}

/* Classic mode fallback */
#next-letter {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: clamp(30px, calc(var(--game-size) * 0.12), 60px);
  height: clamp(30px, calc(var(--game-size) * 0.12), 60px);
  font-family: Arial, sans-serif;
  font-weight: bold;
  font-size: clamp(20px, calc(var(--game-size) * 0.09), 46px);
  background-color: #fdf6e3;
  color: #1a1a1a;
  border-radius: 6px;
  box-shadow:
    inset 3px 3px 5px rgba(255, 255, 255, 1),
    inset -3px -3px 5px rgba(0, 0, 0, 0.15),
    2px 3px 5px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  user-select: none;
  transition: transform 0.1s;
  z-index: 3;
  flex-shrink: 0;
}

#next-letter:active {
  transform: scale(0.95);
}

.queued-letter {
  display: none;
  justify-content: center;
  align-items: center;
  width: clamp(30px, calc(var(--game-size) * 0.12), 60px);
  height: clamp(30px, calc(var(--game-size) * 0.12), 60px);
  font-family: Arial, sans-serif;
  font-weight: bold;
  font-size: clamp(20px, calc(var(--game-size) * 0.09), 46px);
  border-radius: 6px;
  user-select: none;
  flex-shrink: 0;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.queued-letter.is-active {
  display: inline-flex;
}

#queue-1 {
  background-color: #cbd5e1;
  color: #475569;
  transform: scale(0.9);
  opacity: 0.6;
  box-shadow:
    inset 2px 2px 4px rgba(255, 255, 255, 0.6),
    inset -2px -2px 4px rgba(0, 0, 0, 0.15),
    1px 2px 3px rgba(0, 0, 0, 0.3);
  z-index: 2;
  margin-left: -4px;
}

#queue-2 {
  background-color: #94a3b8;
  color: #334155;
  transform: scale(0.82);
  opacity: 0.45;
  box-shadow:
    inset 1px 1px 3px rgba(255, 255, 255, 0.4),
    inset -1px -1px 3px rgba(0, 0, 0, 0.2),
    1px 1px 2px rgba(0, 0, 0, 0.2);
  z-index: 1;
  margin-left: -12px;
}

#score {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-width: clamp(30px, calc(var(--game-size) * 0.12), 60px);
  height: clamp(30px, calc(var(--game-size) * 0.12), 60px);
  padding: 0 15px;
  font-family: Arial, sans-serif;
  font-weight: bold;
  font-size: clamp(20px, calc(var(--game-size) * 0.08), 36px);
  background-color: #2b4c7e;
  color: #ffffff;
  border-radius: 6px;
  box-shadow:
    inset 2px 2px 5px rgba(255, 255, 255, 0.3),
    inset -3px -3px 5px rgba(0, 0, 0, 0.3),
    2px 3px 5px rgba(0, 0, 0, 0.4);
  user-select: none;
}

.score-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  align-self: flex-end;
}

.score-meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tetris-clock {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: clamp(72px, calc(var(--game-size) * 0.16), 110px);
  padding: 8px 12px;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(255, 244, 216, 0.16), rgba(255, 255, 255, 0.06));
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    0 8px 18px rgba(0, 0, 0, 0.18);
  color: #f8fafc;
  text-align: center;
  user-select: none;
  align-self: flex-end;
}

.top-bar.tetris-mode .tetris-clock {
  display: flex;
  min-width: clamp(50px, calc(var(--game-size) * 0.105), 60px);
  height: clamp(34px, calc(var(--game-size) * 0.075), 40px);
  padding: 0 6px;
  border-radius: 6px;
  gap: 0;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    1px 2px 3px rgba(0, 0, 0, 0.24);
}

.top-bar.tetris-mode .tetris-clock-value {
  font-size: clamp(14px, calc(var(--game-size) * 0.035), 18px);
  font-variant-numeric: tabular-nums;
  color: #e8edf4;
  text-shadow: none;
}

.tetris-clock-label {
  font-family: Arial, sans-serif;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(226, 232, 240, 0.72);
}

.tetris-clock-value {
  font-family: Arial, sans-serif;
  font-size: clamp(18px, calc(var(--game-size) * 0.06), 28px);
  font-weight: 900;
  line-height: 1;
  color: #fff7d6;
  text-shadow: 0 0 12px rgba(255, 236, 160, 0.18);
}

.tetris-clock.is-urgent .tetris-clock-value {
  color: #fecaca;
  text-shadow: 0 0 12px rgba(248, 113, 113, 0.22);
}

.top-bar.tetris-mode .tetris-clock.is-urgent .tetris-clock-value {
  color: #e8edf4;
  text-shadow: none;
}

.mode-badge {
  font-family: Arial, sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 3px 8px;
  line-height: 1;
}

.top-help-btn {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  font-family: Arial, sans-serif;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.top-help-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

@media (max-width: 700px) {
  .top-bar.tetris-mode {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
  }

  .top-bar.tetris-mode #left-header {
    display: contents;
  }

  .top-bar.tetris-mode #tetris-active-tile {
    width: clamp(48px, calc(var(--game-size) * 0.13), 58px);
    height: clamp(48px, calc(var(--game-size) * 0.13), 58px);
    font-size: clamp(28px, calc(var(--game-size) * 0.08), 36px);
    margin: 0;
  }

  .top-bar.tetris-mode .queue-container {
    margin-left: 8px;
    gap: 3px;
  }

  .top-bar.tetris-mode #next-letter {
    width: clamp(43px, calc(var(--game-size) * 0.115), 52px);
    height: clamp(43px, calc(var(--game-size) * 0.115), 52px);
    font-size: clamp(25px, calc(var(--game-size) * 0.067), 31px);
  }

  .top-bar.tetris-mode #queue-1 {
    width: clamp(39px, calc(var(--game-size) * 0.105), 48px);
    height: clamp(39px, calc(var(--game-size) * 0.105), 48px);
    font-size: clamp(23px, calc(var(--game-size) * 0.06), 28px);
  }

  .top-bar.tetris-mode #queue-2 {
    width: clamp(36px, calc(var(--game-size) * 0.095), 44px);
    height: clamp(36px, calc(var(--game-size) * 0.095), 44px);
    font-size: clamp(22px, calc(var(--game-size) * 0.055), 26px);
  }

  .tetris-status-group {
    gap: 3px;
    padding-left: 5px;
    padding-right: 16px;
  }

  .top-bar.tetris-mode .score-stack {
    align-items: center;
    align-self: center;
  }

  .top-bar.tetris-mode .score-meta-row {
    display: none;
  }

  .top-bar.tetris-mode #score {
    min-width: clamp(37px, calc(var(--game-size) * 0.092), 41px);
    height: clamp(37px, calc(var(--game-size) * 0.092), 41px);
    padding: 0 6px;
    font-size: clamp(18px, calc(var(--game-size) * 0.05), 22px);
  }

  .top-bar.tetris-mode .tetris-clock {
    min-width: clamp(48px, calc(var(--game-size) * 0.12), 54px);
    height: clamp(32px, calc(var(--game-size) * 0.08), 36px);
    padding: 0 4px;
  }

  .top-bar.tetris-mode .tetris-clock-value {
    font-size: clamp(13px, calc(var(--game-size) * 0.034), 15px);
  }

  .score-stack {
    gap: 3px;
  }

  .score-meta-row {
    gap: 5px;
  }

  .mode-badge {
    font-size: 9px;
    padding: 2px 7px;
  }

  .top-help-btn {
    width: 20px;
    height: 20px;
    font-size: 12px;
  }

  .tetris-clock:not(.top-bar.tetris-mode .tetris-clock) {
    min-width: 64px;
    padding: 6px 10px;
  }

  .tetris-clock-value:not(.top-bar.tetris-mode .tetris-clock-value) {
    font-size: 16px;
  }
}

@media (max-width: 360px) {
  .top-bar.tetris-mode .queue-container {
    margin-left: 0;
    gap: 1px;
  }

  .tetris-status-group {
    gap: 2px;
    padding-left: 2px;
    padding-right: 8px;
  }
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 220px;
  margin: 15px auto 0;
  flex-shrink: 0;
}

#play-again-btn {
  animation: playAgainBling 2s infinite ease-in-out;
  border: 1px solid #a8c2ea;
}

#play-again-btn:active {
  animation: none;
}

.results-area {
  width: 100%;
  max-width: var(--game-size);
  margin-top: 40px;
  font-size: clamp(14px, calc(var(--game-size) * 0.04), 20px);
  line-height: 1.6;
}

.result-row {
  margin-bottom: 15px;
}

.result-label {
  margin-bottom: 8px;
}

.word-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.settings-area {
  width: 100%;
  max-width: var(--game-size);
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid rgba(255,255,255,0.2);
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  gap: 12px;
}

.version-tag {
  width: 100%;
  max-width: var(--game-size);
  text-align: right;
  margin-top: 20px;
  font-size: 11px;
  color: var(--highlight);
  opacity: 0.7;
}

@media (min-width: 701px) and (max-width: 1024px) {
  .top-bar.tetris-mode {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
  }

  .top-bar.tetris-mode #left-header {
    display: contents;
  }
}