/* ========================================
   成语点选连线 - 水墨国风样式
   ======================================== */

/* ---------- CSS Variables ---------- */
:root {
  --rice-paper: #F5F0E8;
  --ink-dark: #2C2C2C;
  --ink-medium: #5A5A5A;
  --ink-light: #8B7D6B;
  --vermillion: #C0392B;
  --vermillion-light: #E74C3C;
  --bamboo-green: #2E8B57;
  --mountain-blue: #5D6D7E;
  --paper-shadow: rgba(139, 125, 107, 0.15);
  --ink-splash: rgba(44, 44, 44, 0.08);

  --font-cn: 'Noto Serif SC', 'STSong', 'SimSun', 'Songti SC', serif;
  --font-en: 'Crimson Text', Georgia, serif;

  --grid-gap: 8px;
  --cell-size: min(18vw, 72px);
  --transition-fast: 0.2s ease;
  --transition-medium: 0.4s ease;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-cn);
  background-color: var(--rice-paper);
  color: var(--ink-dark);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Rice paper texture background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(139, 125, 107, 0.02) 2px,
      rgba(139, 125, 107, 0.02) 4px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 3px,
      rgba(139, 125, 107, 0.015) 3px,
      rgba(139, 125, 107, 0.015) 6px
    );
  pointer-events: none;
  z-index: 0;
}

/* ---------- Typography ---------- */
h1, h2, h3 {
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.4;
}

p, span, div {
  line-height: 1.6;
}

/* ---------- Screen Container ---------- */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 20px 16px;
  position: relative;
  z-index: 1;
}

.screen.active {
  display: flex;
}

/* ---------- Home Screen ---------- */
.home-title {
  font-size: clamp(2.4rem, 8vw, 3.6rem);
  color: var(--ink-dark);
  margin-top: 12vh;
  margin-bottom: 4px;
  text-shadow: 2px 2px 4px var(--ink-splash);
  writing-mode: horizontal-tb;
  position: relative;
}

.home-subtitle {
  font-family: var(--font-en);
  font-size: clamp(0.9rem, 3vw, 1.2rem);
  color: var(--ink-light);
  letter-spacing: 0.2em;
  margin-bottom: 6vh;
}

/* Brush stroke decoration */
.brush-divider {
  width: 120px;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--ink-dark), var(--ink-dark), transparent);
  margin: 16px auto;
  border-radius: 2px;
  opacity: 0.5;
}

/* Seal stamp button */
.seal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--vermillion);
  color: var(--rice-paper);
  border: 3px solid var(--vermillion);
  padding: 14px 48px;
  font-family: var(--font-cn);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  cursor: pointer;
  position: relative;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: 3px 3px 0 rgba(192, 57, 43, 0.3);
}

.seal-btn::before {
  content: '';
  position: absolute;
  inset: 3px;
  border: 1.5px solid rgba(245, 240, 232, 0.5);
}

.seal-btn:hover {
  transform: scale(1.04);
  box-shadow: 4px 4px 0 rgba(192, 57, 43, 0.4);
}

.seal-btn:active {
  transform: scale(0.97);
  box-shadow: 1px 1px 0 rgba(192, 57, 43, 0.3);
}

/* Scroll container (rules) */
.scroll-box {
  background: linear-gradient(135deg, #F8F3EB, #F0E8D8);
  border: 1.5px solid var(--ink-light);
  border-radius: 2px;
  padding: 20px 24px;
  max-width: 380px;
  width: 90%;
  margin-top: 4vh;
  position: relative;
  box-shadow: 0 2px 8px var(--paper-shadow);
}

.scroll-box::before,
.scroll-box::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 12px;
  background: linear-gradient(180deg, rgba(139, 125, 107, 0.15), transparent);
}

.scroll-box::before { top: 0; }
.scroll-box::after { bottom: 0; transform: rotate(180deg); }

.scroll-box h3 {
  font-size: 1rem;
  color: var(--ink-dark);
  margin-bottom: 10px;
  text-align: center;
}

.scroll-box p {
  font-size: 0.85rem;
  color: var(--ink-light);
  margin-bottom: 6px;
  text-align: left;
}

.scroll-box .rule-line {
  padding-left: 1.2em;
  text-indent: -1.2em;
}

