:root {
  color-scheme: dark;
  --bg: #12131a;
  --panel: #1c1e29;
  --cell: #262939;
  --cell-given: #1c1e29;
  --line: #3a3d52;
  --line-thick: #5eead4;
  --accent: #5eead4;
  --accent-2: #f472b6;
  --text: #e6e7ee;
  --text-dim: #8a8da3;
  --error: #ef4444;
  --hint: #facc15;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 0%, #1e2130, var(--bg));
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  overflow-x: hidden;
  overflow-y: auto;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(0.5rem, 2vmin, 0.85rem);
  padding: clamp(0.75rem, 3vmin, 1.5rem);
  width: min(460px, 96vw);
}

h1 {
  margin: 0;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-size: clamp(1.1rem, 5.5vmin, 1.6rem);
  color: var(--accent);
}

.hud {
  display: flex;
  width: 100%;
  justify-content: space-between;
  background: var(--panel);
  border-radius: 12px;
  padding: clamp(0.4rem, 2vmin, 0.75rem) clamp(0.5rem, 2.5vmin, 1rem);
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  flex: 1;
}

.hud-label {
  font-size: clamp(0.5rem, 1.7vmin, 0.7rem);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.hud-value {
  font-size: clamp(0.8rem, 2.8vmin, 1.1rem);
  font-weight: 600;
}

.board-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
}

.tool-btn {
  padding: 0.4rem 0.7rem;
  border: none;
  border-radius: 8px;
  background: var(--cell);
  color: var(--text);
  font-weight: 600;
  font-size: 0.78rem;
  cursor: pointer;
  touch-action: manipulation;
}

.tool-btn.active {
  background: var(--accent);
  color: #08221d;
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.board-wrap {
  position: relative;
  width: min(380px, 90vmin);
  aspect-ratio: 1 / 1;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  background: var(--line-thick);
  border: 2px solid var(--line-thick);
  border-radius: 8px;
  overflow: hidden;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell);
  color: var(--accent);
  font-weight: 700;
  font-size: clamp(0.9rem, 3.6vmin, 1.3rem);
  cursor: pointer;
  border: 0.5px solid var(--line);
}

.cell.border-right-thick { border-right: 2px solid var(--line-thick); }
.cell.border-bottom-thick { border-bottom: 2px solid var(--line-thick); }

.cell.given {
  background: var(--cell-given);
  color: var(--text);
  cursor: default;
}

.cell.hint {
  color: var(--hint);
}

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

.cell.peer {
  background: #2b2e42;
}

/* Opaco a propósito: con alfa se transparentaba el turquesa del tablero y
   teñía de verde la fila y la columna enteras, comiéndose el resaltado. */
.cell.given.peer {
  background: #232636;
}

/* Mismo número en otras casillas: tiene que cantar a la primera, así que
   cambia fondo, color y borde, no solo un fondo azulado apenas distinto del
   de la fila/columna. */
.cell.same-value {
  background: #17505c;
  color: #8ff5e4;
  box-shadow: inset 0 0 0 2px rgba(94, 234, 212, 0.6);
}

/* El estado de error o de pista manda sobre el color del resaltado. */
.cell.same-value.error { color: var(--error); }
.cell.same-value.hint { color: var(--hint); }

.cell.selected {
  background: #3a4a63;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.cell.selected.same-value {
  background: #1d6675;
}

/* Una nota con el dígito resaltado también se marca. */
.note-digit-match {
  color: var(--accent);
  font-weight: 800;
}

.cell.has-notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}

.note-digit {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.45rem, 1.6vmin, 0.6rem);
  font-weight: 600;
  color: var(--text-dim);
}

.numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 0.3rem;
  width: min(380px, 90vmin);
}

.num-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: clamp(0.3rem, 1.5vmin, 0.45rem) 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--cell);
  color: var(--text);
  font-weight: 700;
  font-size: clamp(0.85rem, 2.8vmin, 1.05rem);
  cursor: pointer;
  touch-action: manipulation;
}

.num-digit {
  line-height: 1;
}

