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

:root {
  --bg: #fff;
  --text: #1a1a1a;
  --hex-bg: #e6e6e6;
  --hex-hover: #d4d4d4;
  --hex-center-bg: #f7c948;
  --hex-center-hover: #e6b830;
  --hex-text: #1a1a1a;
  --accent: #f7c948;
  --progress-bg: #e6e6e6;
  --progress-fill: #f7c948;
  --found-bg: #fafafa;
  --border: #e0e0e0;
  --message-bg: #1a1a1a;
  --message-text: #fff;
  --btn-bg: #f0f0f0;
  --btn-hover: #e0e0e0;
  --submit-bg: #1a1a1a;
  --submit-text: #fff;
  --submit-hover: #333;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --text: #e0e0e0;
    --hex-bg: #2a2a2a;
    --hex-hover: #3a3a3a;
    --hex-center-bg: #d4a520;
    --hex-center-hover: #c49518;
    --hex-text: #fff;
    --accent: #d4a520;
    --progress-bg: #2a2a2a;
    --progress-fill: #d4a520;
    --found-bg: #1a1a1a;
    --border: #333;
    --message-bg: #e0e0e0;
    --message-text: #1a1a1a;
    --btn-bg: #2a2a2a;
    --btn-hover: #3a3a3a;
    --submit-bg: #d4a520;
    --submit-text: #1a1a1a;
    --submit-hover: #c49518;
  }
}

html {
  overflow-y: auto;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}

#game-area {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Header */
header {
  text-align: center;
  padding: 12px 0 8px;
  flex-shrink: 0;
  padding-top: max(12px, env(safe-area-inset-top, 12px));
}

header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

#rank-display {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}

#rank-name {
  font-weight: 600;
  white-space: nowrap;
  min-width: 70px;
  text-align: left;
}

#score-display {
  font-weight: 700;
  font-size: 0.85rem;
  min-width: 28px;
  text-align: right;
}

#progress-container {
  flex: 1;
  height: 6px;
  background: var(--progress-bg);
  border-radius: 3px;
  position: relative;
  overflow: visible;
}

#progress-bar {
  height: 100%;
  background: var(--progress-fill);
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 0%;
  position: relative;
  z-index: 1;
}

#progress-dots {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 0;
  z-index: 2;
}

.progress-dot {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--progress-bg);
  border: 2px solid var(--bg);
  transform: translate(-50%, -50%);
  transition: background 0.3s ease, border-color 0.3s ease;
}

.progress-dot.active {
  background: var(--progress-fill);
  border-color: var(--progress-fill);
}

/* Main */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 0;
  min-height: 0;
}

/* Message toast */
.message {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--message-bg);
  color: var(--message-text);
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 100;
  white-space: nowrap;
  animation: fadeInOut 1.5s ease forwards;
}

.message.hidden {
  display: none;
}

@keyframes fadeInOut {
  0%   { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  70%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* Input display */
#input-display {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  flex-shrink: 0;
}

#cursor {
  animation: blink 1s step-end infinite;
  font-weight: 300;
  color: var(--accent);
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Honeycomb */
#honeycomb {
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  flex-shrink: 0;
  touch-action: manipulation;
}

.hex-row {
  display: flex;
  gap: 4px;
  margin-top: -14px;
}

.hex-row:first-child {
  margin-top: 0;
}

.hex {
  width: 64px;
  height: 72px;
  border: none;
  cursor: pointer;
  font-size: 1.3rem;
  font-weight: 700;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  transition: transform 0.1s ease, background 0.15s ease;
  color: var(--hex-text);
  background: var(--hex-bg);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  outline: none;
}

.hex:hover {
  background: var(--hex-hover);
}

.hex:active {
  transform: scale(0.93);
}

.hex.center {
  background: var(--hex-center-bg);
}

.hex.center:hover {
  background: var(--hex-center-hover);
}

.hex.pop {
  animation: hexPop 0.15s ease;
}

@keyframes hexPop {
  0%   { transform: scale(1); }
  50%  { transform: scale(0.88); }
  100% { transform: scale(1); }
}

/* Controls */
#controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
  touch-action: manipulation;
}

.ctrl-btn {
  padding: 10px 20px;
  border: 2px solid var(--border);
  border-radius: 28px;
  background: var(--btn-bg);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  outline: none;
}

.ctrl-btn:hover {
  background: var(--btn-hover);
}

