/* ══════════════════════════════════════════════════════════════
   Mahjong Discard Trainer
   ══════════════════════════════════════════════════════════════ */

/* ── Reset ────────────────────────────────────────────────────── */
body {
  background-color: #060a07 !important;
  background-image:
    radial-gradient(ellipse 140% 55% at 50% 0%,   rgba(12, 38, 16, 0.85) 0%, transparent 65%),
    radial-gradient(ellipse 70%  45% at 15% 100%,  rgba(6, 22, 10, 0.6)   0%, transparent 55%),
    radial-gradient(ellipse 60%  40% at 85% 90%,   rgba(8, 28, 12, 0.5)   0%, transparent 50%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28'%3E%3Cpath d='M14 1L27 14L14 27L1 14Z' fill='none' stroke='rgba(255,255,255,0.018)' stroke-width='0.6'/%3E%3C/svg%3E") !important;
}

:root {
  --bg:           #050709;
  --felt:         #08120a;
  --felt-rim:     #152018;
  --surface:      #0d1a10;
  --surface-2:    #132018;
  --border:       rgba(255,255,255,0.06);
  --border-md:    rgba(255,255,255,0.1);
  --text:         #c0d4b8;
  --text-muted:   #3e5440;
  --text-mid:     #78987a;
  --gold:         #c8a020;
  --gold-bright:  #e4bc30;
  --gold-dim:     rgba(200,160,32,0.1);
  --correct:      #38b858;
  --wrong:        #c84030;
}

/* ── Layout ───────────────────────────────────────────────────── */
.mj-container {
  text-align: center;
  padding: 52px 16px 80px;
  width: 100%;
  min-height: 100vh;
  box-sizing: border-box;
  max-width: 820px;
  margin: 0 auto;
  position: relative;
  z-index: 2;
}

/* ── Nav ──────────────────────────────────────────────────────── */
.mj-back {
  position: absolute;
  top: 14px;
  left: 16px;
  z-index: 100;
}

.mj-nav {
  position: absolute;
  top: 14px;
  right: 16px;
  display: flex;
  gap: 6px;
  z-index: 100;
}

.mj-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-md);
  color: var(--text-mid);
  padding: 6px 12px;
  border-radius: 3px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  letter-spacing: 0.01em;
}

.mj-btn:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text);
}

.mj-btn-icon { padding: 6px 10px; }

.mj-btn-primary {
  background: var(--gold);
  border-color: var(--gold-bright);
  color: #050709;
  font-weight: 700;
  padding: 12px 36px;
  font-size: 0.9rem;
  letter-spacing: 0.05em;
  border-radius: 3px;
}

.mj-btn-primary:hover {
  background: var(--gold-bright);
  color: #050709;
}

/* ── Title ────────────────────────────────────────────────────── */
.mj-title {
  font-family: Zyzol, sans-serif;
  font-size: 2.4rem;
  color: var(--gold-bright);
  margin: 0 0 4px;
  letter-spacing: 0.06em;
  text-shadow: 0 0 40px rgba(228,188,48,0.2);
}

.mj-subtitle {
  font-size: 0.62rem;
  color: var(--text-muted);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  margin-bottom: 24px;
}

/* ── Difficulty Selector ──────────────────────────────────────── */
.diff-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 20px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.07);
  width: 100%;
}

