/* ─── Date navigation bar ────────────────────────────────────────────────── */
#date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 360px;
  padding: 4px 0 2px;
  gap: 8px;
}

#date-nav-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  gap: 1px;
}

#date-nav-puzzle {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: #818384;
  text-transform: uppercase;
}

#date-nav-date {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-tile-text);
}

#nav-prev, #nav-next {
  background: none;
  border: none;
  color: var(--color-tile-text);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 4px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

#nav-prev:hover, #nav-next:hover {
  background: rgba(255,255,255,0.1);
}

#nav-next:disabled {
  color: var(--color-border);
  cursor: default;
}
#nav-next:disabled:hover {
  background: none;
}

/* ─── Variables ─────────────────────────────────────────────────────────── */
:root {
  --color-bg:        #121213;
  --color-header:    #1a1a1b;
  --color-border:    #3a3a3c;
  --color-tile-text: #ffffff;
  --color-key-bg:    #818384;
  --color-key-text:  #ffffff;
  --color-correct:   #538d4e;
  --color-present:   #b59f3b;
  --color-absent:    #3a3a3c;
  --color-toast-bg:  #ffffff;
  --color-toast-text:#121213;
  --tile-size:       62px;
  --tile-gap:        5px;
  --header-height:   50px;
}

/* Light theme overrides */
body[data-theme="light"] {
  --color-bg:        #ffffff;
  --color-header:    #f6f6f6;
  --color-border:    #e5e5e5;
  --color-tile-text: #121213;
  --color-key-bg:    #e6e6e6;
  --color-key-text:  #121213;
  --color-correct:   #538d4e;
  --color-present:   #b59f3b;
  --color-absent:    #b0b3b8;
  --color-toast-bg:  #121213;
  --color-toast-text:#ffffff;
}

/* Header menu (collapsed mobile) */
#menu-btn { display: none; background: none; border: none; color: var(--color-tile-text); cursor: pointer; padding: 6px; border-radius: 4px; }
.header-menu {
  position: absolute;
  right: 12px;
  top: calc(var(--header-height) + 8px);
  background: var(--color-header);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 200;
  min-width: 160px;
}
.header-menu button { background: none; border: none; color: var(--color-tile-text); padding: 8px; text-align: left; border-radius: 6px; cursor: pointer; }
.header-menu button:hover { background: rgba(255,255,255,0.04); }

/* When header menu is open, hide other header controls to leave space */
body.header-menu-open .header-left,
body.header-menu-open .header-right { display: none !important; }

/* Visible backdrop for header menu to dim page when open */
#header-menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 140;
  transition: opacity 0.18s ease-in-out;
}

/* Improve contrast for excluded keys (absent) so they differ from unused keys */
.key[data-state="absent"] {
  background: var(--color-absent);
  color: var(--color-key-text);
  opacity: 0.92;
  border: 1px solid var(--color-border);
}

/* Responsive: collapse header controls into hamburger on small screens */
@media (max-width: 640px) {
  .header-left, .header-right { display: none; }
  #menu-btn { display: inline-flex; }
}

/* Strong overrides placed at end: ensure mobile hides CTAs immediately and keeps title centered */
@media (max-width: 640px) {
  header { position: relative; }
  header .header-left, header .header-right { display: none !important; }
  header #menu-btn { display: inline-flex !important; position: absolute !important; right: 12px; top: 8px; }
  header #title-home { flex: 1 1 auto !important; display: flex; align-items: center; justify-content: center; }
  header #title-home h1 { margin: 0; }
}

/* Ensure body background uses variable */
body { background: var(--color-bg); }

