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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  touch-action: manipulation;
}

.container {
  background: #16213e;
  padding: 20px;
  border-radius: 16px;
  width: 100%;
  max-width: 1100px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  overflow-x: auto;
}

.main-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.symbol-stats-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.symbol-stats {
  width: 180px;
  min-width: 180px;
  background: #0f3460;
  border-radius: 8px;
  padding: 10px;
  text-align: left;
}

.symbol-stats.collapsed,
.keyboard-wrapper.collapsed {
  display: none;
}

.collapse-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 180px;
  padding: 8px 12px;
  background: #0f3460;
  border: none;
  border-radius: 8px;
  color: #eee;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.collapse-toggle:hover {
  background: #1a4a7a;
}

.collapse-toggle:focus-visible {
  outline: 2px solid #e94560;
  outline-offset: 2px;
}

.collapse-icon {
  font-size: 0.7rem;
  transition: transform 0.2s;
  color: #4ade80;
}

.collapse-toggle[aria-expanded="false"] .collapse-icon {
  transform: rotate(-90deg);
}

.symbol-stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  margin-bottom: 10px;
}

.symbol-stats-header .overall-label {
  font-weight: bold;
  color: #eee;
}

.symbol-stats-header .overall-count {
  color: #888;
  font-size: 0.85rem;
}

.symbol-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.symbol-stats-separator {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 8px 0;
}

.symbol-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 2px;
  border-radius: 4px;
  font-size: 0.7rem;
}

.symbol-stat.neutral {
  color: #888;
}

.symbol-stat.good {
  background: rgba(74, 222, 128, 0.15);
  color: #4ade80;
}

.symbol-stat.caution {
  background: rgba(250, 204, 21, 0.15);
  color: #facc15;
}

.symbol-stat.needs-work {
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
}

.symbol-char {
  font-weight: bold;
  min-width: 24px;
}

.symbol-pct {
  flex: 1;
  text-align: center;
}

.symbol-count {
  color: #666;
  font-size: 0.75rem;
}

.no-stats {
  color: #666;
  font-size: 0.85rem;
  text-align: center;
  padding: 20px 10px;
}

.main-content {
  flex: 1;
  min-width: 0;
}

h1 {
  font-size: 1.8rem;
  margin-bottom: 20px;
  color: #e94560;
}

.version {
  font-size: 0.9rem;
  color: #eee;
  background: #0f3460;
  padding: 4px 8px;
  border-radius: 4px;
  position: absolute;
  top: 10px;
  right: 10px;
  pointer-events: none;
}

.mode-toggle {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.mode-btn {
  flex: 1;
  padding: 12px;
  border: 2px solid #0f3460;
  background: transparent;
  color: #888;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
}

.mode-btn.active {
  border-color: #e94560;
  color: #e94560;
  background: rgba(233, 69, 96, 0.1);
}

.mode-btn:focus-visible,
.keyboard-btn:focus-visible,
.play-btn:focus-visible,
.play-target-btn:focus-visible,
.tap-btn:focus-visible,
.reset-btn:focus-visible {
  outline: 2px solid #e94560;
  outline-offset: 2px;
}

.settings {
  margin-bottom: 20px;
}

.settings label {
  display: block;
  margin-bottom: 8px;
  color: #888;
}

#wpmSlider {
  width: 100%;
  accent-color: #e94560;
}

.character-select {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.character-select label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #888;
  cursor: pointer;
}

.character-select input[type="checkbox"] {
  accent-color: #e94560;
}

.mode-content {
  margin-bottom: 20px;
}

.hidden {
  display: none;
}

.play-btn {
  background: #e94560;
  color: white;
  border: none;
  padding: 15px 40px;
  font-size: 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s;
}

.play-btn:hover {
  background: #ff5a7a;
}

.play-btn:active {
  transform: scale(0.95);
}

.input-area {
  display: flex;
  gap: 10px;
  margin-top: 15px;
}

