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

body {
  font-family: Arial, Helvetica, sans-serif;
  background: #121213;
  color: #ffffff;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===== Header ===== */
header {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 16px 8px;
  border-bottom: 1px solid #3a3a3c;
}

header img {
  max-width: 220px;
  height: auto;
}

header p {
  font-size: 0.85rem;
  color: #818384;
  margin-top: 6px;
  text-align: center;
}

/* ===== Main layout ===== */
main {
  width: 100%;
  max-width: 640px;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

/* ===== Section labels ===== */
.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #818384;
  text-transform: uppercase;
  align-self: flex-start;
  margin-bottom: -16px;
}

/* ===== Game board ===== */
#board-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.guess-row {
  display: flex;
  gap: 6px;
}

/* ===== Tiles ===== */
.tile {
  width: 58px;
  height: 58px;
  border: 2px solid #3a3a3c;
  border-radius: 4px;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  text-align: center;
  color: #ffffff;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: background 0.1s, border-color 0.1s;
  /* allow keyboard input via contenteditable trick — we use a hidden input overlay */
  position: relative;
}

.tile.has-letter {
  border-color: #565758;
}

/* Color states */
.tile.absent {
  background: #3a3a3c;
  border-color: #3a3a3c;
  color: #ffffff;
}

.tile.present {
  background: #b59f3b;
  border-color: #b59f3b;
  color: #ffffff;
}

.tile.correct {
  background: #538d4e;
  border-color: #538d4e;
  color: #ffffff;
}

/* focus ring */
.tile.focused {
  border-color: #999999;
  outline: none;
}

/* ===== Hidden real inputs (one per tile for keyboard access) ===== */
.tile-input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  cursor: pointer;
  font-size: 2rem;
  text-align: center;
  text-transform: uppercase;
  background: transparent;
  border: none;
  outline: none;
  color: transparent;
  caret-color: transparent;
}

/* ===== Instructions ===== */
.instructions {
  width: 100%;
  background: #1a1a1b;
  border: 1px solid #3a3a3c;
  border-radius: 8px;
  padding: 14px 18px;
  font-size: 0.82rem;
  line-height: 1.7;
  color: #818384;
}

.instructions strong { color: #d7dadc; }

.color-key {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 4px;
}
.color-key.green  { background: #538d4e; }
.color-key.yellow { background: #c9b14a; border: 1px solid #d4bc55; }
.color-key.gray   { background: #3a3a3c; }

/* ===== Buttons ===== */
.btn-row {
  display: flex;
  gap: 12px;
  width: 100%;
  justify-content: center;
}

button {
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 700;
  padding: 14px 28px;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: opacity 0.15s;
}

button:hover { opacity: 0.85; }
button:active { opacity: 0.7; }

#btn-search {
  background: #538d4e;
  color: #ffffff;
}

#btn-clear {
  background: #3a3a3c;
  color: #ffffff;
}

/* ===== Results area ===== */
#results-section {
  width: 100%;
}

#result-count {
  font-size: 0.85rem;
  color: #818384;
  margin-bottom: 10px;
  min-height: 1.2em;
}

#result-count span {
  color: #ffffff;
  font-weight: 700;
}

#error-msg {
  color: #e57373;
  font-size: 0.9rem;
  margin-bottom: 8px;
  min-height: 1.2em;
}

#results-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px 8px;
  list-style: none;
}

#results-grid li {
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 0;
  color: #d7dadc;
}

/* ===== Spinner ===== */
#spinner {
  display: none;
  width: 28px;
  height: 28px;
  border: 3px solid #3a3a3c;
  border-top-color: #538d4e;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .tile {
    width: 48px;
    height: 48px;
    font-size: 1.6rem;
  }

  #results-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  button {
    padding: 12px 20px;
    font-size: 0.9rem;
  }
}

@media (max-width: 340px) {
  .tile {
    width: 42px;
    height: 42px;
    font-size: 1.4rem;
  }

  #results-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
