* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Pretendard', sans-serif;
  background: var(--egg-bg, #1a1a2e);
  color: var(--egg-text, #e0e0e0);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--egg-brand, #FF6F00);
  color: #fff;
  padding: 8px 16px;
  z-index: 9999;
  border-radius: 0 0 8px 0;
}
.skip-link:focus { top: 0; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 56px 16px 80px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.screen { display: none; width: 100%; }
.screen.active { display: flex; flex-direction: column; align-items: center; }

.title {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--egg-brand, #FF6F00), #ffab40);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  font-size: 0.95rem;
  color: var(--egg-text-secondary, #aaa);
  margin-bottom: 32px;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 400px;
  margin-bottom: 24px;
}

.mode-btn {
  background: var(--egg-surface-raised, #2a2a3e);
  border: 2px solid var(--egg-border, #333);
  border-radius: 12px;
  padding: 20px 16px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  color: var(--egg-text, #e0e0e0);
}
.mode-btn:hover, .mode-btn:focus-visible {
  border-color: var(--egg-brand, #FF6F00);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(255, 111, 0, 0.2);
}
.mode-btn .mode-icon { font-size: 2rem; margin-bottom: 8px; }
.mode-btn .mode-name { font-weight: 700; font-size: 1rem; }
.mode-btn .mode-desc { font-size: 0.8rem; color: var(--egg-text-secondary, #aaa); margin-top: 4px; }

.home-ranking-btn {
  background: var(--egg-surface-raised, #2a2a3e);
  border: 2px solid var(--egg-border, #333);
  border-radius: 12px;
  padding: 12px 32px;
  cursor: pointer;
  color: var(--egg-text, #e0e0e0);
  font-size: 1rem;
  font-weight: 700;
  transition: all 0.2s;
  margin-top: 8px;
}
.home-ranking-btn:hover, .home-ranking-btn:focus-visible {
  border-color: var(--egg-brand, #FF6F00);
  background: var(--egg-brand, #FF6F00);
  color: #fff;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.stat-bar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.stat {
  text-align: center;
}
.stat-label {
  font-size: 0.7rem;
  color: var(--egg-text-secondary, #aaa);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--egg-brand, #FF6F00);
}

.timer-ring {
  width: 56px;
  height: 56px;
  position: relative;
}
.timer-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.timer-ring circle {
  fill: none;
  stroke-width: 4;
}
.timer-ring .bg { stroke: var(--egg-border, #333); }
.timer-ring .fg {
  stroke: var(--egg-brand, #FF6F00);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s;
}
.timer-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
}

.text-display {
  width: 100%;
  background: var(--egg-surface-raised, #2a2a3e);
  border: 2px solid var(--egg-border, #333);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 16px;
  font-size: 1.3rem;
  line-height: 2;
  letter-spacing: 0.02em;
  min-height: 120px;
  position: relative;
  overflow: hidden;
  word-break: break-all;
}

.text-display .char {
  transition: color 0.1s;
}
.text-display .char.correct { color: var(--egg-brand, #FF6F00); }
.text-display .char.wrong { color: #ef4444; text-decoration: underline; }
.text-display .char.current {
  background: rgba(255, 111, 0, 0.25);
  border-radius: 2px;
}
.text-display .char.pending { color: var(--egg-text-secondary, #666); }

.input-area {
  width: 100%;
  position: relative;
}

.type-input {
  width: 100%;
  background: var(--egg-surface, #222236);
  border: 2px solid var(--egg-border, #333);
  border-radius: 12px;
  padding: 16px 20px;
  font-size: 1.2rem;
  color: var(--egg-text, #e0e0e0);
  font-family: 'Pretendard', sans-serif;
  outline: none;
  transition: border-color 0.2s;
}
.type-input:focus {
  border-color: var(--egg-brand, #FF6F00);
}
.type-input::placeholder {
  color: var(--egg-text-secondary, #666);
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--egg-border, #333);
  border-radius: 2px;
  margin-top: 12px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--egg-brand, #FF6F00), #ffab40);
  border-radius: 2px;
  transition: width 0.3s;
  width: 0%;
}

.result-screen {
  text-align: center;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 24px 0;
  width: 100%;
  max-width: 360px;
}

.result-card {
  background: var(--egg-surface-raised, #2a2a3e);
  border: 1px solid var(--egg-border, #333);
  border-radius: 12px;
  padding: 20px 12px;
}
.result-card .result-label {
  font-size: 0.75rem;
  color: var(--egg-text-secondary, #aaa);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.result-card .result-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--egg-brand, #FF6F00);
}
.result-card .result-unit {
  font-size: 0.8rem;
  color: var(--egg-text-secondary, #aaa);
}

.btn-row {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  padding: 12px 28px;
  border-radius: 10px;
  border: none;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Pretendard', sans-serif;
}
.btn-primary {
  background: var(--egg-brand, #FF6F00);
  color: #fff;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-secondary {
  background: var(--egg-surface-raised, #2a2a3e);
  color: var(--egg-text, #e0e0e0);
  border: 2px solid var(--egg-border, #333);
}
.btn-secondary:hover { border-color: var(--egg-brand, #FF6F00); }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.active { display: flex; }

.modal {
  background: var(--egg-surface-raised, #2a2a3e);
  border: 1px solid var(--egg-border, #333);
  border-radius: 16px;
  padding: 28px 24px;
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  overflow-y: auto;
  animation: egg-modalIn 0.25s ease;
}

@keyframes egg-modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal h2 {
  font-size: 1.2rem;
  margin-bottom: 16px;
  text-align: center;
}

.nick-input {
  width: 100%;
  background: var(--egg-surface, #222236);
  border: 2px solid var(--egg-border, #333);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 1rem;
  color: var(--egg-text, #e0e0e0);
  font-family: 'Pretendard', sans-serif;
  outline: none;
  margin-bottom: 12px;
  text-align: center;
}
.nick-input:focus { border-color: var(--egg-brand, #FF6F00); }

.score-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  justify-content: center;
}
.score-tabs button {
  padding: 6px 16px;
  border-radius: 8px;
  border: 1px solid var(--egg-border, #333);
  background: transparent;
  color: var(--egg-text-secondary, #aaa);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: 'Pretendard', sans-serif;
  transition: all 0.2s;
}
.score-tabs button.active {
  background: var(--egg-brand, #FF6F00);
  color: #fff;
  border-color: var(--egg-brand, #FF6F00);
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.score-table th {
  color: var(--egg-text-secondary, #aaa);
  font-weight: 600;
  padding: 8px 4px;
  border-bottom: 1px solid var(--egg-border, #333);
  text-align: center;
}
.score-table td {
  padding: 8px 4px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.score-table tr.highlight {
  background: rgba(255, 111, 0, 0.1);
}
.score-table tr.highlight td { font-weight: 700; }

.loading {
  text-align: center;
  padding: 24px;
  color: var(--egg-text-secondary, #aaa);
}

@media (max-width: 480px) {
  .title { font-size: 1.5rem; }
  .text-display { font-size: 1.1rem; padding: 16px; }
  .type-input { font-size: 1rem; padding: 12px 16px; }
  .mode-grid { grid-template-columns: 1fr; }
  .result-stats { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 1.1rem; }
}
