/* ============================================================
   FONTS
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Raleway:wght@300;400;500;600;700;800&family=Source+Code+Pro:wght@400;600&family=Nanum+Gothic:wght@400;700&display=swap');

/* ============================================================
   DESIGN TOKENS — Navy Vintage
   ============================================================ */
:root {
  /* Navy palette */
  --navy-950:  #060E1E;
  --navy-900:  #0A1628;
  --navy-800:  #0F2040;
  --navy-700:  #163059;
  --navy-600:  #1E4080;
  --navy-500:  #2B55A0;
  --navy-400:  #4A78C0;
  --navy-300:  #7AAAD8;
  --navy-200:  #AECCE8;
  --navy-100:  #D8EAF5;
  --navy-50:   #EFF5FB;

  /* Brass accent (keeps the vintage warmth) */
  --brass:       #C4A84A;
  --brass-light: #DFC878;
  --brass-dark:  #8A7230;

  /* Semantic */
  --text-on-dark:    #D8EAF5;
  --text-muted-dark: #7AAAD8;
  --text-on-light:   #0F2040;
  --text-muted-light:#2B55A0;
  --correct:         #3AB87A;
  --incorrect:       #E06060;
  --pending:         #5880A8;
  --current-bg:      rgba(196, 168, 74, 0.2);

  /* Shadows (navy-tinted) */
  --shadow-sm: 0 2px 8px  rgba(6, 14, 30, 0.4);
  --shadow-md: 0 4px 20px rgba(6, 14, 30, 0.5);
  --shadow-lg: 0 8px 40px rgba(6, 14, 30, 0.6);

  /* Fonts — all sans-serif */
  --f-head: 'Raleway', 'Segoe UI', sans-serif;
  --f-body: 'Raleway', 'Segoe UI', sans-serif;
  --f-mono: 'Source Code Pro', 'Consolas', monospace;
  --f-ko:   'Nanum Gothic', 'Malgun Gothic', sans-serif;
}

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

html { height: 100%; }

body {
  min-height: 100vh;
  font-family: var(--f-body);
  color: var(--text-on-dark);

  /* Animated deep navy gradient */
  background: linear-gradient(135deg,
    #060E1E, #0F2040, #163059, #1E4080, #163059, #0F2040, #060E1E);
  background-size: 500% 500%;
  animation: bgDrift 18s ease infinite;

  /* Subtle diagonal hatching — vintage chart texture */
  background-image:
    linear-gradient(135deg, #060E1E 0%, #0F2040 40%, #163059 70%, #060E1E 100%),
    repeating-linear-gradient(
      55deg,
      transparent 0px,
      transparent 20px,
      rgba(74, 120, 192, 0.04) 20px,
      rgba(74, 120, 192, 0.04) 21px
    );
}

@keyframes bgDrift {
  0%   { background-position: 0%   50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0%   50%; }
}

/* ============================================================
   SCREEN MANAGEMENT
   ============================================================ */
.screen {
  display: none;
  min-height: 100vh;
  padding: 2rem 1rem;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

/* Landing fills exactly the viewport — no scrollbar */
#screen-landing {
  height: 100vh;
  overflow: hidden;
}

.screen.active {
  display: flex;
  animation: screenIn 0.45s ease both;
}

@keyframes screenIn {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   ORNAMENTAL DIVIDERS
   ============================================================ */
.ornament {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  margin: 0.8rem 0;
}

.orn-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--brass), transparent);
}

.orn-diamond {
  color: var(--brass);
  font-size: 0.75rem;
  filter: drop-shadow(0 0 5px rgba(196,168,74,0.7));
  animation: diamondPulse 3s ease infinite;
}

@keyframes diamondPulse {
  0%, 100% { filter: drop-shadow(0 0 4px rgba(196,168,74,0.45)); }
  50%       { filter: drop-shadow(0 0 12px rgba(196,168,74,0.95)); }
}

.orn-text {
  color: var(--text-muted-dark);
  font-family: var(--f-body);
  font-weight: 400;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  white-space: nowrap;
  text-transform: uppercase;
}

/* ============================================================
   LANDING SCREEN
   ============================================================ */
.landing-card {
  width: 100%;
  max-width: 680px;
  padding: 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;

  background: linear-gradient(160deg,
    rgba(15, 32, 64, 0.96),
    rgba(22, 48, 89, 0.93));
  border: 1px solid rgba(196,168,74,0.45);
  border-radius: 2px;
  box-shadow: var(--shadow-lg), inset 0 0 80px rgba(30,64,128,0.15);

  position: relative;
  overflow: hidden;
}

