@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700;900&display=swap');

:root {
  --bg: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-surface: #16162a;
  --bg-glass: rgba(255, 255, 255, 0.04);
  --border-empty: #334155;
  --border-filled: #64748b;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --text-muted: #475569;
  --correct: #22c55e;
  --correct-glow: rgba(34, 197, 94, 0.35);
  --present: #eab308;
  --present-glow: rgba(234, 179, 8, 0.35);
  --absent: #334155;
  --accent: #8b5cf6;
  --accent-glow: rgba(139, 92, 246, 0.35);
  --radius: 16px;
  --radius-sm: 10px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  touch-action: manipulation;
}

body {
  font-family: 'Noto Sans SC', 'PingFang SC', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 420px;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 0) 16px env(safe-area-inset-bottom, 0);
  height: 100dvh;
}

/* === HEADER === */
.header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.header-title {
  text-align: center;
}

.header-title h1 {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(135deg, #a78bfa, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.puzzle-number {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 1px;
  margin-top: 1px;
}

.header-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1.5px solid var(--border-subtle);
  background: var(--bg-glass);
  color: var(--text-dim);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  font-family: inherit;
}

.header-btn:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.08);
}

/* === SUB HEADER (category + timer) === */
.sub-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding: 6px 0;
}

.category-hint {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 1px;
  opacity: 0.85;
}

.category-hint .cat-label {
  color: var(--text-muted);
  font-weight: 500;
}

.timer {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}

.timer.running {
  color: var(--text);
}

/* === GAME BOARD === */
.board {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 0;
  min-height: 0;
  overflow: hidden;
}

.row {
  display: flex;
  gap: 8px;
  perspective: 600px;
}

/* === TILES — the star of the show === */
.tile {
  width: 62px;
  height: 62px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 900;
  border: 2px solid var(--border-empty);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  transition: border-color 0.15s;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04),
              0 2px 4px rgba(0, 0, 0, 0.2);
}

.tile.filled {
  border-color: var(--border-filled);
  animation: pop 0.1s ease;
}

/* 3D flip reveal — Wordle-style rotateX */
.tile.reveal {
  animation: flip-in 0.5s ease forwards;
}

