* {
  box-sizing: border-box;
}

:root {
  --bg: #2c2c2c;
  --panel: #111111;
  --panel-2: #1a1a1a;
  --text: #e5e5e5;
  --muted: #737373;
  --accent: #22d3ee;
  --ok: #22c55e;
  --warn: #ef4444;
  --cursor: #facc15;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "JetBrains Mono", monospace;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 260px;
}

.container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 16px;
}

.page-title {
  margin: 0;
  font-size: clamp(28px, 4vw, 40px);
  color: var(--text);
  letter-spacing: 0.4px;
}

.config-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(1000px, 96vw);
}

.config-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.option-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.option-label {
  color: var(--muted);
  font-size: 14px;
  align-self: center;
  padding: 6px 2px;
}

.config-btn {
  border: 1px solid #262626;
  background: var(--panel);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
}

.config-btn.active {
  border-color: #164e63;
  color: var(--accent);
  background: #082f49;
}

.option-btn {
  border: 1px solid #262626;
  background: var(--panel);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 9px;
  cursor: pointer;
  font: inherit;
}

.option-btn.active {
  border-color: #1d4ed8;
  color: #93c5fd;
  background: #172554;
}

.custom-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.custom-input {
  width: min(900px, 96vw);
  min-height: 90px;
  border: 1px solid #262626;
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 10px;
  font: inherit;
  resize: vertical;
}

.stats {
  text-align: center;
}

.main-stat {
  color: var(--accent);
  font-size: 28px;
  margin-bottom: 8px;
}

.stat-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.stat-chip {
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--panel-2);
}

.typing-wrap {
  width: min(1000px, 96vw);
  position: relative;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  cursor: pointer;
  z-index: 2;
}

.overlay.show {
  display: flex;
}

.overlay span {
  color: #d4d4d4;
}

.typing-area {
  background: var(--panel);
  border: 1px solid #262626;
  border-radius: 14px;
  padding: 16px;
  min-height: 160px;
  line-height: 2;
  font-size: 28px;
  outline: none;
  user-select: none;
  white-space: pre-wrap;
  word-break: break-word;
}

.char {
  color: var(--muted);
}

.char.correct {
  color: #7dd3fc;
}

.char.wrong {
  color: var(--warn);
}

.char.current {
  border-left: 2px solid var(--cursor);
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 49% {
    border-left-color: var(--cursor);
  }
  50%, 100% {
    border-left-color: transparent;
  }
}

.result-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.result-dialog.show {
  display: flex;
}

.result-card {
  background: var(--panel);
  border: 1px solid #262626;
  border-radius: 14px;
  padding: 20px;
  width: min(420px, 90vw);
  text-align: center;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0;
}

.result-value {
  font-size: 24px;
  font-weight: 700;
}

.result-label {
  font-size: 12px;
  color: var(--muted);
}

.reset-btn {
  border: 1px solid #262626;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
}

.hidden {
  display: none;
}

.live-keyboard-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 14px 16px;
  background: transparent;
  z-index: 4;
}

.live-keyboard {
  width: min(1100px, 96vw);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border: 1px solid #273647;
  border-radius: 16px;
  background: #11161d;
  box-shadow: 0 0 0 1px rgba(39, 54, 71, 0.2), 0 8px 24px rgba(0, 0, 0, 0.4);
}

.keyboard-row {
  display: grid;
  grid-template-columns: repeat(30, minmax(0, 1fr));
  gap: 6px;
}

.key {
  grid-column: span 2;
  min-height: 40px;
  border: 1px solid #2a3340;
  border-radius: 8px;
  background: #0f1115;
  color: #c6c8cc;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.key.dual-label {
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  line-height: 1;
}

.key-shift {
  font-size: 10px;
  color: #d7dadf;
}

.key-base {
  font-size: 11px;
  color: #a7adb7;
}

.key.wide-1 {
  grid-column: span 1;
}

.key.wide-3 {
  grid-column: span 3;
}

.key.wide-4 {
  grid-column: span 4;
}

.key.wide-5 {
  grid-column: span 5;
}

.key.wide-6 {
  grid-column: span 6;
}

.key.wide-14 {
  grid-column: span 14;
}

.key.wide-12 {
  grid-column: span 12;
}

.key.wide-11 {
  grid-column: span 11;
}

.key.active {
  border-color: var(--accent);
  color: #67e8f9;
  background: #083344;
  box-shadow: inset 0 0 0 1px rgba(103, 232, 249, 0.35);
}

@media (max-width: 640px) {
  .typing-area {
    font-size: 22px;
  }

  .custom-input {
    min-height: 120px;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }

  body {
    padding-bottom: 220px;
  }

  .live-keyboard-wrap {
    padding: 10px;
  }

  .keyboard-row {
    gap: 4px;
  }

  .key {
    min-height: 30px;
    font-size: 10px;
  }

  .key-shift,
  .key-base {
    font-size: 9px;
  }
}
