:root {
  --green: #4caf50;
  --yellow: #f6c945;
  --orange: #ff6a00;
  --black: #2b2b2f;
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --border: #d3d6da;
  --text: #1a1a1a;
  --accent: #3f6df5;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.logo {
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: 0.12em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.player-name {
  font-size: 0.85rem;
  color: #555;
  margin-right: 6px;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  padding: 6px 8px;
  border-radius: 8px;
  text-decoration: none;
  line-height: 1;
}
.icon-btn:hover { background: var(--bg); }

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px;
}

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

.overlay-card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}

.rules-card, .stats-card { max-width: 560px; }

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  padding: 0 4px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 4px;
  font-size: 0.82rem;
  border-bottom: 2px solid transparent;
  color: #666;
}
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.tab-panel { display: none; flex-direction: column; gap: 12px; }
.tab-panel.active { display: flex; }

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #333;
}
input, select, textarea {
  font-size: 1rem;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-weight: 400;
  font-family: inherit;
}

.primary-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 11px 18px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 1rem;
}
.primary-btn:disabled { opacity: 0.5; cursor: default; }
.secondary-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 9px 14px;
  border-radius: 10px;
  font-weight: 600;
}
.secondary-btn.small { font-size: 0.78rem; padding: 6px 10px; }

.form-error { color: #c62828; font-size: 0.82rem; min-height: 1em; margin: 0; }
.form-success { color: #2e7d32; font-size: 0.82rem; min-height: 1em; margin: 0; }

.guest-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 12px;
  color: #999;
  font-size: 0.78rem;
}
.guest-divider::before, .guest-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.guest-note {
  text-align: center;
  font-size: 0.75rem;
  color: #888;
  margin-top: 8px;
}

.rules-text ul { padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 2px;
}
.swatch.green { background: var(--green); }
.swatch.yellow { background: var(--yellow); }
.swatch.black { background: var(--black); }

/* Stats table */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { cursor: pointer; user-select: none; color: #444; }
th:hover { color: var(--accent); }

/* Board */
.board { display: flex; flex-direction: column; gap: 14px; align-items: center; }

.strikes-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; max-width: 100%; }
.strike {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #c62828;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 800;
  color: #c62828;
}
.strike.used { background: #c62828; color: white; }

.word-rows {
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  width: fit-content;
  max-width: 100%;
  align-items: flex-start;
}

.word-row-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.tiles {
  display: flex;
  gap: 6px;
}

.tile {
  width: 40px;
  height: 40px;
  border: 2px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 800;
  text-transform: uppercase;
  background: white;
  color: var(--text);
}
.tile.filled { border-color: #999; }
.tile.green { background: var(--green); border-color: var(--green); color: white; }
.tile.yellow { background: var(--yellow); border-color: var(--yellow); color: white; }
.tile.black { background: var(--black); border-color: var(--black); color: white; }

.word-row-wrap.active .tiles .tile { border-color: var(--orange); border-width: 2px; }
.word-row-wrap.active { box-shadow: 0 0 0 3px rgba(255,106,0,0.18); border-radius: 10px; padding: 4px; }
.word-row-wrap.solved .tile { background: var(--green); border-color: var(--green); color: white; }

.hints-row { display: flex; gap: 4px; min-height: 20px; }
.hint-box {
  width: 18px;
  height: 18px;
  background: var(--yellow);
  color: black;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
}

/* Keyboard */
.keyboard-controls { display: flex; justify-content: center; }
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  align-items: center;
}
.kb-row { display: flex; gap: 4px; justify-content: center; width: 100%; }
.key {
  min-width: 30px;
  flex: 1;
  max-width: 40px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  font-weight: 700;
  font-size: 0.95rem;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
}
.key.green { background: var(--green); border-color: var(--green); color: white; }
.key.black { background: var(--black); border-color: var(--black); color: white; pointer-events: none; opacity: 0.55; }

.guess-row { min-height: 46px; display: flex; justify-content: center; }

/* Admin: regenerate today's puzzle, for testing */
.new-puzzle-fab {
  position: fixed;
  bottom: 16px;
  right: 16px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 10px 16px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  opacity: 0.85;
  transition: opacity 0.15s ease;
  z-index: 200;
}
.new-puzzle-fab:hover, .new-puzzle-fab:focus-visible { opacity: 1; }

@media (max-width: 480px) {
  .tile { width: 32px; height: 32px; font-size: 1rem; }
  .key { height: 40px; font-size: 0.85rem; }
  .logo { font-size: 1.05rem; }
  .icon-btn { font-size: 1.05rem; padding: 5px 6px; }
}
