/**
 * English Word Match Game - Responsive CSS
 *
 * 响应式断点：
 * - Mobile (iPhone): < 768px
 * - Tablet (iPad): 769px - 1440px
 * - Laptop (MacBook Pro): 1441px - 2560px
 * - Desktop (iMac 4K): > 2561px
 */

/* ==================== CSS Variables ==================== */
:root {
  /* iMac 4K (默认) */
  --card-size: 180px;
  --card-font-size: 36px;  /* 放大到卡片高度的20% */
  --gap-size: 24px;
  --container-padding: 40px;
  --header-font-size: 32px;
  --button-height: 60px;
}

/* MacBook Pro (1441px - 2560px) */
@media (min-width: 1441px) and (max-width: 2560px) {
  :root {
    --card-size: 140px;
    --card-font-size: 28px;  /* 放大 */
    --gap-size: 20px;
    --container-padding: 32px;
    --header-font-size: 28px;
    --button-height: 50px;
  }
}

/* iPad (769px - 1440px) */
@media (min-width: 769px) and (max-width: 1440px) {
  :root {
    --card-size: 120px;
    --card-font-size: 24px;  /* 放大 */
    --gap-size: 16px;
    --container-padding: 24px;
    --header-font-size: 24px;
    --button-height: 48px;
  }
}

/* iPhone (< 768px) */
@media (max-width: 768px) {
  :root {
    --card-size: 100px;
    --card-font-size: 20px;  /* 放大 */
    --gap-size: 12px;
    --container-padding: 16px;
    --header-font-size: 20px;
    --button-height: 44px;
  }
}

/* ==================== Layout ==================== */
.game-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--container-padding);
}

/* ==================== Header ==================== */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
  flex-wrap: wrap;
  gap: 16px;
}

.game-title {
  font-size: var(--header-font-size);
  font-weight: bold;
  color: var(--text-primary);
}

.game-stats {
  display: flex;
  gap: 24px;
  align-items: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-label {
  font-size: 14px;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 20px;
  font-weight: bold;
  color: var(--accent);
}

/* ==================== Game Controls ==================== */
.game-controls {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  gap: 12px;
  align-items: center;
}

.control-label {
  font-size: 16px;
  color: var(--text-primary);
  font-weight: 500;
}

.control-select {
  height: var(--button-height);
  padding: 0 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.control-select:hover {
  border-color: var(--accent);
}

.control-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.control-button {
  height: var(--button-height);
  padding: 0 24px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.control-button:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.control-button:active {
  transform: translateY(0);
}

/* ==================== Game Board ==================== */
.game-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--card-size), var(--card-size)));
  gap: var(--gap-size);
  justify-content: center;
  margin-bottom: 32px;
}

/* 响应式列数调整 */
@media (max-width: 768px) {
  .game-board {
    grid-template-columns: repeat(3, minmax(var(--card-size), var(--card-size)));
  }
}

@media (min-width: 769px) and (max-width: 1440px) {
  .game-board {
    grid-template-columns: repeat(4, minmax(var(--card-size), var(--card-size)));
  }
}

/* ==================== Card Styles ==================== */
.card {
  width: var(--card-size);
  height: var(--card-size);
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  cursor: pointer;
  user-select: none;
  transition: all 0.3s ease;
  font-size: var(--card-font-size);
  color: var(--text-primary);
  font-weight: 500;
  line-height: 1.4;
  word-wrap: break-word;
}

