:root {
  --red: #C41E3A;
  --black: #2D2D2D;
  --blue: #0066CC;
  --green: #228B22;
  --purple: #6B3FA0;
  --gold: #D4AF37;
  --parchment: #FDF8E8;
  --parchment-dark: #F5E6C8;
  --silk: #FFFEF5;
}

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

body {
  font-family: 'Crimson Pro', serif;
  background: linear-gradient(135deg, var(--parchment) 0%, var(--parchment-dark) 100%);
  min-height: 100vh;
  color: var(--black);
  overflow-x: hidden;
}

.app-container {
  position: relative;
  min-height: 100vh;
}

/* Particles */
.particles {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--gold);
  border-radius: 50%;
  opacity: 0.4;
  animation: float linear infinite;
}

@keyframes float {
  0% { transform: translateY(100vh) rotate(0deg); opacity: 0; }
  10% { opacity: 0.4; }
  90% { opacity: 0.4; }
  100% { transform: translateY(-100px) rotate(720deg); opacity: 0; }
}

/* Header */
.header {
  text-align: center;
  padding: 1.5rem 1rem;
  background: linear-gradient(180deg, rgba(139, 0, 139, 0.1) 0%, transparent 100%);
  border-bottom: 3px solid var(--gold);
  position: relative;
}

.header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 300px;
  height: 4px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.title {
  font-family: 'Ma Shan Zheng', cursive;
  font-size: 3.5rem;
  color: var(--purple);
  text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
  letter-spacing: 0.5rem;
}

@media (min-width: 768px) {
  .title {
    font-size: 5rem;
  }
}

.subtitle {
  font-family: 'Crimson Pro', serif;
  font-size: 1.3rem;
  color: var(--black);
  font-weight: 400;
  margin-top: 0.25rem;
}

.tagline {
  font-size: 0.95rem;
  color: var(--blue);
  margin-top: 0.25rem;
}

.poetic-line {
  font-style: italic;
  color: var(--red);
  margin-top: 0.5rem;
  font-size: 1.1rem;
}

.first-edition {
  font-size: 0.85rem;
  color: var(--gold);
  margin-top: 0.5rem;
  font-weight: 600;
}

/* Main content */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1rem;
  max-width: 1600px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

@media (min-width: 1200px) {
  .main-content {
    flex-direction: row;
    padding: 2rem;
    gap: 2rem;
  }
}

/* Grid section */
.grid-section {
  flex: 1;
}

/* Controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  justify-content: center;
}

.mode-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
}

.mode-btn {
  padding: 0.4rem 0.8rem;
  border: 2px solid var(--gold);
  background: var(--silk);
  color: var(--black);
  font-family: 'Crimson Pro', serif;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.3s;
}

.mode-btn:hover, .mode-btn.active {
  background: var(--gold);
  color: white;
}

.action-buttons {
  display: flex;
  gap: 0.4rem;
}

.action-btn {
  padding: 0.4rem 0.8rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'Crimson Pro', serif;
  font-size: 0.85rem;
  transition: all 0.3s;
}

.action-btn.clear {
  background: var(--red);
  color: white;
}

.action-btn.random {
  background: var(--blue);
  color: white;
}

.action-btn.share {
  background: var(--purple);
  color: white;
}

.action-btn.share:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.action-btn.tts {
  background: var(--black);
  color: white;
}

.action-btn.tts.active {
  background: var(--gold);
}

/* Grid container */
.grid-container {
  background: var(--silk);
  border: 4px solid var(--gold);
  border-radius: 8px;
  padding: 0.5rem;
  overflow-x: auto;
  box-shadow: 
    0 4px 30px rgba(0,0,0,0.15),
    inset 0 0 100px rgba(212, 175, 55, 0.08);
}

/* HTML Table styling - AUTHENTIC COLORS */
.xuanji-table {
  border-collapse: collapse;
  margin: 0 auto;
  background: var(--silk);
}

.xuanji-table td.grid-cell {
  width: 18px;
  height: 18px;
  text-align: center;
  vertical-align: middle;
  font-family: 'Noto Serif SC', serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  background: rgba(255,255,255,0.6);
  border: 1px solid rgba(200, 180, 140, 0.2);
  padding: 0;
  position: relative;
}

@media (min-width: 480px) {
  .xuanji-table td.grid-cell {
    width: 20px;
    height: 20px;
    font-size: 13px;
  }
}

