/* style.css - Piano Words 钢琴式记忆单词 */

/* ── Reset & Base ─────────────────────────────────────────────────── */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Navbar ────────────────────────────────────────────────────────── */
#navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: #16213e;
  border-bottom: 1px solid #0f3460;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.nav-left .logo {
  font-size: 1.3rem;
  font-weight: 700;
  background: linear-gradient(135deg, #e94560, #0f3460);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 1px;
}

.nav-center {
  font-size: 1rem;
  color: #aaa;
  font-weight: 500;
}

.nav-right {
  display: flex;
  gap: 8px;
}

.nav-btn {
  background: none;
  border: 1px solid #0f3460;
  color: #eee;
  font-size: 1.2rem;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.nav-btn:hover {
  background: #0f3460;
  border-color: #e94560;
}

/* ── Main Content ─────────────────────────────────────────────────── */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 16px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

/* ── Word Area ────────────────────────────────────────────────────── */
#word-area {
  text-align: center;
  padding: 16px 0 8px;
}

.meaning-text {
  font-size: 1.8rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: 8px;
}

.phonetic-text {
  font-size: 1rem;
  color: #888;
  font-style: italic;
}

/* ── Spelling Area ────────────────────────────────────────────────── */
#spelling-area {
  text-align: center;
  padding: 16px 0;
}

#letter-boxes {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  flex-direction: row;
}

/* When in scramble mode, letter-boxes contains two rows stacked vertically */
#letter-boxes:has(.scramble-answer-row) {
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.letter-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 52px;
  font-size: 1.5rem;
  font-weight: 700;
  color: #555;
  border-bottom: 3px solid #0f3460;
  background: rgba(15, 52, 96, 0.2);
  border-radius: 6px 6px 0 0;
  transition: all 0.2s ease;
  text-transform: uppercase;
}

.letter-box.current {
  border-bottom-color: #e94560;
  color: #e94560;
  animation: currentBounce 1s ease-in-out infinite;
}

.letter-box.filled {
  color: #4CAF50;
  border-bottom-color: #4CAF50;
  background: rgba(76, 175, 80, 0.1);
  animation: popIn 0.3s ease forwards;
}

.letter-box.shake {
  animation: shake 0.4s ease;
}

.hint {
  font-size: 0.9rem;
  color: #888;
  margin-top: 4px;
}

/* ── Word Display (Reading Mode) ─────────────────────────────────── */
.word-display-text {
  display: none;
  font-size: 2.4rem;
  font-weight: 700;
  color: #64B5F6;
  letter-spacing: 4px;
  text-transform: lowercase;
  margin-bottom: 4px;
}

.meaning-text.sub-meaning {
  font-size: 1.1rem;
  color: #aaa;
  font-weight: 400;
}