/* Language toggle */
.lang-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  background: rgba(245, 240, 232, 0.92);
  border: 1.5px solid var(--ink-light);
  color: var(--ink-light);
  font-family: var(--font-en);
  font-size: 0.75rem;
  padding: 4px 10px;
  cursor: pointer;
  transition: all var(--transition-fast);
  letter-spacing: 0.05em;
  z-index: 9999;
  border-radius: 2px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

.lang-toggle:hover {
  border-color: var(--ink-dark);
  color: var(--ink-dark);
}

.lang-toggle:active {
  background: rgba(245, 240, 232, 1);
  transform: scale(0.95);
}

/* Ad banner */
.ad-banner {
  width: 90%;
  max-width: 380px;
  height: 50px;
  background: linear-gradient(90deg, rgba(139, 125, 107, 0.06), rgba(139, 125, 107, 0.12), rgba(139, 125, 107, 0.06));
  border: 1px dashed var(--ink-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-light);
  font-size: 0.7rem;
  margin-top: auto;
  margin-bottom: 12px;
  letter-spacing: 0.1em;
  opacity: 0.7;
}

/* ---------- Game Screen ---------- */
.game-header {
  width: 100%;
  max-width: 400px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px;
  margin-bottom: 12px;
}

.game-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-stat-label {
  font-size: 0.7rem;
  color: var(--ink-light);
  letter-spacing: 0.08em;
}

.game-stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ink-dark);
}

.game-level {
  font-size: 0.85rem;
  color: var(--mountain-blue);
  letter-spacing: 0.1em;
}

/* Selected characters display */
.selected-area {
  width: 100%;
  max-width: 400px;
  min-height: 56px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding: 8px 12px;
  background: rgba(139, 125, 107, 0.06);
  border: 1px solid rgba(139, 125, 107, 0.15);
  border-radius: 2px;
}

.selected-char {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--vermillion);
  border: 1.5px solid var(--vermillion);
  background: rgba(192, 57, 43, 0.05);
  animation: inkAppear 0.3s ease;
}

.selected-char.empty {
  border-color: rgba(139, 125, 107, 0.2);
  color: transparent;
  background: transparent;
}

/* 4×4 Grid */
.grid-container {
  display: grid;
  grid-template-columns: repeat(4, var(--cell-size));
  grid-template-rows: repeat(4, var(--cell-size));
  gap: var(--grid-gap);
  margin: 8px auto;
}

