/* === Font Faces === */
@font-face {
  font-family: "Clear Sans";
  src: url("/fonts/ClearSans-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Clear Sans";
  src: url("/fonts/ClearSans-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "benjamin";
  src: url("/fonts/benjamin-regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
}

@font-face {
  font-family: "benjamin";
  src: url("/fonts/benjamin-semibold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
}

@font-face {
  font-family: "benjamin";
  src: url("/fonts/benjamin-bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
}

@font-face {
  font-family: "nyt-karnak";
  src: url("/fonts/karnak-regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
}

@font-face {
  font-family: "nyt-karnakcondensed";
  src: url("/fonts/karnakcondensed-bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
}

/* === CSS Custom Properties === */
:root {
  --color-correct: #6aaa64;
  --color-present: #c9b458;
  --color-absent: #787c7e;
  --color-tone-1: #000000;
  --color-tone-2: #787c7e;
  --color-tone-4: #d3d6da;
  --color-tone-7: #ffffff;
  --color-background: #ffffff;
  --tile-text-color: #ffffff;
  --key-bg: #d3d6da;
  --key-text-color: #000000;
  --key-evaluated-text-color: #ffffff;
  --modal-bg: #ffffff;
  --modal-overlay: rgba(0, 0, 0, 0.5);
  --header-border: #d3d6da;
  --tile-border: #d3d6da;
  --tile-border-filled: #878a8c;
  --toast-bg: #000000;
  --toast-color: #ffffff;
  --switch-bg: #787c7e;
  --switch-bg-active: #6aaa64;
  --stat-bar-bg: #787c7e;
}

html.dark {
  --color-correct: #538d4e;
  --color-present: #b59f3b;
  --color-absent: #3a3a3c;
  --color-tone-1: #ffffff;
  --color-tone-2: #818384;
  --color-tone-4: #3a3a3c;
  --color-tone-7: #121213;
  --color-background: #121213;
  --tile-text-color: #ffffff;
  --key-bg: #818384;
  --key-text-color: #ffffff;
  --key-evaluated-text-color: #ffffff;
  --modal-bg: #121213;
  --modal-overlay: rgba(0, 0, 0, 0.7);
  --header-border: #3a3a3c;
  --tile-border: #3a3a3c;
  --tile-border-filled: #565758;
  --toast-bg: #ffffff;
  --toast-color: #000000;
  --switch-bg: #565758;
  --switch-bg-active: #538d4e;
  --stat-bar-bg: #3a3a3c;
}

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

/* === Base === */
html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "benjamin", "Helvetica Neue", Arial, sans-serif;
  background-color: var(--color-background);
  color: var(--color-tone-1);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

/* === Layout === */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 500px;
  margin: 0 auto;
}

/* === Header === */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 50px;
  padding: 0 16px;
  border-bottom: 1px solid var(--header-border);
  flex-shrink: 0;
  position: relative;
}

header .header-left,
header .header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 1;
}

header h1 {
  font-family: "nyt-karnakcondensed", "Arial Narrow", Arial, sans-serif;
  font-size: 37px;
  font-weight: 700;
  letter-spacing: 0.025em;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

header button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--color-tone-1);
}

header button svg {
  width: 24px;
  height: 24px;
  fill: var(--color-tone-1);
}

/* === Countdown Timer === */
.countdown {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
  color: var(--color-tone-2);
  flex-shrink: 0;
}

.countdown-label {
  font-weight: 400;
}

.countdown-time {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  color: var(--color-tone-1);
  letter-spacing: 0.05em;
}

/* === Board === */
#board-container {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-grow: 1;
  overflow: hidden;
}

/* Desktop: keyboard close to board */
@media (min-width: 500px) and (min-height: 600px) {
  #board-container {
    flex-grow: 0;
    padding: 16px 0;
  }
}

#board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 5px;
  padding: 10px;
  width: 280px;
  height: 336px;
}

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

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  font-size: 32px;
  font-weight: 700;
  text-transform: uppercase;
  border: 2px solid var(--tile-border);
  color: var(--color-tone-1);
  user-select: none;
  line-height: 32px;
}

.tile[data-state="filled"] {
  border-color: var(--tile-border-filled);
  animation: pop 0.1s ease-in-out;
}

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

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

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

/* === Keyboard === */
#keyboard {
  padding: 8px;
  flex-shrink: 0;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 8px;
}

.keyboard-row:last-child {
  margin-bottom: 0;
}

.key {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 58px;
  min-width: 43px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background-color: var(--key-bg);
  color: var(--key-text-color);
  font-family: "benjamin", "Helvetica Neue", Arial, sans-serif;
  font-size: 20px;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  flex: 1;
  -webkit-tap-highlight-color: transparent;
}

.key.wide {
  flex: 1.5;
  font-size: 12px;
}

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

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

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

/* === Toast Notifications === */
#toast-container {
  position: fixed;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background-color: var(--toast-bg);
  color: var(--toast-color);
  padding: 12px 24px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 700;
  opacity: 1;
  transition: opacity 0.3s ease;
  pointer-events: auto;
}

.toast.fade-out {
  opacity: 0;
}

