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

:root {
  --bg: #0d0d0f;
  --surface: rgba(18, 18, 19, 0.95);
  --surface-solid: #121213;
  --border: rgba(58, 58, 60, 0.7);
  --text: #ffffff;
  --text-dim: #818384;
  --green: #538d4e;
  --green-bright: #6aaa64;
  --yellow: #b59f3b;
  --gray-tile: #3a3a3c;
  --purple: #7b68ee;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 500px;
  margin: 0 auto;
  padding: 0 12px;
  position: relative;
  overflow: hidden;
}

/* ===== Header ===== */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 4px 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.title {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--text);
}

/* ===== Guess Counter ===== */
.guess-counter {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-dim);
  background: rgba(58, 58, 60, 0.5);
  padding: 2px 10px;
  border-radius: 10px;
  letter-spacing: 0.05em;
  min-width: 28px;
  text-align: center;
}

/* ===== Word Size Toggle ===== */
.word-size-toggle {
  display: flex;
  gap: 4px;
  align-items: center;
}

.ws-btn {
  width: 30px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-dim);
  background: rgba(58, 58, 60, 0.5);
  border: 1.5px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s ease;
  font-family: inherit;
  padding: 0;
}

.ws-btn:active {
  transform: scale(0.93);
}

.ws-btn.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  box-shadow: 0 0 8px rgba(106, 170, 100, 0.4);
}

/* ===== Game Area ===== */
#game-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 10px 0 10px 0;
  justify-content: center;
  align-items: center;
}

/* On narrow portrait screens, reserve right space for player pfps (MP only) */
@media (max-width: 500px) {
  body[data-mode="mp"] #game-area {
    padding-right: 30px;
  }
}

/* ===== Wordle Grid ===== */
.wordle-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
  max-width: calc(var(--cols, 5) * 69px + (var(--cols, 5) - 1) * 5px);
  margin: 0 auto;
}

.wordle-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  position: relative;
}

/* ===== Tiles ===== */
.wordle-tile {
  width: clamp(46px, calc(100% / var(--cols, 5) - 5px), 64px);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  font-weight: 800;
  letter-spacing: 0.05em;
  border-radius: 4px;
  text-transform: uppercase;
  transition: all 0.15s ease;
}

.wordle-tile.empty {
  background: rgba(42, 42, 43, 0.3);
  border: 2px solid rgba(58, 58, 60, 0.5);
  color: transparent;
}

.wordle-tile.typing {
  background: rgba(42, 42, 43, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.4);
  color: var(--text);
  animation: tilePop 0.1s ease;
}

.wordle-tile.typed {
  background: rgba(42, 42, 43, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.4);
  color: var(--text);
}