/* Cuántas casillas quedan por poner de ese número. */
.num-left {
  min-height: 1em;
  line-height: 1;
  font-size: clamp(0.5rem, 1.5vmin, 0.62rem);
  font-weight: 700;
  color: var(--text-dim);
}

.num-btn:active {
  background: var(--accent);
  color: #08221d;
}

/* Dígito resaltado ahora mismo en el tablero. */
.num-btn.selected-digit {
  background: var(--accent);
  color: #08221d;
}

.num-btn.selected-digit .num-left {
  color: #08221d;
  opacity: 0.7;
}

/* Ya están los 9 colocados: no queda nada que poner. */
.num-btn.done,
.num-btn:disabled {
  background: transparent;
  border-color: var(--line);
  color: var(--text-dim);
  opacity: 0.45;
  cursor: default;
}

.num-btn.done .num-digit {
  text-decoration: line-through;
}

.difficulty-select {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.diff-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.5rem 0.4rem;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--cell);
  color: var(--text);
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.diff-btn small {
  font-weight: 500;
  font-size: 0.65rem;
  color: var(--text-dim);
}

.diff-btn:hover {
  transform: translateY(-1px);
}

.diff-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 11, 16, 0.75);
  border-radius: 16px;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  background: var(--panel);
  border-radius: 14px;
  padding: 1.5rem;
  width: min(420px, 85vw);
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.overlay-card h2 {
  margin: 0;
  color: var(--accent);
}

.overlay-card p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.4;
}

.auth-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.auth-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.auth-btn {
  padding: 0.45rem 0.9rem;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.auth-btn:hover {
  transform: translateY(-1px);
}

.auth-btn-primary {
  background: var(--accent);
  color: #08221d;
}

.auth-btn-secondary {
  background: var(--cell);
  color: var(--text);
}

.auth-user {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 0.75rem;
  background: var(--cell);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
}

.auth-username {
  font-weight: 600;
}

.auth-coins {
  color: var(--accent);
  font-weight: 600;
}

.auth-link-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-align: left;
}

.auth-form input {
  background: var(--cell);
  border: 1px solid #1a1b24;
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  color: var(--text);
  font-size: 0.9rem;
}

.auth-form input:focus {
  outline: 1px solid var(--accent);
}

.auth-form-error {
  margin: 0;
  color: #ef4444;
  font-size: 0.8rem;
  min-height: 1em;
}

.auth-form-actions {
  display: flex;
  gap: 0.5rem;
}

.auth-form-actions .auth-btn {
  flex: 1;
}

.auth-switch {
  margin: 0;
  font-size: 0.8rem;
  text-align: center;
}

.auth-switch a {
  color: var(--accent);
}

.reward-text {
  margin: 0;
  color: var(--accent);
  font-weight: 700;
}

.reward-text.hidden {
  display: none;
}

#start-btn {
  margin-top: 0.5rem;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #08221d;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.1s ease;
}

#start-btn:hover {
  transform: translateY(-1px);
}

#start-btn:disabled {
  opacity: 0.6;
  cursor: default;
  transform: none;
}

.back-btn {
  margin-top: 0.25rem;
  padding: 0.5rem 1.1rem;
  border-radius: 8px;
  background: var(--cell);
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  transition: transform 0.1s ease;
}

.back-btn:hover {
  transform: translateY(-1px);
}

.back-btn.hidden {
  display: none;
}

.leaderboard-box {
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid #1a1b24;
}

.leaderboard-box h3 {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.leaderboard-list {
  list-style: none;
  counter-reset: leaderboard;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 220px;
  overflow-y: auto;
}

.leaderboard-list li {
  counter-increment: leaderboard;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--cell);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
}

.leaderboard-list li::before {
  content: counter(leaderboard);
  flex: 0 0 auto;
  width: 1.4em;
  color: var(--text-dim);
  font-weight: 700;
  text-align: right;
}

.leaderboard-name {
  flex: 1;
  text-align: left;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-score {
  color: var(--accent);
  font-weight: 700;
}

.leaderboard-mistakes {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.leaderboard-empty {
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
  background: none !important;
}