.ctrl-btn:active {
  background: var(--btn-hover);
}

.shuffle-btn {
  font-size: 1.2rem;
  padding: 10px 14px;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.submit-btn {
  background: var(--submit-bg);
  color: var(--submit-text);
  border-color: var(--submit-bg);
}

.submit-btn:hover,
.submit-btn:active {
  background: var(--submit-hover);
  border-color: var(--submit-hover);
}

/* Shake animation for invalid words */
.shake {
  animation: shake 0.4s ease;
}

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

/* Bounce animation for valid words */
.bounce {
  animation: bounce 0.4s ease;
}

@keyframes bounce {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.15); }
  60%  { transform: scale(0.95); }
  100% { transform: scale(1); }
}

/* Footer - found words */
footer {
  padding: 8px 0 16px;
  flex-shrink: 0;
  padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
}

.words-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  cursor: pointer;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  -webkit-tap-highlight-color: transparent;
}

#toggle-arrow {
  transition: transform 0.2s ease;
  font-size: 0.75rem;
}

#toggle-arrow.open {
  transform: rotate(180deg);
}

#found-words {
  max-height: 200px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--found-bg);
  border-radius: 8px;
  padding: 8px 10px;
}

#found-words.hidden {
  display: none;
}

#words-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

#words-list li {
  background: var(--btn-bg);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 500;
  text-transform: uppercase;
}

#words-list li.pangram {
  background: var(--accent);
  color: var(--hex-text);
  font-weight: 700;
}

/* Tagline */
#tagline {
  font-size: 0.8rem;
  color: var(--text);
  opacity: 0.6;
  margin-bottom: 10px;
  font-weight: 400;
}

/* SEO content section */
#seo-content {
  padding: 32px 0 48px;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
  opacity: 0.85;
}

#seo-content h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 12px;
  border-top: 1px solid var(--border);
  padding-top: 24px;
}

#seo-content h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 8px;
}

#seo-content p {
  margin-bottom: 12px;
}

#seo-content ul {
  list-style: disc;
  padding-left: 20px;
  margin-bottom: 12px;
}

#seo-content li {
  margin-bottom: 4px;
}

#seo-content a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

#seo-content a:hover {
  text-decoration: underline;
}

/* ---- Mobile: small phones (SE, mini, older Android) ---- */
@media (max-height: 640px) {
  header h1 {
    font-size: 1.1rem;
    margin-bottom: 6px;
  }

  header {
    padding: 8px 0 4px;
  }

  main {
    gap: 10px;
    padding: 4px 0;
  }

  #input-display {
    min-height: 32px;
    font-size: 1.2rem;
  }

  .hex {
    width: 54px;
    height: 60px;
    font-size: 1.1rem;
  }

  .hex-row {
    margin-top: -12px;
    gap: 3px;
  }

  .hex-row:first-child {
    margin-top: 0;
  }

  .ctrl-btn {
    padding: 8px 16px;
    font-size: 0.8rem;
  }

  .shuffle-btn {
    width: 38px;
    height: 38px;
    font-size: 1rem;
  }

  #found-words {
    max-height: 140px;
  }
}

/* ---- Mobile: narrow screens ---- */
@media (max-width: 360px) {
  .hex {
    width: 56px;
    height: 64px;
    font-size: 1.1rem;
  }

  .hex-row {
    margin-top: -13px;
    gap: 3px;
  }

  .hex-row:first-child {
    margin-top: 0;
  }

  #input-display {
    font-size: 1.2rem;
  }

  .ctrl-btn {
    padding: 8px 16px;
    font-size: 0.8rem;
  }
}

/* ---- Standard phones (375-414px) ---- */
@media (min-width: 375px) and (min-height: 641px) {
  .hex {
    width: 68px;
    height: 76px;
    font-size: 1.35rem;
  }

  .hex-row {
    margin-top: -15px;
  }

  .hex-row:first-child {
    margin-top: 0;
  }
}

/* ---- Larger phones & tablets ---- */
@media (min-width: 500px) {
  .hex {
    width: 84px;
    height: 94px;
    font-size: 1.6rem;
  }

  .hex-row {
    margin-top: -19px;
  }

  .hex-row:first-child {
    margin-top: 0;
  }

  #input-display {
    font-size: 1.8rem;
  }

  header h1 {
    font-size: 1.5rem;
  }
}