#answerInput {
  flex: 1;
  padding: 12px;
  font-size: 1.2rem;
  text-align: center;
  text-transform: uppercase;
  border: 2px solid #0f3460;
  background: #0f3460;
  color: #eee;
  border-radius: 8px;
  outline: none;
}

#answerInput:focus {
  border-color: #e94560;
}

.hint {
  color: #888;
  margin-bottom: 15px;
}

.tap-btn {
  background: #0f3460;
  color: #eee;
  border: none;
  padding: 40px;
  font-size: 2rem;
  border-radius: 50%;
  width: 150px;
  height: 150px;
  cursor: pointer;
  transition: all 0.1s;
  user-select: none;
}

.tap-btn:active,
.tap-btn.active {
  background: #e94560;
  transform: scale(0.95);
}

.tap-hint {
  color: #666;
  font-size: 0.85rem;
  margin-top: 10px;
}

.transmit-target {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-bottom: 20px;
  color: #888;
}

.target-char {
  font-size: 2rem;
  font-weight: bold;
  color: #e94560;
  min-width: 40px;
}

.play-target-btn {
  padding: 8px 16px;
  background: #0f3460;
  color: #eee;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.transmit-feedback {
  margin-top: 15px;
  font-size: 1.2rem;
  min-height: 30px;
}

.transmit-feedback.correct {
  color: #4ade80;
}

.transmit-feedback.incorrect {
  color: #f87171;
}

.scoreboard {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin-bottom: 20px;
}

.score {
  background: #0f3460;
  padding: 15px 25px;
  border-radius: 8px;
  min-width: 100px;
}

.score .count {
  display: block;
  font-size: 2rem;
  font-weight: bold;
}

.score .label {
  color: #888;
  font-size: 0.9rem;
}

.score.correct .count {
  color: #4ade80;
}

.score.incorrect .count {
  color: #f87171;
}

.reset-btn {
  background: transparent;
  color: #888;
  border: 1px solid #0f3460;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.reset-btn:hover {
  border-color: #e94560;
  color: #e94560;
}

.feedback {
  margin-top: 15px;
  font-size: 1.2rem;
  height: 30px;
}

.feedback.correct {
  color: #4ade80;
}

.feedback.incorrect {
  color: #f87171;
}

.keyboard-wrapper {
  margin-top: 15px;
}

#keyboardToggle {
  width: auto;
  margin: 25px auto 10px;
}

#keyboardToggle + .keyboard-wrapper {
  border-top: 1px solid #0f3460;
  padding-top: 20px;
}

.keyboard {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
  display: flex;
  gap: 30px;
  justify-content: center;
}