/* ── Reading Mode Letter Boxes ───────────────────────────────────── */
.letter-box.reading-letter {
  width: 52px;
  height: 62px;
  font-size: 1.6rem;
  background: linear-gradient(180deg, #fff 0%, #e8e8e8 100%);
  color: #333;
  border: 1px solid #ccc;
  border-bottom: 3px solid #ccc;
  border-radius: 6px 6px 10px 10px;
  box-shadow:
    0 4px 6px rgba(0,0,0,0.3),
    0 1px 3px rgba(0,0,0,0.2);
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.letter-box.reading-letter:active {
  transform: translateY(3px);
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.letter-box.reading-letter.current {
  border-bottom-color: #e94560;
  animation: currentBounce 1s ease-in-out infinite;
  color: #333;
}

.letter-box.reading-letter.filled {
  background: linear-gradient(180deg, #4CAF50 0%, #45a049 100%);
  color: #fff;
  border-color: #388E3C;
  border-bottom-color: #388E3C;
  box-shadow:
    0 4px 6px rgba(0,0,0,0.3),
    0 0 10px rgba(76, 175, 80, 0.4);
  cursor: default;
  animation: popIn 0.3s ease forwards;
}

.letter-box.reading-letter.shake {
  animation: shake 0.4s ease;
}

.letter-box.reading-letter.wave {
  animation: wave 0.5s ease;
}

/* ── Mode Toggle Button ──────────────────────────────────────────── */
.mode-toggle {
  font-size: 1rem;
  letter-spacing: 0;
}

/* ── Scramble Mode ───────────────────────────────────────────────── */
.scramble-answer-row,
.scramble-source-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.scramble-slot {
  border: 2px dashed #0f3460;
  background: rgba(15, 52, 96, 0.15);
  border-radius: 6px;
}

.scramble-slot.filled {
  border-style: solid;
  border-color: #4CAF50;
  color: #4CAF50;
  background: rgba(76, 175, 80, 0.1);
  animation: popIn 0.3s ease forwards;
}

.scramble-btn.used {
  opacity: 0.3;
  pointer-events: none;
  transform: scale(0.9);
}

/* ── Speed Mode ──────────────────────────────────────────────────── */
.speed-flash {
  animation: speedFlash 0.5s ease-in-out 3;
}

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

.letter-box.timeout {
  color: #f44336;
  border-bottom-color: #f44336;
  background: rgba(244, 67, 54, 0.1);
  animation: popIn 0.3s ease forwards;
}

/* ── Listening Mode Replay Hint ──────────────────────────────────── */
#hint-text {
  cursor: default;
}

/* ── Piano Section ────────────────────────────────────────────────── */
#piano-section {
  width: 100%;
  padding: 8px 0 12px;
}

#piano-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.piano-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.piano-row-2 {
  padding-left: 20px;
}

.piano-row-3 {
  padding-left: 50px;
}

/* ── Piano Key ────────────────────────────────────────────────────── */
.piano-key {
  width: 60px;
  height: 80px;
  background: linear-gradient(180deg, #fff 0%, #e8e8e8 100%);
  border: 1px solid #ccc;
  border-radius: 4px 4px 8px 8px;
  box-shadow:
    0 4px 6px rgba(0,0,0,0.3),
    0 1px 3px rgba(0,0,0,0.2),
    inset 0 -2px 4px rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: #333;
  cursor: pointer;
  user-select: none;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s ease;
  position: relative;
}

.piano-key:active,
.piano-key.pressed {
  transform: translateY(3px);
  box-shadow:
    0 1px 2px rgba(0,0,0,0.3),
    inset 0 -1px 2px rgba(0,0,0,0.05);
}

.piano-key.correct {
  background: linear-gradient(180deg, #4CAF50 0%, #45a049 100%);
  color: #fff;
  border-color: #388E3C;
  box-shadow:
    0 4px 6px rgba(0,0,0,0.3),
    0 0 12px rgba(76, 175, 80, 0.5);
}

.piano-key.error {
  background: #f44336;
  color: #fff;
  border-color: #d32f2f;
  animation: shake 0.4s ease;
}

.piano-key.pulse,
.piano-key.pulse-hint {
  animation: pulse 1.2s ease-in-out infinite;
}

.piano-key.wave {
  animation: wave 0.5s ease;
}

.piano-key.disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* ── Animations ───────────────────────────────────────────────────── */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 4px 6px rgba(0,0,0,0.3), 0 0 5px rgba(76,175,80,0.3); }
  50% { box-shadow: 0 4px 6px rgba(0,0,0,0.3), 0 0 20px rgba(76,175,80,0.6); }
}

@keyframes wave {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); background: linear-gradient(180deg, #64B5F6, #42A5F5); color: #fff; }
  100% { transform: scale(1); }
}

@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

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

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

/* ── Modal Overlay ────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 16px;
  padding: 32px;
  max-width: 500px;
  width: 90%;
  animation: fadeIn 0.3s ease;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content h2 {
  text-align: center;
  margin-bottom: 24px;
  font-size: 1.4rem;
  color: #fff;
}

/* ── Complete Overlay ─────────────────────────────────────────────── */
.complete-content {
  text-align: center;
}

.complete-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.complete-word-text {
  font-size: 2.2rem;
  font-weight: 700;
  color: #4CAF50;
  margin-bottom: 8px;
  letter-spacing: 3px;
}

.complete-phonetic-text {
  font-size: 1rem;
  color: #888;
  font-style: italic;
  margin-bottom: 8px;
}

.complete-meaning-text {
  font-size: 1.2rem;
  color: #ddd;
  margin-bottom: 16px;
}

.complete-example-text {
  font-size: 0.95rem;
  color: #aaa;
  font-style: italic;
  margin-bottom: 24px;
  line-height: 1.5;
  padding: 12px;
  background: rgba(15, 52, 96, 0.3);
  border-radius: 8px;
}

.complete-example-text strong {
  color: #4CAF50;
  font-style: normal;
}

/* ── Stats Grid ───────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-item {
  text-align: center;
  padding: 12px 8px;
  background: rgba(15, 52, 96, 0.3);
  border-radius: 10px;
}

.stat-value {
  display: block;
  font-size: 1.8rem;
  font-weight: 700;
  color: #e94560;
  margin-bottom: 4px;
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  color: #888;
}

/* ── Settings ─────────────────────────────────────────────────────── */
.settings-group {
  margin-bottom: 24px;
}

.settings-group h3 {
  font-size: 1rem;
  color: #aaa;
  margin-bottom: 12px;
}

.difficulty-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.difficulty-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(15, 52, 96, 0.3);
  border: 1px solid #0f3460;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.difficulty-option:hover {
  border-color: #e94560;
}