.card:hover:not(.card-matched):not(.card-selected) {
  transform: translateY(-4px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
  border-color: var(--accent);
}

.card-selected {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: scale(1.05);
}

.card-matched {
  background: #10b981;
  color: white;
  border-color: #10b981;
  opacity: 0.7;
  cursor: default;
  animation: matchSuccess 0.5s ease;
}

.card-wrong {
  animation: shake 0.5s ease;
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

/* ==================== Result Modal ==================== */
.result-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.result-content {
  background: var(--bg-primary);
  border-radius: 16px;
  padding: 40px;
  max-width: 500px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.result-title {
  font-size: 32px;
  font-weight: bold;
  color: var(--text-primary);
  margin-bottom: 24px;
}

.stars {
  font-size: 48px;
  margin-bottom: 24px;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 32px;
}

.result-stat {
  background: var(--bg-secondary);
  padding: 16px;
  border-radius: 8px;
}

.result-stat-label {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.result-stat-value {
  font-size: 24px;
  font-weight: bold;
  color: var(--accent);
}

.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.result-button {
  padding: 16px 32px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.result-button-primary {
  background: var(--accent);
  color: white;
}

.result-button-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

.result-button-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 2px solid var(--border);
}

.result-button-secondary:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

/* ==================== Hidden State ==================== */
.hidden {
  display: none !important;
}

/* ==================== Loading State ==================== */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.loading-spinner {
  width: 60px;
  height: 60px;
  border: 6px solid var(--bg-secondary);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==================== Mobile Optimizations ==================== */
@media (max-width: 768px) {
  .game-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .game-stats {
    width: 100%;
    justify-content: space-around;
  }

  .game-controls {
    flex-direction: column;
    width: 100%;
  }

  .control-group {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .control-select,
  .control-button {
    width: 100%;
  }

  .result-content {
    padding: 24px;
  }

  .result-stats {
    grid-template-columns: 1fr;
  }

  .result-actions {
    flex-direction: column;
  }

  .result-button {
    width: 100%;
  }
}

/* ==================== Vocabulary Book Button ==================== */
.vocab-book-button {
  height: var(--button-height);
  padding: 0 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.vocab-book-button:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ==================== Card Enhancements (Phonetic + Speak) ==================== */
.card {
  flex-direction: column;
  position: relative;
}

.card-word {
  font-size: var(--card-font-size);
  font-weight: 700;  /* 加粗 */
  margin-bottom: 4px;
  line-height: 1.2;
}

.card-phonetic {
  font-size: calc(var(--card-font-size) * 0.5);  /* 音标相对更小 */
  color: var(--text-secondary);
  font-weight: normal;
  display: block;
  margin-top: 4px;
}

.card-speak-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 36px;  /* 稍微放大 */
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  font-size: 18px;  /* 放大图标 */
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
}

.card-speak-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

/* 移动端调整 */
@media (max-width: 768px) {
  .card-speak-btn {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }
}

/* ==================== Vocabulary Book Modal ==================== */
.vocab-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.vocab-modal-content {
  background: var(--bg-primary);
  border-radius: 16px;
  max-width: 800px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.vocab-modal-header {
  padding: 24px;
  border-bottom: 2px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.vocab-modal-header h2 {
  font-size: 24px;
  font-weight: bold;
  color: var(--text-primary);
  margin: 0;
}

.vocab-modal-close {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 24px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.vocab-modal-close:hover {
  background: var(--accent);
  color: white;
  transform: rotate(90deg);
}

.vocab-modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.vocab-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  font-size: 16px;
}

.vocab-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.vocab-item {
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  transition: all 0.2s;
}

.vocab-item:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.vocab-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.vocab-item-word {
  font-size: 20px;
  font-weight: bold;
  color: var(--text-primary);
}

.vocab-item-phonetic {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: normal;
  margin-left: 8px;
}

.vocab-item-speak {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s;
}

.vocab-item-speak:hover {
  background: var(--accent-hover);
  transform: scale(1.1);
}

.vocab-item-meaning {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.vocab-item-example {
  background: rgba(52, 152, 219, 0.1);
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.vocab-item-example-en {
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 4px;
  font-style: italic;
}

.vocab-item-example-cn {
  font-size: 14px;
  color: var(--text-secondary);
}

.vocab-item-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

.vocab-item-count {
  color: var(--accent);
  font-weight: 600;
}

.vocab-item-remove {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.vocab-item-remove:hover {
  border-color: #ef4444;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.vocab-modal-footer {
  padding: 24px;
  border-top: 2px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.vocab-button {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.vocab-button-primary {
  background: var(--accent);
  color: white;
}

.vocab-button-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

.vocab-button-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 2px solid var(--border);
}

.vocab-button-secondary:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

/* ==================== Example Modal ==================== */
.example-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
  padding: 20px;
}

.example-modal-content {
  background: var(--bg-primary);
  border-radius: 16px;
  max-width: 600px;
  width: 100%;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  position: relative;
}

.example-modal-header {
  position: absolute;
  top: 16px;
  right: 16px;
}

.example-modal-close {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 24px;
  cursor: pointer;
  transition: all 0.2s;
}

.example-modal-close:hover {
  background: var(--accent);
  color: white;
  transform: rotate(90deg);
}

.example-modal-body {
  padding-top: 20px;
}

.example-word {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.example-word-text {
  font-size: 36px;
  font-weight: bold;
  color: var(--text-primary);
}

.example-phonetic {
  font-size: 20px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.example-meaning {
  font-size: 18px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.example-sentence-section {
  background: rgba(52, 152, 219, 0.1);
  padding: 20px;
  border-radius: 12px;
}

.example-sentence-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.example-sentence {
  font-size: 18px;
  color: var(--text-primary);
  margin-bottom: 8px;
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 12px;
}

.example-sentence-cn {
  font-size: 16px;
  color: var(--text-secondary);
}

.example-speak-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.example-speak-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.1);
}

/* ==================== Mobile Adjustments for New Components ==================== */
@media (max-width: 768px) {
  .vocab-modal-content {
    max-height: 90vh;
  }

  .vocab-modal-header,
  .vocab-modal-body,
  .vocab-modal-footer {
    padding: 16px;
  }

  .vocab-modal-header h2 {
    font-size: 20px;
  }

  .vocab-item {
    padding: 12px;
  }

  .vocab-item-word {
    font-size: 18px;
  }

  .vocab-item-footer {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .example-word-text {
    font-size: 28px;
  }

  .example-phonetic {
    font-size: 16px;
  }

  .example-meaning {
    font-size: 16px;
  }

  .example-sentence {
    font-size: 16px;
    flex-direction: column;
    align-items: flex-start;
  }

  .example-sentence-cn {
    font-size: 14px;
  }

  .card-speak-btn {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
}

/* ==================== Matched Examples Section ==================== */
.matched-examples-section {
  margin: 32px auto;
  max-width: 1200px;
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.matched-examples-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.matched-examples-list {
  max-height: 500px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 16px;
}

.no-matched {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-secondary);
  font-size: 18px;
  padding: 48px;
}

.matched-example-item {
  background: var(--bg-primary);
  border-radius: 12px;
  padding: 16px;
  border: 2px solid var(--border);
  transition: all 0.3s ease;
}

.matched-example-item:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  border-color: var(--accent);
}

.matched-example-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.matched-example-number {
  color: var(--accent);
  font-weight: 700;
  font-size: 20px;
  min-width: 32px;
}

.matched-example-word {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 1px;
}

.matched-example-phonetic {
  font-size: 16px;
  color: var(--text-secondary);
  font-style: italic;
}

.matched-speak-btn-inline {
  background: var(--accent);
  border: none;
  color: white;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 16px;
  transition: all 0.2s ease;
  margin-left: auto;
}

.matched-speak-btn-inline:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.matched-speak-btn-inline:active {
  transform: scale(0.95);
}

.matched-example-meaning {
  font-size: 18px;
  color: var(--text-primary);
  margin-bottom: 12px;
  font-weight: 500;
}

.matched-example-sentence {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 12px;
}

.matched-example-en {
  font-size: 16px;
  color: var(--text-primary);
  line-height: 1.6;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.matched-example-cn {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.5;
  font-style: italic;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .matched-examples-section {
    margin: 20px 12px;
    padding: 16px;
  }

  .matched-examples-title {
    font-size: 20px;
  }

  .matched-examples-list {
    grid-template-columns: 1fr;
    max-height: 400px;
    gap: 12px;
  }

  .matched-example-item {
    padding: 12px;
  }

  .matched-example-word {
    font-size: 22px;
  }

  .matched-example-phonetic {
    font-size: 14px;
  }

  .matched-example-meaning {
    font-size: 16px;
  }

  .matched-example-en {
    font-size: 15px;
  }

  .matched-example-cn {
    font-size: 14px;
  }

  .matched-speak-btn-inline {
    padding: 4px 10px;
    font-size: 14px;
  }
}

/* Scrollbar Styling */
.matched-examples-list::-webkit-scrollbar {
  width: 8px;
}

.matched-examples-list::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 4px;
}

.matched-examples-list::-webkit-scrollbar-thumb {
  background: var(--text-secondary);
  border-radius: 4px;
}

.matched-examples-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-primary);
}