.keyboard-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.keyboard-numpad {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.keyboard-punctuation {
  display: flex;
  justify-content: center;
  gap: 6px;
  border-top: 1px dashed #0f3460;
  margin-top: 10px;
  padding-top: 10px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 4px;
}

.keyboard-btn {
  width: 32px;
  height: 38px;
  background: #0f3460;
  border: none;
  border-radius: 6px;
  color: #eee;
  font-size: 0.85rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.keyboard-btn:hover {
  background: #1a4a7a;
}

.keyboard-btn:active,
.keyboard-btn.active {
  background: #e94560;
  transform: scale(0.95);
}

.keyboard-btn .morse {
  font-size: 0.65rem;
  color: #888;
  margin-top: 2px;
}

.keyboard-btn.active .morse {
  color: #eee;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================
   Mobile Responsive Styles
   ============================================ */

/* Tablet portrait and below */
@media (max-width: 768px) {
  /* Reduce body padding on mobile */
  body {
    padding: 10px;
  }

  .container {
    padding: 15px;
  }

  /* Stack layout vertically - stats on top */
  .main-layout {
    flex-direction: column;
    align-items: center;
  }

  /* On mobile: stats below keyboard (order determines position) */
  .symbol-stats-wrapper {
    order: 2;
    width: 100%;
    max-width: 300px;
  }

  .main-content {
    order: 1;
    width: 100%;
  }

  .collapse-toggle,
  .symbol-stats {
    width: 100%;
    max-width: 100%;
  }

  .collapse-toggle {
    justify-content: center;
    gap: 8px;
  }

  /* On mobile: hide stats by default, show when NOT collapsed */
  .symbol-stats {
    display: none;
  }

  /* When stats toggle is expanded, show the stats panel */
  .symbol-stats:not(.collapsed) {
    display: block;
  }

  /* Adjust title size */
  h1 {
    font-size: 1.5rem;
    margin-bottom: 15px;
  }

  /* Smaller mode buttons */
  .mode-btn {
    padding: 10px 8px;
    font-size: 0.9rem;
  }

  /* Adjust character select spacing */
  .character-select {
    gap: 10px;
  }

  .character-select label {
    font-size: 0.9rem;
  }

  /* Smaller play button */
  .play-btn {
    padding: 12px 25px;
    font-size: 1rem;
  }

  /* Smaller input */
  #answerInput {
    padding: 10px;
    font-size: 1rem;
  }

  /* Smaller tap button - reduce from 150px */
  .tap-btn {
    width: 120px;
    height: 120px;
    font-size: 1.5rem;
    padding: 30px;
  }

  /* Adjust transmit target */
  .transmit-target {
    flex-wrap: wrap;
    gap: 10px;
  }

  .target-char {
    font-size: 1.5rem;
  }

  /* Scoreboard adjustments */
  .scoreboard {
    gap: 10px;
  }

  .score {
    padding: 10px 15px;
    min-width: 80px;
  }

  .score .count {
    font-size: 1.5rem;
  }

  .score .label {
    font-size: 0.8rem;
  }

  /* Keyboard improvements */
  .keyboard {
    gap: 15px;
  }

  .keyboard-btn {
    width: 28px;
    height: 34px;
    font-size: 0.75rem;
  }

  .keyboard-btn .morse {
    font-size: 0.55rem;
  }

  /* Adjust keyboard row gap */
  .keyboard-row {
    gap: 3px;
    margin-bottom: 3px;
  }

  /* Punctuation keyboard row */
  .keyboard-punctuation {
    flex-wrap: wrap;
    gap: 4px;
  }

  .keyboard-punctuation .keyboard-btn {
    width: 26px;
    height: 30px;
  }
}

/* Small mobile phones */
@media (max-width: 400px) {
  body {
    padding: 8px;
  }

  .container {
    padding: 10px;
    border-radius: 12px;
  }

  h1 {
    font-size: 1.3rem;
  }

  /* Even smaller tap button for very small screens */
  .tap-btn {
    width: 100px;
    height: 100px;
    font-size: 1.3rem;
    padding: 25px;
  }

  /* Smaller keyboard buttons */
  .keyboard-btn {
    width: 24px;
    height: 30px;
    font-size: 0.7rem;
  }

  .keyboard-btn .morse {
    display: none; /* Hide morse dots on very small screens */
  }

  .keyboard {
    gap: 10px;
  }

  .keyboard-row {
    gap: 2px;
  }

  /* Stack scoreboard vertically on very small screens */
  .scoreboard {
    flex-direction: column;
    align-items: center;
    gap: 8px;
  }

  .score {
    width: 100%;
    max-width: 150px;
    min-width: auto;
  }

  /* Smaller settings text */
  .settings label {
    font-size: 0.9rem;
  }

  /* Reduce gaps */
  .mode-toggle {
    gap: 8px;
    margin-bottom: 15px;
  }

  .settings,
  .character-select,
  .mode-content {
    margin-bottom: 15px;
  }

  #keyboardToggle {
    margin: 15px auto 10px;
  }
}

/* Landscape mobile - allow horizontal if needed but optimize */
@media (max-height: 500px) and (orientation: landscape) {
  .tap-btn {
    width: 80px;
    height: 80px;
    font-size: 1.2rem;
    padding: 15px;
  }

  .main-layout {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .symbol-stats-wrapper {
    width: auto;
  }

  .symbol-stats {
    width: 140px;
    min-width: 140px;
  }

  .symbol-stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .symbol-stat {
    padding: 2px;
    font-size: 0.6rem;
  }
}
