*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  background: #fffef5;
  color: #1a1a1a;
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  padding: 2rem 1rem;
}

/* --- Accessibility --- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Banner --- */
header { text-align: center; margin-bottom: 2.5rem; }

.banner {
  display: inline-block;
  background: #f7da21;
  color: #1a1a1a;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 0.6rem 2rem;
  border-radius: 6px;
}

.byline {
  text-align: center;
  margin-top: 0.3rem;
  color: #888;
  font-size: 0.8rem;
}

/* --- Main layout --- */
main { max-width: 540px; margin: 0 auto; }

@media (min-width: 640px) {
  main { max-width: 680px; }
  .form-actions { width: auto; align-self: center; }
  button[type="submit"] { width: auto; }
}

/* --- Loading --- */
#loading {
  text-align: center;
  color: #888;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid #ddd;
  border-top-color: #f7da21;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* --- Error box --- */
.error-box {
  background: #fef9e7;
  border: 1px solid #c0392b;
  color: #922b21;
  padding: 1rem;
  border-radius: 4px;
  font-size: 0.9rem;
  line-height: 1.6;
}

.error-box code {
  background: #fdebd0;
  padding: 0.1em 0.4em;
  border-radius: 3px;
}

/* --- Form --- */
#solver-form { display: flex; flex-direction: column; gap: 1.5rem; align-items: center; }

.field-error {
  color: #c0392b;
  font-size: 0.82rem;
  min-height: 1em;
  text-align: center;
}

.form-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

button[type="submit"] {
  background: #f7da21;
  border: none;
  border-radius: 4px;
  color: #1a1a1a;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0.7rem 1.8rem;
  transition: background 0.15s;
  width: 100%;
}

button[type="submit"]:hover:not(:disabled) { background: #f5c518; }
button[type="submit"]:active:not(:disabled) { background: #e6b800; }
button[type="submit"]:disabled { opacity: 0.35; cursor: default; }

#clear-btn {
  background: transparent;
  border: 1px solid #555;
  border-radius: 4px;
  color: #888;
  cursor: pointer;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  padding: 0.35rem 1rem;
  transition: border-color 0.15s, color 0.15s;
}

#clear-btn:hover:not(:disabled) { border-color: #aaa; color: #ccc; }
#clear-btn:active:not(:disabled) { border-color: #fff; color: #fff; }
#clear-btn:disabled { opacity: 0.3; cursor: default; }

/* --- Hive --- */

/*
  Hex cell: pointy-top, 70px wide × 80px tall
  clip-path: pointy-top hexagon
  Positions (left, top) for each cell in the 220px × 216px container:
    outer[0]: (37,  0)    outer[1]: (112,  0)
    outer[2]: ( 0, 68)    center:   ( 75, 68)    outer[3]: (150, 68)
    outer[4]: (37,136)    outer[5]: (112,136)
*/

.hive-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.hive {
  position: relative;
  width: 220px;
  height: 216px;
  border: none;
  padding: 0;
}

/* Hidden keyboard-capture input — off-screen but not display:none so mobile keyboard fires */
#hive-input {
  position: absolute;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.hex {
  position: absolute;
  width: 70px;
  height: 80px;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background: #e8e8e0;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, filter 0.1s;
  padding: 0;
}

.hex.center {
  background: #f7da21;
}

.hex:hover {
  filter: brightness(0.93);
}

.hex.focused {
  filter: brightness(0.82);
}

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

.hex.shake { animation: shake 0.3s ease; }

.hex.cursor .hex-letter::after {
  content: '|';
  font-weight: 300;
  animation: blink 1s step-end infinite;
}

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

.hex-letter {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1a1a1a;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
  pointer-events: none;
  user-select: none;
}

/* Hex positions — pointy-top layout */
.hex[data-index="0"] { left: 37px;  top:   0px; }
.hex[data-index="1"] { left: 112px; top:   0px; }
.hex[data-index="2"] { left: 0px;   top:  68px; }
.hex[data-index="6"] { left: 75px;  top:  68px; }  /* center */
.hex[data-index="3"] { left: 150px; top:  68px; }
.hex[data-index="4"] { left: 37px;  top: 136px; }
.hex[data-index="5"] { left: 112px; top: 136px; }

/* Mobile: scale down hive on narrow viewports */
@media (max-width: 399px) {
  .hive {
    transform: scale(0.82);
    transform-origin: top center;
    /* reserve the scaled-down height so layout doesn't collapse */
    margin-bottom: calc(216px * (0.82 - 1));
  }
}

/* --- Results --- */
#results { margin-top: 2.5rem; width: 100%; }

.results-group-header {
  color: #bbb;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  margin: 1.4rem 0 0.5rem;
  text-transform: uppercase;
}

.results-group-header:first-child { margin-top: 0; }

.word { font-size: 1rem; padding: 0.2rem 0; }

.results-group-words {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0 1rem;
}

.word.normal { color: #1a1a1a; }

.word.pangram {
  display: inline-block;
  background: #f7da21;
  color: #1a1a1a;
  font-weight: 700;
  padding: 0.15rem 0.6rem;
  border-radius: 3px;
  margin: 0.1rem 0;
}

.word.pangram::before { content: '\2605\00a0'; }

.results-summary {
  border-top: 1px solid #e8e8e8;
  color: #aaa;
  font-size: 0.85rem;
  margin-top: 1.5rem;
  padding-top: 0.8rem;
}

.results-summary .count { color: #1a1a1a; font-weight: 600; }

.results-summary .points { color: #b8860b; font-weight: 600; }

.no-words { color: #aaa; font-size: 0.95rem; }

/* --- Footer --- */
footer {
  color: #bbb;
  font-size: 0.75rem;
  margin-top: 3rem;
  max-width: 540px;
  margin-left: auto;
  margin-right: auto;
  padding: 1rem 1rem 0;
  border-top: 1px solid #e8e8e8;
  line-height: 1.5;
}

@media (min-width: 640px) {
  footer { max-width: 680px; }
}
