/* ============================================================
   TypeForge — style.css
   Theme: Dark terminal meets luxury — amber/gold on deep charcoal
   ============================================================ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
/* ── CSS VARIABLES ── */
:root {
  /* Dark theme (default) */
  --bg:           #0f0f11;
  --bg-2:         #16161a;
  --bg-3:         #1e1e24;
  --surface:      #222228;
  --surface-2:    #2a2a32;
  --border:       rgba(255,255,255,0.07);
  --border-bright:rgba(255,255,255,0.14);

  --accent:       #f0a500;
  --accent-dim:   rgba(240,165,0,0.15);
  --accent-glow:  rgba(240,165,0,0.35);

  --text:         #e8e8f0;
  --text-2:       #9090a8;
  --text-3:       #55556a;

  --correct:      #4ade80;
  --incorrect:    #f87171;
  --cursor-clr:   #f0a500;

  --font-mono:    'Space Mono', monospace;
  --font-ui:      'Syne', sans-serif;

  --radius:       14px;
  --radius-sm:    8px;
  --shadow:       0 8px 32px rgba(0,0,0,0.45);
  --shadow-sm:    0 2px 12px rgba(0,0,0,0.3);

  --transition:   0.25s cubic-bezier(0.4,0,0.2,1);
}

[data-theme="light"] {
  --bg:           #f0ede8;
  --bg-2:         #e8e4de;
  --bg-3:         #ddd9d2;
  --surface:      #ffffff;
  --surface-2:    #f5f2ee;
  --border:       rgba(0,0,0,0.08);
  --border-bright:rgba(0,0,0,0.16);

  --accent:       #c07800;
  --accent-dim:   rgba(192,120,0,0.12);
  --accent-glow:  rgba(192,120,0,0.3);

  --text:         #1a1a22;
  --text-2:       #55556a;
  --text-3:       #9090a8;

  --correct:      #16a34a;
  --incorrect:    #dc2626;

  --shadow:       0 8px 32px rgba(0,0,0,0.12);
  --shadow-sm:    0 2px 12px rgba(0,0,0,0.08);
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background var(--transition), color var(--transition);
  overflow-x: hidden;
}

/* Subtle grid background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* ── HEADER ── */
.header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  backdrop-filter: blur(12px);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-ui);
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}

.logo-icon {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #000;
  border-radius: var(--radius-sm);
  font-size: 1rem;
}

.logo em { color: var(--accent); font-style: normal; }

.theme-toggle {
  width: 38px; height: 38px;
  border: 1px solid var(--border-bright);
  background: var(--surface);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.95rem;
  display: grid; place-items: center;
  transition: all var(--transition);
}
.theme-toggle:hover {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

/* ── LAYOUT ── */
.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 230px 1fr 230px;
  gap: 20px;
  padding: 24px 24px;
  flex: 1;
  align-items: start;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

/* ── PANELS (shared) ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 24px;
}

.panel-title {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ── STAT CARDS ── */
.stat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
  border-color: var(--border-bright);
  box-shadow: 0 0 0 1px var(--border-bright);
}

.stat-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
  opacity: 0.6;
  border-radius: 99px 0 0 99px;
}

.stat-icon {
  font-size: 1rem;
  color: var(--accent);
  width: 30px; height: 30px;
  display: grid; place-items: center;
  background: var(--accent-dim);
  border-radius: 6px;
  flex-shrink: 0;
}

.stat-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
}

.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  font-weight: 700;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  transition: color 0.2s;
}

.stat-unit {
  font-size: 0.6rem;
  color: var(--text-3);
  letter-spacing: 0.05em;
}

/* SVG Ring on time card */
.ring {
  width: 36px; height: 36px;
  transform: rotate(-90deg);
  flex-shrink: 0;
}
.ring-bg {
  fill: none;
  stroke: var(--border-bright);
  stroke-width: 3;
  stroke-linecap: round;
}
.ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dasharray 1s linear;
}

/* ── PROGRESS BAR ── */
.progress-wrap { margin-top: 4px; }

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--text-3);
  margin-bottom: 6px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.progress-track {
  height: 5px;
  background: var(--bg-3);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent), #ffd166);
  border-radius: 99px;
  transition: width 1s linear, background 0.5s;
  box-shadow: 0 0 8px var(--accent-glow);
}

/* ── CENTER PANEL ── */
.center-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
}

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

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(240,165,0,0.25);
  padding: 4px 12px;
  border-radius: 99px;
}

.icon-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--border-bright);
  background: var(--surface);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  display: grid; place-items: center;
  transition: all var(--transition);
}
.icon-btn:hover {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
  transform: rotate(20deg);
}

/* ── PARAGRAPH BOX ── */
.paragraph-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  line-height: 1.95;
  letter-spacing: 0.01em;
  color: var(--text-3);
  min-height: 150px;
  user-select: none;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
    white-space: normal;        /* allow line breaks */
  word-wrap: break-word;      /* break long words */
  overflow-wrap: break-word;  /* modern version */
  word-break: break-word;     /* fallback for safety */
}

.paragraph-box::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  box-shadow: inset 0 0 40px rgba(0,0,0,0.2);
  pointer-events: none;
}

/* Character spans */
.char { position: relative; }
.char.correct { color: var(--correct); }
.char.incorrect {
  color: var(--incorrect);
  background: rgba(248,113,113,0.12);
  border-radius: 2px;
  display: inline;
  white-space: pre; /* preserve spaces for better highlighting */
}
.char.active {
  color: var(--text);
  position: relative;
}
.char.active::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 2px;
  background: var(--cursor-clr);
  border-radius: 1px;
  animation: blink 1s steps(1) infinite;
  box-shadow: 0 0 6px var(--accent-glow);
}

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

