/* ==========================================================================
   IT Track Institute - Typing Master
   Core Stylesheet & Modern UI Architecture
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.5;
  transition: background-color var(--transition-slow), color var(--transition-slow);
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 15% 15%, var(--accent-glow) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, var(--accent-glow) 0%, transparent 40%);
  background-attachment: fixed;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-subtle);
}

/* Container */
.app-container {
  max-width: 1100px;
  width: 92%;
  margin: 0 auto;
  padding: 1.5rem 0 3rem 0;
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* ==========================================================================
   HEADER & NAVBAR
   ========================================================================== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: 2rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  text-decoration: none;
  color: inherit;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 1.4rem;
  font-weight: 800;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-text .badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  background: var(--badge-bg);
  color: var(--badge-text);
  border: 1px solid var(--border-color);
  letter-spacing: 0.05em;
}

.brand-text p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Quick Tools in Header */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.icon-btn {
  background: var(--bg-secondary);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.icon-btn:hover {
  color: var(--text-main);
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(0);
}

.icon-btn svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

/* Dropdown Selects */
.select-wrapper {
  position: relative;
}

.styled-select {
  appearance: none;
  background: var(--bg-secondary);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.6rem 2rem 0.6rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: border-color var(--transition-fast);
}

.styled-select:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.select-arrow {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* ==========================================================================
   CONFIG & CONTROLS TOOLBAR
   ========================================================================== */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  margin-bottom: 2rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.control-group {
  display: flex;
  align-items: center;
  background: var(--bg-primary);
  border-radius: var(--radius-full);
  padding: 0.25rem;
  border: 1px solid var(--border-color);
}

.pill-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.pill-btn:hover {
  color: var(--text-main);
}

.pill-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 2px 10px var(--accent-glow);
}

[data-theme="light"] .pill-btn.active {
  color: #ffffff;
}

.sub-options {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding-left: 0.5rem;
  border-left: 1px solid var(--border-color);
}

.sub-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-mono);
}

.sub-btn:hover {
  color: var(--text-main);
}

.sub-btn.active {
  color: var(--accent-primary);
  font-weight: 700;
  background: var(--bg-tertiary);
}

/* ==========================================================================
   METRICS DASHBOARD (LIVE STATS)
   ========================================================================== */
.stats-banner {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-primary);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  opacity: 0.8;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-value {
  font-size: 2.1rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-main);
  line-height: 1.1;
}

.stat-unit {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 0.25rem;
}

/* Progress bar */
.test-progress-container {
  width: 100%;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.test-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  border-radius: var(--radius-full);
  transition: width 0.2s linear;
}

/* ==========================================================================
   TYPING ENGINE WRAPPER & WORDS AREA
   ========================================================================== */
.typing-box {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.25rem;
  position: relative;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.16);
  min-height: 220px;
  cursor: text;
  margin-bottom: 2rem;
  outline: none;
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

.typing-box:focus-within,
.typing-box.focused {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow), 0 16px 40px rgba(0, 0, 0, 0.2);
}

/* Hidden Keystroke Interceptor */
#hidden-input {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
  width: 1px;
  height: 1px;
}

/* Focus Overlay Alert */
.focus-indicator {
  position: absolute;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  font-size: 1.1rem;
  font-weight: 600;
  gap: 0.6rem;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.typing-box.unfocused .focus-indicator {
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
}

.focus-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-primary);
  box-shadow: 0 0 12px var(--accent-primary);
  animation: pulse 1.6s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.6; }
}

/* Words Stream Container */
.words-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 0.95rem;
  font-family: var(--font-mono);
  font-size: 1.65rem;
  line-height: 1.7;
  max-height: 160px;
  overflow: hidden;
  position: relative;
  user-select: none;
}

.word {
  position: relative;
  display: inline-flex;
  transition: color var(--transition-fast);
}

.word.active {
  color: var(--text-main);
}

.letter {
  position: relative;
  color: var(--text-subtle);
  transition: color 0.08s ease, background-color 0.08s ease;
}

.letter.correct {
  color: var(--color-correct);
}

.letter.incorrect {
  color: var(--color-incorrect);
  background-color: rgba(244, 63, 94, 0.15);
  border-radius: 2px;
}

.letter.extra {
  color: var(--color-extra);
  opacity: 0.8;
}

