/* ============================================================
   style.css — Rajasthan Typing Test
   Theme: Desert Royale — terracotta, royal blue, gold on cream
   Updated: passage display overflow fix, backspace notice
   ============================================================ */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --rust:        #C84B1F;
  --rust-dark:   #9E3710;
  --rust-light:  #F5D5C5;
  --royal:       #1E3A8A;
  --royal-light: #3B5EC6;
  --gold:        #D4A017;
  --gold-light:  #F5E4A0;
  --cream:       #FDF6EC;
  --cream-dark:  #F0E4CE;
  --ink:         #1A1209;
  --ink-mid:     #5C4A2A;
  --ink-light:   #7A5C3A;
  --white:       #FFFFFF;
  --green:       #15803D;
  --red:         #DC2626;
  --shadow-sm:   0 2px 8px rgba(26,18,9,.12);
  --shadow-md:   0 4px 20px rgba(26,18,9,.16);
  --shadow-lg:   0 8px 40px rgba(26,18,9,.2);
  --radius:      10px;
  --radius-lg:   18px;
  --transition:  0.22s ease;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body:    'DM Sans', 'Segoe UI', sans-serif;
  --font-hindi:   'Tiro Devanagari Hindi', 'Mangal', serif;
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--cream);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.65;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    repeating-linear-gradient(45deg, transparent, transparent 40px, rgba(200,75,31,.03) 40px, rgba(200,75,31,.03) 41px),
    repeating-linear-gradient(-45deg, transparent, transparent 40px, rgba(30,58,138,.03) 40px, rgba(30,58,138,.03) 41px);
  pointer-events: none;
  z-index: 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

a { color: var(--royal); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--rust); }

img { max-width: 100%; height: auto; }

/* ── Typography ─────────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--ink);
  line-height: 1.2;
}

.hindi-text {
  font-family: var(--font-hindi);
  font-size: 1.05em;
  line-height: 1.8;
}

/* ── Header ─────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--royal);
  box-shadow: var(--shadow-md);
  border-bottom: 3px solid var(--gold);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 68px;
  gap: 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.logo-icon { font-size: 2rem; line-height: 1; }

.logo-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.logo-hindi {
  font-family: var(--font-hindi);
  font-size: 1.15rem;
  color: #ffffff;
  font-weight: 700;
  letter-spacing: .5px;
}

.logo-eng {
  font-size: .75rem;
  color: rgba(255,255,255,.95);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.main-nav a {
  color: rgba(255,255,255,.85);
  font-size: .88rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 6px;
  transition: background var(--transition), color var(--transition);
}

.main-nav a:hover { background: rgba(255,255,255,.12); color: #fff; }

.nav-cta {
  background: var(--rust) !important;
  color: #fff !important;
  border-radius: 6px;
}
.nav-cta:hover { background: var(--rust-dark) !important; }
.nav-cta--outline {
  background: transparent !important;
  border: 1.5px solid rgba(255,255,255,.4) !important;
  color: rgba(255,255,255,.9) !important;
}
.nav-admin { background: var(--gold) !important; color: var(--ink) !important; }
.nav-logout { opacity: .75; font-size: .82rem !important; }

.hamburger {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.6rem;
  cursor: pointer;
}

.mobile-nav {
  display: none;
  flex-direction: column;
  background: var(--royal);
  padding: 12px 24px 20px;
  border-bottom: 3px solid var(--gold);
  position: sticky;
  top: 71px;
  z-index: 99;
}
.mobile-nav.open { display: flex; }
.mobile-nav a {
  color: rgba(255,255,255,.97);
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.1);
  font-size: .95rem;
}

/* ── Main content ───────────────────────────────────────────── */
.site-main { flex: 1; padding: 40px 0 60px; position: relative; z-index: 1; }