.diff-btn {
  background: #080d09;
  border: none;
  border-right: 1px solid rgba(255,255,255,0.07);
  color: var(--text-muted);
  padding: 11px 4px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.diff-btn:last-child { border-right: none; }

.diff-btn:hover:not(.diff-active) {
  background: #0d1610;
  color: var(--text-mid);
}

.diff-btn[data-diff="easy"].diff-active   { background: #0e3a14; color: #60e870; }
.diff-btn[data-diff="medium"].diff-active { background: #0a1e58; color: #60a0f8; }
.diff-btn[data-diff="hard"].diff-active   { background: #4a3000; color: #f8c040; }
.diff-btn[data-diff="expert"].diff-active { background: #480808; color: #f06868; }

/* ── HUD ──────────────────────────────────────────────────────── */
.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 0 2px;
}

.hud-level {
  font-family: Zyzol, sans-serif;
  font-size: 0.85rem;
  color: var(--gold);
  min-width: 50px;
  text-align: left;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.xp-bar-wrap {
  flex: 1;
  height: 2px;
  background: rgba(255,255,255,0.06);
  border-radius: 1px;
  overflow: visible;
}

.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  border-radius: 1px;
  transition: width 0.5s ease;
}

.xp-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.hud-streak {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  transition: color 0.2s;
}

.hud-multiplier {
  font-family: Zyzol, sans-serif;
  font-size: 0.75rem;
  color: var(--gold);
  background: var(--gold-dim);
  border: 1px solid rgba(200,160,32,0.2);
  border-radius: 2px;
  padding: 1px 6px;
}

.streak-hot     { color: var(--gold) !important; }
.streak-fire    { color: #e07828 !important; }
.streak-inferno { color: #e04030 !important; }

/* ── Game Wrapper (no visual styling — just spacing) ─────────── */
.game-wrapper {
  background: none;
  border: none;
  padding: 0;
  margin-bottom: 12px;
}

/* ── Puzzle Header ────────────────────────────────────────────── */
.puzzle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.puzzle-question {
  font-size: 0.68rem;
  color: var(--text-muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.puzzle-difficulty {
  font-size: 0.66rem;
  padding: 2px 7px;
  border-radius: 2px;
  border: 1px solid currentColor;
  opacity: 0.65;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Hearts + Potential XP ────────────────────────────────────── */
.puzzle-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.hearts-container {
  display: flex;
  gap: 4px;
  font-size: 0.95rem;
}

.heart-empty { opacity: 0.1; }

.potential-xp {
  font-family: Zyzol, sans-serif;
  font-size: 0.9rem;
  color: var(--gold);
  letter-spacing: 0.04em;
  transition: opacity 0.15s;
}

/* ══════════════════════════════════════════════════════════════
   TILE MAT — the centrepiece
   ══════════════════════════════════════════════════════════════ */

.hand-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: center;
  padding: 22px 14px 26px;
  background: radial-gradient(ellipse 90% 80% at 50% 40%, #0c1a0e 0%, var(--felt) 100%);
  border: 1px solid var(--felt-rim);
  border-radius: 6px;
  box-shadow:
    inset 0 2px 20px rgba(0,0,0,0.6),
    inset 0 0 0 1px rgba(0,0,0,0.4),
    0 1px 0 rgba(255,255,255,0.03);
  min-height: 90px;
}

.loading-msg {
  color: var(--text-muted);
  font-family: -apple-system, sans-serif;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  padding: 20px;
}

/* ══════════════════════════════════════════════════════════════
   TILE
   ══════════════════════════════════════════════════════════════ */

.tile {
  position: relative;
  width: 54px;
  height: 76px;
  border-radius: 5px;
  background: linear-gradient(170deg, #fefbee 0%, #ecddb8 100%);
  border: 1.5px solid #b89840;
  box-shadow:
    0 6px 0 #5a3808,
    0 8px 24px rgba(0,0,0,0.8),
    inset 0 1px 0 rgba(255,255,255,0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: default;
  user-select: none;
  flex-shrink: 0;
  /* Only transition transform — box-shadow transitions repaint every frame */
  transition: transform 0.1s ease;
  overflow: hidden;
  will-change: transform;
}

.tile::before {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 3px;
  border: 1px solid rgba(160,120,40,0.2);
  pointer-events: none;
}

/* Hover shadow via opacity on a pseudo-element — compositor only, no repaint */
.tile::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 5px;
  box-shadow: 0 20px 2px #5a3808, 0 24px 36px rgba(0,0,0,0.95);
  opacity: 0;
  transition: opacity 0.1s ease;
  pointer-events: none;
  z-index: -1;
}

/* ── Tile Image ───────────────────────────────────────────────── */
.tile-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  user-select: none;
  position: relative;
  z-index: 1;
}

/* ── Interactive States ───────────────────────────────────────── */
.tile-clickable { cursor: pointer; }

.tile-clickable:hover {
  transform: translateY(-13px) scale(1.04);
  z-index: 20;
}

.tile-clickable:hover::after { opacity: 1; }

.tile-clickable:active {
  transform: translateY(-3px);
}

.tile-dimmed {
  filter: brightness(0.35) saturate(0.2);
  transform: scale(0.91);
  box-shadow: 0 3px 0 #5a3808, 0 4px 8px rgba(0,0,0,0.4);
}

.tile-wrong {
  background: linear-gradient(170deg, #fde8e4 0%, #e8b8b0 100%);
  border-color: #a02818;
  box-shadow: 0 6px 0 #501008, 0 8px 24px rgba(0,0,0,0.7);
}

.tile-correct {
  background: linear-gradient(170deg, #eafaee 0%, #c0e8c8 100%);
  border-color: #206830;
  box-shadow: 0 6px 0 #0e4018, 0 8px 28px rgba(32,104,48,0.4);
  transform: translateY(-8px) scale(1.06);
  z-index: 10;
}

.tile-selected { animation: tile-pop 0.28s cubic-bezier(0.34,1.56,0.64,1); }
.tile-shake    { animation: tile-shake 0.36s ease !important; }

/* Rank badge */
.tile-rank {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  font-size: 0.55rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-family: -apple-system, sans-serif;
  z-index: 2;
}
.rank-0 { background: #206830; color: #fff; }
.rank-1 { background: #1a4888; color: #fff; }
.rank-2 { background: #555; color: #fff; }

/* ── Result Panel ─────────────────────────────────────────────── */
.result-panel {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  animation: slide-up 0.22s ease;
  background: none;
}

.result-heading {
  font-family: Zyzol, sans-serif;
  font-size: 1.1rem;
  margin-bottom: 18px;
  letter-spacing: 0.04em;
}
.result-correct .result-heading { color: var(--correct); }
.result-wrong   .result-heading { color: var(--wrong); }

.result-choices {
  display: flex;
  flex-direction: column;
}

.choice-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px 0;
  border-top: 1px solid var(--border);
  text-align: left;
}

.choice-item:first-child { border-top: none; padding-top: 0; }

.choice-tile-wrap { flex-shrink: 0; }

.choice-tile-wrap .tile {
  width: 38px;
  height: 54px;
  cursor: default;
  transform: none !important;
  box-shadow: 0 4px 0 #5a3808, 0 5px 12px rgba(0,0,0,0.5) !important;
}

.choice-meta { flex: 1; min-width: 0; }

.choice-rank-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  margin-bottom: 3px;
}
.choice-best  .choice-rank-label { color: var(--correct); }
.choice-item:not(.choice-best) .choice-rank-label { color: var(--text-muted); }

.choice-stats {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-variant-numeric: tabular-nums;
  margin-bottom: 6px;
}
.choice-stats strong { color: var(--gold); }

.choice-reason {
  font-size: 0.83rem;
  color: var(--text-mid);
  line-height: 1.6;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Next Button ──────────────────────────────────────────────── */
.next-btn-wrap {
  text-align: center;
  margin-top: 24px;
}

/* ── Modals ───────────────────────────────────────────────────── */
.mj-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  backdrop-filter: blur(4px);
  padding: 20px;
}

.mj-modal-box {
  background: var(--surface);
  border: 1px solid var(--border-md);
  border-radius: 4px;
  padding: 24px;
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  animation: slide-up 0.2s ease;
  box-shadow: 0 24px 80px rgba(0,0,0,0.8);
}

.mj-modal-box h2 {
  font-family: Zyzol, sans-serif;
  color: var(--gold-bright);
  margin: 0 0 20px;
  font-size: 1.2rem;
  letter-spacing: 0.06em;
}

.mj-modal-close {
  float: right;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0;
  transition: color 0.12s;
}
.mj-modal-close:hover { color: var(--text); }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 12px;
  text-align: center;
}

.stat-card-value {
  font-family: Zyzol, sans-serif;
  font-size: 1.5rem;
  color: var(--gold-bright);
  display: block;
  font-variant-numeric: tabular-nums;
}

.stat-card-label {
  font-size: 0.66rem;
  color: var(--text-muted);
  margin-top: 3px;
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Help */
.help-section { margin-bottom: 16px; }

.help-section h3 {
  font-family: Zyzol, sans-serif;
  color: var(--gold);
  margin: 0 0 7px;
  font-size: 0.88rem;
  letter-spacing: 0.06em;
}

.help-section p,
.help-section li {
  font-size: 0.83rem;
  color: var(--text-mid);
  line-height: 1.6;
  margin: 3px 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.help-section ul { padding-left: 16px; margin: 0; }

.tile-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
  justify-content: center;
}

.tile-legend .tile { cursor: default !important; }
.tile-legend .tile:hover {
  transform: none !important;
  box-shadow: 0 6px 0 #5a3808, 0 8px 24px rgba(0,0,0,0.8) !important;
}

/* ── XP Popups ────────────────────────────────────────────────── */
.xp-popup {
  position: absolute;
  font-family: Zyzol, sans-serif;
  font-size: 0.95rem;
  font-weight: bold;
  pointer-events: none;
  white-space: nowrap;
  z-index: 9999;
  transform: translate(-50%, 0);
  animation: xp-float 1.0s ease forwards;
}

.xp-popup-center {
  position: fixed;
  top: 28%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.35rem;
  animation: xp-float-center 1.4s ease forwards;
}

/* ── Animations ───────────────────────────────────────────────── */
@keyframes xp-float {
  0%   { opacity: 0; transform: translate(-50%, 0) scale(0.8); }
  18%  { opacity: 1; transform: translate(-50%, -10px) scale(1.05); }
  65%  { opacity: 1; transform: translate(-50%, -30px); }
  100% { opacity: 0; transform: translate(-50%, -46px) scale(0.9); }
}

@keyframes xp-float-center {
  0%   { opacity: 0; transform: translateX(-50%) scale(0.7); }
  22%  { opacity: 1; transform: translateX(-50%) scale(1.08); }
  60%  { opacity: 1; transform: translateX(-50%); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-18px); }
}

@keyframes tile-pop {
  0%   { transform: translateY(-8px) scale(1.06); }
  45%  { transform: translateY(-16px) scale(1.1); }
  100% { transform: translateY(-8px) scale(1.06); }
}

@keyframes tile-shake {
  0%, 100% { transform: translateX(0); }
  20%  { transform: translateX(-6px) rotate(-2deg); }
  40%  { transform: translateX(6px) rotate(2deg); }
  65%  { transform: translateX(-3px) rotate(-1deg); }
  82%  { transform: translateX(3px) rotate(1deg); }
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Misc ─────────────────────────────────────────────────────── */
p[style*="rgba(255,255,255,0.3)"] { color: var(--text-muted) !important; }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 580px) {
  .mj-container  { padding: 48px 10px 64px; }
  .mj-title      { font-size: 1.9rem; }
  .tile          { width: 44px; height: 62px; }
  .hand-tiles    { gap: 5px; padding: 16px 10px 18px; }
  .diff-btn      { padding: 10px 2px; font-size: 0.66rem; letter-spacing: 0.06em; }
  .tile-clickable:hover { transform: translateY(-9px) scale(1.03); }
  .choice-tile-wrap .tile { width: 34px; height: 48px; }
}