.difficulty-option.selected {
  border-color: #e94560;
  background: rgba(233, 69, 96, 0.1);
}

.difficulty-option input[type="radio"] {
  accent-color: #e94560;
  width: 18px;
  height: 18px;
}

.difficulty-label {
  font-weight: 600;
  font-size: 1rem;
  color: #fff;
}

.difficulty-desc {
  font-size: 0.8rem;
  color: #888;
  margin-left: auto;
}

/* ── Buttons ──────────────────────────────────────────────────────── */
.modal-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.btn, .btn-primary, .btn-secondary, .btn-danger {
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-primary {
  background: #e94560;
  color: #fff;
}

.btn-primary:hover {
  background: #d63851;
  transform: translateY(-1px);
}

.btn-secondary {
  background: #0f3460;
  color: #eee;
}

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

.btn-danger {
  background: transparent;
  color: #f44336;
  border: 1px solid #f44336;
}

.btn-danger:hover {
  background: rgba(244, 67, 54, 0.1);
}

/* ── Responsive: Tablet ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .meaning-text {
    font-size: 1.4rem;
  }

  .piano-key {
    width: 45px;
    height: 60px;
    font-size: 0.95rem;
    border-radius: 3px 3px 6px 6px;
  }

  .piano-row-2 {
    padding-left: 14px;
  }

  .piano-row-3 {
    padding-left: 36px;
  }

  .letter-box {
    width: 36px;
    height: 44px;
    font-size: 1.2rem;
  }

  .letter-box.reading-letter {
    width: 42px;
    height: 52px;
    font-size: 1.3rem;
  }

  .word-display-text {
    font-size: 1.8rem;
  }

  .scramble-answer-row,
  .scramble-source-row {
    gap: 6px;
  }

  #navbar {
    padding: 10px 16px;
  }

  .modal-content {
    padding: 24px 20px;
  }

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

/* ── Responsive: Phone ────────────────────────────────────────────── */
@media (max-width: 480px) {
  .meaning-text {
    font-size: 1.2rem;
  }

  .phonetic-text {
    font-size: 0.85rem;
  }

  .piano-key {
    width: 32px;
    height: 48px;
    font-size: 0.8rem;
    border-radius: 2px 2px 5px 5px;
  }

  .piano-row {
    gap: 3px;
  }

  .piano-row-2 {
    padding-left: 10px;
  }

  .piano-row-3 {
    padding-left: 26px;
  }

  .letter-box {
    width: 30px;
    height: 38px;
    font-size: 1rem;
    gap: 5px;
  }

  .letter-box.reading-letter {
    width: 36px;
    height: 46px;
    font-size: 1.1rem;
  }

  .word-display-text {
    font-size: 1.4rem;
    letter-spacing: 2px;
  }

  .scramble-answer-row,
  .scramble-source-row {
    gap: 4px;
  }

  .scramble-slot,
  .scramble-btn {
    width: 30px;
    height: 38px;
    font-size: 1rem;
  }

  #letter-boxes {
    gap: 5px;
  }

  #main-content {
    padding: 12px 8px 8px;
  }

  .complete-word-text {
    font-size: 1.6rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-value {
    font-size: 1.4rem;
  }
}
