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

:root {
  --bg-color: #121213;
  --surface-color: #1a1a1b;
  --modal-bg: #1f2023;
  --text-main: #ffffff;
  --text-muted: #8a8d91;
  --border-empty: #3a3a3c;
  --border-active: #66696d;
  
  /* Classic Wordle Palette */
  --tile-correct: #538d4e;
  --tile-present: #c9b458;
  --tile-absent: #3a3a3c;
  --tile-empty: transparent;

  /* High Contrast / Colorblind Mode */
  --tile-correct-hc: #f5793a;
  --tile-present-hc: #85c0f9;
  
  --key-bg: #818384;
  --key-text: #ffffff;
  --key-shadow: #525456;
  
  --brand-coral: #ff6b57;
  --brand-yellow: #ffc857;
  --brand-green: #58c46c;
  --brand-blue: #4d96ff;
  
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body.high-contrast {
  --tile-correct: var(--tile-correct-hc);
  --tile-present: var(--tile-present-hc);
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-family);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  perspective: 1000px;
}

/* Confetti Canvas */
.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 95;
}

.game-container {
  width: 100%;
  max-width: 500px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 8px 12px 14px;
  position: relative;
  z-index: 10;
}

/* Header */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-empty);
  padding: 6px 0 10px;
  height: 56px;
  gap: 10px;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.game-title {
  font-size: 1.7rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #fff;
  margin: 0;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Mode Segmented Switch */
.mode-segmented {
  display: inline-flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 2px;
  gap: 2px;
}

.mode-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 750;
  padding: 6px 11px;
  border-radius: 9px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  -webkit-tap-highlight-color: transparent;
}

.mode-tab:hover:not(.active) {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.mode-tab.active#tab-mode-daily {
  background: linear-gradient(135deg, var(--brand-coral), #ff8877);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(255, 107, 87, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.mode-tab.active#tab-mode-unlimited {
  background: linear-gradient(135deg, var(--brand-blue), #66a5ff);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(77, 150, 255, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* Action Icons */
.icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #f1f3f5;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background 0.16s, border-color 0.16s, transform 0.1s, box-shadow 0.16s;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.28);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.icon-btn:active {
  transform: translateY(1.5px);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
}

.icon-btn .header-svg {
  stroke-width: 2.2;
  transition: transform 0.15s ease;
}

.icon-btn:hover .header-svg {
  transform: scale(1.08);
}

.badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--brand-yellow);
  color: #121213;
  font-size: 0.68rem;
  font-weight: 850;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-color);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
}

/* Active Clue Banner */
.clue-banner {
  background: linear-gradient(135deg, rgba(88, 196, 108, 0.15), rgba(255, 200, 87, 0.15));
  border: 1px solid var(--brand-yellow);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 6px 0 2px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 4px 14px rgba(255, 200, 87, 0.15);
}

.clue-banner.hidden {
  display: none;
}

.clue-icon {
  font-size: 1.1rem;
}

.clue-label {
  font-weight: 800;
  color: var(--brand-yellow);
  text-transform: uppercase;
  font-size: 0.75rem;
}

