@font-face {
  font-family: "ZCOOL KuaiLe";
  src: url("../assets/fonts/zcool-kuaile-subset.woff2") format("woff2");
  font-display: swap;
}

:root {
  --ink: #2a1b3d;
  --panel: rgba(38, 26, 74, 0.88);
  --panel-line: rgba(255, 246, 220, 0.22);
  --cream: #fff6dc;
  --dim: rgba(255, 246, 220, 0.72);
  --gold: #ffd76a;
  --gold-deep: #e8a530;
  --display: "ZCOOL KuaiLe", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --body: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  /* notch and home-indicator insets, for phones held sideways */
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --pb: 56px; /* on-screen button size */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1a1230;
  color: var(--cream);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  cursor: grab;
  touch-action: none;
}
#game.dragging { cursor: grabbing; }
#game.targeting { cursor: crosshair; }

[hidden] { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; }
kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 1px 6px;
  margin: 0 2px;
  border: 1.5px solid rgba(255, 246, 220, 0.5);
  border-bottom-width: 3px;
  border-radius: 6px;
  font: 600 12px/1.5 var(--body);
  text-align: center;
  background: rgba(255, 255, 255, 0.08);
}

/* ---------- shared pieces ---------- */

.btn {
  font-family: var(--display);
  font-size: 19px;
  padding: 10px 22px;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  background: linear-gradient(#fff6dc, #f1dfb4);
  color: var(--ink);
  box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.06s, box-shadow 0.06s, filter 0.12s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: linear-gradient(#ffe38e, #ffb93c); font-size: 22px; padding: 11px 30px; }

.link {
  background: none;
  border: none;
  padding: 4px 6px;
  color: var(--dim);
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link:hover { color: var(--gold); }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(20, 12, 40, 0.5);
  backdrop-filter: blur(3px);
  z-index: 20;
  overflow: auto;
}
.screen.side {
  justify-content: flex-start;
  padding-left: clamp(16px, 5vw, 80px);
  background: linear-gradient(90deg, rgba(20, 12, 40, 0.62), rgba(20, 12, 40, 0.1) 62%, rgba(20, 12, 40, 0));
  backdrop-filter: none;
}

.card {
  width: min(480px, 100%);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overscroll-behavior: contain;
  overflow: auto;
  padding: 24px 26px 18px;
  border: 2.5px solid var(--ink);
  border-radius: 22px;
  background: linear-gradient(160deg, rgba(58, 42, 110, 0.96), rgba(34, 24, 70, 0.96));
  box-shadow: 0 8px 0 rgba(20, 12, 40, 0.75), 0 0 0 2px rgba(255, 246, 220, 0.14) inset;
}
.card.wide { width: min(900px, 100%); }
.card.narrow { width: min(430px, 100%); text-align: center; }

h1, h2, h3 { font-family: var(--display); font-weight: 400; margin: 0; }
h1 {
  font-size: 56px;
  line-height: 1.05;
  color: var(--gold);
  text-shadow: 0 3px 0 var(--ink), 3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 -3px 0 var(--ink), 0 7px 0 rgba(20, 12, 40, 0.6);
  letter-spacing: 2px;
}
h2 { font-size: 32px; color: var(--gold); margin-bottom: 12px; text-shadow: 0 3px 0 var(--ink); }
h3 { font-size: 20px; color: var(--gold); margin: 14px 0 6px; }
p { margin: 6px 0; line-height: 1.6; font-size: 14.5px; color: var(--dim); }
.sub { font-family: var(--display); font-size: 17px; color: var(--cream); margin: 6px 0 0; }

.logo { display: flex; align-items: center; gap: 6px; margin: -8px 0 12px -14px; }
.logo canvas { width: 108px; height: 90px; flex: none; }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.mode {
  padding: 10px 4px 8px;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  background: rgba(255, 246, 220, 0.1);
  box-shadow: 0 4px 0 var(--ink);
  font-family: var(--display);
  font-size: 19px;
  line-height: 1.25;
}
.mode small { display: block; font: 12px var(--body); color: var(--dim); margin-top: 2px; }
.mode.on { background: linear-gradient(#ffe38e, #ffb93c); color: var(--ink); }
.mode.on small { color: rgba(42, 27, 61, 0.75); }

.opts { display: grid; gap: 8px; margin-bottom: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.row > label { width: 76px; flex: none; font-family: var(--display); font-size: 16px; color: var(--cream); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  padding: 4px 11px;
  border: 2px solid rgba(255, 246, 220, 0.35);
  border-radius: 999px;
  background: transparent;
  font-size: 14px;
  color: var(--cream);
}
.seg button:hover { border-color: var(--gold); }
.seg button.on { background: var(--gold); border-color: var(--ink); color: var(--ink); font-weight: 600; }
.row.off { opacity: 0.35; pointer-events: none; }

.actions { display: flex; gap: 12px; justify-content: space-between; align-items: center; }
.actions.center { justify-content: center; margin-top: 16px; }
.links { display: flex; flex-wrap: wrap; gap: 4px 10px; justify-content: center; margin-top: 14px; }
.stack { display: grid; gap: 14px; margin: 14px auto 6px; width: min(260px, 100%); }
.stack.row { grid-template-columns: 1fr 1fr; width: 100%; }
.stack.row .btn { font-size: 19px; padding: 10px 8px; }

/* ---------- help / credits ---------- */

.help-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 6px 30px; }
@media (max-width: 760px) { .help-grid { grid-template-columns: 1fr; } }
.keys { border-collapse: collapse; width: 100%; font-size: 14px; }
.keys td { padding: 4px 6px 4px 0; vertical-align: middle; color: var(--cream); }
.keys td:last-child { color: var(--dim); }
.spell-line { display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: center; padding: 4px 0; }
.spell-line canvas { width: 40px; height: 40px; }
.spell-line b { font-family: var(--display); font-weight: 400; font-size: 16px; color: var(--cream); }
.spell-line span { display: block; font-size: 13px; color: var(--dim); line-height: 1.4; }
.credits-list { font-size: 13.5px; line-height: 1.6; color: var(--dim); max-height: 50vh; overflow: auto; }
.credits-list h3 { margin-top: 10px; }
.credits-list a { color: var(--gold); }
.credits-list li { margin: 2px 0; }
.credits-list ul { margin: 4px 0; padding-left: 20px; }

.stats { width: 100%; margin: 14px 0 6px; border-collapse: collapse; font-size: 15px; }
.stats th { font-family: var(--display); font-weight: 400; font-size: 18px; padding: 4px; }
.stats td { padding: 5px 4px; color: var(--cream); }
.stats td:first-child { color: var(--dim); text-align: left; }
.stats tr + tr td { border-top: 1px solid var(--panel-line); }

/* ---------- HUD ---------- */

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; font-family: var(--display); }
#hud button, #spellpanel, #spellbar { pointer-events: auto; }

.topbar {
  position: absolute;
  top: 10px;
  left: calc(12px + var(--sl));
  right: calc(12px + var(--sr));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
.team {
  justify-self: start;
  width: min(330px, 100%);
  padding: 8px 12px 9px;
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 4px 0 rgba(20, 12, 40, 0.6);
  transition: box-shadow 0.2s, transform 0.2s;
}
.team.right { justify-self: end; }
.team.turn { box-shadow: 0 4px 0 rgba(20, 12, 40, 0.6), 0 0 0 3px var(--gold); transform: translateY(2px); }
.team-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.team-name { font-size: 20px; }
.team-tag { font: 12px var(--body); color: var(--dim); }
.team-bar {
  position: relative;
  height: 16px;
  margin: 5px 0 6px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.team-fill { height: 100%; width: 100%; border-radius: 999px; transition: width 0.45s cubic-bezier(.2, .8, .2, 1); }
.team-hp {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; line-height: 1; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}
.team-members { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  padding: 1px 7px;
  border-radius: 999px;
  border: 1.5px solid transparent;
  background: rgba(255, 246, 220, 0.12);
  font-size: 13px;
  white-space: nowrap;
}
.chip i { font-style: normal; color: var(--dim); margin-left: 4px; font-size: 12px; }
.chip.active { border-color: var(--gold); background: rgba(255, 215, 106, 0.22); }
.chip.dead { opacity: 0.4; text-decoration: line-through; }

.center { display: grid; justify-items: center; gap: 6px; }
#timer {
  width: 70px; height: 70px;
  display: grid; place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4a3a8a, #2a1f5a);
  box-shadow: 0 4px 0 rgba(20, 12, 40, 0.6), 0 0 0 3px rgba(255, 246, 220, 0.16) inset;
  font-size: 34px;
  line-height: 1;
}
#timer.low { background: radial-gradient(circle at 35% 30%, #e8503a, #8a1f1a); animation: pulse 0.5s infinite alternate; }
#timer.retreat { background: radial-gradient(circle at 35% 30%, #3fbf8f, #1f6a55); }
#timer.idle { opacity: 0.75; }
@keyframes pulse { to { transform: scale(1.08); } }

#wind {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--panel);
  font-size: 14px;
}
.wind-track { position: relative; width: 130px; height: 10px; border-radius: 999px; background: rgba(0, 0, 0, 0.4); overflow: hidden; }
.wind-track i { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: rgba(255, 246, 220, 0.6); }
#wind-fill { position: absolute; top: 0; bottom: 0; background: linear-gradient(90deg, #8affea, #5ab8ff); transition: left 0.4s, width 0.4s; }
#wind-arrow { width: 26px; text-align: center; color: #8affea; }
#round { font: 12px var(--body); color: var(--cream); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); }

.corner { position: absolute; top: 124px; right: calc(12px + var(--sr)); display: flex; gap: 6px; }
.mini {
  padding: 3px 11px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--panel);
  font-size: 14px;
  box-shadow: 0 3px 0 rgba(20, 12, 40, 0.6);
}
.mini:hover { background: rgba(70, 52, 130, 0.95); }
.mini.on { background: var(--gold); color: var(--ink); }

#banner {
  position: absolute; top: 24%; left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  padding: 8px 30px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 6px 0 rgba(20, 12, 40, 0.6);
  font-size: 30px;
  white-space: nowrap;
  opacity: 0;
}
#banner.show { animation: banner 1.7s ease both; }
#banner.big { font-size: 40px; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  20% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -64%) scale(0.96); }
}

#toast {
  position: absolute; top: 148px; left: 50%;
  transform: translateX(-50%);
  padding: 4px 18px;
  border-radius: 999px;
  background: rgba(20, 12, 40, 0.72);
  font-size: 19px;
  white-space: nowrap;
  opacity: 0;
}
#toast.show { animation: toast 2.4s ease both; }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 8px); }
  10%, 80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -6px); }
}

