/* ============================================================
   Gem Mahjong: Chains of Andromeda — Aegean dusk, gold on marble
   ============================================================ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --ink: #201b2e;
  --sub: #6b6280;
  --gold: #d9a441;
  --gold-lt: #f0cd85;
  --gold-dk: #9d6f24;
  --night: #0d1024;
  --night-2: #1b1b40;
  --coral: #e2705a;
  --pearl: #7fe6d6;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1100px 620px at 12% -10%, #3b2a63 0%, rgba(59,42,99,0) 60%),
    radial-gradient(900px 560px at 108% 8%, #6b3350 0%, rgba(107,51,80,0) 62%),
    linear-gradient(180deg, #12132c 0%, #1d1a3c 46%, #2a1c36 100%);
  background-attachment: fixed;
  padding: 18px 14px 46px;
}

/* ---------------- site chrome ---------------- */
.site-head {
  max-width: 1080px; margin: 0 auto 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}
.site-head .logo {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
  color: #fff; font-weight: 800; letter-spacing: .3px; font-size: 17px;
}
.site-head .logo span.mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  border-radius: 9px; background: linear-gradient(150deg, var(--gold-lt), var(--gold-dk));
  color: #2b1c04; font-size: 16px;
  box-shadow: 0 4px 14px rgba(217,164,65,.35);
}
.site-nav { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #bdb4d4; flex-wrap: wrap; }
.site-nav a { color: #e6dcff; text-decoration: none; border-bottom: 1px solid rgba(230,220,255,.24); }
.site-nav a:hover { color: #fff; border-color: var(--gold); }
.site-nav em { color: var(--gold-lt); font-style: normal; }

.main { max-width: 1080px; margin: 0 auto; }

.hero { text-align: center; margin: 6px auto 18px; max-width: 760px; }
.hero h1 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: clamp(25px, 4.6vw, 42px);
  line-height: 1.14;
  letter-spacing: -.4px;
  color: #fff;
  text-shadow: 0 2px 26px rgba(217,164,65,.30), 0 1px 0 rgba(0,0,0,.4);
}
.hero h1 em {
  font-style: italic;
  background: linear-gradient(180deg, #fff4d8, var(--gold) 62%, #b8791c);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero .tagline { margin: 0; color: #c3bade; font-size: 14.5px; line-height: 1.7; }
.hero .chips { margin-top: 12px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.hero .chips span {
  font-size: 11.5px; font-weight: 700; letter-spacing: .3px;
  padding: 4px 11px; border-radius: 999px;
  color: #f4e4bd; background: rgba(217,164,65,.13);
  border: 1px solid rgba(217,164,65,.34);
}

/* ---------------- shell ---------------- */
.shell { max-width: 620px; margin: 0 auto; }

.hud {
  display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px;
}
.hud-row { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.hud-chip {
  font-size: 12.5px; font-weight: 700; letter-spacing: .2px;
  padding: 5px 11px; border-radius: 10px;
  color: #f2e9ff;
  background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.04));
  border: 1px solid rgba(217,164,65,.30);
  backdrop-filter: blur(6px);
}
.hud-chip.gold { color: #ffeec4; border-color: rgba(240,205,133,.5); }
.hud-chip.combo {
  color: #fff; background: linear-gradient(180deg, #e2705a, #a83f2c);
  border-color: rgba(255,220,200,.5);
}
.hud-chip.combo.pulse { animation: pop .45s ease; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.16); } 100% { transform: scale(1); } }
.hud-tools { margin-left: auto; display: flex; gap: 6px; }
.hud-tools button {
  width: 32px; height: 32px; border-radius: 10px; cursor: pointer;
  font-size: 14px; line-height: 1; color: #f0e8ff;
  background: linear-gradient(180deg, rgba(255,255,255,.11), rgba(255,255,255,.03));
  border: 1px solid rgba(217,164,65,.28);
}
.hud-tools button:hover { border-color: var(--gold); color: #fff; }

.time-bar {
  position: relative; height: 12px; border-radius: 999px; overflow: hidden;
  background: rgba(0,0,0,.42);
  border: 1px solid rgba(217,164,65,.30);
}
.time-fill {
  position: absolute; inset: 0 auto 0 0; width: 100%;
  background: linear-gradient(90deg, #f0cd85, var(--gold) 55%, #b8791c);
  box-shadow: 0 0 14px rgba(217,164,65,.5);
  transition: width .18s linear;
}
.time-fill.low { background: linear-gradient(90deg, #ff9b7d, #d64b32); box-shadow: 0 0 16px rgba(214,75,50,.6); }
.time-bar span {
  position: absolute; right: 8px; top: -1px;
  font-size: 9.5px; font-weight: 800; color: #22190a; letter-spacing: .4px;
}

.stage {
  position: relative; width: 100%;
  height: min(72vh, 660px); min-height: 380px;
  border-radius: 22px; overflow: hidden;
  background: #10122a;
  border: 1px solid rgba(217,164,65,.30);
  box-shadow: 0 26px 60px rgba(0,0,0,.55), inset 0 0 0 1px rgba(255,255,255,.05);
  touch-action: manipulation;
}
.stage canvas { display: block; position: absolute; left: 0; top: 0; }

.toast-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.toast {
  position: absolute; transform: translate(-50%, -100%);
  font-size: 13px; font-weight: 800; letter-spacing: .2px;
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
  color: #1d1508; background: linear-gradient(180deg, #ffeec4, var(--gold));
  box-shadow: 0 6px 18px rgba(0,0,0,.4);
  opacity: 0; transition: opacity .18s ease, transform 1s ease;
}
.toast.go { opacity: 1; transform: translate(-50%, calc(-100% - 26px)); }
.toast.bad { background: linear-gradient(180deg, #ffd0c4, #d64b32); color: #fff; }
.toast.warn { background: linear-gradient(180deg, #ffe7bd, #c78a1e); }
.toast.pearl { background: linear-gradient(180deg, #d5fff5, var(--pearl)); color: #07352e; }

.tray-warn {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  font-size: 11px; font-weight: 800; letter-spacing: .5px;
  padding: 5px 12px; border-radius: 999px; white-space: nowrap;
  color: #fff; background: rgba(190,56,36,.92);
  border: 1px solid rgba(255,200,180,.5);
  animation: warnPulse 1s ease-in-out infinite;
}
@keyframes warnPulse { 0%,100% { opacity: .82; } 50% { opacity: 1; } }

.glance-tag {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  font-size: 11px; font-weight: 800; letter-spacing: .5px;
  padding: 5px 12px; border-radius: 999px; white-space: nowrap;
  color: #06332c; background: linear-gradient(180deg, #d5fff5, var(--pearl));
  border: 1px solid rgba(255,255,255,.6);
}

/* ---------------- power-ups ---------------- */
.pu-bar { margin-top: 10px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pu {
  position: relative; cursor: pointer; border-radius: 14px; padding: 8px 6px 7px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: #f4ecff;
  background: linear-gradient(180deg, rgba(255,255,255,.11), rgba(255,255,255,.035));
  border: 1px solid rgba(217,164,65,.32);
  transition: transform .14s ease, border-color .14s ease, box-shadow .14s ease;
}
.pu:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--gold); box-shadow: 0 10px 22px rgba(0,0,0,.4); }
.pu:disabled, .pu.off { opacity: .42; cursor: default; }
.pu .pu-i { font-size: 17px; line-height: 1; }
.pu .pu-t { font-size: 9.5px; font-weight: 800; letter-spacing: .3px; text-transform: uppercase; }
.pu .pu-n {
  position: absolute; top: -6px; right: -6px;
  min-width: 19px; height: 19px; padding: 0 4px; border-radius: 999px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 900; color: #2a1c04;
  background: linear-gradient(180deg, var(--gold-lt), var(--gold));
  box-shadow: 0 3px 9px rgba(0,0,0,.45);
}

/* ---------------- overlays ---------------- */
.overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center; padding: 14px;
  background: linear-gradient(180deg, rgba(8,10,24,.72), rgba(8,10,24,.9));
  backdrop-filter: blur(7px);
  animation: fadeIn .22s ease;
}
[hidden] { display: none !important; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: 100%; max-height: 100%; overflow: auto;
  border-radius: 18px; padding: 20px 18px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.015)),
    linear-gradient(160deg, #242048, #17142e);
  border: 1px solid rgba(217,164,65,.36);
  box-shadow: 0 22px 50px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.09);
  color: #efe8ff;
}
.crest {
  width: 58px; height: 58px; margin: 0 auto 10px; border-radius: 16px;
  display: grid; place-items: center; font-size: 28px;
  background: linear-gradient(160deg, var(--gold-lt), var(--gold-dk));
  color: #2b1c04;
  box-shadow: 0 10px 26px rgba(217,164,65,.36);
}
.panel h2 {
  margin: 0 0 4px; font-family: var(--serif); font-weight: 700;
  font-size: clamp(22px, 4.8vw, 30px); color: #fff; letter-spacing: -.3px;
}
.panel h2 em { font-style: italic; color: var(--gold-lt); }
.panel .subtitle {
  margin: 0 0 12px; font-size: 12px; font-weight: 700; letter-spacing: 2.4px;
  text-transform: uppercase; color: var(--gold);
}
.panel p.blurb { margin: 0 0 16px; font-size: 13.5px; line-height: 1.75; color: #c8bfe2; }

.btn {
  display: block; width: 100%; margin: 8px 0 0; cursor: pointer;
  font-family: inherit; font-size: 14.5px; font-weight: 800; letter-spacing: .2px;
  padding: 12px 14px; border-radius: 13px;
  color: #f5edff;
  background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,.04));
  border: 1px solid rgba(217,164,65,.34);
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(0,0,0,.4); border-color: var(--gold); }
.btn-primary {
  color: #2b1c04;
  background: linear-gradient(180deg, var(--gold-lt), var(--gold) 60%, var(--gold-dk));
  border-color: rgba(255,240,200,.7);
  box-shadow: 0 12px 30px rgba(217,164,65,.34), inset 0 1px 0 rgba(255,255,255,.6);
}
.btn-primary:hover { box-shadow: 0 16px 34px rgba(217,164,65,.45); }
.btn-ghost { background: rgba(255,255,255,.05); }
.btn-foot { margin-top: 6px; }

.menu-row { display: flex; gap: 10px; margin-top: 8px; }
.menu-row .btn { margin: 0; }
.menu-stats { margin-top: 14px; font-size: 12px; color: #a99fc4; }
.menu-stats b { color: var(--gold-lt); }
.switch {
  display: inline-flex; align-items: center; gap: 7px; margin-top: 12px;
  font-size: 12px; color: #b6acd0; cursor: pointer;
}
.switch input { accent-color: var(--gold); }

/* level select */
.panel.level-panel { text-align: left; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 10px; }
.panel-head h2 { margin: 0; font-size: 20px; }
.panel-close {
  width: 30px; height: 30px; border-radius: 9px; cursor: pointer; flex: 0 0 auto;
  color: #efe8ff; font-size: 15px;
  background: rgba(255,255,255,.07); border: 1px solid rgba(217,164,65,.3);
}
#levelGrid { max-height: min(52vh, 420px); overflow: auto; padding-right: 4px; }
.lv-act { margin: 10px 0 6px; }
.lv-act b { display: block; font-family: var(--serif); font-size: 15px; color: var(--gold-lt); }
.lv-act span { font-size: 11.5px; color: #a99fc4; }
.lv-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.lv-btn {
  cursor: pointer; border-radius: 11px; padding: 7px 4px 5px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: #f0e8ff;
  background: linear-gradient(180deg, rgba(255,255,255,.09), rgba(255,255,255,.03));
  border: 1px solid rgba(217,164,65,.28);
}
.lv-btn:hover:not(.locked) { border-color: var(--gold); }
.lv-btn .lv-n { font-size: 14px; font-weight: 800; }
.lv-btn .lv-s { font-size: 10px; color: var(--gold); letter-spacing: 1px; }
.lv-btn.done { background: linear-gradient(180deg, rgba(217,164,65,.22), rgba(217,164,65,.07)); }
.lv-btn.locked { opacity: .34; cursor: default; }
.lv-btn.locked .lv-n::after { content: ' 🔒'; font-size: 10px; }
.lv-meta {
  display: flex; justify-content: space-between; gap: 10px;
  margin: 12px 0 4px; font-size: 12px; color: #b6acd0; flex-wrap: wrap;
}
.lv-meta span { background: rgba(255,255,255,.06); padding: 4px 10px; border-radius: 8px; }

.shop-btn {
  display: block; width: 100%; margin: 8px 0 0; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 700;
  padding: 11px 12px; border-radius: 12px; color: #f2e9ff;
  background: linear-gradient(180deg, rgba(127,230,214,.16), rgba(127,230,214,.05));
  border: 1px solid rgba(127,230,214,.4);
}
.shop-btn:disabled { opacity: .42; cursor: default; }
.shop-btn.owned { background: rgba(127,230,214,.10); color: var(--pearl); }

/* story */
.story-panel {
  width: 100%; max-height: 100%; overflow: auto; text-align: left;
  border-radius: 18px; padding: 22px 20px;
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(217,164,65,.14), rgba(217,164,65,0) 55%),
    linear-gradient(170deg, #211c42, #12102a);
  border: 1px solid rgba(217,164,65,.4);
  box-shadow: 0 22px 50px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.08);
  color: #e6dffb;
}
.story-act {
  margin: 0 0 6px; font-size: 11px; font-weight: 800; letter-spacing: 2.6px;
  text-transform: uppercase; color: var(--gold);
}
.story-panel h2 {
  margin: 0 0 12px; font-family: var(--serif); font-size: clamp(20px, 4.4vw, 27px);
  color: #fff; letter-spacing: -.2px;
}
.story-panel h2::after {
  content: ''; display: block; width: 68px; height: 2px; margin-top: 10px;
  background: linear-gradient(90deg, var(--gold), rgba(217,164,65,0));
}
.story-panel p { margin: 0 0 12px; font-size: 14px; line-height: 1.82; color: #cdc5e6; }
.story-panel p:first-of-type::first-letter {
  float: left; font-family: var(--serif); font-size: 42px; line-height: .92;
  padding: 3px 8px 0 0; color: var(--gold-lt);
}

/* win / lose */
.win-stars { font-size: 34px; letter-spacing: 4px; color: var(--gold); text-shadow: 0 4px 20px rgba(217,164,65,.5); margin-bottom: 4px; }
.panel h2.win-title { font-size: clamp(20px, 4.4vw, 27px); }
#winStats, #loseStats { font-size: 13px; line-height: 1.8; color: #c3bade; margin: 10px 0 6px; }
#winStats b, #loseStats b { color: var(--gold-lt); font-size: 16px; }
.flaw { color: var(--pearl); font-weight: 700; }
#loseBody { font-size: 13.5px; line-height: 1.75; color: #c3bade; }

/* how to play */
.rules-lite { text-align: left; font-size: 13px; line-height: 1.8; color: #cdc5e6; }
.rules-lite b { color: var(--gold-lt); }
.rules-lite ul { margin: 6px 0 10px; padding-left: 18px; }
.rules-lite li { margin-bottom: 5px; }
.warn-line { color: #ffb9a5; font-weight: 700; }
.pearl-line { color: var(--pearl); font-weight: 700; }

/* ---------------- prose / SEO ---------------- */
.prose {
  max-width: 820px; margin: 44px auto 0;
  background: rgba(255,255,255,.96);
  border-radius: 20px; padding: 30px 26px 26px;
  box-shadow: 0 22px 52px rgba(0,0,0,.4);
  color: #2a2438;
}
.prose h2 { font-family: var(--serif); font-size: 21px; margin: 26px 0 8px; color: #1e1a2c; }
.prose h2:first-child { margin-top: 0; }
.prose p { font-size: 14.5px; line-height: 1.82; color: #4b445e; margin: 0 0 12px; }
.prose ol.steps { margin: 0 0 14px; padding-left: 22px; }
.prose ol.steps li { font-size: 14.5px; line-height: 1.8; color: #4b445e; margin-bottom: 7px; }
.prose ol.steps b { color: #1e1a2c; }
.prose table.rules {
  width: 100%; border-collapse: collapse; margin: 4px 0 16px; font-size: 13.5px;
}
.prose table.rules th, .prose table.rules td {
  text-align: left; padding: 9px 11px; border-bottom: 1px solid #e8e3f0;
  vertical-align: top; line-height: 1.6;
}
.prose table.rules th { background: #f6f2fb; color: #1e1a2c; font-weight: 800; width: 34%; }
.prose table.rules tr:last-child td { border-bottom: none; }
.prose .faq h3 { font-size: 15.5px; margin: 16px 0 4px; color: #1e1a2c; }
.prose .faq p { margin: 0 0 6px; }
.prose .note { font-size: 13px; color: #6d6685; }

.site-foot {
  max-width: 1080px; margin: 26px auto 0; text-align: center;
  font-size: 12.5px; color: #a99fc4; line-height: 1.9;
}
.site-foot a { color: #e6dcff; }

@media (max-width: 560px) {
  body { padding: 12px 10px 34px; }
  .stage { height: min(66vh, 560px); border-radius: 18px; }
  .panel { padding: 17px 14px; border-radius: 15px; }
  .prose { padding: 22px 17px; border-radius: 16px; }
  .pu .pu-t { font-size: 8.5px; }
  .lv-row { grid-template-columns: repeat(4, 1fr); }
}
