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

:root {
  --color-bg: #faf9f7;
  --color-surface: #ffffff;
  --color-border: #e0ddd8;
  --color-text: #1a1a1a;
  --color-muted: #6b6b6b;
  --color-primary: #f5c518;
  --color-primary-hover: #e0b010;
  --color-secondary: #e8e6e1;
  --color-secondary-hover: #d5d2cc;
  --color-success: #4a9e6b;
  --color-error: #c0392b;
  --color-pangram: #e67e22;
  --hex-size: 72px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

body {
  font-family: var(--font);
  background-color: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===========================
   Header
   =========================== */
header {
  width: 100%;
  max-width: 500px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.5rem;
  border-bottom: 2px solid var(--color-text);
}

header h1 {
  font-size: 1.75rem;
  font-weight: 900;
  letter-spacing: -0.5px;
}

#date-display {
  font-size: 0.85rem;
  color: var(--color-muted);
}

/* ===========================
   Main layout
   =========================== */
main {
  width: 100%;
  max-width: 500px;
  padding: 1rem 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.game-area {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ===========================
   Score section
   =========================== */
.score-section {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.rank-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.score-bar-wrap {
  width: 100%;
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
}

.score-bar {
  height: 100%;
  width: 0%;
  background: var(--color-primary);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.score-display {
  font-size: 0.85rem;
  color: var(--color-muted);
}

.score-sep {
  margin: 0 0.2em;
}

.score-unit {
  margin-left: 0.2em;
}

/* ===========================
   Word display
   =========================== */
.input-row {
  display: flex;
  justify-content: center;
}

.word-display {
  min-height: 2.5rem;
  min-width: 200px;
  max-width: 100%;
  border-bottom: 2px solid var(--color-text);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 0.25rem 0.5rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

#word-text {
  color: var(--color-text);
}

.cursor {
  display: inline-block;
  width: 2px;
  color: var(--color-text);
  animation: blink 1s step-end infinite;
  font-weight: 300;
  font-size: 1.4rem;
  line-height: 1;
  margin-left: 1px;
}

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

/* ===========================
   Toast
   =========================== */
.toast {
  min-height: 1.5rem;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: transparent;
  transition: color 0.1s;
}

.toast.visible {
  color: var(--color-text);
}

.toast.success { color: var(--color-success); }
.toast.error   { color: var(--color-error); }
.toast.pangram { color: var(--color-pangram); }

/* ===========================
   Hex grid
   =========================== */
.hex-grid {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  /* width  = hexSize * 2.5  (= 3 × apothem + hexSize)           */
  /* height = hexSize * 2.6  (≈ hexSize × 3√3/2, three hex-rows) */
  width: calc(var(--hex-size) * 2.5);
  height: calc(var(--hex-size) * 2.6);
  margin: 0 auto;
  user-select: none;
  /* extra breathing room above the action buttons */
  margin-bottom: 0.5rem;
}

.hex-btn {
  position: absolute;
  width: var(--hex-size);
  /* flat-top hex: height = width × (√3/2) ≈ width × 0.866 */
  height: calc(var(--hex-size) * 0.866);
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
  border: none;
  background: var(--color-secondary);
  color: var(--color-text);
  /* scale(0.91) creates the gap; drop-shadow traces the clip-path for the faint border */
  transform: scale(0.91);
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.22));
  transition: background 0.1s, transform 0.08s, filter 0.08s;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.hex-btn:hover {
  background: var(--color-secondary-hover);
  transform: scale(0.97);  /* 0.91 × 1.06 ≈ 0.97 */
}

.hex-btn:active {
  transform: scale(0.86);  /* 0.91 × 0.95 ≈ 0.86 */
}

.hex-btn.center {
  background: var(--color-primary);
  color: #000;
}

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

/* ===========================
   Action row
   =========================== */
.action-row {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.6rem 1.2rem;
  border: 2px solid var(--color-text);
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  background: transparent;
  color: var(--color-text);
  transition: background 0.12s, color 0.12s;
}

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

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

.btn-primary:hover {
  background: #333;
}

.btn-secondary {
  background: transparent;
}

/* ===========================
   Hint
   =========================== */
.hint {
  text-align: center;
  font-size: 0.78rem;
  color: var(--color-muted);
}

/* ===========================
   Found words section
   =========================== */
.words-section h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#found-count {
  font-weight: 400;
  font-size: 0.85rem;
}

.found-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.found-list li {
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: 999px;
  padding: 0.2rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 500;
  animation: pop-in 0.2s ease;
}

.found-list li.is-pangram {
  border-color: var(--color-pangram);
  color: var(--color-pangram);
  font-weight: 700;
}

@keyframes pop-in {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ===========================
   Toolbar (below header line)
   =========================== */
.toolbar {
  width: 100%;
  max-width: 500px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 1.25rem;
}

/* ===========================
   Help button
   =========================== */
.help-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--color-text);
  background: var(--color-surface);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}

.help-btn:hover {
  background: var(--color-text);
  color: var(--color-bg);
}

/* ===========================
   Hints button
   =========================== */
.hints-btn {
  height: 32px;
  padding: 0 0.75rem;
  border-radius: 999px;
  border: 2px solid var(--color-text);
  background: var(--color-surface);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  font-family: var(--font);
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}

.hints-btn:hover {
  background: var(--color-text);
  color: var(--color-bg);
}

/* ===========================
   Hints modal styles
   =========================== */
.modal--hints {
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}

.hints-summary {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-muted);
  margin-bottom: 1.25rem;
}

.hints-grid-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-bottom: 1.5rem;
  font-variant-numeric: tabular-nums;
}

.hints-grid-table th,
.hints-grid-table td {
  text-align: right;
  padding: 0.28rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
  min-width: 2rem;
}

.hints-grid-table th:first-child,
.hints-grid-table td:first-child {
  text-align: left;
  font-weight: 700;
  padding-left: 0;
}

.hints-grid-table thead th {
  font-weight: 700;
  color: var(--color-muted);
  border-bottom: 2px solid var(--color-border);
  font-size: 0.78rem;
}

.hints-grid-table tr.hints-sigma td,
.hints-grid-table td.hints-sigma {
  font-weight: 700;
  border-top: 2px solid var(--color-border);
}

.hints-grid-table td.hints-zero {
  color: var(--color-border);
}

.hints-two-letter h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
  margin-bottom: 0.6rem;
}

.hints-letter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  margin-bottom: 0.75rem;
  align-items: baseline;
}

.hints-letter-group-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-muted);
  margin-right: 0.25rem;
}

.hints-pair {
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  background: var(--color-secondary);
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
}

.hints-loading,
.hints-error {
  font-size: 0.9rem;
  color: var(--color-muted);
  text-align: center;
  padding: 1.5rem 0;
}

.hints-error { color: var(--color-error); }

/* ===========================
   Modal
   =========================== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--color-surface);
  border-radius: 12px;
  padding: 2rem 1.75rem;
  max-width: 380px;
  width: 90%;
  position: relative;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.modal h2 {
  font-size: 1.3rem;
  margin-bottom: 1rem;
}

.modal h3 {
  font-size: 1rem;
  margin: 1rem 0 0.5rem;
}

.modal ul {
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.9rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-muted);
  line-height: 1;
}

.modal-close:hover { color: var(--color-text); }

.modal-start {
  margin-top: 1.5rem;
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
}

/* ===========================
   Responsive tweaks
   =========================== */
@media (max-width: 380px) {
  :root { --hex-size: 60px; }
  header h1 { font-size: 1.4rem; }
}
