* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Malgun Gothic", sans-serif;
}

body {
  background-color: #f1f5f9;
  color: #334155;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 24px 0;
  overflow-x: hidden;
}

/* =====================================================================
   접속 로딩 화면 & Fade-in
   ===================================================================== */
.loading-screen {
  position: fixed;
  inset: 0;
  background-color: #f8fafc;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 18px;
  z-index: 9999;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.5s;
}

.loading-screen.fade-out {
  opacity: 0;
  visibility: hidden;
}

.spinner {
  width: 46px;
  height: 46px;
  border: 4px solid #e2e8f0;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 1.05rem;
  font-weight: 600;
  color: #64748b;
  letter-spacing: -0.2px;
}

.fade-init {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.55s cubic-bezier(0.16, 1, 0.3, 1), transform 0.55s cubic-bezier(0.16, 1, 0.3, 1);
}

.fade-in {
  opacity: 1 !important;
  transform: translateY(0) !important;
}

/* =====================================================================
   메인 로비(모드 선택) 화면
   ===================================================================== */
.lobby-container {
  width: 860px;
  max-width: 92%;
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 12px 38px rgba(0, 0, 0, 0.07), 0 1px 3px rgba(0, 0, 0, 0.04);
  padding: 44px 40px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

.lobby-container.hidden {
  display: none !important;
}

.lobby-header {
  text-align: center;
}

.lobby-logo {
  font-size: 2.1rem;
  color: #2563eb;
  font-weight: 900;
  letter-spacing: -1px;
  margin-bottom: 8px;
}

.lobby-sub {
  font-size: 1rem;
  color: #64748b;
  font-weight: 600;
}

.mode-card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  width: 100%;
}

.mode-card {
  background: #f8fafc;
  border: 1.8px solid #e2e8f0;
  border-radius: 14px;
  padding: 22px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.mode-card:hover {
  background: #ffffff;
  border-color: #2563eb;
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.12);
}

.card-icon {
  font-size: 2.3rem;
  line-height: 1;
  flex-shrink: 0;
}

.card-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-title {
  font-size: 1.25rem;
  color: #0f172a;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.mode-card:hover .card-title {
  color: #2563eb;
}

.card-desc {
  font-size: 0.86rem;
  color: #64748b;
  font-weight: 500;
  line-height: 1.35;
}

/* =====================================================================
   메인 타자연습 컨테이너
   ===================================================================== */
.typing-container {
  width: 920px;
  max-width: 95%;
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.typing-container.hidden {
  display: none !important;
}

/* 상단 헤더 */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 18px;
}

.logo {
  font-size: 1.35rem;
  color: #2563eb;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.logo.clickable {
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.logo.clickable:hover {
  opacity: 0.85;
}

.mode-nav {
  display: flex;
  gap: 6px;
}

.mode-btn, .sub-btn {
  border: 1px solid transparent;
  background: #f1f5f9;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-btn:hover, .sub-btn:hover {
  background: #e2e8f0;
  color: #1e293b;
}

.mode-btn.active, .sub-btn.active {
  background: #2563eb;
  color: #ffffff;
}

.header-right {
  display: flex;
  gap: 6px;
}

.header-action-btn {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 0.83rem;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s ease;
}

.header-action-btn:hover {
  background: #f8fafc;
  color: #1e293b;
  border-color: #94a3b8;
}

.header-action-btn.off {
  background: #fef2f2;
  border-color: #fecaca;
  color: #ef4444;
}

/* 서브 메뉴 바 */
.sub-menu-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
}

.sub-btn {
  padding: 5px 11px;
  font-size: 0.82rem;
}

/* 장문 완독 셀렉트 드롭다운 */
.song-select-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.song-select-label {
  font-size: 0.86rem;
  font-weight: 700;
  color: #475569;
  user-select: none;
}

.select-wrapper {
  position: relative;
  flex: 1;
  max-width: 440px;
}

.song-select {
  width: 100%;
  padding: 7px 34px 7px 12px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #1e293b;
  background-color: #ffffff;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.song-select:hover {
  border-color: #94a3b8;
}

.song-select:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* =====================================================================
   대시보드 (오도미터 듀얼 롤링 넘버)
   ===================================================================== */
.dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stat-label {
  font-size: 0.8rem;
  color: #64748b;
  margin-bottom: 4px;
  font-weight: 600;
}

.stat-value-group {
  display: flex;
  align-items: baseline;
  gap: 4px;
  overflow: visible;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: #0f172a;
  display: inline-block;
  will-change: transform, opacity;
}

.stat-value.highlight {
  color: #2563eb;
}

.stat-unit {
  font-size: 0.85rem;
  color: #64748b;
}

/* 롤링 숫자 슬롯 */
.time-group {
  display: inline-flex;
  align-items: center;
}

.digit-box {
  position: relative;
  display: inline-block;
  width: 0.64em;
  height: 1.25em;
  line-height: 1.25em;
  overflow: hidden;
  vertical-align: -0.06em;
}

.digit-val {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  transform: translateY(0%);
  will-change: transform;
}

.time-colon {
  display: inline-block;
  margin: 0 1.5px;
  font-weight: 600;
  opacity: 0.75;
}

/* 정확도 하락 / 띠용~ 관성 */
.acc-drop {
  animation: accFall 0.35s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}