/* Animated Cursor Caret */
.caret {
  position: absolute;
  width: 2.5px;
  height: 1.55rem;
  background-color: var(--color-cursor);
  border-radius: 2px;
  top: 5px;
  left: 0;
  box-shadow: 0 0 10px var(--accent-primary);
  transition: left 0.09s ease-out, top 0.12s ease-out;
  pointer-events: none;
  animation: blink 1.1s infinite;
  z-index: 5;
}

.caret.typing {
  animation: none;
  opacity: 1;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Quick Restart Bar */
.typing-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-color);
}

.key-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

kbd {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-bottom: 2px solid var(--border-color);
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-main);
}

.restart-btn {
  background: var(--bg-secondary);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.6rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.restart-btn:hover {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
  box-shadow: 0 4px 14px var(--accent-glow);
  transform: translateY(-1px);
}

.restart-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  transition: transform 0.3s ease;
}

.restart-btn:hover svg {
  transform: rotate(180deg);
}

/* ==========================================================================
   VIRTUAL INTERACTIVE KEYBOARD
   ========================================================================== */
.keyboard-section {
  background: var(--keyboard-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  margin-bottom: 2.5rem;
  transition: all var(--transition-normal);
}

.keyboard-section.hidden {
  display: none;
}

.keyboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.keyboard-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.keyboard-toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
}

.keyboard-layout {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-width: 820px;
  margin: 0 auto;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
}

.key {
  background: var(--keyboard-key-bg);
  color: var(--keyboard-key-text);
  border: 1px solid var(--border-color);
  box-shadow: 0 3px 0 var(--keyboard-key-shadow);
  border-radius: var(--radius-sm);
  height: 44px;
  min-width: 44px;
  padding: 0 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.08s ease;
  user-select: none;
}

.key.key-wide {
  min-width: 65px;
}
.key.key-wider {
  min-width: 80px;
}
.key.key-space {
  min-width: 280px;
}

/* Key Active (When typed) */
.key.active-press {
  background: var(--keyboard-key-active);
  color: var(--keyboard-key-active-text);
  box-shadow: 0 0 14px var(--accent-glow);
  transform: translateY(2px);
}

/* Target Key (Next letter prompt) */
.key.target-key {
  border-color: var(--accent-primary);
  outline: 2px solid var(--accent-primary);
  outline-offset: -2px;
  animation: keyGlow 1.2s infinite alternate;
}

@keyframes keyGlow {
  0% { box-shadow: 0 0 2px var(--accent-primary); }
  100% { box-shadow: 0 0 10px var(--accent-primary); }
}

/* ==========================================================================
   RESULTS MODAL & CERTIFICATE MODAL
   ========================================================================== */
dialog.custom-modal {
  border: none;
  background: transparent;
  padding: 0;
  margin: auto;
  max-width: 640px;
  width: 92%;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
  overflow: visible;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.modal-content {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.25rem;
  color: var(--text-main);
  position: relative;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-title-group h2 {
  font-size: 1.45rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-title-group p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.close-modal-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: all var(--transition-fast);
}

.close-modal-btn:hover {
  color: var(--text-main);
  background: var(--color-incorrect);
}

/* Score Highlight Cards */
.result-hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.result-card-large {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.result-card-large::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
}

.result-card-large .hero-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}

.result-card-large .hero-num {
  font-size: 3.2rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--accent-primary);
  line-height: 1;
}

/* Details Grid */
.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.result-pill {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  text-align: center;
}

.result-pill span {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.result-pill strong {
  display: block;
  font-size: 1.25rem;
  font-family: var(--font-mono);
  color: var(--text-main);
  margin-top: 0.2rem;
}

/* Rank / Achievement Badge */
.rank-badge-box {
  background: var(--bg-tertiary);
  border: 1px dashed var(--accent-primary);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.rank-info h4 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-primary);
}

.rank-info p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.rank-medal {
  font-size: 2rem;
}

/* Certificate Generator Box */
.certificate-action-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.cert-input-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.cert-input {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.95rem;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
}

.cert-input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.cert-generate-btn {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.65rem 1.2rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: opacity var(--transition-fast);
}

.cert-generate-btn:hover {
  opacity: 0.92;
}

/* Modal Bottom Actions */
.modal-actions {
  display: flex;
  gap: 0.85rem;
  justify-content: flex-end;
}