/* === Modals === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  z-index: 2000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--modal-bg);
  color: var(--color-tone-1);
  border-radius: 8px;
  padding: 24px;
  max-width: 480px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 24px;
  color: var(--color-tone-1);
  line-height: 1;
  padding: 4px;
}

.modal h2 {
  font-size: 16px;
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 16px;
  letter-spacing: 0.5px;
}

/* === Stats Modal === */
.stats-container {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  text-align: center;
}

.stat .stat-value {
  font-size: 36px;
  font-weight: 400;
}

.stat .stat-label {
  font-size: 12px;
  text-transform: capitalize;
}

.guess-distribution {
  margin-bottom: 16px;
}

.graph-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
  font-size: 14px;
}

.graph-row .guess-number {
  width: 12px;
  text-align: right;
  flex-shrink: 0;
}

.graph-row .graph-bar {
  min-width: 24px;
  padding: 2px 8px;
  text-align: right;
  font-weight: 700;
  font-size: 14px;
  color: var(--tile-text-color);
  background-color: var(--stat-bar-bg);
}

.graph-row .graph-bar.highlight {
  background-color: var(--color-correct);
}

.share-btn {
  display: block;
  margin: 16px auto 0;
  padding: 12px 32px;
  background-color: var(--color-correct);
  color: #ffffff;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.share-btn:hover {
  opacity: 0.9;
}

/* === Settings Modal === */
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--header-border);
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-label {
  font-size: 16px;
}

.setting-description {
  font-size: 12px;
  color: var(--color-tone-2);
}

/* Theme select */
.theme-select {
  display: flex;
  gap: 4px;
  background: var(--key-bg);
  border-radius: 20px;
  padding: 3px;
}

.theme-option {
  padding: 6px 12px;
  border: none;
  border-radius: 17px;
  background: transparent;
  color: var(--color-tone-1);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.theme-option.active {
  background: var(--modal-bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* Auth section in settings */
.auth-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--header-border);
}

.auth-section input[type="email"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--tile-border);
  border-radius: 4px;
  font-size: 14px;
  background: var(--color-background);
  color: var(--color-tone-1);
  margin-bottom: 8px;
}

.auth-section button {
  width: 100%;
  padding: 10px;
  background: var(--color-tone-1);
  color: var(--color-tone-7);
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

/* === Help Modal === */
.help-section {
  margin-bottom: 16px;
  font-size: 14px;
  line-height: 1.5;
}

.help-section p {
  margin-bottom: 8px;
}

.help-examples {
  margin: 12px 0;
}

.help-example-row {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.help-tile {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  text-transform: uppercase;
  border: 2px solid var(--tile-border);
  color: var(--color-tone-1);
}

.help-tile.correct {
  background-color: var(--color-correct);
  border-color: var(--color-correct);
  color: var(--tile-text-color);
}

.help-tile.present {
  background-color: var(--color-present);
  border-color: var(--color-present);
  color: var(--tile-text-color);
}

.help-tile.absent {
  background-color: var(--color-absent);
  border-color: var(--color-absent);
  color: var(--tile-text-color);
}

/* === Animations === */
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

@keyframes flip-in {
  0% { transform: rotateX(0deg); }
  100% { transform: rotateX(-90deg); }
}

@keyframes flip-out {
  0% { transform: rotateX(-90deg); }
  100% { transform: rotateX(0deg); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

@keyframes bounce {
  0%, 20% { transform: translateY(0); }
  40% { transform: translateY(-30px); }
  50% { transform: translateY(5px); }
  60% { transform: translateY(-15px); }
  80% { transform: translateY(2px); }
  100% { transform: translateY(0); }
}

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

.tile.flip-in {
  animation: flip-in 0.25s ease-in forwards;
}

.tile.flip-out {
  animation: flip-out 0.25s ease-out forwards;
}

.tile.bounce {
  animation: bounce 1s ease;
}

/* === Responsive === */

/* Mobile: larger tiles, keyboard fits screen */
@media (max-width: 499px) {
  #board {
    width: calc(100vw - 20px);
    max-width: 350px;
    height: auto;
    aspect-ratio: 5 / 6;
    padding: 0;
  }
  .row {
    gap: 5px;
  }
  .tile {
    width: 100%;
    height: 100%;
    font-size: clamp(24px, 8vw, 32px);
    line-height: 1;
  }
  #keyboard {
    width: 100%;
    max-width: 500px;
    padding: 8px 8px;
  }
  .keyboard-row {
    gap: 4px;
  }
  .key {
    height: 58px;
    min-width: 0;
    flex: 1;
    font-size: clamp(12px, 4vw, 20px);
    padding: 0 2px;
  }
  .key.wide {
    flex: 1.5;
    font-size: clamp(10px, 2.5vw, 12px);
  }
}

/* Small height screens */
@media (max-height: 680px) and (min-width: 500px) {
  #board {
    width: 250px;
    height: 300px;
  }
  .tile {
    width: 46px;
    height: 46px;
    font-size: 28px;
    line-height: 28px;
  }
  .key {
    height: 50px;
    font-size: 18px;
  }
}

@media (max-height: 580px) and (min-width: 500px) {
  #board {
    width: 220px;
    height: 264px;
  }
  .tile {
    width: 40px;
    height: 40px;
    font-size: 24px;
    line-height: 24px;
  }
  .key {
    height: 44px;
    font-size: 16px;
  }
}