/* Corner brass accents */
.landing-card::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at top center,
    rgba(74,120,192,0.08) 0%, transparent 65%);
}

/* Title */
.title-block {
  text-align: center;
  margin: 0.75rem 0;
}

.pre-title {
  font-family: var(--f-body);
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--text-muted-dark);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  animation: riseIn 0.7s ease 0.1s both;
}

.main-title {
  font-family: var(--f-head);
  font-size: clamp(1.9rem, 5.5vw, 3.2rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0.04em;
  text-transform: uppercase;

  background: linear-gradient(135deg,
    var(--navy-100) 0%,
    var(--brass-light) 50%,
    var(--brass) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;

  animation: riseIn 0.7s ease 0.25s both;
}

.subtitle-ko {
  font-family: var(--f-ko), var(--f-body);
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--text-muted-dark);
  margin-top: 0.35rem;
  letter-spacing: 0.15em;
  animation: riseIn 0.7s ease 0.4s both;
}

@keyframes riseIn {
  from { opacity: 0; transform: translateY(-14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Language cards */
.lang-row {
  display: flex;
  align-items: stretch;
  gap: 1.5rem;
  margin: 1.25rem 0;
  flex-wrap: wrap;
  justify-content: center;
  animation: riseUp 0.7s ease 0.55s both;
}

@keyframes riseUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.lang-card {
  flex: 1;
  min-width: 170px;
  max-width: 220px;
  padding: 1.75rem 1.25rem;
  cursor: pointer;
  border: 1px solid rgba(74,120,192,0.35);
  border-radius: 16px;
  background: linear-gradient(160deg,
    rgba(22, 48, 89, 0.9),
    rgba(15, 32, 64, 0.85));
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

/* Shimmer sweep on hover */
.lang-card::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg,
    transparent, rgba(196,168,74,0.12), transparent);
  transition: left 0.5s ease;
}
.lang-card:hover::before { left: 100%; }

.lang-card:hover {
  transform: translateY(-5px);
  border-color: var(--brass);
  box-shadow:
    var(--shadow-md),
    0 0 12px rgba(196,168,74,0.5),
    0 0 28px rgba(196,168,74,0.3),
    0 0 55px rgba(196,168,74,0.12);
}
.lang-card:active { transform: translateY(-2px); }

.lang-badge {
  width: 54px; height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brass-light), var(--brass-dark));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--f-head);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--navy-900);
  box-shadow: 0 4px 14px rgba(196,168,74,0.35);
  margin-bottom: 0.35rem;
}

.lang-name {
  font-family: var(--f-head);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-on-dark);
}

.lang-hint {
  font-family: var(--f-body);
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-muted-dark);
  text-align: center;
  line-height: 1.5;
}

.lang-or {
  font-family: var(--f-body);
  font-weight: 300;
  color: var(--text-muted-dark);
  font-size: 0.85rem;
  letter-spacing: 0.1em;
}

/* ============================================================
   TEST SCREEN
   ============================================================ */
.test-wrap {
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

/* Header */
.test-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.25rem;
  background: linear-gradient(135deg,
    rgba(6, 14, 30, 0.96), rgba(15, 32, 64, 0.92));
  border: 1px solid rgba(196,168,74,0.25);
  border-radius: 2px;
  box-shadow: var(--shadow-md);
}

.back-btn {
  background: transparent;
  border: 1px solid rgba(196,168,74,0.3);
  color: var(--brass-light);
  padding: 0.4rem 0.85rem;
  border-radius: 2px;
  cursor: pointer;
  font-family: var(--f-body);
  font-weight: 500;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.back-btn:hover {
  background: rgba(196,168,74,0.12);
  border-color: var(--brass);
  color: var(--brass);
}

.lang-badge-sm {
  font-family: var(--f-head);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--navy-200);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.timer-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.timer-num {
  font-family: var(--f-head);
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--brass-light);
  transition: color 0.3s;
  min-width: 2.4ch;
  text-align: center;
}

.timer-num.danger {
  color: #FF8888;
  animation: timerPulse 0.9s ease infinite;
}

@keyframes timerPulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.1); }
}

.timer-label {
  font-family: var(--f-body);
  font-weight: 400;
  font-size: 0.58rem;
  color: rgba(196,168,74,0.55);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  margin-top: 0.1rem;
}