/* ─── Reset & Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--color-bg);
  color: var(--color-tile-text);
  font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

/* ─── Toast ──────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: var(--color-toast-bg);
  color: var(--color-toast-text);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 10px 16px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1000;
  white-space: nowrap;
}
#toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Login Screen ───────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  padding: 20px;
}

.login-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  max-width: 360px;
  width: 100%;
  padding: 48px 32px;
  border: 1px solid var(--color-border);
  border-radius: 16px;
}

.login-logo {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 6px;
  text-transform: uppercase;
}

.login-desc {
  color: #818384;
  text-align: center;
  line-height: 1.5;
  font-size: 0.95rem;
}

.btn-google {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  color: #1f1f1f;
  border: none;
  border-radius: 4px;
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-google:hover { background: #eeeeee; }

.login-anon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 16px;
}

.btn-anon {
  background: none;
  border: none;
  color: var(--color-absent);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 4px 8px;
  transition: color 0.15s;
}
.btn-anon:hover { color: #ffffff; }

.anon-note {
  font-size: 0.72rem;
  color: #666;
  margin: 0;
  text-align: center;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */
header {
  width: 100%;
  max-width: 500px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid var(--color-border);
}

header h1 {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: 4px;
  text-transform: uppercase;
  flex: 1;
  text-align: center;
}

#title-home {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-decoration: none;
  color: inherit;
  border-radius: 6px;
  padding: 4px 8px;
  transition: background 0.15s;
}
#title-home:hover { background: rgba(255,255,255,0.08); }

.header-left, .header-right {
  display: flex;
  gap: 4px;
  min-width: 60px;
}
.header-right { justify-content: flex-end; }

header button {
  background: none;
  border: none;
  color: var(--color-tile-text);
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: background 0.15s;
}
header button:hover { background: rgba(255,255,255,0.1); }

/* ─── Main layout ────────────────────────────────────────────────────────── */
#game-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 500px;
}

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 20px;
  padding: 20px 0;
  width: 100%;
}

/* ─── Board ──────────────────────────────────────────────────────────────── */
#board-container {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
}

#board {
  display: grid;
  grid-template-rows: repeat(6, var(--tile-size));
  gap: var(--tile-gap);
}

.row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile-size));
  gap: var(--tile-gap);
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 800;
  text-transform: uppercase;
  border: 2px solid var(--color-border);
  color: var(--color-tile-text);
  user-select: none;
  transition: border-color 0.05s;
}

.tile[data-state="tbd"] {
  border-color: #565758;
  animation: none;
}

.tile[data-state="correct"] {
  background: var(--color-correct);
  border-color: var(--color-correct);
}
.tile[data-state="present"] {
  background: var(--color-present);
  border-color: var(--color-present);
}
.tile[data-state="absent"] {
  background: var(--color-absent);
  border-color: var(--color-absent);
}

/* ─── Tile animations ────────────────────────────────────────────────────── */
@keyframes pop-anim {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.tile.pop { animation: pop-anim 0.1s ease-in-out; }

@keyframes flip-out-anim {
  from { transform: scaleY(1); }
  to   { transform: scaleY(0); }
}
@keyframes flip-in-anim {
  from { transform: scaleY(0); }
  to   { transform: scaleY(1); }
}
.tile.flip-out { animation: flip-out-anim 0.35s ease forwards; }
.tile.flip-in  { animation: flip-in-anim  0.35s ease forwards; }

@keyframes bounce-anim {
  0%, 100% { transform: translateY(0); }
  40%       { transform: translateY(-20px); }
  60%       { transform: translateY(-10px); }
}
.tile.bounce { animation: bounce-anim 0.5s ease; }

/* ─── Row animations ─────────────────────────────────────────────────────── */
@keyframes shake-anim {
  0%, 100% { transform: translateX(0); }
  16%       { transform: translateX(-6px); }
  33%       { transform: translateX(6px); }
  50%       { transform: translateX(-4px); }
  67%       { transform: translateX(4px); }
  83%       { transform: translateX(-2px); }
}
.row.shake { animation: shake-anim 0.5s ease; }

/* ─── Keyboard ───────────────────────────────────────────────────────────── */
#keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 8px 16px;
  width: 100%;
  max-width: 484px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: clamp(3px, 1.2vw, 6px);
}

