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

body {
  font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
  background: #fff;
  color: #1a1a1b;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  /* Reserve space for iPhone home indicator */
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Header ── */

header {
  width: 100%;
  max-width: 500px;
  padding: 6px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#day-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  font-weight: 700;
}

#day-stars {
  color: #b59a10;
}

#help-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #1a1a1b;
  background: transparent;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#help-btn:hover { background: #f0f0f0; }

/* ── Word progress tracker ── */

#word-progress {
  display: flex;
  gap: 8px;
  align-items: center;
}

.progress-slot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #d3d6da;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #878a8c;
  transition: all 0.3s ease;
}

.progress-slot.active {
  border-color: #1a1a1b;
  color: #1a1a1b;
}

.progress-slot.completed {
  border-color: #b59a10;
  background: #b59a10;
  color: #fff;
  font-size: 0.65rem;
  letter-spacing: 0.02em;
}

/* ── End-of-day summary board ── */

.summary-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #878a8c;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.summary-row {
  display: flex;
  gap: 5px;
}

.summary-row .tile {
  width: 48px;
  height: 48px;
  font-size: 1.5rem;
  background: #fff;
  border: 6px solid #1a1a1b;
  border-radius: 50%;
  color: #1a1a1b;
}

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

/* ── Main layout ── */

main {
  flex: 1;
  min-height: 0;           /* allow shrinking inside the flex body */
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 8px 8px;
  gap: 6px;
  width: 100%;
  max-width: 500px;
}

/* ── Tile board ── */

#board {
  flex: 1;                 /* grow to fill available space */
  min-height: 0;           /* allow shrinking */
  overflow-y: auto;        /* scroll when guesses overflow */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding-bottom: 4px;
}

.row {
  display: flex;
  gap: 5px;
}

.tile {
  width: 62px;
  height: 62px;
  border: 2px solid #d3d6da;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  text-transform: uppercase;
  user-select: none;
}

/* Evaluated tile states */
.tile.absent {
  background: #1e2d3d;
  border-color: #1e2d3d;
  color: #c0c4c8;
}

.tile.present {
  background: #b59a10;
  border-color: #b59a10;
  color: #fff;
}

.tile.correct {
  background: #fff;
  border: 8px solid #1a1a1b;
  border-radius: 50%;
  color: #1a1a1b;
}

/* Active (current input) row */
.row.active .tile {
  border-color: #878a8c;
}

.tile.invalid {
  color: #c0392b;
  border-color: #c0392b;
}

/* ── Result / star rating ── */

#result,
#keyboard {
  flex-shrink: 0;
}

#result {
  font-size: 2rem;
  letter-spacing: 0.15em;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #b59a10;
}

#result:empty {
  display: none;
}

.result-hint {
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  color: #878a8c;
  margin-top: 2px;
}

/* ── On-screen keyboard ── */

#keyboard {
  width: 100%;
  display: flex;
  flex-direction: column;
  /* Row gap shrinks on short screens (landscape mobile) */
  gap: clamp(5px, 1vh, 8px);
}

.key-row {
  display: flex;
  /* Key gap shrinks on narrow screens */
  gap: clamp(4px, 1vw, 6px);
}

.key {
  /* Fill the row evenly; no min/max-width so it scales with the container */
  flex: 1;
  /* Height fluid between 42 px (landscape phone) and 58 px (desktop) */
  height: clamp(42px, 8vh, 58px);
  padding: 0;
  border: none;
  border-radius: 4px;
  background: #d3d6da;
  font-family: inherit;
  /* Font fluid between 0.65 rem (narrow) and 0.85 rem (wide) */
  font-size: clamp(0.65rem, 2.2vw, 0.85rem);
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Prevent double-tap zoom on touch devices */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.key.wide {
  /* Enter / Backspace take 1.5× the space of a letter key */
  flex: 1.5;
  font-size: clamp(0.55rem, 1.8vw, 0.75rem);
}

.key:hover {
  background: #b3b6ba;
}

/* Keyboard key hint states — must not be overridden by :hover */
.key.absent {
  background: #1e2d3d;
  color: #c0c4c8;
}

.key.present {
  background: #b59a10;
  color: #fff;
}

.key.correct {
  position: relative;
  background: transparent;
  color: #1a1a1b;
}

.key.correct::before {
  content: '';
  position: absolute;
  width: 100%;
  aspect-ratio: 1;
  max-width: clamp(42px, 8vh, 58px);
  border-radius: 50%;
  background: #fff;
  border: 6px solid #1a1a1b;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: -1;
}

.key.absent:hover  { background: #162230; }
.key.present:hover { background: #b5a040; }
.key.correct:hover { background: transparent; }
.key.correct:hover::before { background: #f0f0f0; }

/* ── Ad banner ── */

#ad-banner {
  flex-shrink: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 4px 0;
}

/* ── Help modal ── */

[hidden] { display: none !important; }

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

.modal-panel {
  position: relative;
  background: #fff;
  border-radius: 8px;
  padding: 28px 24px 20px;
  width: min(400px, 92vw);
  max-height: 85vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: transparent;
  border: none;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  color: #555;
}

.modal-close:hover { color: #1a1a1b; }

.modal-panel h2 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.modal-panel h3 {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-top: 1px solid #d3d6da;
  margin: 14px 0 8px;
  padding-top: 12px;
}

.modal-panel p {
  font-size: 0.88rem;
  line-height: 1.55;
  margin-bottom: 8px;
}

.help-tiles {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.help-tile-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
}

.help-tile-row .tile {
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  flex-shrink: 0;
}

/* ── Animations ── */

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  40%       { transform: translateX(6px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}

.row.shake {
  animation: shake 0.4s ease;
}

/* ── Responsive adjustments ── */

/* Shrink board tiles on short screens so keyboard stays visible */
@media (max-height: 620px) {
  .tile {
    width: 48px;
    height: 48px;
    font-size: 1.5rem;
  }

  main {
    padding-top: 8px;
    gap: 8px;
  }

  .progress-slot {
    width: 26px;
    height: 26px;
    font-size: 0.6rem;
  }

  .progress-slot.completed {
    font-size: 0.55rem;
  }

  .summary-row .tile {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    border-width: 5px;
  }
}