/* ── Page Title Banner ──────────────────────────────────────── */
.page-banner {
  background: linear-gradient(135deg, var(--royal) 0%, #152B6B 100%);
  padding: 42px 0 36px;
  margin-bottom: 40px;
  border-bottom: 4px solid var(--gold);
  position: relative;
  overflow: hidden;
}

.page-banner::after {
  content: '🌸';
  position: absolute;
  right: 5%;
  top: 50%;
  transform: translateY(-50%);
  font-size: 5rem;
  opacity: .07;
}

.page-banner h1 { color: #fff; font-size: 2.2rem; }
.page-banner p  { color: rgba(255,255,255,.7); margin-top: 6px; font-size: 1rem; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--cream-dark);
  overflow: hidden;
}

.card-header {
  background: linear-gradient(to right, var(--rust), #E8622A);
  color: #fff;
  padding: 16px 24px;
  font-family: var(--font-display);
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-body { padding: 28px; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 20px; }

.form-group label {
  display: block;
  font-weight: 600;
  font-size: .9rem;
  margin-bottom: 6px;
  color: var(--ink-mid);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.form-control {
  width: 100%;
  padding: 11px 16px;
  border: 2px solid var(--cream-dark);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: .97rem;
  background: var(--cream);
  color: var(--ink);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--royal-light);
  box-shadow: 0 0 0 3px rgba(30,58,138,.12);
  background: #fff;
}

select.form-control { cursor: pointer; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 11px 24px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  line-height: 1;
}

.btn-primary  { background: var(--rust);  color: #fff; }
.btn-primary:hover  { background: var(--rust-dark); color: #fff; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-royal    { background: var(--royal); color: #fff; }
.btn-royal:hover    { background: var(--royal-light); color: #fff; }
.btn-gold     { background: var(--gold);  color: var(--ink); }
.btn-gold:hover     { background: #BF8C00; }
.btn-outline  { background: transparent; border: 2px solid var(--rust); color: var(--rust); }
.btn-outline:hover  { background: var(--rust); color: #fff; }
.btn-sm       { padding: 7px 14px; font-size: .83rem; }
.btn-lg       { padding: 14px 32px; font-size: 1.05rem; }
.btn-block    { width: 100%; justify-content: center; }
.btn-danger   { background: var(--red);   color: #fff; }
.btn-danger:hover   { background: #b91c1c; }
.btn-success  { background: var(--green); color: #fff; }
.btn-success:hover  { background: #15803d; }

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
  padding: 13px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: .94rem;
  border-left: 4px solid;
}

.alert-error   { background: #FEE2E2; border-color: var(--red);   color: #991B1B; }
.alert-success { background: #DCFCE7; border-color: var(--green); color: #166534; }
.alert-info    { background: #DBEAFE; border-color: var(--royal); color: #1E3A8A; }

/* ── Hero ───────────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--royal) 0%, #0F214D 100%);
  padding: 70px 0 60px;
  text-align: center;
  position: relative;
  overflow: hidden;
  border-bottom: 4px solid var(--gold);
}

.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle at 20% 80%, rgba(212,160,23,.15) 0%, transparent 50%),
                    radial-gradient(circle at 80% 20%, rgba(200,75,31,.12) 0%, transparent 50%);
}

.hero-content { position: relative; z-index: 1; }
.hero h1 { font-size: clamp(2.2rem, 5vw, 3.4rem); color: #fff; margin-bottom: 10px; }
.hero .subtitle-hindi { font-family: var(--font-hindi); font-size: 1.35rem; color: var(--gold); margin-bottom: 16px; }
.hero p { color: rgba(255,255,255,.75); font-size: 1.05rem; max-width: 560px; margin: 0 auto 32px; }
.hero-actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

/* ── Stats bar ──────────────────────────────────────────────── */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 20px;
  margin: 36px 0;
}

.stat-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 22px;
  text-align: center;
  border: 1px solid var(--cream-dark);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

.stat-value { font-family: var(--font-display); font-size: 2.4rem; font-weight: 700; color: var(--rust); line-height: 1; margin-bottom: 6px; }
.stat-label { font-size: .82rem; text-transform: uppercase; letter-spacing: 1px; color: #5C3D1E; font-weight: 700; }

/* ── Typing Test UI ─────────────────────────────────────────── */
.test-controls {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.test-controls .form-group { margin-bottom: 0; }

/* Metrics bar */
.metrics-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}

.metric {
  background: #fff;
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  border: 1px solid var(--cream-dark);
}

.metric-value { font-family: var(--font-display); font-size: 2rem; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.metric-label { font-size: .75rem; text-transform: uppercase; letter-spacing: 1px; color: #5C3D1E; font-weight: 600; }

.metric--timer .metric-value { color: var(--royal); }
.metric--wpm   .metric-value { color: var(--rust); }
.metric--acc   .metric-value { color: var(--green); }
.metric--err   .metric-value { color: var(--red); }

/* ── PASSAGE DISPLAY — Fixed overflow ───────────────────────── */
.passage-display {
  background: #FFFBF4;
  border: 2px solid var(--cream-dark);
  border-radius: var(--radius);
  padding: 22px 24px;
  font-size: 1.05rem;
  line-height: 1.9;
  margin-bottom: 18px;
  min-height: 120px;
  position: relative;
  user-select: none;
  /* Overflow fix */
  width: 100%;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
  white-space: normal;
  overflow: hidden;
}

.passage-display.hindi {
  font-family: var(--font-hindi);
  font-size: 1.15rem;
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
  white-space: normal;
}

/* ── Character spans — Fixed overflow ───────────────────────── */
.char {
  display: inline;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
}

.word-group {
  display: inline;
  white-space: normal;
}

.char-correct { color: var(--green); }
.char-wrong   { color: var(--red); background: #FEE2E2; border-radius: 2px; }
.char-current { border-bottom: 2px solid var(--royal); animation: blink .8s steps(1) infinite; }
.char-pending { color: var(--ink-mid); }

@keyframes blink {
  0%, 100% { border-color: var(--royal); }
  50%       { border-color: transparent; }
}

/* ── Typing input — Fixed overflow ──────────────────────────── */
.typing-area {
  width: 100%;
  max-width: 100%;
  min-height: 120px;
  padding: 16px;
  border: 2px solid var(--cream-dark);
  border-radius: var(--radius);
  font-size: 1rem;
  line-height: 1.7;
  resize: vertical;
  font-family: var(--font-body);
  background: #fff;
  color: var(--ink);
  transition: border-color var(--transition);
  outline: none;
  overflow-wrap: break-word;
  word-break: break-word;
}

.typing-area:focus    { border-color: var(--royal-light); }
.typing-area.hindi    { font-family: var(--font-hindi); font-size: 1.1rem; }
.typing-area:disabled { background: var(--cream); cursor: not-allowed; }

/* Timer warning */
.metric--timer.warn   .metric-value { color: var(--gold); }
.metric--timer.danger .metric-value { color: var(--red); animation: pulse .6s ease infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .5; }
}

/* ── Backspace disabled notice ──────────────────────────────── */
#backspaceNote {
  display: none;
  background: #FEF3C7;
  border: 1px solid #D4A017;
  border-left: 4px solid #D4A017;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: .88rem;
  color: #92400E;
  font-weight: 600;
  margin-top: 10px;
}

#backspaceNote.flash {
  animation: bsFlash 0.6s ease;
}

@keyframes bsFlash {
  0%   { background: #FEF3C7; border-color: #D4A017; color: #92400E; }
  30%  { background: #FEE2E2; border-color: #dc2626; color: #991B1B; }
  100% { background: #FEF3C7; border-color: #D4A017; color: #92400E; }
}

/* ── Result overlay ─────────────────────────────────────────── */
.result-overlay {
  display: none;
  background: linear-gradient(135deg, var(--royal) 0%, #0A1A4A 100%);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  color: #fff;
  margin-top: 24px;
  animation: fadeIn .4s ease;
}

.result-overlay.show { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.result-overlay h2 { font-size: 1.8rem; color: var(--gold); margin-bottom: 24px; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 18px;
  margin-bottom: 30px;
}

.result-item .val { font-family: var(--font-display); font-size: 2.6rem; font-weight: 700; color: var(--gold); }
.result-item .lbl { font-size: .8rem; text-transform: uppercase; letter-spacing: 1.5px; opacity: .7; margin-top: 4px; }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }

table { width: 100%; border-collapse: collapse; font-size: .93rem; }

thead tr { background: var(--royal); color: #fff; }
thead th { padding: 13px 16px; text-align: left; font-weight: 600; text-transform: uppercase; font-size: .78rem; letter-spacing: .8px; white-space: nowrap; }

tbody tr { border-bottom: 1px solid var(--cream-dark); transition: background var(--transition); }
tbody tr:hover { background: #FDF0E0; }
tbody td { padding: 12px 16px; }

.rank-badge { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; font-weight: 700; font-size: .9rem; }
.rank-1     { background: var(--gold);    color: var(--ink); }
.rank-2     { background: #C0C0C0;        color: var(--ink); }
.rank-3     { background: #CD7F32;        color: #fff; }
.rank-other { background: var(--cream-dark); color: var(--ink-mid); }

/* ── Admin ──────────────────────────────────────────────────── */
.admin-grid { display: grid; grid-template-columns: 260px 1fr; gap: 28px; align-items: start; }
.admin-sidebar .card { position: sticky; top: 80px; }

.admin-menu a {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px; color: var(--ink);
  border-left: 3px solid transparent;
  transition: all var(--transition); font-size: .93rem;
}
.admin-menu a:hover, .admin-menu a.active { background: var(--cream); border-color: var(--rust); color: var(--rust); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: .75rem; font-weight: 600; margin-left: auto; }
.badge-lang-english { background: #DBEAFE; color: #1e40af; }
.badge-lang-hindi   { background: #FCE7F3; color: #9d174d; }
.badge-diff-easy    { background: #D1FAE5; color: #065f46; }
.badge-diff-medium  { background: #FEF3C7; color: #92400e; }
.badge-diff-hard    { background: #FEE2E2; color: #991b1b; }

/* ── Auth ───────────────────────────────────────────────────── */
.auth-page  { display: flex; justify-content: center; align-items: flex-start; padding: 40px 24px; }
.auth-card  { width: 100%; max-width: 440px; }
.auth-title { text-align: center; margin-bottom: 28px; }
.auth-title h1 { font-size: 1.9rem; margin-bottom: 4px; }
.auth-title p  { color: #5C3D1E; font-size: .92rem; }

/* ── Section title ──────────────────────────────────────────── */
.section-title {
  font-size: 1.5rem; color: var(--ink); margin-bottom: 20px;
  padding-bottom: 10px; border-bottom: 2px solid var(--cream-dark);
  display: flex; align-items: center; gap: 10px;
}
.section-title::before { content: ''; display: block; width: 5px; height: 1.4em; background: var(--rust); border-radius: 3px; }

/* ── Leaderboard podium ─────────────────────────────────────── */
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 12px; margin: 30px 0; }

.podium-place {
  text-align: center; background: #fff;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 18px 24px 12px; border: 1px solid var(--cream-dark);
  min-width: 130px; transition: transform var(--transition);
}
.podium-place:hover { transform: translateY(-4px); }
.podium-place.p1 { height: 180px; border-top: 4px solid var(--gold); }
.podium-place.p2 { height: 150px; border-top: 4px solid #C0C0C0; }
.podium-place.p3 { height: 125px; border-top: 4px solid #CD7F32; }

.podium-name { font-weight: 700; font-size: .95rem; margin-top: 8px; }
.podium-wpm  { font-family: var(--font-display); font-size: 1.5rem; color: var(--rust); }
.podium-acc  { font-size: .8rem; color: #5C3D1E; }

/* ── Utility ────────────────────────────────────────────────── */
.text-center    { text-align: center; }
.mt-4           { margin-top: 16px; }
.mt-6           { margin-top: 24px; }
.mb-4           { margin-bottom: 16px; }
.mb-6           { margin-bottom: 24px; }
.flex           { display: flex; }
.items-center   { align-items: center; }
.justify-between{ justify-content: space-between; }
.w-full         { width: 100%; }
.hidden         { display: none !important; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .main-nav  { display: none; }
  .hamburger { display: block; }
  .metrics-bar { grid-template-columns: repeat(2, 1fr); }
  .admin-grid  { grid-template-columns: 1fr; }
  .podium      { flex-direction: column; align-items: center; }
  .podium-place { height: auto !important; width: 100%; max-width: 280px; }
  .test-controls { flex-direction: column; }
  .test-controls .form-group, .test-controls .btn { width: 100%; }
  .hero h1 { font-size: 1.9rem; }
}

@media (max-width: 480px) {
  .card-body   { padding: 18px; }
  .metrics-bar { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .metric-value { font-size: 1.6rem; }
}

/* ── Backspace disabled notice ──────────────────────────── */
#backspaceNote.flash {
  animation: bsFlash 0.6s ease;
}
@keyframes bsFlash {
  0%   { background: #FEF3C7; border-color: #D4A017; color: #92400E; }
  40%  { background: #FEE2E2; border-color: #DC2626; color: #991B1B; }
  100% { background: #FEF3C7; border-color: #D4A017; color: #92400E; }
}
/* STAT LABEL CONTRAST FIX */
.stat-label {
  color: #5C3D1E !important;
  font-weight: 700 !important;
}