.key {
  height: 58px;
  min-width: 43px;
  border: none;
  border-radius: 4px;
  background: var(--color-key-bg);
  color: var(--color-key-text);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  max-width: 43px;
  padding: 0;
  text-transform: uppercase;
  transition: background 0.1s, color 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.key-wide {
  min-width: 65px;
  max-width: 65px;
  font-size: 0.75rem;
  flex: 1.5;
}

.key:active { filter: brightness(0.85); }

.key[data-state="correct"] { background: var(--color-correct); }
.key[data-state="present"] { background: var(--color-present); }
.key[data-state="absent"]  { background: var(--color-absent);  }

/* On narrow screens: keys shrink to fit viewport (10 keys per row + gaps) */
@media (max-width: 484px) {
  #keyboard {
    padding: 0 4px 12px;
    max-width: 100%;
    box-sizing: border-box;
  }
  .keyboard-row { gap: 4px; }
  .key {
    min-width: 0;
    max-width: none;
    flex: 1;
    font-size: clamp(0.6rem, 3vw, 0.85rem);
    height: clamp(42px, 11vw, 58px);
  }
  .key-wide {
    min-width: 0;
    max-width: none;
    flex: 1.5;
    font-size: clamp(0.5rem, 2.4vw, 0.75rem);
  }
}


/* ─── Modals ─────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}

.modal-content {
  position: relative;
  background: #1a1a1b;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 32px 24px 24px;
  width: 100%;
  max-width: 360px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: #818384;
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.15s;
}
.modal-close:hover { color: #ffffff; }

.modal-content h2 {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #ffffff;
}

.modal-content h3 {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #818384;
  align-self: flex-start;
}

/* ─── Stats ──────────────────────────────────────────────────────────────── */
.stats-grid {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 60px;
}

.stat-item span {
  font-size: 2rem;
  font-weight: 700;
}

.stat-item label {
  font-size: 0.65rem;
  color: #818384;
  text-align: center;
  line-height: 1.2;
}

/* ─── Distribution ───────────────────────────────────────────────────────── */
#distribution {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 22px;
}

.dist-label {
  font-size: 0.85rem;
  font-weight: 700;
  min-width: 10px;
  text-align: right;
}

.dist-bar {
  background: var(--color-absent);
  height: 100%;
  min-width: 8%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  border-radius: 2px;
  transition: width 0.6s ease;
}

.dist-bar-current { background: var(--color-correct); }

.dist-bar span {
  font-size: 0.8rem;
  font-weight: 700;
  color: #ffffff;
}

/* ─── Modal actions ──────────────────────────────────────────────────────── */
.modal-actions {
  width: 100%;
  display: flex;
  justify-content: center;
  padding-top: 8px;
  border-top: 1px solid var(--color-border);
}

.btn-share {
  background: var(--color-correct);
  color: #ffffff;
  border: none;
  border-radius: 4px;
  padding: 14px 28px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 1px;
  transition: filter 0.15s;
}
.btn-share:hover { filter: brightness(1.1); }

/* ─── History ────────────────────────────────────────────────────────────── */
#history-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 60vh;
  overflow-y: auto;
}

.history-empty {
  color: #818384;
  text-align: center;
  font-size: 0.9rem;
}

.history-item {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}

.history-date  { color: #818384; }
.history-word  { font-weight: 700; letter-spacing: 2px; text-transform: uppercase; }
.history-win   { color: var(--color-correct); font-weight: 700; }
.history-loss  { color: #e74c3c; font-weight: 700; }

.history-grid {
  font-size: 1.1rem;
  line-height: 1.4;
  font-family: monospace;
}

/* ─── Utility ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-height: 700px) {
  :root {
    --tile-size: 52px;
  }
  .key { height: 48px; }
  main { gap: 12px; padding: 12px 0; }
}