/* Stats row */
.stats-row {
  display: flex;
  gap: 0.75rem;
}

.stat-box {
  flex: 1;
  padding: 0.7rem 0.75rem;
  background: linear-gradient(160deg,
    rgba(15, 32, 64, 0.9), rgba(22, 48, 89, 0.85));
  border: 1px solid rgba(74,120,192,0.3);
  border-radius: 2px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-val {
  font-family: var(--f-head);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
  background: linear-gradient(135deg, var(--navy-100), var(--brass-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-lbl {
  font-family: var(--f-body);
  font-weight: 500;
  font-size: 0.62rem;
  color: var(--text-muted-dark);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  margin-top: 0.2rem;
}

/* Passage */
.passage-wrap {
  position: relative;
  padding: 1.75rem 2rem;
  min-height: 140px;
  background: linear-gradient(160deg,
    rgba(10, 22, 40, 0.97) 0%,
    rgba(15, 32, 64, 0.95) 100%);
  border: 1px solid rgba(74,120,192,0.3);
  border-radius: 2px;
  box-shadow: var(--shadow-md), inset 0 0 50px rgba(30,64,128,0.1);
}

.passage-text {
  font-family: var(--f-mono);
  font-size: 1.1rem;
  font-weight: 400;
  line-height: 2;
  color: var(--pending);
  word-wrap: break-word;
  white-space: pre-wrap;
  user-select: none;
}

.passage-text.ko {
  font-family: var(--f-ko), var(--f-mono);
  font-size: 1.1rem;
  line-height: 2.1;
}

/* Character states */
.ch {
  position: relative;
  display: inline;
  transition: color 0.07s ease;
}

.ch.correct   { color: var(--correct); }
.ch.incorrect {
  color: var(--incorrect);
  text-decoration: underline;
  text-decoration-color: rgba(224,96,96,0.4);
}

.ch.current {
  color: var(--brass-light);
  background: var(--current-bg);
  border-radius: 2px;
  padding: 0 1px;
}

/* Cursor underline on current char */
.ch.current::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0;
  width: 100%; height: 2px;
  background: var(--brass);
  border-radius: 1px;
  animation: blink 0.75s ease infinite;
}

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

/* Correct flash */
.ch.flash-ok {
  animation: flashOK 0.35s ease forwards;
}
@keyframes flashOK {
  0%   { background: rgba(58, 184, 122, 0.3); border-radius: 2px; }
  100% { background: transparent; }
}

/* Incorrect shake */
.ch.flash-err {
  animation: flashErr 0.3s ease forwards;
}
@keyframes flashErr {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-3px); }
  75%      { transform: translateX(3px); }
}

/* Veil overlay */
.passage-veil {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 22, 40, 0.82);
  backdrop-filter: blur(3px);
  border-radius: 2px;
  cursor: text;
}
.passage-veil.hidden { display: none; }
.passage-veil span {
  font-family: var(--f-body);
  font-weight: 400;
  font-size: 0.88rem;
  color: var(--text-muted-dark);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  animation: veilPulse 2.5s ease infinite;
}
@keyframes veilPulse {
  0%, 100% { opacity: 0.6; }
  50%       { opacity: 1; }
}

/* Progress bar */
.progress-track {
  height: 3px;
  background: rgba(74,120,192,0.15);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg,
    var(--brass-dark), var(--brass), var(--brass-light));
  border-radius: 2px;
  transition: width 0.25s ease;
  box-shadow: 0 0 8px rgba(196,168,74,0.5);
}

/* Typing textarea */
.input-wrap { position: relative; }

.typing-input {
  width: 100%;
  padding: 1rem 1.25rem;
  background: linear-gradient(160deg,
    rgba(15, 32, 64, 0.92), rgba(22, 48, 89, 0.88));
  border: 1px solid rgba(74,120,192,0.3);
  border-radius: 2px;
  font-family: var(--f-mono);
  font-size: 1rem;
  color: var(--text-on-dark);
  resize: none;
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
  line-height: 1.6;
}
.typing-input:focus {
  border-color: var(--brass);
  box-shadow: 0 0 0 3px rgba(196,168,74,0.18), var(--shadow-sm);
}
.typing-input.ko {
  font-family: var(--f-ko), var(--f-mono);
  font-size: 1.05rem;
}
.typing-input::placeholder {
  color: var(--pending);
  font-weight: 400;
  font-size: 0.9rem;
  letter-spacing: 0.05em;
}
.typing-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================
   RESULT SCREEN
   ============================================================ */