@media (min-width: 768px) {
  .xuanji-table td.grid-cell {
    width: 22px;
    height: 22px;
    font-size: 14px;
  }
}

@media (min-width: 1024px) {
  .xuanji-table td.grid-cell {
    width: 24px;
    height: 24px;
    font-size: 15px;
  }
}

@media (min-width: 1400px) {
  .xuanji-table td.grid-cell {
    width: 26px;
    height: 26px;
    font-size: 16px;
  }
}

/* Authentic Five-Color classes */
.grid-cell.color-red { color: #C41E3A; }
.grid-cell.color-blue { color: #0066CC; }
.grid-cell.color-green { color: #228B22; }
.grid-cell.color-purple { color: #6B3FA0; }
.grid-cell.color-gold { color: #D4AF37; }
.grid-cell.color-black { color: #2D2D2D; }

.xuanji-table td.grid-cell:hover {
  transform: scale(1.5);
  z-index: 20;
  box-shadow: 0 0 20px currentColor;
  background: white;
  border: 2px solid currentColor;
  border-radius: 4px;
}

.xuanji-table td.grid-cell.selected {
  background: rgba(212, 175, 55, 0.5);
  box-shadow: 0 0 12px var(--gold);
  transform: scale(1.15);
  z-index: 10;
  border: 2px solid var(--gold);
  border-radius: 3px;
}

.selection-number {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--red);
  color: white;
  font-size: 8px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: sans-serif;
  font-weight: bold;
}

.xuanji-table td.grid-cell.hovered {
  background: white;
  box-shadow: 0 0 25px currentColor;
}

.xuanji-table td.grid-cell.center-heart {
  animation: heartbeat 2s infinite;
  font-size: 18px !important;
  font-weight: bold;
  color: var(--gold) !important;
  text-shadow: 0 0 10px var(--gold);
}

.xuanji-table td.grid-cell.signature {
  background: rgba(139, 0, 139, 0.08);
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); box-shadow: 0 0 15px var(--gold); }
  50% { transform: scale(1.25); box-shadow: 0 0 30px var(--gold); }
}

.grid-info {
  text-align: center;
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: #666;
}

.cell-info {
  color: var(--purple);
  font-weight: 600;
}

/* Poem panel */
.poem-panel {
  width: 100%;
  background: var(--silk);
  border: 3px solid var(--gold);
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 4px 25px rgba(0,0,0,0.12);
}

@media (min-width: 1200px) {
  .poem-panel {
    width: 360px;
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
  }
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--gold);
}

.panel-header h3 {
  font-family: 'Ma Shan Zheng', cursive;
  font-size: 1.5rem;
  color: var(--purple);
}

.char-count {
  font-size: 0.85rem;
  color: var(--blue);
  background: rgba(0, 102, 204, 0.1);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.empty-state {
  text-align: center;
  padding: 1.5rem 1rem;
  color: #666;
}

.empty-state .hint {
  font-size: 0.85rem;
  margin-top: 0.75rem;
  font-style: italic;
}

.empty-state .hint.special {
  color: var(--gold);
  font-style: normal;
  font-weight: 600;
}

.poem-display {
  text-align: center;
}

.chinese-poem {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.poem-char {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.poem-char .char {
  font-family: 'Ma Shan Zheng', cursive;
  font-size: 2.2rem;
}

.poem-char .pinyin {
  font-size: 0.65rem;
  color: #666;
}

.poem-text {
  border-top: 1px solid rgba(212, 175, 55, 0.4);
  padding-top: 1rem;
}

.chinese-line {
  font-family: 'Noto Serif SC', serif;
  font-size: 1.15rem;
  letter-spacing: 0.25rem;
  margin-bottom: 0.5rem;
  color: var(--purple);
}

.translation {
  font-style: italic;
  color: #666;
  font-size: 0.85rem;
}

/* Sample poems */
.sample-poems {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 2px solid var(--gold);
}

.sample-poems h4 {
  font-size: 0.9rem;
  color: var(--purple);
  margin-bottom: 0.75rem;
  font-family: 'Ma Shan Zheng', cursive;
  font-size: 1.1rem;
}

.sample-poem {
  display: flex;
  flex-direction: column;
  padding: 0.6rem;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.08) 0%, rgba(212, 175, 55, 0.15) 100%);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.sample-poem:hover {
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.15) 0%, rgba(212, 175, 55, 0.25) 100%);
  border-color: var(--gold);
  transform: translateX(4px);
}

.sample-name {
  font-size: 0.75rem;
  color: var(--blue);
  font-weight: 600;
}

.sample-chars {
  font-family: 'Noto Serif SC', serif;
  font-size: 1.1rem;
  color: var(--red);
  margin: 0.25rem 0;
}

.sample-translation {
  font-size: 0.7rem;
  color: #666;
  font-style: italic;
}

.wiki-link {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--gold);
  text-align: center;
}

.wiki-link a {
  color: var(--blue);
  text-decoration: none;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.wiki-link a:hover {
  color: var(--purple);
  text-decoration: underline;
}

/* About section */
.about-section {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1rem;
  position: relative;
  z-index: 1;
}

.about-toggle {
  width: 100%;
  padding: 1rem;
  background: linear-gradient(135deg, var(--purple) 0%, #9333EA 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-family: 'Crimson Pro', serif;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 15px rgba(139, 0, 139, 0.3);
}

.about-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(139, 0, 139, 0.4);
}

.about-content {
  margin-top: 1rem;
  animation: slideDown 0.4s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-15px); }
  to { opacity: 1; transform: translateY(0); }
}