.primary-btn {
  background: var(--accent-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
  font-family: inherit;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.primary-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.secondary-btn {
  background: var(--bg-secondary);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.secondary-btn:hover {
  background: var(--bg-tertiary);
}

/* ==========================================================================
   OFFICIAL PRINTABLE CERTIFICATE VIEW
   ========================================================================== */
#certificate-modal .modal-content {
  max-width: 780px;
}

.certificate-card {
  background: #ffffff;
  color: #0f172a;
  border: 8px double #1e293b;
  border-radius: var(--radius-sm);
  padding: 2.5rem;
  text-align: center;
  position: relative;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  margin-bottom: 1.5rem;
}

.cert-corner-decor {
  position: absolute;
  width: 32px;
  height: 32px;
  border: 3px solid #2563eb;
}
.cert-top-left { top: 10px; left: 10px; border-right: none; border-bottom: none; }
.cert-top-right { top: 10px; right: 10px; border-left: none; border-bottom: none; }
.cert-bottom-left { bottom: 10px; left: 10px; border-right: none; border-top: none; }
.cert-bottom-right { bottom: 10px; right: 10px; border-left: none; border-top: none; }

.cert-header h3 {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #1e3a8a;
  text-transform: uppercase;
}

.cert-header p {
  font-size: 0.9rem;
  color: #475569;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-top: 0.2rem;
}

.cert-divider {
  height: 2px;
  background: linear-gradient(90deg, transparent, #2563eb, transparent);
  margin: 1.25rem 0;
}

.cert-recipient-title {
  font-size: 0.9rem;
  color: #64748b;
  font-style: italic;
}

.cert-recipient-name {
  font-size: 2.2rem;
  font-weight: 800;
  color: #0f172a;
  text-decoration: underline;
  text-decoration-color: #2563eb;
  margin: 0.5rem 0;
  font-family: Georgia, serif;
}

.cert-description {
  font-size: 1rem;
  color: #334155;
  max-width: 580px;
  margin: 0 auto 1.5rem auto;
  line-height: 1.6;
}

.cert-stats-grid {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin: 1.5rem 0;
  background: #f8fafc;
  padding: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid #e2e8f0;
}

.cert-stat-item strong {
  display: block;
  font-size: 1.6rem;
  font-weight: 800;
  color: #2563eb;
}

.cert-stat-item span {
  font-size: 0.75rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
}

.cert-footer-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 2rem;
  padding: 0 1rem;
}

.cert-sig-block {
  text-align: center;
  border-top: 1px solid #94a3b8;
  padding-top: 0.4rem;
  min-width: 140px;
}

.cert-sig-block span {
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
}

.cert-official-seal {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 3px dashed #d97706;
  background: #fffbeb;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #b45309;
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  box-shadow: 0 4px 10px rgba(217, 119, 6, 0.2);
}

/* Print Certificate Rules */
@media print {
  body * {
    visibility: hidden;
  }
  #certificate-modal,
  #certificate-modal * {
    visibility: visible;
  }
  #certificate-modal {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    margin: 0;
    padding: 0;
    box-shadow: none;
  }
  .modal-actions, .close-modal-btn {
    display: none !important;
  }
  .certificate-card {
    border: 5px solid #000;
    box-shadow: none;
    margin: 0;
  }
}

/* ==========================================================================
   HISTORY DRAWER / MODAL
   ========================================================================== */
.history-table-container {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.history-table th {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.75rem;
}

.history-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  font-family: var(--font-mono);
}

.history-table tr:last-child td {
  border-bottom: none;
}

.empty-history-text {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ==========================================================================
   FOOTER
   ========================================================================== */
.footer {
  margin-top: auto;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.footer-links {
  display: flex;
  gap: 1.25rem;
}

.footer-link {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer-link:hover {
  color: var(--accent-primary);
}

/* ==========================================================================
   RESPONSIVENESS (MOBILE & TABLET)
   ========================================================================== */
@media (max-width: 860px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .stats-banner {
    grid-template-columns: repeat(2, 1fr);
  }

  .words-container {
    font-size: 1.35rem;
    line-height: 1.6;
    max-height: 140px;
  }

  .keyboard-section {
    display: none !important; /* Hide virtual keyboard on smaller screens for ergonomic touch input */
  }

  .result-hero {
    grid-template-columns: 1fr;
  }

  .result-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .footer {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .controls-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .control-group {
    justify-content: center;
  }

  .sub-options {
    justify-content: center;
  }

  .typing-box {
    padding: 1.25rem;
  }

  .words-container {
    font-size: 1.15rem;
  }
}