.result-card {
  width: 100%;
  max-width: 580px;
  padding: 2.5rem 2.25rem;
  background: linear-gradient(160deg,
    rgba(10, 22, 40, 0.97), rgba(22, 48, 89, 0.94));
  border: 1px solid rgba(196,168,74,0.4);
  border-radius: 2px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  animation: resultReveal 0.55s ease both;
}

@keyframes resultReveal {
  from { opacity: 0; transform: scale(0.94) translateY(22px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

.result-title {
  font-family: var(--f-head);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--navy-100), var(--brass-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.result-sub {
  font-family: var(--f-body);
  font-weight: 400;
  color: var(--text-muted-dark);
  font-size: 0.85rem;
  margin-top: -0.5rem;
  letter-spacing: 0.06em;
}

/* Main speed box */
.result-main-box {
  width: 100%;
  text-align: center;
  padding: 1.75rem 1rem;
  background: linear-gradient(135deg,
    rgba(6, 14, 30, 0.97), rgba(10, 22, 40, 0.95));
  border: 1px solid rgba(196,168,74,0.2);
  border-radius: 2px;
  box-shadow: var(--shadow-md);
}

.result-speed-num {
  font-family: var(--f-head);
  font-size: clamp(4rem, 12vw, 6rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg,
    var(--brass-light), var(--brass), var(--brass-dark));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 20px rgba(196,168,74,0.4));
}

.result-speed-unit {
  font-family: var(--f-head);
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--brass);
  letter-spacing: 0.3em;
  margin-top: 0.3rem;
  text-transform: uppercase;
}

.result-speed-desc {
  font-family: var(--f-body);
  font-weight: 400;
  font-size: 0.65rem;
  color: rgba(196,168,74,0.5);
  text-transform: uppercase;
  letter-spacing: 0.22em;
  margin-top: 0.3rem;
}

/* Stats grid */
.result-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  width: 100%;
}

.r-stat {
  text-align: center;
  padding: 0.75rem 0.5rem;
  background: rgba(30, 64, 128, 0.2);
  border: 1px solid rgba(74,120,192,0.25);
  border-radius: 2px;
}

.r-stat-val {
  font-family: var(--f-head);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-on-dark);
}

.r-stat-lbl {
  font-family: var(--f-body);
  font-weight: 500;
  font-size: 0.6rem;
  color: var(--text-muted-dark);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  margin-top: 0.2rem;
}

/* Performance quote */
.result-quote {
  font-family: var(--f-body);
  font-weight: 400;
  font-style: italic;
  color: var(--navy-200);
  text-align: center;
  font-size: 0.9rem;
  line-height: 1.65;
  padding: 0.65rem 1.25rem;
  border-left: 3px solid var(--brass);
  background: rgba(196,168,74,0.06);
  border-radius: 0 2px 2px 0;
  width: 100%;
}

/* Action buttons */
.result-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 0.25rem;
}

.btn-primary, .btn-secondary {
  padding: 0.7rem 1.9rem;
  border-radius: 2px;
  font-family: var(--f-body);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: linear-gradient(135deg,
    var(--brass-light), var(--brass), var(--brass-dark));
  border: none;
  color: var(--navy-900);
  box-shadow: 0 4px 16px rgba(196,168,74,0.35);
}
.btn-primary::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg,
    transparent, rgba(255,255,255,0.22), transparent);
  transition: left 0.4s ease;
}
.btn-primary:hover::before { left: 100%; }
.btn-primary:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 24px rgba(196,168,74,0.5);
}

.btn-secondary {
  background: transparent;
  border: 1px solid rgba(74,120,192,0.4);
  color: var(--navy-300);
}
.btn-secondary:hover {
  border-color: var(--brass);
  color: var(--brass-light);
  background: rgba(196,168,74,0.07);
  transform: translateY(-3px);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 540px) {
  .landing-card          { padding: 1.75rem 1.25rem; }
  .test-header           { flex-wrap: wrap; gap: 0.5rem; }
  .passage-wrap          { padding: 1.25rem 1rem; }
  .passage-text          { font-size: 0.95rem; }
  .result-stats-grid     { grid-template-columns: repeat(2, 1fr); }
  .timer-num             { font-size: 1.6rem; }
}