.about-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 768px) {
  .about-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .about-card.full-width {
    grid-column: span 3;
  }
}

.about-card {
  background: var(--silk);
  border: 2px solid var(--gold);
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 4px 15px rgba(0,0,0,0.08);
}

.about-card h4 {
  font-family: 'Ma Shan Zheng', cursive;
  font-size: 1.25rem;
  color: var(--purple);
  margin-bottom: 0.5rem;
}

.about-card p {
  font-size: 0.9rem;
  line-height: 1.6;
  color: #444;
}

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

.modal {
  background: var(--silk);
  border-radius: 12px;
  padding: 2rem;
  max-width: 420px;
  width: 100%;
  position: relative;
  border: 3px solid var(--gold);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  font-size: 1.8rem;
  cursor: pointer;
  color: #666;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--red);
}

.modal h3 {
  font-family: 'Ma Shan Zheng', cursive;
  font-size: 1.6rem;
  color: var(--purple);
  margin-bottom: 1rem;
  text-align: center;
}

.share-preview {
  background: linear-gradient(135deg, #FFF9E6 0%, #FFF5D6 100%);
  border: 2px solid var(--gold);
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 1.5rem;
}

.preview-chars {
  font-family: 'Ma Shan Zheng', cursive;
  font-size: 2.5rem;
  color: var(--red);
  letter-spacing: 0.3rem;
  word-break: break-all;
}

.preview-attribution {
  font-style: italic;
  color: #666;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

.share-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.share-btn {
  padding: 1rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-family: 'Crimson Pro', serif;
  font-size: 1.05rem;
  cursor: pointer;
  transition: all 0.3s;
}

.share-btn.twitter {
  background: #000;
  color: white;
}

.share-btn.copy {
  background: var(--blue);
  color: white;
}

.share-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(0,0,0,0.25);
}

/* Celebration */
.celebration {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.celebration-content {
  text-align: center;
  position: relative;
  padding: 2rem;
}

.celebration-heart {
  font-family: 'Ma Shan Zheng', cursive;
  font-size: 10rem;
  color: var(--gold);
  animation: pulse 1.2s infinite;
  text-shadow: 0 0 60px var(--gold), 0 0 120px rgba(212, 175, 55, 0.5);
}

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

.celebration-text {
  color: white;
  font-style: italic;
  font-size: 1.2rem;
  margin-top: 1.5rem;
  white-space: pre-line;
  line-height: 1.8;
}

.sparkle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--gold);
  border-radius: 50%;
  animation: sparkle 1.2s ease-out forwards;
}

@keyframes sparkle {
  0% { transform: scale(0); opacity: 1; }
  100% { transform: scale(4); opacity: 0; }
}

/* Footer */
.footer {
  text-align: center;
  padding: 2rem 1rem;
  background: linear-gradient(180deg, transparent 0%, rgba(139, 0, 139, 0.1) 100%);
  border-top: 2px solid var(--gold);
  position: relative;
  z-index: 1;
}

.footer a {
  color: var(--purple);
  text-decoration: none;
  font-weight: 600;
}

.footer a:hover {
  text-decoration: underline;
}

.footer .honor {
  font-style: italic;
  color: #666;
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--parchment);
}

::-webkit-scrollbar-thumb {
  background: var(--gold);
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: #C9A227;
}