.tile.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: #fff;
  box-shadow: 0 0 24px var(--correct-glow),
              inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.tile.present {
  background: var(--present);
  border-color: var(--present);
  color: #fff;
  box-shadow: 0 0 24px var(--present-glow),
              inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.tile.absent {
  background: var(--absent);
  border-color: var(--absent);
  color: var(--text-dim);
  box-shadow: none;
}

.tile.win-bounce {
  animation: bounce 0.8s ease;
}

@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes flip-in {
  0%   { transform: rotateX(0deg); }
  50%  { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}

@keyframes bounce {
  0%, 20%  { transform: translateY(0); }
  40%      { transform: translateY(-28px); }
  50%      { transform: translateY(4px); }
  60%      { transform: translateY(-12px); }
  80%      { transform: translateY(2px); }
  100%     { transform: translateY(0); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80%      { transform: translateX(5px); }
}

.row.shake {
  animation: shake 0.5s ease;
}

/* === INPUT AREA === */
.input-area {
  width: 100%;
  padding: 12px 0 24px;
  flex-shrink: 0;
}

.input-wrap {
  position: relative;
  width: 100%;
}

.guess-input {
  width: 100%;
  padding: 14px 80px 14px 20px;
  border-radius: var(--radius);
  border: 2px solid var(--border-empty);
  background: var(--bg-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  font-family: inherit;
  outline: none;
  letter-spacing: 10px;
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.guess-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

.guess-input::placeholder {
  color: var(--text-muted);
  letter-spacing: 2px;
  font-size: 14px;
  font-weight: 500;
}

.guess-input:disabled {
  opacity: 0.3;
}

.btn-submit {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  padding: 10px 20px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: white;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 2px 10px var(--accent-glow);
  white-space: nowrap;
  z-index: 2;
}

.btn-submit:active {
  transform: translateY(-50%) scale(0.95);
}

.btn-submit:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  box-shadow: none;
}

.input-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
  min-height: 28px;
}

.input-hint {
  font-size: 13px;
  color: var(--text-muted);
}

.btn-hint {
  padding: 6px 16px;
  border-radius: 50px;
  border: 1.5px solid var(--accent);
  background: rgba(139, 92, 246, 0.1);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  white-space: nowrap;
  animation: hint-pulse 2s ease-in-out infinite;
}

.btn-hint:active {
  transform: scale(0.95);
  background: rgba(139, 92, 246, 0.2);
}

@keyframes hint-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(139, 92, 246, 0.3); }
  50% { box-shadow: 0 0 0 6px rgba(139, 92, 246, 0); }
}

/* === DONE AREA (game over state) === */
.done-area {
  width: 100%;
  padding: 12px 0 24px;
  flex-shrink: 0;
  animation: fade-in 0.3s ease;
}

.done-buttons {
  display: flex;
  gap: 10px;
}

.btn-done {
  flex: 1;
  padding: 14px 16px;
  border-radius: 14px;
  border: none;
  background: var(--bg-glass);
  border: 1.5px solid var(--border-subtle);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

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

.btn-done-share {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 10px var(--accent-glow);
}

.btn-practice {
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  border-radius: 50px;
  border: 1.5px solid rgba(234, 179, 8, 0.3);
  background: rgba(234, 179, 8, 0.08);
  color: #eab308;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.btn-practice:active {
  transform: scale(0.97);
  background: rgba(234, 179, 8, 0.15);
}

/* 练习模式标记 */
.practice-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 50px;
  background: rgba(234, 179, 8, 0.15);
  color: #eab308;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  margin-left: 6px;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === TOAST === */
.toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  padding: 14px 32px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  font-weight: 700;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* === MODALS — Glassmorphism === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  padding: 40px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal {
  position: relative;
  background: rgba(22, 22, 42, 0.88);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  flex-shrink: 0;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5),
              inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transform: translateY(30px) scale(0.95);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.show .modal {
  transform: translateY(0) scale(1);
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.modal-close:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.1);
}

.modal h2 {
  font-size: 20px;
  font-weight: 900;
  margin-bottom: 16px;
  text-align: center;
  letter-spacing: 3px;
}

.modal h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 24px 0 12px;
  text-align: center;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.modal p {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* === Help examples === */
.help-examples {
  margin: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.help-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.help-tiles {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.help-tile {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 900;
  background: var(--absent);
  border: 1.5px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
  color: var(--text-dim);
}

.help-tile.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: #fff;
  box-shadow: 0 0 16px var(--correct-glow);
}

.help-tile.present {
  background: var(--present);
  border-color: var(--present);
  color: #fff;
  box-shadow: 0 0 16px var(--present-glow);
}

.help-desc {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
  flex: 1;
  min-width: 100%;
}

.help-note {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
  line-height: 1.8;
}

/* === Stats === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  text-align: center;
  margin-bottom: 8px;
  padding: 16px 0;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
}

.stat-num {
  font-size: 32px;
  font-weight: 900;
  line-height: 1.1;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Distribution bars */
.distribution {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.dist-label {
  width: 14px;
  text-align: right;
  color: var(--text-muted);
  font-weight: 700;
  flex-shrink: 0;
}

.dist-bar {
  min-width: 28px;
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--absent);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  text-align: right;
  transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dist-bar.highlight {
  background: linear-gradient(90deg, var(--correct), #4ade80);
  box-shadow: 0 0 12px var(--correct-glow);
}

/* 结果区内的分享按钮和倒计时 */
#resultSection .share-buttons {
  margin-top: 20px;
}

#resultSection .next-puzzle {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
  margin-bottom: 4px;
}

.next-puzzle {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.next-puzzle strong {
  font-size: 20px;
  font-weight: 900;
  color: var(--text);
  letter-spacing: 2px;
  margin-left: 4px;
}

.btn-share {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 24px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(34, 197, 94, 0.4);
}

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

.share-buttons {
  display: flex;
  gap: 10px;
}

.share-buttons .btn-share {
  padding: 14px 12px;
  font-size: 14px;
  flex: 1;
  min-width: 0;
}

.btn-share-img {
  background: linear-gradient(135deg, var(--accent), #7c3aed) !important;
  box-shadow: 0 4px 16px var(--accent-glow) !important;
}

/* === RESULT SECTION === */
.result-title {
  text-align: center;
  font-size: 36px;
  font-weight: 900;
  margin-bottom: 4px;
}

.result-meta {
  text-align: center;
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.result-streak {
  text-align: center;
  font-size: 14px;
  color: #f59e0b;
  font-weight: 700;
  margin-bottom: 16px;
}

/* === IMAGE MODAL === */
.img-modal {
  text-align: center;
  padding: 20px;
}

.img-tip {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.share-img {
  width: 100%;
  max-width: 320px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* === RESPONSIVE === */

/* 窄屏手机 */
@media (max-width: 380px) {
  .tile { width: 52px; height: 52px; font-size: 24px; }
  .row { gap: 6px; }
  .board { gap: 6px; }
  .guess-input { padding: 12px 72px 12px 14px; font-size: 18px; letter-spacing: 6px; }
  .btn-submit { padding: 9px 14px; font-size: 13px; }
}

@media (max-width: 340px) {
  .tile { width: 46px; height: 46px; font-size: 20px; }
  .row { gap: 5px; }
  .board { gap: 5px; }
}

/* 矮屏：激进压缩，确保输入区可见 */
@media (max-height: 740px) {
  .tile { width: 54px; height: 54px; font-size: 26px; }
  .board { gap: 6px; padding: 8px 0; }
  .row { gap: 6px; }
  .header { padding: 6px 0; }
  .input-area { padding: 4px 0 10px; }
  .category-hint { padding: 4px 16px; font-size: 12px; }
  .guess-input { padding: 10px 70px 10px 14px; font-size: 16px; letter-spacing: 6px; }
  .btn-submit { padding: 8px 14px; font-size: 13px; }
}

@media (max-height: 640px) {
  .tile { width: 46px; height: 46px; font-size: 22px; }
  .board { gap: 5px; padding: 4px 0; }
  .row { gap: 5px; }
  .header-title h1 { font-size: 18px; }
}

/* 超矮屏（带浏览器地址栏等） */
@media (max-height: 560px) {
  .tile { width: 40px; height: 40px; font-size: 18px; }
  .board { gap: 4px; padding: 2px 0; }
  .row { gap: 4px; }
  .category-hint { padding: 2px 12px; font-size: 11px; }
}