.clue-text {
  color: #f1f3f5;
  flex: 1;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.pos-badge {
  background: rgba(255, 200, 87, 0.22);
  border: 1px solid rgba(255, 200, 87, 0.45);
  color: var(--brand-yellow);
  font-size: 0.72rem;
  font-weight: 850;
  padding: 1px 7px;
  border-radius: 5px;
  letter-spacing: 0.04em;
  font-style: normal;
  display: inline-block;
  line-height: 1.4;
}

.clue-body {
  font-style: italic;
  color: #f1f3f5;
}

/* Toasts */
.toast-container {
  position: absolute;
  top: 65px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  pointer-events: none;
}

.toast {
  background-color: #f8f9fa;
  color: #121213;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 800;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: popToast 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  text-align: center;
  letter-spacing: 0.02em;
}

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

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

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

/* Board Grid */
.board-container {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  padding: 8px 0;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  grid-gap: 6px;
  width: 330px;
  height: 395px;
  max-width: 100%;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-gap: 6px;
}

.tile {
  width: 100%;
  height: 100%;
  border: 2px solid var(--border-empty);
  display: inline-flex;
  justify-content: center;
  align-items: center;
  font-size: 2rem;
  font-weight: 800;
  text-transform: uppercase;
  user-select: none;
  background-color: var(--tile-empty);
  color: var(--text-main);
  border-radius: 5px;
  transition: border-color 0.12s;
  box-sizing: border-box;
}

.tile[data-state="active"] {
  border-color: var(--border-active);
  animation: elasticPop 0.14s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes elasticPop {
  0% { transform: scale(0.82); }
  60% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.row.shake {
  animation: shakeRow 0.45s ease-in-out;
}

@keyframes shakeRow {
  10%, 90% { transform: translateX(-4px); }
  20%, 80% { transform: translateX(6px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(4px); }
}

/* 3D Flip */
.tile.flip {
  animation: flipTile3D 0.52s ease-in-out forwards;
}

@keyframes flipTile3D {
  0% { transform: rotateX(0deg); }
  45% { transform: rotateX(90deg); }
  55% { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}

/* Winning Wave */
.tile.bounce {
  animation: winWave 0.65s cubic-bezier(0.28, 0.84, 0.42, 1) forwards;
}

@keyframes winWave {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(-24px) scale(1.06); }
  50% { transform: translateY(-6px); }
  75% { transform: translateY(-10px); }
}

/* Tile States with Top Specular Glow */
.tile[data-state="correct"] {
  background-color: var(--tile-correct) !important;
  border-color: var(--tile-correct) !important;
  color: #fff;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.28);
}

.tile[data-state="present"] {
  background-color: var(--tile-present) !important;
  border-color: var(--tile-present) !important;
  color: #fff;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.28);
}

.tile[data-state="absent"] {
  background-color: var(--tile-absent) !important;
  border-color: var(--tile-absent) !important;
  color: #f1f3f5;
}

/* Keyboard */
.keyboard-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 auto;
  width: 100%;
  max-width: 500px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  width: 100%;
}

.key {
  font-family: inherit;
  font-weight: 750;
  border: 0;
  padding: 0;
  height: 56px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  background-color: var(--key-bg);
  color: var(--key-text);
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  text-transform: uppercase;
  font-size: 1.1rem;
  box-shadow: 0 3px 0 var(--key-shadow), 0 4px 6px rgba(0, 0, 0, 0.25);
  transition: background-color 0.18s, transform 0.08s, box-shadow 0.08s;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

.key:hover {
  filter: brightness(1.1);
}

.key:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 var(--key-shadow);
}

.key.wide {
  flex: 1.5;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

.key[data-state="correct"] {
  background-color: var(--tile-correct);
  color: #ffffff;
  --key-shadow: rgba(0, 0, 0, 0.4);
}

.key[data-state="present"] {
  background-color: var(--tile-present);
  color: #ffffff;
  --key-shadow: rgba(0, 0, 0, 0.4);
}

.key[data-state="absent"] {
  background-color: var(--tile-absent);
  color: #72767a;
  --key-shadow: #28292b;
}

.key.purged {
  opacity: 0.18;
  text-decoration: line-through;
  pointer-events: none;
  background-color: #262729;
  box-shadow: none;
}

/* Modals & Overlays */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  animation: fadeIn 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

.overlay.hidden {
  display: none !important;
}

.modal-card {
  background: var(--modal-bg);
  border: 1px solid var(--border-empty);
  border-radius: 16px;
  padding: 26px 24px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
  position: relative;
}

.modal-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-muted);
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  transition: all 0.16s ease;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
}

.modal-close-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.35);
  color: #ffffff;
  transform: scale(1.08);
}

.modal-close-btn:active {
  transform: scale(0.92);
}

.modal-card h2 {
  font-size: 1.7rem;
  font-weight: 850;
  letter-spacing: -0.01em;
  color: #fff;
}

.modal-card .subtitle {
  font-size: 0.92rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.title-tiles {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: -4px;
}

.title-tiles .tile {
  width: 44px;
  height: 44px;
  font-size: 1.4rem;
}

.mode-select-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mode-card-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid var(--border-empty);
  border-radius: 12px;
  padding: 12px 16px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.mode-card-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--text-muted);
}

.mode-card-btn.active {
  border-color: var(--brand-coral);
  background: rgba(255, 107, 87, 0.1);
  box-shadow: 0 4px 16px rgba(255, 107, 87, 0.2);
}

.mode-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mode-name {
  font-size: 1.05rem;
  font-weight: 800;
  color: #fff;
}

.mode-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.options-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-empty);
  border-radius: 10px;
  padding: 10px 14px;
  text-align: left;
}