@keyframes tilePop {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.wordle-tile.filled {
  border: 2px solid transparent;
  color: #fff;
  animation: tileFlip 0.5s ease calc(var(--i, 0) * 0.15s) both;
}

/* Prevent animations from replaying on already-settled rows */
.wordle-row.settled .wordle-tile.filled,
.wordle-row.guessed .wordle-tile.filled {
  animation: none;
}

.wordle-tile.correct {
  background: var(--green);
  border-color: var(--green);
}

.wordle-tile.present {
  background: var(--yellow);
  border-color: var(--yellow);
}

.wordle-tile.absent {
  background: var(--gray-tile);
  border-color: var(--gray-tile);
}

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

/* ===== Player name on MP guesses ===== */
.guess-player {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translate(calc(100% + 6px), -50%);
  font-size: 0;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0;
  opacity: 0.8;
}

.guess-pfp {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid rgba(255,255,255,0.15);
}


/* ===== Input Preview ===== */
.input-preview {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 4px 0 2px;
  min-height: 38px;
  align-items: center;
}

.preview-tile {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-radius: 4px;
  background: rgba(42, 42, 43, 0.5);
  border: 2px solid rgba(58, 58, 60, 0.4);
  color: transparent;
  transition: border-color 0.1s, color 0.1s;
}

.preview-tile.has-letter {
  border-color: rgba(255, 255, 255, 0.35);
  color: var(--text-dim);
}

.preview-tile.cursor {
  border-color: rgba(255, 255, 255, 0.6);
  animation: previewBlink 1s ease infinite;
}

@keyframes previewBlink {
  0%, 100% { border-color: rgba(255, 255, 255, 0.6); }
  50%       { border-color: rgba(58, 58, 60, 0.4); }
}

/* ===== QWERTY Keyboard ===== */
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 0 10px;
  flex-shrink: 0;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.kb-key {
  height: 48px;
  flex: 1;
  max-width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  background: rgba(58, 58, 60, 0.8);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, transform 0.1s;
  font-family: inherit;
  padding: 0;
  user-select: none;
}

.kb-key:active {
  background: rgba(90, 90, 92, 0.9);
  transform: scale(0.95);
}

.kb-key.wide {
  flex: 1.5;
  max-width: 62px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.kb-key.enter {
  background: var(--green);
  color: #fff;
}

.kb-key.enter:active {
  background: var(--green-bright);
}

.kb-key.backspace {
  font-size: 1.2rem;
}

/* Keyboard letter states */
.kb-key.correct {
  background: var(--green) !important;
  color: #fff;
}

.kb-key.present {
  background: var(--yellow) !important;
  color: #fff;
}

.kb-key.absent {
  background: rgba(58, 58, 60, 0.4) !important;
  color: rgba(255, 255, 255, 0.4);
}

/* ===== Error Toast ===== */
.error-toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: #dc2626;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 20px;
  border-radius: 8px;
  z-index: 50;
  animation: toastIn 0.3s ease-out;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.error-toast.hidden {
  display: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.error-toast.shake {
  animation: toastIn 0.3s ease-out, toastShake 0.4s ease 0.1s;
}

@keyframes toastShake {
  0%, 100% { transform: translate(-50%, 0); }
  25% { transform: translate(calc(-50% - 6px), 0); }
  75% { transform: translate(calc(-50% + 6px), 0); }
}

/* ===== Win Overlay ===== */
.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

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

.win-modal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  background: var(--surface-solid);
  padding: 24px 28px;
  border-radius: 20px;
  border: 2px solid var(--green-bright);
  box-shadow: 0 0 40px rgba(74, 222, 128, 0.3);
  animation: bounceIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 340px;
  width: 100%;
  position: relative;
  overflow: visible;
}

@keyframes bounceIn {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.win-pic {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 3px solid var(--green-bright);
  box-shadow: 0 0 24px rgba(74, 222, 128, 0.3);
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: visible;
}

.win-pic img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.win-pic .placeholder-letter {
  font-size: 48px;
  font-weight: 800;
  color: var(--green-bright);
}

.win-badge {
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  background: #39ff14;
  color: #1a1a2e;
  font-size: 13px;
  font-weight: 800;
  min-width: 24px;
  height: 24px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 7px;
  box-shadow: 0 0 8px rgba(57, 255, 20, 0.5);
  border: 2px solid var(--surface-solid);
  line-height: 1;
}

.win-name {
  font-size: 20px;
  font-weight: 800;
  color: var(--green-bright);
  text-shadow: 0 0 16px rgba(74, 222, 128, 0.4);
  letter-spacing: 1.5px;
}

.win-word {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 0.25em;
  color: var(--green-bright);
}

.win-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.win-countdown {
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}

/* ===== Daily / Frenzy Badges ===== */
.daily-badge {
  background: linear-gradient(135deg, #ffd700, #ff8c00);
  color: #1a1a2e;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 800;
  margin-left: 6px;
  letter-spacing: 1px;
  animation: daily-glow 2s ease-in-out infinite alternate;
  white-space: nowrap;
}
@keyframes daily-glow {
  from { box-shadow: 0 0 4px #ffd700; }
  to   { box-shadow: 0 0 12px #ff8c00, 0 0 20px rgba(255, 215, 0, 0.25); }
}

.frenzy-badge {
  background: linear-gradient(135deg, #ff4500, #ff6347);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 800;
  margin-left: 6px;
  letter-spacing: 0.5px;
  animation: frenzy-pulse 0.8s ease-in-out infinite alternate;
  white-space: nowrap;
}
.frenzy-label { margin-right: 3px; }
@keyframes frenzy-pulse {
  from { box-shadow: 0 0 4px #ff4500; transform: scale(1); }
  to   { box-shadow: 0 0 16px #ff6347, 0 0 24px rgba(255, 69, 0, 0.25); transform: scale(1.05); }
}

/* ===== Cosmetic Animations ===== */
.cosmetic-title { font-size: 9px; font-weight: 600; letter-spacing: 0.5px; margin-left: 3px; opacity: 0.9; }
@keyframes cosmetic-prismatic { 0% { filter: hue-rotate(0deg); } 100% { filter: hue-rotate(360deg); } }
@keyframes cosmetic-void-pulse { 0%, 100% { opacity: 0.9; } 50% { opacity: 1; } }

/* ===== Safe area padding for notched phones ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .keyboard {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
}