#hint {
  position: absolute; left: calc(14px + var(--sl)); bottom: 14px;
  max-width: min(36vw, 620px);
  padding: 6px 12px;
  border-radius: 12px;
  background: rgba(20, 12, 40, 0.62);
  font: 13px/1.7 var(--body);
  color: var(--cream);
}
#hint:empty { display: none; }
#hint kbd { font-size: 11px; }

#spellbar {
  position: absolute; left: 50%; bottom: calc(12px + var(--sb));
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  padding: 6px 16px 6px 6px;
  border: 2.5px solid var(--ink);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: 0 4px 0 rgba(20, 12, 40, 0.6);
}
#spell-current {
  position: relative;
  width: 58px; height: 58px;
  padding: 0;
  border: 2.5px solid var(--ink);
  border-radius: 15px;
  background: radial-gradient(circle at 35% 30%, #5a48a0, #33266a);
  box-shadow: 0 0 0 2px rgba(255, 246, 220, 0.16) inset;
}
#spell-current:hover { filter: brightness(1.15); }
#spell-current canvas { width: 48px; height: 48px; display: block; margin: 2px auto 0; }
#spell-ammo {
  position: absolute; right: -7px; bottom: -6px;
  min-width: 24px; padding: 0 5px;
  border: 2px solid var(--ink); border-radius: 999px;
  background: var(--gold); color: var(--ink);
  font-size: 13px; line-height: 18px; text-align: center;
}
.spell-info { min-width: 150px; max-width: 250px; }
#spell-name { font-size: 20px; line-height: 1.2; }
#spell-desc { font: 12.5px/1.4 var(--body); color: var(--dim); }
#fuse { display: flex; gap: 4px; align-items: center; font-size: 13px; color: var(--dim); }
#fuse button {
  width: 26px; height: 26px; padding: 0;
  border: 2px solid rgba(255, 246, 220, 0.35); border-radius: 50%;
  background: transparent; font-size: 14px;
}
#fuse button.on { background: var(--gold); color: var(--ink); border-color: var(--ink); }