.grid-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.2rem, 5vw, 1.8rem);
  font-weight: 700;
  color: var(--ink-dark);
  background: linear-gradient(145deg, #FAF6EE, #F0E8D8);
  border: 1.5px solid rgba(139, 125, 107, 0.25);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.grid-cell::after {
  content: '';
  position: absolute;
  inset: 0;
  background: transparent;
  transition: background var(--transition-fast);
  pointer-events: none;
}

.grid-cell:hover:not(.found):not(.selected) {
  border-color: var(--ink-medium);
  background: linear-gradient(145deg, #F5EFE3, #EBE2D0);
}

.grid-cell.selected {
  color: var(--vermillion);
  border-color: var(--vermillion);
  background: rgba(192, 57, 43, 0.06);
  box-shadow: 0 0 0 2px rgba(192, 57, 43, 0.15);
  animation: inkSelect 0.35s ease;
}

.grid-cell.found {
  animation: inkFadeOut 0.6s ease forwards;
  pointer-events: none;
}

.grid-cell.wrong {
  animation: inkShake 0.4s ease;
}

.grid-cell.hint {
  animation: inkHint 0.8s ease;
  border-color: var(--bamboo-green);
}

/* Found idiom list */
.found-list {
  width: 100%;
  max-width: 400px;
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.found-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(46, 139, 87, 0.04);
  border-left: 3px solid var(--bamboo-green);
  font-size: 0.9rem;
  color: var(--ink-dark);
  animation: slideInLeft 0.3s ease;
}

.found-item .idiom-text {
  font-weight: 700;
  letter-spacing: 0.1em;
}

.found-item .story-btn {
  background: none;
  border: 1px solid var(--mountain-blue);
  color: var(--mountain-blue);
  font-size: 0.7rem;
  padding: 2px 8px;
  cursor: pointer;
  font-family: var(--font-cn);
  transition: all var(--transition-fast);
}

.found-item .story-btn:hover {
  background: var(--mountain-blue);
  color: var(--rice-paper);
}

/* Game controls */
.game-controls {
  width: 100%;
  max-width: 400px;
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
}

.ctrl-btn {
  background: transparent;
  border: 1.5px solid var(--ink-light);
  color: var(--ink-light);
  font-family: var(--font-cn);
  font-size: 0.8rem;
  padding: 8px 20px;
  cursor: pointer;
  transition: all var(--transition-fast);
  letter-spacing: 0.08em;
}

.ctrl-btn:hover {
  border-color: var(--ink-dark);
  color: var(--ink-dark);
}

.ctrl-btn:active {
  transform: scale(0.96);
}

.ctrl-btn.primary {
  border-color: var(--vermillion);
  color: var(--vermillion);
}

.ctrl-btn.primary:hover {
  background: var(--vermillion);
  color: var(--rice-paper);
}

/* ---------- Result Screen ---------- */
.result-scroll {
  background: linear-gradient(135deg, #F8F3EB, #F0E8D8);
  border: 2px solid var(--ink-light);
  border-radius: 2px;
  padding: 32px 28px;
  max-width: 360px;
  width: 90%;
  text-align: center;
  margin-top: 8vh;
  position: relative;
  box-shadow: 0 4px 16px var(--paper-shadow);
  animation: scrollUnroll 0.6s ease;
}

.result-scroll::before,
.result-scroll::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 16px;
  background: linear-gradient(180deg, rgba(139, 125, 107, 0.12), transparent);
}

.result-scroll::before { top: 0; }
.result-scroll::after { bottom: 0; transform: rotate(180deg); }

.result-title {
  font-size: 1.6rem;
  color: var(--ink-dark);
  margin-bottom: 16px;
  letter-spacing: 0.12em;
}

.result-rank {
  display: inline-block;
  width: 80px;
  height: 80px;
  line-height: 80px;
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  color: var(--vermillion);
  border: 3px solid var(--vermillion);
  margin: 12px auto;
  position: relative;
}

.result-rank::before {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1.5px solid rgba(192, 57, 43, 0.4);
}

.result-score {
  font-size: 1.1rem;
  color: var(--ink-dark);
  margin: 12px 0;
}

.result-score span {
  font-size: 2rem;
  font-weight: 700;
  color: var(--vermillion);
}

.result-details {
  font-size: 0.8rem;
  color: var(--ink-light);
  margin-bottom: 20px;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.share-row {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.share-btn {
  background: transparent;
  border: 1.5px solid var(--ink-light);
  color: var(--ink-light);
  font-family: var(--font-cn);
  font-size: 0.8rem;
  padding: 8px 16px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.share-btn:hover {
  border-color: var(--ink-dark);
  color: var(--ink-dark);
}

/* ---------- Story Modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(44, 44, 44, 0.5);
  z-index: 100;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

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

.modal-content {
  background: linear-gradient(135deg, #F8F3EB, #F0E8D8);
  border: 2px solid var(--ink-light);
  border-radius: 2px;
  padding: 28px 24px;
  max-width: 380px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  animation: modalIn 0.3s ease;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--ink-light);
  cursor: pointer;
  transition: color var(--transition-fast);
  font-family: var(--font-cn);
}

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

.modal-idiom-title {
  font-size: 1.4rem;
  color: var(--ink-dark);
  text-align: center;
  margin-bottom: 4px;
  letter-spacing: 0.12em;
}

.modal-idiom-pinyin {
  font-family: var(--font-en);
  font-size: 0.85rem;
  color: var(--mountain-blue);
  text-align: center;
  margin-bottom: 14px;
}

.modal-idiom-meaning {
  font-size: 0.85rem;
  color: var(--ink-medium);
  margin-bottom: 12px;
  padding: 10px 14px;
  background: rgba(139, 125, 107, 0.06);
  border-left: 3px solid var(--ink-light);
}

.modal-story-title {
  font-size: 0.85rem;
  color: var(--vermillion);
  margin-bottom: 6px;
  letter-spacing: 0.06em;
}

.modal-story-text {
  font-size: 0.82rem;
  color: var(--ink-medium);
  line-height: 1.8;
}

/* Watch ad to unlock story */
.unlock-ad-btn {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 10px;
  background: var(--vermillion);
  color: var(--rice-paper);
  border: none;
  font-family: var(--font-cn);
  font-size: 0.85rem;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: all var(--transition-fast);
}

.unlock-ad-btn:hover {
  background: var(--vermillion-light);
}

/* ---------- Animations ---------- */
@keyframes inkSelect {
  0% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.3); }
  50% { box-shadow: 0 0 0 6px rgba(192, 57, 43, 0.1); }
  100% { box-shadow: 0 0 0 2px rgba(192, 57, 43, 0.15); }
}

@keyframes inkAppear {
  0% { opacity: 0; transform: scale(0.8); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes inkFadeOut {
  0% { opacity: 1; transform: scale(1); }
  30% { opacity: 0.8; transform: scale(1.1); background: rgba(46, 139, 87, 0.15); }
  100% { opacity: 0; transform: scale(0.6); }
}

@keyframes inkShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes inkHint {
  0%, 100% { border-color: rgba(139, 125, 107, 0.25); }
  50% { border-color: var(--bamboo-green); box-shadow: 0 0 8px rgba(46, 139, 87, 0.3); }
}

@keyframes scrollUnroll {
  0% { opacity: 0; transform: scaleY(0.3); transform-origin: top center; }
  60% { opacity: 1; transform: scaleY(1.02); }
  100% { transform: scaleY(1); }
}

@keyframes slideInLeft {
  0% { opacity: 0; transform: translateX(-20px); }
  100% { opacity: 1; transform: translateX(0); }
}

@keyframes modalIn {
  0% { opacity: 0; transform: translateY(20px); }
  100% { opacity: 1; transform: translateY(0); }
}

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

/* ---------- Responsive ---------- */
@media (min-width: 480px) {
  :root {
    --cell-size: 72px;
    --grid-gap: 10px;
  }

  .home-title {
    margin-top: 15vh;
  }
}

@media (max-width: 360px) {
  :root {
    --cell-size: 16vw;
    --grid-gap: 6px;
  }

  .grid-cell {
    font-size: 1.1rem;
  }

  .seal-btn {
    padding: 12px 36px;
    font-size: 1.1rem;
  }
}

@media (min-height: 800px) {
  .home-title {
    margin-top: 15vh;
  }
}

/* ---------- Utility ---------- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 24px;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  z-index: 200;
  pointer-events: none;
  animation: toastAnim 1.5s ease forwards;
}

.toast.success {
  color: var(--bamboo-green);
  background: rgba(46, 139, 87, 0.08);
  border: 1px solid var(--bamboo-green);
}

.toast.error {
  color: var(--vermillion);
  background: rgba(192, 57, 43, 0.08);
  border: 1px solid var(--vermillion);
}

@keyframes toastAnim {
  0% { opacity: 0; transform: translateX(-50%) translateY(10px); }
  15% { opacity: 1; transform: translateX(-50%) translateY(0); }
  70% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* ---------- Progress bar ---------- */
.progress-bar {
  width: 100%;
  max-width: 400px;
  height: 4px;
  background: rgba(139, 125, 107, 0.15);
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  background: var(--bamboo-green);
  transition: width var(--transition-medium);
}

/* ---------- Ad rewarded video simulation ---------- */
.ad-sim-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 300;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--font-cn);
}

.ad-sim-overlay.active {
  display: flex;
}

.ad-sim-text {
  font-size: 1.1rem;
  margin-bottom: 16px;
  letter-spacing: 0.08em;
}

.ad-sim-countdown {
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--vermillion);
}

.ad-sim-skip {
  margin-top: 24px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: rgba(255, 255, 255, 0.6);
  padding: 8px 20px;
  font-size: 0.8rem;
  cursor: not-allowed;
  font-family: var(--font-cn);
}

.ad-sim-skip.ready {
  cursor: pointer;
  border-color: var(--vermillion);
  color: var(--vermillion);
}

/* Bamboo divider */
.bamboo-divider {
  width: 80%;
  max-width: 300px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--bamboo-green), var(--bamboo-green), transparent);
  margin: 12px auto;
  opacity: 0.3;
}

/* Ink corner decorations */
.ink-corner {
  position: relative;
}

.ink-corner::before,
.ink-corner::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: var(--ink-light);
  opacity: 0.3;
}

.ink-corner::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid;
  border-left: 2px solid;
}

.ink-corner::after {
  bottom: -1px;
  right: -1px;
  border-bottom: 2px solid;
  border-right: 2px solid;
}

/* Legal footer */
.legal-footer {
  margin-top: 12px;
  margin-bottom: 4px;
  text-align: center;
}

.legal-link {
  font-size: 0.7rem;
  color: var(--ink-light);
  text-decoration: none;
  letter-spacing: 0.05em;
  transition: color var(--transition-fast);
}

.legal-link:hover {
  color: var(--ink-dark);
  text-decoration: underline;
}