@keyframes accFall {
  0% { transform: translateY(-55%); opacity: 0.3; color: #ef4444; }
  70% { transform: translateY(6%); color: #ef4444; }
  100% { transform: translateY(0); opacity: 1; }
}

.acc-bounce-up {
  animation: accBounce 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes accBounce {
  0% { transform: translateY(60%) scale(0.9); opacity: 0.3; color: #2563eb; }
  45% { transform: translateY(-16%) scale(1.15); color: #2563eb; }
  70% { transform: translateY(5%) scale(0.97); }
  88% { transform: translateY(-2%) scale(1.02); }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

.progress-card {
  grid-column: 1 / -1;
  padding: 10px 18px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.progress-text {
  font-size: 0.9rem;
  font-weight: 700;
  color: #2563eb;
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: #2563eb;
  transition: width 0.2s ease;
}

/* =====================================================================
   타자 연습 보드 & 3초 카운트다운 오버레이
   ===================================================================== */
.practice-area {
  width: 100%;
}

.practice-board {
  position: relative;
  width: 100%;
  background: #ffffff;
  border: 1.5px solid #cbd5e1;
  border-radius: 16px;
  padding: 24px 28px;
  cursor: text;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.03);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.practice-board:focus-within {
  border-color: #2563eb;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

/* 3초 카운트다운 오버레이 */
.countdown-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  z-index: 50;
  user-select: none;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.countdown-overlay.hidden {
  display: none !important;
}

.countdown-number {
  font-size: 3.8rem;
  font-weight: 900;
  color: #2563eb;
  line-height: 1;
  will-change: transform, opacity;
}

.countdown-number.pop {
  animation: countdownPop 0.65s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes countdownPop {
  0% { transform: scale(1.6); opacity: 0.2; }
  50% { transform: scale(0.95); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.countdown-sub {
  font-size: 0.95rem;
  font-weight: 600;
  color: #64748b;
}

/* 피드 슬롯 */
.sentence-slot {
  width: 100%;
  will-change: transform, opacity;
}

/* 1단: 당장 입력해야 할 구역 (1.65rem) */
.slot-current {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.text-line {
  width: 100%;
  display: block;
  text-align: left;
  margin: 0;
  padding: 0;
}

.line-content {
  display: block;
  text-align: left;
  margin: 0;
  padding: 0;
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: 2px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: none;
}

.target-char-done {
  color: #0f172a;
}

.target-char-pending {
  color: #94a3b8;
}

.input-line {
  border-top: 1px solid #f1f5f9;
  padding-top: 10px;
}

.user-char-correct {
  color: #2563eb;
}

.user-char-wrong {
  color: #ef4444;
  background-color: #fee2e2;
  border-radius: 3px;
  text-decoration: underline;
}

.blinking-cursor {
  display: inline-block;
  font-weight: 300;
  color: #2563eb;
  margin-left: 1px;
  animation: blink 0.9s infinite;
}

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

/* 2단: 그 다음 입력할 문장 (1.25rem) */
.slot-next {
  padding-top: 14px;
  border-top: 1px dashed #e2e8f0;
  margin-bottom: 8px;
  font-size: 1.25rem;
  opacity: 0.7;
}

.preview-text {
  font-size: inherit;
  font-weight: 500;
  color: #64748b;
  letter-spacing: 1.5px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: none;
  text-align: left;
}

/* 3단: 그 다음다음 입력할 문장 (0.95rem) */
.slot-after {
  margin-bottom: 4px;
  font-size: 0.95rem;
  opacity: 0.4;
}

/* 실제 인풋 필드 및 에러 흔들림 */
.hidden-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: text;
  z-index: 5;
}

.practice-board.input-error {
  border-color: #ef4444 !important;
  background-color: #fffbfb;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.15) !important;
  animation: shake 0.25s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
}

/* =====================================================================
   가상 키보드
   ===================================================================== */
.keyboard-wrapper {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  user-select: none;
}

.keyboard-wrapper.hidden {
  display: none !important;
}

.key-row {
  display: flex;
  gap: 5px;
  width: 100%;
}

.key {
  flex: 1;
  height: 42px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: #475569;
  box-shadow: 0 2px 0 #cbd5e1;
  cursor: default;
  transition: background-color 0.05s, transform 0.05s, box-shadow 0.05s;
  line-height: 1.1;
}

.key span.ko {
  font-weight: 700;
  font-size: 0.85rem;
  color: #1e293b;
}

.key span.en {
  font-size: 0.65rem;
  color: #94a3b8;
}

.key-backspace { flex: 1.6; font-size: 0.75rem; }
.key-tab { flex: 1.25; font-size: 0.75rem; }
.key-backslash { flex: 1.25; }
.key-caps { flex: 1.4; font-size: 0.75rem; }
.key-enter { flex: 1.8; font-size: 0.75rem; font-weight: 600; }
.key-shift { flex: 2.1; font-size: 0.75rem; }
.key-space { flex: 6; font-size: 0.8rem; font-weight: 600; color: #64748b; }

.key.key-active {
  background-color: #2563eb !important;
  color: #ffffff !important;
  border-color: #1d4ed8 !important;
  box-shadow: 0 0 0 #1d4ed8 !important;
  transform: translateY(2px);
}

.key.key-active span.ko,
.key.key-active span.en {
  color: #ffffff !important;
}

/* 모달 */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #ffffff;
  padding: 32px 38px;
  border-radius: 18px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.12);
  width: 360px;
}

.modal-content h2 {
  font-size: 1.5rem;
  color: #2563eb;
  margin-bottom: 20px;
}

.result-stats {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 22px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1rem;
  color: #475569;
}

.result-val strong {
  font-size: 1.25rem;
  color: #0f172a;
}

.modal-btn-group {
  display: flex;
  gap: 8px;
}

.modal-sub-btn {
  flex: 1;
  padding: 12px 0;
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.modal-sub-btn:hover {
  background: #e2e8f0;
  color: #1e293b;
}

.restart-btn {
  flex: 1.5;
  padding: 12px 0;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.restart-btn:hover {
  background: #1d4ed8;
}