/* ── TYPE INPUT ── */
.type-input {
  width: 100%;
  min-height: 135px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text);
  resize: none;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow-sm);
  line-height: 1.7;
}

.type-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim), var(--shadow-sm);
}

.type-input::placeholder { color: var(--text-3); }
.type-input:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── RESULT OVERLAY ── */
.result-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15,15,17,0.85);
  backdrop-filter: blur(12px);
  border-radius: var(--radius);
  z-index: 20;
  animation: fadeIn 0.4s ease;
}

[data-theme="light"] .result-overlay {
  background: rgba(240,237,232,0.88);
}

.result-overlay.hidden { display: none; }

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

.result-card {
  text-align: center;
  padding: 40px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  max-width: 360px;
  width: 100%;
}

.result-badge {
  width: 64px; height: 64px;
  background: var(--accent);
  color: #000;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  box-shadow: 0 0 30px var(--accent-glow);
  animation: pulse-badge 1.5s ease infinite;
}

@keyframes pulse-badge {
  0%,100% { box-shadow: 0 0 20px var(--accent-glow); }
  50%      { box-shadow: 0 0 40px var(--accent-glow); }
}

.result-card h2 {
  font-family: var(--font-ui);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

.result-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ri-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-3);
  font-weight: 700;
}

.ri-value {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 28px;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all var(--transition);
  box-shadow: 0 4px 16px var(--accent-glow);
  letter-spacing: 0.02em;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--accent-glow);
  filter: brightness(1.1);
}
.btn-primary:active { transform: translateY(0); }

/* ── MODE PANEL ── */
.mode-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mode-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  position: relative;
  overflow: hidden;
}

.mode-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent-dim);
  opacity: 0;
  transition: opacity var(--transition);
}

.mode-card:hover::after { opacity: 1; }
.mode-card.active::after { opacity: 1; }

.mode-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 4px 16px var(--accent-glow);
}

.mode-icon {
  position: relative; z-index: 1;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  background: var(--surface);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--accent);
  flex-shrink: 0;
  transition: background var(--transition);
}

.mode-card.active .mode-icon {
  background: var(--accent);
  color: #000;
}

.mode-info {
  position: relative; z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
}

.mode-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}

.mode-desc {
  font-size: 0.62rem;
  color: var(--text-3);
  letter-spacing: 0.04em;
}

.mode-check {
  position: relative; z-index: 1;
  font-size: 0.7rem;
  color: var(--accent);
  opacity: 0;
  transition: opacity var(--transition);
}
.mode-card.active .mode-check { opacity: 1; }

/* ── SOUND TOGGLE ── */
.sound-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.toggle-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  letter-spacing: 0.03em;
}

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer;
  inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--border-bright);
  border-radius: 99px;
  transition: background var(--transition);
}
.slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 2px; top: 2px;
  background: var(--text-3);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
}
.switch input:checked + .slider { background: var(--accent-dim); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(16px); background: var(--accent); }

/* ── TIPS BOX ── */
.tips-box {
  background: var(--accent-dim);
  border: 1px solid rgba(240,165,0,0.2);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-top: 4px;
}

.tips-title {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tips-body {
  font-size: 0.72rem;
  color: var(--text-2);
  line-height: 1.55;
}

/* ── ANIMATIONS ── */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.stat-card, .mode-card, .panel {
  animation: slideIn 0.4s ease both;
}
.stat-card:nth-child(2) { animation-delay: 0.05s; }
.stat-card:nth-child(3) { animation-delay: 0.1s; }
.stat-card:nth-child(4) { animation-delay: 0.15s; }
.stat-card:nth-child(5) { animation-delay: 0.2s; }
.mode-card:nth-child(2) { animation-delay: 0.07s; }
.mode-card:nth-child(3) { animation-delay: 0.14s; }

/* Number counter animation */
@keyframes numPop {
  0% { transform: scale(1.25); color: var(--accent); }
  100% { transform: scale(1); }
}
.stat-value.updated { animation: numPop 0.2s ease; }

/* Low-time warning */
.stat-value.warning { color: var(--incorrect) !important; }
.progress-bar.warning {
  background: linear-gradient(90deg, var(--incorrect), #ff9999);
  box-shadow: 0 0 8px rgba(248,113,113,0.5);
}

/* ── RESPONSIVE ── */
@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 200px 1fr 200px;
    gap: 14px;
    padding: 16px;
  }
}

@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .panel {
    position: static;
  }

  .stats-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .panel-title { grid-column: 1 / -1; }
  .progress-wrap { grid-column: 1 / -1; }

  .mode-cards { flex-direction: row; }
  .mode-card { flex: 1; flex-direction: column; text-align: center; }
  .mode-icon { margin: 0 auto; }
  .mode-check { display: none; }

  .sound-row, .tips-box { display: none; }
}

@media (max-width: 520px) {
  .header { padding: 14px 16px; }
  .paragraph-box { padding: 18px 16px; font-size: 0.9rem; }
  .type-input { font-size: 0.85rem; }

  .stats-panel {
    grid-template-columns: 1fr 1fr;
  }

  .stat-value { font-size: 1.2rem; }
  .result-card { padding: 28px 20px; }
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }