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

:root {
  --bg:          #121213;
  --surface:     #1a1a1b;
  --border:      #3a3a3c;
  --text:        #ffffff;
  --text-muted:  #818384;

  --green:       #538d4e;
  --yellow:      #b59f3b;
  --gray:        #3a3a3c;

  --green-light: #6aaf64;
  --yellow-light:#d4b84a;

  --tile-size:   clamp(48px, 11vw, 62px);
  --gap:         5px;
  --key-h:       58px;
  --radius:      4px;
  --header-h:    60px;
  --hint-h:      40px;
  --anim-flip:   0.5s;
}

html { height: 100%; }

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

/* ── Header ────────────────────────────────────────────────────────────────── */
header {
  width: 100%;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.header-top {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 10px 12px 4px;
}

.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.header-side { display: flex; align-items: center; }
.header-side--right { justify-content: flex-end; }

.logo {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  line-height: 1;
  padding: 0;
}

.tagline {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  font-style: italic;
  margin-top: 3px;
}

.how-to-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}
.how-to-btn:hover { border-color: var(--text); color: var(--text); }

.hint-bar {
  width: 100%;
  background: #1e1e2e;
  border-top: 1px solid #3a3a5c;
  text-align: center;
  padding: 8px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #a9b1d6;
  transition: opacity 0.4s;
}

.hint-bar span {
  color: #7dcfff;
  font-size: 1.05rem;
  letter-spacing: 0.12em;
}

.hidden { display: none !important; }

/* ── Main / board ──────────────────────────────────────────────────────────── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 8px 12px;
  width: 100%;
}

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

/* ── Tiles ──────────────────────────────────────────────────────────────────── */
.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 800;
  text-transform: uppercase;
  border: 2px solid var(--border);
  color: var(--text);
  user-select: none;
  position: relative;
  perspective: 250px;
}

.tile[data-letter] {
  border-color: #565758;
}

/* Pop animation when a letter is typed */
.tile.pop {
  animation: pop 0.1s ease-in-out;
}
@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Shake animation for invalid word */
.tile.shake {
  animation: shake 0.5s ease-in-out;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-4px); }
  40%      { transform: translateX(4px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

/* Flip-reveal animation */
.tile.flip {
  animation: flip var(--anim-flip) ease forwards;
}
@keyframes flip {
  0%   { transform: rotateX(0deg);    }
  45%  { transform: rotateX(-90deg);  }
  55%  { transform: rotateX(-90deg);  }
  100% { transform: rotateX(0deg);    }
}

/* Color states (applied mid-flip) */
.tile[data-state="green"]  { background: var(--green);  border-color: var(--green);  }
.tile[data-state="yellow"] { background: var(--yellow); border-color: var(--yellow); }
.tile[data-state="gray"]   { background: var(--gray);   border-color: var(--gray);   }

/* Win bounce on correct row */
.tile.bounce {
  animation: bounce 0.6s ease forwards;
}
@keyframes bounce {
  0%,100% { transform: translateY(0); }
  40%      { transform: translateY(-18px); }
  60%      { transform: translateY(-9px); }
  80%      { transform: translateY(-4px); }
}

/* ── Message strip ─────────────────────────────────────────────────────────── */
.message {
  min-height: 32px;
  margin-top: 14px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text);
  background: transparent;
  text-align: center;
  opacity: 0;
  transition: opacity 0.2s;
}
.message.visible {
  opacity: 1;
}

/* ── Keyboard ──────────────────────────────────────────────────────────────── */
footer {
  width: 100%;
  max-width: 500px;
  padding: 0 8px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.key {
  height: var(--key-h);
  min-width: clamp(28px, 8.5vw, 43px);
  padding: 0 4px;
  border: none;
  border-radius: var(--radius);
  background: #818384;
  color: var(--text);
  font-family: inherit;
  font-size: clamp(0.75rem, 2.5vw, 0.875rem);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.key.wide {
  min-width: clamp(48px, 13vw, 65px);
  font-size: clamp(0.65rem, 2vw, 0.75rem);
}

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

/* Keyboard letter state colors */
.key[data-state="green"]  { background: var(--green);  color: #fff; }
.key[data-state="yellow"] { background: var(--yellow); color: #fff; }
.key[data-state="gray"]   { background: var(--gray);   color: #fff; }

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal h2 {
  font-size: 1.6rem;
  letter-spacing: 0.08em;
}

.modal p {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

#modal-answer {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.12em;
}

#modal-hint {
  color: #7dcfff;
  font-weight: 600;
}

.btn-primary {
  margin-top: 4px;
  padding: 14px 0;
  border: none;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--green-light); }
.btn-primary:active { filter: brightness(0.9); }

.share-confirm {
  font-size: 0.8rem;
  color: var(--green-light) !important;
  font-weight: 600;
}

/* ── How to Play modal ──────────────────────────────────────────────────────── */
.howto-modal {
  text-align: left;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 24px;
  position: relative;
  gap: 14px;
}

.howto-modal h2 {
  font-size: 1rem;
  letter-spacing: 0.12em;
  text-align: center;
  margin-bottom: 4px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.howto-intro { color: var(--text) !important; font-size: 0.9rem; }

.howto-rules {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.howto-rules li {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding-left: 14px;
  position: relative;
  line-height: 1.4;
}
.howto-rules li::before { content: '•'; position: absolute; left: 0; }

.howto-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.howto-examples-label {
  font-size: 0.7rem !important;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted) !important;
}

.howto-example {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.howto-example p {
  font-size: 0.82rem !important;
  color: var(--text-muted) !important;
}
.howto-example strong { color: var(--text); }

.howto-tiles {
  display: flex;
  gap: 4px;
}

.howto-tile {
  width: 38px;
  height: 38px;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 800;
  text-transform: uppercase;
}
.howto-tile.green  { background: var(--green);  border-color: var(--green);  color: #fff; }
.howto-tile.yellow { background: var(--yellow); border-color: var(--yellow); color: #fff; }
.howto-tile.gray   { background: var(--gray);   border-color: var(--gray);   color: #fff; }

.howto-hint-note {
  background: #1e1e2e;
  border: 1px solid #3a3a5c;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.82rem !important;
  color: #a9b1d6 !important;
  line-height: 1.5;
}
.howto-hint-note strong { color: #7dcfff; }

.howto-footer {
  text-align: center;
  font-size: 0.78rem !important;
  color: var(--text-muted) !important;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* ── Loader ─────────────────────────────────────────────────────────────────── */
#loader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  z-index: 200;
}

/* ── Responsive tweaks ──────────────────────────────────────────────────────── */
@media (max-height: 700px) {
  :root { --tile-size: 46px; --key-h: 48px; }
  .logo { font-size: 1.5rem; padding: 8px 0 6px; }
  main  { padding-top: 10px; }
}
