:root {
  --bg: #15161a;
  --panel: #1e2025;
  --panel-2: #26282f;
  --ink: #e9e7e2;
  --dim: #6b6e78;
  --dimmer: #45474f;
  --amber: #ffb454;
  --green: #7fd858;
  --red: #ff6b6b;
  --line: #33353c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Hind Siliguri', 'IBM Plex Mono', monospace;
  display: flex;
  justify-content: center;
  align-items: center;
}

.app-viewport {
  width: 100%;
  max-width: 100%;
  height: 100vh;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}

.brand .key {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 700;
  font-size: 13px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom: 3px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  color: var(--amber);
}

h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
  text-align: center;
}

.sub {
  color: var(--dim);
  font-size: 12px;
}

/* Dashboard Layout - 3 Columns (Left Sidebar + Expanded Center Stage + Right Sidebar) */
.main-layout {
  display: grid;
  grid-template-columns: 260px 1fr 280px;
  gap: 18px;
  flex: 1;
  min-height: 0;
}

.sidebar-left {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.sidebar-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.center-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  justify-content: center;
}

.controls-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  flex: 1;
  overflow-y: auto;
}

.controls-card h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13px;
  color: var(--dim);
  margin-top: 0;
  margin-bottom: 10px;
}

.controls-vertical {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-label {
  font-size: 11px;
  color: var(--dimmer);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.controls-vertical .seg {
  flex-wrap: wrap;
}

.controls-vertical .seg button {
  flex: 1;
  padding: 6px 10px;
  font-size: 12px;
}

.actions-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

.actions-card h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  color: var(--dim);
  margin-top: 0;
  margin-bottom: 12px;
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-buttons .btn {
  width: 100%;
  text-align: center;
}

/* History in Sidebar */
.history {
  margin-top: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.history h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  color: var(--dim);
  font-weight: 600;
  margin-top: 0;
  margin-bottom: 10px;
}

#historyList {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

#historyList::-webkit-scrollbar {
  display: none;
}

#restartBtn {
  background: var(--panel-2);
  color: var(--amber);
}

footer {
  margin-top: 8px;
  color: var(--dimmer);
  font-size: 11px;
  text-align: center;
}

/* controls */
.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.seg {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.seg button {
  background: transparent;
  border: none;
  color: var(--dim);
  font-family: 'Hind Siliguri', sans-serif;
  font-size: 13px;
  padding: 7px 14px;
  cursor: pointer;
  transition: all .15s;
}

.seg button.active {
  background: var(--panel-2);
  color: var(--amber);
}

.seg button:hover:not(.active) {
  color: var(--ink);
}

/* stat keycaps */
.stats {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.cap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom: 3px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  min-width: 76px;
  flex: 1;
  text-align: center;
}

.cap .n {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.1;
}

.cap .l {
  font-size: 10px;
  color: var(--dim);
  margin-top: 2px;
  letter-spacing: .03em;
}

.cap.live .n {
  color: var(--amber);
}

.cap.green-cap .n {
  color: var(--green);
}

.cap.red-cap .n {
  color: var(--red);
}

/* typing stage */
.stage {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 24px;
  position: relative;
  cursor: text;
  overflow-y: auto;
  flex: 1;
  min-height: 120px;
  max-height: 170px;
  scroll-behavior: smooth;
}

.stage::-webkit-scrollbar {
  display: none;
}

.stage {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

#passage {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 19px;
  line-height: 1.8;
  letter-spacing: 0.2px;
  color: var(--dimmer);
  user-select: none;
  word-break: normal;
  overflow-wrap: break-word;
}

#passage.bangla {
  font-family: 'Hind Siliguri', sans-serif;
  font-size: 20px;
}

#passage span {
  position: relative;
}

#passage span.correct {
  color: #ffffff;
  font-weight: 500;
}

#passage span.incorrect {
  color: var(--red);
  background: rgba(255, 107, 107, 0.12);
  border-radius: 3px;
}

#passage span.current {
  color: var(--amber);
  border-bottom: 2px solid var(--amber);
}

#hiddenInput {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(21, 22, 26, 0.88);
  border-radius: 14px;
  font-size: 15px;
  color: var(--dim);
  text-align: center;
  padding: 20px;
  z-index: 10;
}

.overlay b {
  color: var(--amber);
}

.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 18px;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: 'Hind Siliguri', sans-serif;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 9px;
  cursor: pointer;
  transition: all .15s;
  border-bottom: 3px solid var(--line);
}

.btn:hover {
  border-color: var(--amber);
  color: var(--amber);
}

.btn.primary {
  background: var(--amber);
  color: #1a1200;
  border-color: var(--amber);
  font-weight: 600;
}

.btn.primary:hover {
  color: #1a1200;
  opacity: .9;
}

/* virtual keyboard */
.keyboard-panel {
  margin-top: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  user-select: none;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.kb-key {
  height: 38px;
  min-width: 36px;
  padding: 0 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom: 3px solid var(--line);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  font-weight: 500;
  color: var(--dim);
  transition: all 0.08s ease;
}

.kb-key.space {
  width: 260px;
}

.kb-key.wide {
  min-width: 55px;
}

.kb-key.active {
  background: var(--amber) !important;
  color: #1a1200 !important;
  font-weight: 700;
  border-color: var(--amber) !important;
  transform: translateY(2px);
  box-shadow: 0 0 12px rgba(255, 180, 84, 0.4);
}

/* history */
.history {
  margin-top: 0;
}

.history h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  color: var(--dim);
  font-weight: 600;
  margin-bottom: 8px;
}

.hrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
}

.hrow .d {
  color: var(--dim);
  font-size: 10px;
  flex-shrink: 0;
}

.hrow .wpm {
  font-family: 'IBM Plex Mono', monospace;
  color: var(--amber);
  font-weight: 700;
  font-size: 12px;
}

.hrow .acc {
  color: var(--green);
  font-size: 11px;
}

.hrow .tag {
  font-size: 10px;
  color: var(--dim);
  background: var(--panel-2);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

.empty {
  color: var(--dim);
  font-size: 12px;
  padding: 10px 2px;
}

footer {
  margin-top: 6px;
  color: var(--dimmer);
  font-size: 10px;
  text-align: center;
}

/* Result Modal Overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 16, 20, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 30px;
  width: 90%;
  max-width: 440px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  transform: translateY(20px);
  transition: all 0.25s ease;
}

.modal-overlay.active .modal-card {
  transform: translateY(0);
}

.modal-card h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 20px;
  color: var(--amber);
  margin-top: 0;
  margin-bottom: 20px;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.modal-item {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

.modal-item .num {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 24px;
  font-weight: 700;
}

.modal-item .lbl {
  font-size: 11px;
  color: var(--dim);
  margin-top: 4px;
}