:root {
  --green: #6aaa64;
  --yellow: #c9b458;
  --gray: #787c7e;
  --bg: #ffffff;
  --text: #1a1a1b;
  --tile-border: #d3d6da;
  --tile-border-filled: #878a8c;
  --key-bg: #d3d6da;
  --key-text: #1a1a1b;
  --modal-bg: #ffffff;
  --toast-bg: #1a1a1b;
  --toast-text: #ffffff;
}

body.dark {
  --green: #538d4e;
  --yellow: #b59f3b;
  --gray: #3a3a3c;
  --bg: #121213;
  --text: #f8f8f8;
  --tile-border: #3a3a3c;
  --tile-border-filled: #565758;
  --key-bg: #818384;
  --key-text: #f8f8f8;
  --modal-bg: #121213;
  --toast-bg: #f8f8f8;
  --toast-text: #1a1a1b;
}

body.colorblind {
  --green: #f5793a;
  --yellow: #85c0f9;
}

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

/* Author display rules (e.g. .modal { display: flex }) would otherwise
   override the browser's default styling for the hidden attribute. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
}

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

h1 {
  font-size: 1.6rem;
  letter-spacing: 0.15rem;
  text-transform: uppercase;
  font-weight: 700;
}

.puzzle-number {
  font-size: 0.8rem;
  letter-spacing: 0;
  color: var(--gray);
  vertical-align: middle;
}

.header-right { display: flex; gap: 4px; }

.icon-button {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  max-width: 500px;
  width: 100%;
  margin: 0 auto;
  padding: 10px;
  position: relative;
}

/* Board */

.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 5px;
  width: min(350px, 100%);
  flex: 1;
  max-height: 420px;
  margin: 8px 0;
}

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

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--tile-border);
  font-size: 2rem;
  font-weight: 700;
  text-transform: uppercase;
  user-select: none;
  aspect-ratio: 1;
}

.tile.small {
  width: 40px;
  height: 40px;
  font-size: 1.4rem;
  display: inline-flex;
}

.tile.filled { border-color: var(--tile-border-filled); }

/* Typed word is a valid guess but can never be a daily answer */
.tile.not-answer { color: #e04848; }

.tile.revealed { border: none; color: #fff; }
.tile.revealed.correct { background: var(--green); }
.tile.revealed.present { background: var(--yellow); }
.tile.revealed.absent { background: var(--gray); }

/* Animations */

@keyframes pop {
  0% { transform: scale(0.8); opacity: 0; }
  40% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}
.tile.pop { animation: pop 0.1s ease-in-out; }

@keyframes flip-in {
  from { transform: rotateX(0); }
  to { transform: rotateX(-90deg); }
}
.tile.flip-in { animation: flip-in 0.25s ease-in forwards; }

@keyframes flip-out {
  from { transform: rotateX(-90deg); }
  to { transform: rotateX(0); }
}
.tile.flip-out { animation: flip-out 0.25s ease-out forwards; }

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}
.row.shake { animation: shake 0.6s; }

@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); }
}
.tile.bounce { animation: bounce 1s; }

/* Keyboard */

.keyboard {
  width: 100%;
  padding-bottom: 8px;
  user-select: none;
}

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

.key {
  flex: 1;
  max-width: 43px;
  height: 58px;
  border: none;
  border-radius: 4px;
  background: var(--key-bg);
  color: var(--key-text);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
}

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

.key.correct { background: var(--green); color: #fff; }
.key.present { background: var(--yellow); color: #fff; }
.key.absent { background: var(--gray); color: #fff; }

/* Toasts */

.toasts {
  position: absolute;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.toast {
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 12px 16px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: opacity 0.3s;
}

.toast.fade { opacity: 0; }

/* Modals */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

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

.modal-content h2 {
  text-align: center;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05rem;
  margin: 12px 0;
}

.modal-content p { margin: 8px 0; font-size: 0.9rem; }
.modal-content hr { border: none; border-top: 1px solid var(--tile-border); margin: 12px 0; }

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
}

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

/* Statistics */

.stats-grid {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 8px;
}

.stat { text-align: center; flex: 0 1 70px; }
.stat-number { font-size: 2.2rem; font-weight: 400; }
.stat-label { font-size: 0.75rem; }

.distribution { padding: 0 8px; }

.dist-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 0.85rem;
}

.dist-label { width: 12px; font-weight: 700; }

.dist-bar {
  background: var(--gray);
  color: #fff;
  font-weight: 700;
  text-align: right;
  padding: 2px 8px;
  min-width: 24px;
}

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

.share-area {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  border-top: 1px solid var(--tile-border);
  padding-top: 16px;
}

.next-word { text-align: center; flex: 1; }
.next-word h3 { font-size: 0.8rem; text-transform: uppercase; }
.countdown { font-size: 1.8rem; font-variant-numeric: tabular-nums; }

.share-button {
  flex: 1;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 14px;
  cursor: pointer;
}

/* Settings */

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--tile-border);
}

.setting-title { font-size: 1rem; }
.setting-desc { font-size: 0.75rem; color: var(--gray); }

.switch { position: relative; display: inline-block; width: 32px; height: 20px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  inset: 0;
  background: var(--gray);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(12px); }

@media (max-width: 360px) {
  .tile { font-size: 1.5rem; }
  .key { height: 50px; }
}