.toggle-option {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.toggle-option input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--brand-coral);
  cursor: pointer;
}

.toggle-text {
  display: flex;
  flex-direction: column;
}

.toggle-text strong {
  font-size: 0.9rem;
  color: #fff;
}

.toggle-text small {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--brand-coral);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(255, 107, 87, 0.35);
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-share {
  background: var(--brand-green);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(88, 196, 108, 0.35);
}

.btn-alt {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-main);
  border: 1px solid var(--border-empty);
}

.btn-alt:hover {
  background: rgba(255, 255, 255, 0.12);
}

.controls-hint {
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* Rank Badge */
.rank-badge {
  display: inline-block;
  align-self: center;
  padding: 4px 12px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--brand-yellow), var(--brand-coral));
  color: #121213;
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  box-shadow: 0 4px 14px rgba(255, 200, 87, 0.4);
}

.rank-badge.hidden {
  display: none;
}

/* Target Word Reveal in Game Over Modal */
.target-word-reveal {
  font-size: 1.2rem;
  color: #f1f3f5;
}

.target-word-reveal strong {
  color: var(--brand-yellow);
  letter-spacing: 0.1em;
}

.target-definition {
  font-size: 0.88rem;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.45;
  margin-top: -6px;
}

.near-miss {
  font-size: 0.88rem;
  font-weight: 750;
  color: var(--brand-coral);
  background: rgba(255, 107, 87, 0.12);
  border: 1px dashed var(--brand-coral);
  border-radius: 8px;
  padding: 8px 12px;
}

/* Stats Block */
.stats-block {
  border-top: 1px solid var(--border-empty);
  border-bottom: 1px solid var(--border-empty);
  padding: 14px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stats-block h3, .dist-chart h4 {
  font-size: 0.82rem;
  font-weight: 850;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.stats-row {
  display: flex;
  justify-content: space-around;
  gap: 8px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-val {
  font-size: 1.7rem;
  font-weight: 850;
  color: #ffffff;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.dist-chart {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.dist-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 750;
}

.dist-num {
  width: 14px;
  text-align: center;
  color: var(--text-muted);
}

.dist-bar-wrap {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  overflow: hidden;
  height: 22px;
}

.dist-bar {
  background: var(--tile-absent);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
  min-width: 22px;
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.dist-bar.highlight {
  background: var(--brand-green);
}

/* Countdown Row */
.countdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-empty);
  border-radius: 8px;
  padding: 8px 14px;
  margin-top: 4px;
}

.countdown-label {
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

.countdown-timer {
  font-size: 1.15rem;
  font-weight: 850;
  color: var(--brand-yellow);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
}

/* Modal Actions */
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Hint Options */
.hint-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.hint-option-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-empty);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  color: var(--text-main);
  transition: background 0.15s, border-color 0.15s;
}

.hint-option-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--brand-yellow);
}

.hint-option-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.hint-icon {
  font-size: 1.6rem;
}

.hint-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hint-details strong {
  font-size: 0.98rem;
  color: #fff;
}

.hint-details span {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
}

/* Mobile Media Queries */
@media (max-width: 480px) {
  .game-container {
    padding: 6px 8px 10px;
  }
  
  .game-header {
    height: 48px;
    gap: 4px;
    padding: 4px 0 8px;
  }
  
  .game-title {
    max-width: 5rem;
    font-size: 1rem;
    line-height: 1.05;
    letter-spacing: 0.05em;
  }

  .mode-tab {
    padding: 5px 8px;
    font-size: 0.72rem;
  }

  .icon-btn {
    width: 33px;
    height: 33px;
    border-radius: 8px;
  }

  .icon-btn .header-svg {
    width: 15px;
    height: 15px;
  }

  .badge {
    width: 16px;
    height: 16px;
    font-size: 0.62rem;
    top: -4px;
    right: -4px;
  }

  .board {
    width: 300px;
    height: 360px;
    grid-gap: 5px;
  }
  
  .row {
    grid-gap: 5px;
  }
  
  .tile {
    font-size: 1.7rem;
  }
  
  .key {
    height: 50px;
    font-size: 1rem;
  }
  
  .key.wide {
    font-size: 0.72rem;
  }

  .modal-card {
    padding: 20px 16px;
    gap: 13px;
  }
}

@media (max-height: 650px) {
  .board {
    height: 310px;
    width: 270px;
  }
  .key {
    height: 44px;
  }
  .tile {
    font-size: 1.5rem;
  }
}
