/* ═══════════════════════════════════════════════════════════════════════════
   Number Guessing Game — Stylesheet
   Mobile-first, clean, and readable on phones, tablets, and desktops.
═══════════════════════════════════════════════════════════════════════════ */

/* ── Rules button & modal ─────────────────────────────────────────────────── */
.rules-btn {
  position: fixed;
  top: 0.85rem;
  right: 0.85rem;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border: 2px solid var(--border, #dde3ed);
  background: #fff;
  color: #4f46e5;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
  z-index: 100;
  transition: background 0.15s, transform 0.08s;
}
.rules-btn:hover  { background: #eeecff; }
.rules-btn:active { transform: scale(0.93); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 200;
}
.modal-overlay.hidden { display: none !important; }

.modal-card {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.25rem 0.9rem;
  border-bottom: 1px solid #e2e8f0;
}
.modal-header h2 { font-size: 1.15rem; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  font-size: 1rem;
  color: #64748b;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  line-height: 1;
}
.modal-close:hover { background: #f1f5f9; }

.modal-body {
  padding: 1.1rem 1.25rem 1.3rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.rules-list {
  padding-left: 1.3rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #1e293b;
}

.rules-divider {
  height: 1px;
  background: #e2e8f0;
}

.rules-note {
  font-size: 0.88rem;
  color: #64748b;
  line-height: 1.5;
}

/* ── Variables ────────────────────────────────────────────────────────────── */
/* ── Tie-break panels ─────────────────────────────────────────────────────── */
.tie-chance-badge {
  background: #fef3c7;
  color: #92400e;
  padding: 0.25rem 0.8rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.btn-warning {
  background: #f59e0b;
  color: #fff;
}
.btn-warning:hover:not(:disabled) { background: #d97706; }

:root {
  --bg:           #f0f4f8;
  --card:         #ffffff;
  --border:       #dde3ed;
  --primary:      #4f46e5;
  --primary-dk:   #4338ca;
  --success:      #16a34a;
  --success-dk:   #15803d;
  --danger:       #dc2626;
  --danger-dk:    #b91c1c;
  --text:         #1e293b;
  --muted:        #64748b;
  --light:        #94a3b8;
  --radius:       14px;
  --radius-sm:    9px;
  --shadow:       0 1px 3px rgba(0,0,0,.09), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:    0 4px 12px rgba(0,0,0,.08);
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

/* ── Base ─────────────────────────────────────────────────────────────────── */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
  gap: 0;
}

/* ── Screen containers ────────────────────────────────────────────────────── */
.screen {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-bottom: 2rem;
}
.screen.hidden { display: none !important; }

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  text-align: center;
  width: 100%;
}

/* ── Typography ───────────────────────────────────────────────────────────── */
h1 { font-size: 2.1rem; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 1.5rem;  font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 600; }
p  { font-size: 1rem; line-height: 1.55; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hint  { font-size: 0.8rem; color: var(--muted); max-width: 300px; line-height: 1.5; }
.mono  { font-family: 'Courier New', monospace; }
.subtitle { color: var(--muted); margin-top: -0.5rem; font-size: 0.95rem; }

/* ── Lobby logo ───────────────────────────────────────────────────────────── */
.logo      { font-size: 3.2rem; line-height: 1; }
.lock-icon { font-size: 2.5rem; }
.check-icon { font-size: 2.5rem; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  text-align: left;
}

label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input, select {
  width: 100%;
  padding: 0.8rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
  appearance: none;
  -webkit-appearance: none;
}
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 1rem center; padding-right: 2.5rem; }

input:focus, select:focus { border-color: var(--primary); }

/* Room code input: uppercase monospace */
.code-input {
  text-transform: uppercase;
  letter-spacing: 0.25em;
  font-family: 'Courier New', monospace;
  font-size: 1.2rem;
  text-align: center;
}

/* Secret input: large, centered, masked */
.secret-input {
  font-size: 2rem;
  text-align: center;
  letter-spacing: 0.6em;
  padding: 1rem;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  width: 100%;
  padding: 0.9rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.08s, opacity 0.15s;
  letter-spacing: 0.01em;
}
.btn:active  { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary   { background: var(--primary);  color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--primary-dk); }

.btn-secondary { background: #f1f5f9; color: var(--text); border: 2px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: #e2e8f0; }

.btn-success   { background: var(--success);  color: #fff; }
.btn-success:hover:not(:disabled)  { background: var(--success-dk); }

.btn-danger    { background: var(--danger);   color: #fff; }
.btn-danger:hover:not(:disabled)   { background: var(--danger-dk); }

.btn-ghost     { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled)    { background: #f1f5f9; }

/* Stack of buttons inside a panel */
.btn-stack {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* ── Section divider (lobby) ──────────────────────────────────────────────── */
.section-divider {
  width: 100%;
  position: relative;
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.section-divider::before,
.section-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  height: 1px;
  background: var(--border);
  width: calc(50% - 3.5rem);
}
.section-divider::before { left: 0; }
.section-divider::after  { right: 0; }

/* ── Error messages ───────────────────────────────────────────────────────── */
.error-msg {
  width: 100%;
  padding: 0.6rem 1rem;
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 0.875rem;
  text-align: center;
  animation: shake 0.25s ease;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-6px); }
  75%      { transform: translateX(6px); }
}
.hidden { display: none !important; }

/* ── Big room code display ────────────────────────────────────────────────── */
.big-code {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: 0.45em;
  padding-right: -0.45em; /* compensate last char spacing */
  color: var(--primary);
  background: #eeecff;
  padding: 0.7rem 1.5rem;
  border-radius: var(--radius);
  border: 2px dashed #a5b4fc;
}

/* ── Pulsing dots (waiting animation) ────────────────────────────────────── */
.pulse-row {
  display: flex;
  justify-content: center;
  padding: 0.75rem 0;
}

.dot-pulse {
  position: relative;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  animation: dp 1.3s ease-in-out infinite;
}
.dot-pulse::before,
.dot-pulse::after {
  content: '';
  position: absolute;
  top: 0;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--primary);
  animation: dp 1.3s ease-in-out infinite;
}
.dot-pulse::before { left: -18px; animation-delay: -0.32s; }
.dot-pulse::after  { left:  18px; animation-delay:  0.32s; }
@keyframes dp {
  0%, 80%, 100% { transform: scale(0.55); opacity: 0.35; }
  40%           { transform: scale(1);    opacity: 1; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   GAME SCREEN
═══════════════════════════════════════════════════════════════════════════ */

/* ── Game header bar ──────────────────────────────────────────────────────── */
.game-header {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

.header-meta {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.85rem;
}
.room-badge       { color: var(--muted); }
.vs-label         { color: var(--text); }
.my-secret-label  { color: var(--muted); font-size: 0.8rem; }
.my-secret-label strong { color: var(--primary); letter-spacing: 0.15em; }

.game-mode-badge  { font-size: 0.72rem; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 999px; }
.mode-online      { background: #dbeafe; color: #1d4ed8; }
.mode-inperson    { background: #f3f4f6; color: #374151; }

/* ── Mode toggle (lobby) ──────────────────────────────────────────────────── */
.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.mode-btn {
  padding: 0.65rem 0.5rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f1f5f9;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
}
.mode-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.mode-desc {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.25rem;
  line-height: 1.4;
}

/* Turn badge pill */
.turn-badge {
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.turn-badge.your-turn     { background: #dbeafe; color: #1d4ed8; }
.turn-badge.opponent-turn { background: #f1f5f9; color: #6b7280; }

/* ── Game panels ──────────────────────────────────────────────────────────── */
.game-panel { /* inherits .card */ }
.game-panel.hidden { display: none !important; }

.panel-icon { font-size: 2.5rem; }

/* ── Guess input ──────────────────────────────────────────────────────────── */
.big-input {
  font-size: 2.2rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.45em;
  padding: 0.9rem;
  border: 3px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Courier New', monospace;
  width: 100%;
}
.big-input:focus { border-color: var(--primary); }

/* ── Count entry stepper (panel-enter-count) ─────────────────────────────── */
.count-input-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  width: 100%;
}

.count-btn {
  width: 3.5rem;
  height: 3.5rem;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: #f1f5f9;
  font-size: 1.6rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, transform 0.08s;
  flex-shrink: 0;
}
.count-btn:hover  { background: #e2e8f0; }
.count-btn:active { transform: scale(0.93); }

.count-display {
  font-size: 4rem;
  font-weight: 900;
  color: var(--primary);
  min-width: 3rem;
  text-align: center;
  line-height: 1;
}

/* ── Defending panel ──────────────────────────────────────────────────────── */
.defend-badge {
  background: #fef3c7;
  color: #92400e;
  padding: 0.25rem 0.8rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}


.correct-box {
  background: #f0fdf4;
  border: 2px solid #bbf7d0;
  border-radius: var(--radius);
  padding: 1.1rem 2rem;
  width: 100%;
}
.correct-number {
  font-size: 4rem;
  font-weight: 900;
  color: var(--success);
  line-height: 1;
}
.correct-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #166534;
  margin-top: 0.2rem;
}

.speech-prompt {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
  padding: 0.8rem 1rem;
  font-size: 0.92rem;
  width: 100%;
}

/* ═══════════════════════════════════════════════════════════════════════════
   GUESS HISTORY
═══════════════════════════════════════════════════════════════════════════ */
.history-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}

.history-header {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.guess-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 2px; /* prevent scroll bar overlap */
}

.no-guesses {
  color: var(--light);
  font-size: 0.85rem;
  text-align: center;
  padding: 0.75rem 0;
}

.guess-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  animation: slide-in 0.18s ease-out;
}
@keyframes slide-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.guess-num {
  font-size: 0.72rem;
  color: var(--light);
  min-width: 1.4rem;
  text-align: right;
}

.guess-value {
  font-family: 'Courier New', monospace;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.25em;
  flex: 1;
}

/* Color badge for correct count */
.guess-count {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}
.count-0 { background: #f1f5f9; color: var(--muted); }
.count-1 { background: #fef3c7; color: #92400e; }
.count-2 { background: #fef9c3; color: #713f12; }
.count-3 { background: #dcfce7; color: #166534; }
.count-4 { background: #bbf7d0; color: #14532d; }
.count-5 { background: #86efac; color: #14532d; }
.count-6 { background: #4ade80; color: #14532d; }

/* ═══════════════════════════════════════════════════════════════════════════
   GAME OVER
═══════════════════════════════════════════════════════════════════════════ */
.game-over-emoji { font-size: 3.5rem; line-height: 1; }

.game-over-title {
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: -0.02em;
}
.game-over-title.won  { color: var(--success); }
.game-over-title.lost { color: var(--danger); }
.game-over-title.tie  { color: #d97706; }

.game-over-reason { font-size: 1.05rem; }
.game-over-secret { font-family: 'Courier New', monospace; }

.rematch-note {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  color: #166534;
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
  width: 100%;
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — wider screens get a couple of tweaks
═══════════════════════════════════════════════════════════════════════════ */
.site-footer {
  width: 100%;
  text-align: center;
  font-size: 0.75rem;
  color: var(--light);
  padding: 1.5rem 1rem 1rem;
}

@media (min-width: 520px) {
  body { padding: 2rem 1rem; }

  .btn-stack {
    flex-direction: row;
  }
}