#spellpanel {
  position: absolute; left: 50%; bottom: calc(92px + var(--sb));
  z-index: 2;
  transform: translateX(-50%);
  display: grid; grid-template-columns: repeat(6, 82px); gap: 8px;
  padding: 12px;
  border: 2.5px solid var(--ink);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: 0 6px 0 rgba(20, 12, 40, 0.6);
}
@media (max-width: 620px) { #spellpanel { grid-template-columns: repeat(4, 76px); } }
.spell {
  position: relative;
  display: grid; justify-items: center; gap: 1px;
  padding: 6px 2px 5px;
  border: 2px solid rgba(255, 246, 220, 0.25);
  border-radius: 13px;
  background: rgba(255, 246, 220, 0.07);
  font-size: 13.5px;
  line-height: 1.2;
}
.spell canvas { width: 40px; height: 40px; }
.spell:hover { border-color: var(--gold); background: rgba(255, 215, 106, 0.16); }
.spell.on { border-color: var(--gold); background: rgba(255, 215, 106, 0.28); }
.spell.empty { opacity: 0.32; pointer-events: none; }
.spell em {
  position: absolute; top: 3px; right: 5px;
  font: 12px var(--body); color: var(--gold);
}

@media (max-width: 900px) {
  .team-members { display: none; }
  .team-name { font-size: 17px; }
  #timer { width: 56px; height: 56px; font-size: 26px; }
  .wind-track { width: 90px; }
  .corner { top: 96px; }
  #hint { display: none; }
}

/* ---------- touch ---------- */

#pad, #rotate { display: none; }
html.touch #pad { display: block; }
html.touch .kbd-only, html:not(.touch) .touch-only { display: none; }

.pb {
  position: absolute;
  display: grid; place-items: center;
  width: var(--pb); height: var(--pb);
  padding: 0;
  border: 2.5px solid var(--ink);
  border-radius: 50%;
  background: rgba(46, 32, 92, 0.78);
  box-shadow: 0 3px 0 rgba(20, 12, 40, 0.6), 0 0 0 2px rgba(255, 246, 220, 0.16) inset;
  font-size: 17px;
  color: var(--cream);
  touch-action: none;
  pointer-events: auto;
  transition: opacity 0.2s;
}
.pb svg { width: 60%; height: 60%; pointer-events: none; }
.pb.held { background: var(--gold); color: var(--ink); transform: translateY(2px); box-shadow: 0 1px 0 rgba(20, 12, 40, 0.6); }
#pad.off .pb { opacity: 0.3; }

.pad-l {
  position: absolute;
  left: calc(12px + var(--sl)); bottom: calc(12px + var(--sb));
  width: calc(var(--pb) * 3); height: calc(var(--pb) * 3);
}
.pad-l .up { left: var(--pb); top: 0; }
.pad-l .left { left: 0; top: var(--pb); }
.pad-l .right { left: calc(var(--pb) * 2); top: var(--pb); }
.pad-l .down { left: var(--pb); top: calc(var(--pb) * 2); }

.pad-r { position: absolute; right: calc(12px + var(--sr)); bottom: calc(12px + var(--sb)); }
.pad-r .fire {
  right: 0; bottom: 0;
  width: calc(var(--pb) * 1.6); height: calc(var(--pb) * 1.6);
  background: linear-gradient(#ffe38e, #ffb93c);
  color: var(--ink);
  font-size: 22px;
}
.pad-r .fire.held { background: linear-gradient(#fff3c4, #ffd76a); }
.pad-r .jump { right: calc(var(--pb) * 1.75); bottom: 4px; }
.pad-r .flip { right: calc(var(--pb) * 1.55); bottom: calc(var(--pb) * 1.2); font-size: 15px; }
.pad-r .rotate { right: calc(var(--pb) * 0.3); bottom: calc(var(--pb) * 1.75); font-size: 15px; }

html.touch #hint {
  display: block;
  left: calc(12px + var(--sl)); top: 116px; bottom: auto;
  max-width: 46vw;
  pointer-events: none;
}
html.touch #hint:empty { display: none; }
html.touch #fuse {
  position: absolute; left: 50%; bottom: calc(100% + 8px);
  transform: translateX(-50%);
  padding: 4px 12px;
  border: 2px solid var(--ink); border-radius: 999px;
  background: var(--panel);
  white-space: nowrap;
}
html.touch #fuse button { width: 34px; height: 34px; font-size: 16px; }
html.touch .mini { padding: 6px 13px; }
html.touch .seg button { padding: 6px 12px; }
html.touch .link { padding: 8px 8px; }

#rotate {
  position: fixed; inset: 0; z-index: 50;
  align-items: center; justify-content: center;
  padding: 24px;
  background: #1a1230;
}
@media (orientation: portrait) and (max-width: 600px) {
  html.touch #rotate { display: flex; }
}

/* Phones held sideways: very little height, so everything gets tighter. */
@media (max-height: 520px) {
  :root { --pb: 52px; }
  .screen { padding: 8px; }
  .screen.side { padding-left: calc(10px + var(--sl)); }
  .card { max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); padding: 12px 18px 10px; border-radius: 18px; }
  #menu .card { width: min(720px, 100%); }
  h1 { font-size: 34px; }
  h2 { font-size: 26px; margin-bottom: 8px; }
  .logo { margin: -4px 0 6px -8px; }
  .logo canvas { width: 72px; height: 60px; }
  .logo .sub { font-size: 14px; margin-top: 2px; }
  .modes { gap: 8px; margin-bottom: 10px; }
  .mode { padding: 6px 4px 5px; font-size: 17px; }
  .opts { grid-template-columns: 1fr 1fr; gap: 6px 16px; margin-bottom: 10px; }
  .row > label { width: 62px; font-size: 14px; }
  .seg { gap: 4px; }
  html.touch .seg button, .seg button { padding: 4px 8px; font-size: 13px; }
  .btn { font-size: 17px; padding: 7px 16px; }
  .btn.primary { font-size: 19px; padding: 8px 24px; }
  .links { margin-top: 6px; }
  .stack { gap: 10px; margin: 8px auto 4px; }
  .stats { margin: 6px 0 4px; font-size: 14px; }
  .stats td { padding: 3px 4px; }

  .topbar { top: 6px; gap: 8px; }
  .team { width: min(230px, 100%); padding: 5px 10px 6px; border-radius: 13px; }
  .team-name { font-size: 16px; }
  .team-bar { height: 14px; margin: 3px 0 2px; }
  .team-members { display: none; }
  #timer { width: 46px; height: 46px; font-size: 22px; }
  .center { gap: 3px; }
  #wind { font-size: 12px; padding: 1px 8px; }
  .wind-track { width: 80px; height: 8px; }
  .corner { top: 62px; }
  #banner { font-size: 22px; padding: 5px 20px; top: 34%; }
  #banner.big { font-size: 28px; }
  #toast { top: 104px; font-size: 16px; }
  html.touch #hint { top: 62px; font-size: 12px; }
  #spellbar { bottom: calc(8px + var(--sb)); gap: 8px; padding: 4px 12px 4px 4px; border-radius: 16px; }
  #spell-current { width: 48px; height: 48px; border-radius: 12px; }
  #spell-current canvas { width: 40px; height: 40px; }
  .spell-info { min-width: 0; }
  #spell-name { font-size: 17px; white-space: nowrap; }
  #spell-desc { display: none; }
  #spellpanel { bottom: calc(70px + var(--sb)); grid-template-columns: repeat(6, 76px); gap: 6px; padding: 8px; }
  .spell { padding: 4px 2px 3px; font-size: 12.5px; }
  .spell canvas { width: 34px; height: 34px; }
}
