:root {
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --bg-color: #f3f4f6;
  --card-bg: #ffffff;
  --text-main: #1f2937;
  --text-sub: #6b7280;
  --correct: #10b981;
  --incorrect: #ef4444;
  --app-height: 100dvh;
}

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

html {
  height: 100%;
}

body {
  font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  display: flex;
  justify-content: center;
  align-items: center;
}

#app {
  width: 100%;
  max-width: 480px;
  background-color: var(--card-bg);
  height: var(--app-height);
  min-height: var(--app-height);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

@media (min-width: 481px) {
  #app {
    height: min(85vh, 800px);
    min-height: min(85vh, 800px);
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  }
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: 24px;
  min-height: 0;
  overflow: hidden;
}

.screen.active {
  display: flex;
}

#game-screen {
  min-height: 0;
}

#game-screen.active {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
}

h1 {
  font-size: 24px;
  text-align: center;
  color: var(--primary);
  margin-bottom: 8px;
}

.description {
  text-align: center;
  color: var(--text-sub);
  font-size: 14px;
  margin-bottom: 24px;
}

.btn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  background-color: #9ca3af !important;
  cursor: not-allowed;
  transform: none;
}

.primary-btn {
  background-color: var(--primary);
  color: white;
}

.primary-btn:hover {
  background-color: var(--primary-hover);
}

.secondary-btn {
  background-color: transparent;
  border: 2px solid #d1d5db;
  color: var(--text-sub);
}

.secondary-btn:hover {
  background-color: #f3f4f6;
  color: var(--text-main);
}

#start-screen .btn {
  margin-top: 24px;
}

.difficulty-section {
  margin-bottom: 24px;
}

.difficulty-section h3 {
  font-size: 16px;
  margin-bottom: 12px;
  text-align: center;
}

.radio-group {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.radio-label {
  flex: 1;
  text-align: center;
  padding: 12px 0;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  color: var(--text-sub);
  transition: all 0.2s;
}

.radio-label input {
  display: none;
}

.radio-label.selected {
  border-color: var(--primary);
  background-color: #eff6ff;
  color: var(--primary);
}

.highscore-card {
  background-color: var(--bg-color);
  padding: 16px;
  border-radius: 8px;
  margin-bottom: auto;
}

.highscore-card h3 {
  font-size: 16px;
  margin-bottom: 4px;
  text-align: center;
}

.highscore-desc {
  font-size: 12px;
  color: var(--text-sub);
  text-align: center;
  margin-bottom: 12px;
}

.score-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.score-list li {
  display: flex;
  justify-content: space-between;
  font-size: 15px;
  font-weight: bold;
  padding: 8px 12px;
  border-radius: 6px;
  transition: background-color 0.2s, color 0.2s;
}

.score-list li.highlight-score {
  background-color: #eff6ff;
  color: var(--primary);
  border: 1px solid #bfdbfe;
}

.game-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--bg-color);
  background: var(--card-bg);
  z-index: 2;
}

.game-header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.score-container {
  font-size: 20px;
  font-weight: bold;
}

.score-container span {
  color: var(--primary);
}

.game-header-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.game-subinfo {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
}

.game-difficulty {
  font-size: 14px;
  color: var(--text-sub);
}

.combo-count {
  font-size: 14px;
  font-weight: bold;
  color: var(--correct);
  white-space: nowrap;
}

.combo-count span {
  font-size: 16px;
}

.combo-count.pop {
  animation: comboPop 0.3s ease;
}

.quit-btn {
  width: auto;
  padding: 10px 14px;
  font-size: 14px;
  border-radius: 999px;
  flex-shrink: 0;
}

@keyframes comboPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.timer {
  font-size: 24px;
  font-weight: bold;
  color: var(--primary);
  padding: 6px 16px;
  border-radius: 24px;
  background-color: #eff6ff;
  white-space: nowrap;
}

.timer.warning {
  color: white;
  background-color: var(--incorrect);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.word-display {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 16px 0;
  overscroll-behavior: contain;
}

.english-word {
  font-size: clamp(40px, 10vw, 64px);
  font-weight: bold;
  letter-spacing: 2px;
  line-height: 1.1;
  margin-bottom: 8px;
  word-break: break-word;
}

.japanese-word {
  font-size: 18px;
  color: var(--text-sub);
}

.input-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--card-bg);
  padding-top: 8px;
  padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
  z-index: 2;
}

.message-area {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 16px;
}

.message-area.correct {
  color: var(--correct);
}

.message-area.incorrect {
  color: var(--incorrect);
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

#word-input {
  flex: 1;
  min-width: 0;
  padding: 16px;
  font-size: 20px;
  border: 2px solid #d1d5db;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s;
}

#word-input:disabled {
  background-color: #e5e7eb;
  cursor: not-allowed;
}

#word-input:focus {
  border-color: var(--primary);
}

#submit-btn {
  width: 80px;
  padding: 0;
  flex-shrink: 0;
}

#result-screen .btn + .btn {
  margin-top: 12px;
}

.result-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.result-content h2 {
  font-size: 28px;
  margin-bottom: 16px;
}

.result-difficulty {
  font-size: 18px;
  font-weight: bold;
  color: var(--text-sub);
  margin-bottom: 24px;
}

.result-score {
  font-size: 20px;
  margin-bottom: 12px;
}

.result-score span {
  font-size: 36px;
  font-weight: bold;
  color: var(--primary);
}

.result-hs {
  font-size: 16px;
  color: var(--text-sub);
  margin-bottom: 24px;
}

.new-record {
  color: var(--correct);
  font-weight: bold;
  font-size: 18px;
  margin-bottom: 24px;
  animation: bounce 1s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

body.keyboard-open .game-header {
  padding-bottom: 10px;
}

body.keyboard-open .word-display {
  justify-content: flex-start;
  padding-top: 8px;
}

body.keyboard-open .english-word {
  font-size: clamp(32px, 8vw, 48px);
}

body.keyboard-open .japanese-word {
  font-size: 16px;
}

body.keyboard-open .input-section {
  padding-top: 4px;
}

body.keyboard-open .message-area {
  min-height: 24px;
  font-size: 14px;
}

body.keyboard-open .quit-btn {
  padding: 8px 12px;
  font-size: 13px;
}

@media (max-width: 480px) {
  .screen {
    padding: 16px;
  }

  .game-header {
    padding-bottom: 12px;
  }

  .score-container {
    font-size: 18px;
  }

  .timer {
    font-size: 20px;
    padding: 6px 12px;
  }

  .game-difficulty,
  .combo-count {
    font-size: 13px;
  }

  .combo-count span {
    font-size: 14px;
  }

  .quit-btn {
    padding: 9px 12px;
    font-size: 13px;
  }

  #word-input {
    font-size: 18px;
    padding: 14px;
  }
}