:root {
  --bg: #0d1017;
  --panel: #141923;
  --panel2: #1b2230;
  --line: #2b3547;
  --text: #e9edf5;
  --dim: #8d97ab;
  --gold: #e7c46b;
  --red: #ff4d5e;
  --blue: #4da3ff;
  --green: #3ecf8e;
  --violet: #a98bff;
  --orange: #ff9d5c;
}

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

html, body {
  height: 100%;
}

body {
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(255, 70, 90, 0.10), transparent 60%),
    radial-gradient(900px 500px at 95% 110%, rgba(70, 150, 255, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  overflow-x: hidden;
}

button {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

.screen {
  min-height: 100vh;
}

#start-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.start-card {
  width: min(520px, 94vw);
  text-align: center;
  padding: 42px 38px 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(20, 25, 35, 0.86);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.start-emblem {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: 800;
  color: #fff;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff5a6e 0%, #9b1730 100%);
  box-shadow: 0 0 26px rgba(255, 77, 94, 0.45);
}

.start-title {
  font-size: 40px;
  letter-spacing: 0;
  font-weight: 900;
}

.start-sub {
  margin: 10px 0 28px;
  color: var(--dim);
  font-size: 14px;
}

.mode-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mode-btn {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel2);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.mode-btn:hover {
  border-color: var(--gold);
  transform: translateY(-1px);
}

.mode-btn.hotseat {
  color: #ffd9de;
}

.mode-btn.online {
  color: #d7e9ff;
}

.swap-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 16px 0 4px;
  color: var(--dim);
  font-size: 13px;
  cursor: pointer;
}

.swap-row input {
  accent-color: var(--gold);
  width: 16px;
  height: 16px;
}

.online-box {
  margin-top: 16px;
  display: flex;
  gap: 8px;
}

.online-box input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f141d;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.online-box input:focus {
  border-color: var(--blue);
}

.primary {
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: linear-gradient(135deg, #ff5a6e, #b41635);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.ghost {
  min-height: 40px;
  margin-top: 14px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--dim);
  font-size: 13px;
  cursor: pointer;
}

.ghost:hover {
  color: var(--gold);
  border-color: var(--gold);
}

#online-status {
  margin-top: 12px;
  font-size: 13px;
  color: var(--gold);
  min-height: 18px;
}

#topbar {
  height: 58px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 23, 33, 0.9);
}

.brand {
  font-size: 20px;
  font-weight: 900;
  color: var(--gold);
  white-space: nowrap;
}

#turn-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
}

.turn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.turn-dot.sukuna {
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
}

.turn-dot.gojo {
  background: var(--blue);
  box-shadow: 0 0 8px var(--blue);
}

.top-actions {
  display: flex;
  gap: 8px;
}

.top-btn {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.top-btn:hover {
  border-color: var(--gold);
}

#layout {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 18px;
  padding: 16px;
}

#board-wrap {
  position: relative;
  width: min(94vw, 760px, calc(100vh - 200px));
  flex: none;
}

#board {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #10141d;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.45);
}

.cell {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.035);
  cursor: default;
}

.cell.alt {
  background: rgba(255, 255, 255, 0.022);
}

.cell.edge {
  background: rgba(0, 0, 0, 0.18);
}

.cell.domain-sukuna {
  background: rgba(255, 48, 75, 0.13);
  box-shadow: inset 0 0 0 1px rgba(255, 77, 94, 0.28);
}

.cell.domain-gojo {
  background: rgba(65, 135, 255, 0.13);
  box-shadow: inset 0 0 0 1px rgba(77, 163, 255, 0.28);
}

.cell.move {
  background: rgba(62, 207, 142, 0.30);
  box-shadow: inset 0 0 0 1px var(--green);
  cursor: pointer;
}

.cell.move:hover {
  background: rgba(62, 207, 142, 0.48);
}

.cell.place {
  background: rgba(231, 196, 107, 0.24);
  box-shadow: inset 0 0 0 1px var(--gold);
  cursor: pointer;
}

.cell.place:hover {
  background: rgba(231, 196, 107, 0.40);
}

.cell.target {
  background: rgba(255, 157, 92, 0.32);
  box-shadow: inset 0 0 0 1px var(--orange);
  cursor: pointer;
}

.cell.target:hover {
  background: rgba(255, 157, 92, 0.48);
}

.cell.preview {
  background: rgba(255, 220, 120, 0.26);
  box-shadow: inset 0 0 0 1px rgba(255, 220, 120, 0.7);
}

.token {
  position: absolute;
  inset: 7%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 800;
  z-index: 2;
  overflow: hidden;
  user-select: none;
}

.token.sukuna {
  color: #fff;
  background: radial-gradient(circle at 35% 28%, #ff8a97, #b3122f 72%);
  box-shadow: 0 0 14px rgba(255, 60, 90, 0.55);
}

.token.gojo {
  color: #fff;
  background: radial-gradient(circle at 35% 28%, #a8d5ff, #1c5cac 72%);
  box-shadow: 0 0 14px rgba(70, 150, 255, 0.5);
}

.token.summon {
  inset: 12%;
  font-size: 0.58em;
  border-radius: 22%;
}

.token.mahoraga {
  color: #fff;
  background: radial-gradient(circle at 35% 28%, #d7a5ff, #6b2f9e 72%);
  box-shadow: 0 0 12px rgba(169, 139, 255, 0.5);
}

.token.ebutu {
  color: #fff;
  background: radial-gradient(circle at 35% 28%, #9fe0c8, #1f7a5d 72%);
  box-shadow: 0 0 12px rgba(62, 207, 142, 0.45);
}

.token.wheel {
  color: #fff;
  background: radial-gradient(circle at 35% 28%, #ffd98a, #a86a12 72%);
  box-shadow: 0 0 12px rgba(231, 196, 107, 0.45);
}

.token .sprite {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.token .glyph {
  font-size: clamp(10px, 1.6vw, 15px);
  line-height: 1;
}

.mini-hp {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 7%;
  height: 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.55);
  overflow: hidden;
  z-index: 3;
}

.mini-hp i {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--green);
}

.ball {
  position: absolute;
  width: 34%;
  height: 34%;
  top: 33%;
  left: 33%;
  border-radius: 50%;
  z-index: 3;
  animation: pulse 1.5s ease-in-out infinite;
}

.ball.blue {
  background: radial-gradient(circle at 35% 30%, #9fd0ff, #0b5bd0 75%);
  box-shadow: 0 0 12px #3d9bff;
}

.ball.red {
  background: radial-gradient(circle at 35% 30%, #ffb0a0, #cf2439 75%);
  box-shadow: 0 0 12px #ff5a6e;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.14); }
}

.chant-mark {
  position: absolute;
  left: 50%;
  bottom: -2px;
  transform: translateX(-50%);
  font-size: 0.48em;
  color: #d6b8ff;
  background: rgba(30, 20, 60, 0.9);
  border: 1px solid #7b5fd6;
  border-radius: 4px;
  padding: 0 3px;
  z-index: 4;
  white-space: nowrap;
}

.float-dmg,
.float-heal,
.float-miss {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  z-index: 6;
  pointer-events: none;
  font-weight: 900;
  font-size: clamp(10px, 1.7vw, 16px);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
  animation: floatUp 0.95s ease-out forwards;
  white-space: nowrap;
}

.float-dmg {
  color: #ffd166;
}

.float-heal {
  color: var(--green);
}

.float-miss {
  color: #aeb8c9;
  font-size: clamp(9px, 1.4vw, 13px);
}

@keyframes floatUp {
  from {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -30px);
  }
}

#board-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 92%;
  padding: 8px 12px;
  border: 1px solid var(--gold);
  border-radius: 999px;
  background: rgba(12, 14, 20, 0.92);
  color: var(--gold);
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

#board-banner button {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel2);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

#hp-flash {
  position: absolute;
  top: -58px;
  left: 0;
  right: 0;
  z-index: 30;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 16, 23, 0.96);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  transition: opacity 0.35s;
}

#hp-flash.hidden {
  opacity: 0;
}

#fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 20;
}

.combo-ball {
  position: absolute;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: left 0.7s ease-in-out, top 0.7s ease-in-out;
  z-index: 21;
}

.combo-ball.blue {
  background: radial-gradient(circle at 35% 30%, #9fd0ff, #0b5bd0 75%);
  box-shadow: 0 0 14px #3d9bff;
}

.combo-ball.red {
  background: radial-gradient(circle at 35% 30%, #ffb0a0, #cf2439 75%);
  box-shadow: 0 0 14px #ff5a6e;
}

.combo-purple {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(190, 120, 255, 0.95), rgba(140, 60, 255, 0.35) 58%, transparent 76%);
  animation: comboExpand 1.1s ease-out forwards;
  z-index: 22;
}

@keyframes comboExpand {
  0% {
    opacity: 0.95;
    transform: translate(-50%, -50%) scale(0.18);
  }
  100% {
    opacity: 0.1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.cell.combo-purple {
  background: rgba(160, 90, 255, 0.32) !important;
}

.hp-flash-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
  font-size: 13px;
  font-weight: 800;
}

.hp-flash-head .hp-num {
  color: var(--gold);
}

.hp-flash-track {
  height: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0a0e15;
  overflow: hidden;
}

.hp-flash-fill {
  height: 100%;
  border-radius: 7px;
  transition: width 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.hp-flash-fill.sukuna {
  background: linear-gradient(90deg, #ff5a6e, #a3122e);
}

.hp-flash-fill.gojo {
  background: linear-gradient(90deg, #6ab4ff, #1559a8);
}

#panel {
  width: min(360px, 100%);
  flex: none;
}

.hud-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  background: rgba(20, 25, 35, 0.72);
}

.hud-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--dim);
  margin-bottom: 9px;
  letter-spacing: 0;
}

.hint {
  color: rgba(141, 151, 171, 0.7);
  font-size: 11px;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.action-btn {
  position: relative;
  min-height: 48px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel2);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  line-height: 1.25;
}

.action-btn .tag {
  display: block;
  margin-top: 3px;
  color: var(--dim);
  font-size: 11px;
  font-weight: 400;
}

.action-btn:hover:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold);
}

.action-btn:disabled {
  opacity: 0.36;
  cursor: not-allowed;
}

.action-btn .cd {
  position: absolute;
  top: 5px;
  right: 6px;
  font-size: 10px;
  color: #ffb46b;
}

.action-btn.highlight {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold) inset;
}

.submenu {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px dashed var(--line);
}

.sub-btn {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(31, 38, 53, 0.9);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.sub-btn:hover:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold);
}

.sub-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.end-turn {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(31, 38, 53, 0.9);
  color: var(--dim);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.end-turn:hover:not(:disabled) {
  color: var(--gold);
  border-color: var(--gold);
}

.end-turn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.unit-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  background: rgba(20, 25, 35, 0.72);
}

.unit-card .card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.unit-name {
  font-size: 15px;
  font-weight: 800;
}

.unit-name.sukuna {
  color: #ff8b99;
}

.unit-name.gojo {
  color: #8cc2ff;
}

.hp-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hp-track {
  flex: 1;
  height: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0a0e15;
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.25s;
}

.hp-fill.sukuna {
  background: linear-gradient(90deg, #ff5a6e, #a3122e);
}

.hp-fill.gojo {
  background: linear-gradient(90deg, #6ab4ff, #1559a8);
}

.hp-num {
  min-width: 46px;
  text-align: right;
  font-size: 12px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
  min-height: 20px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel2);
  color: var(--text);
  font-size: 11px;
}

.chip.burn {
  color: #ffb46b;
  border-color: #7a4a22;
}

.chip.domain {
  color: #ffd0d6;
  border-color: var(--red);
}

.chip.domain-gojo {
  color: #cfe3ff;
  border-color: var(--blue);
}

.chip.adapt {
  color: #d9c8ff;
  border-color: #7b5fd6;
}

.chip.amp {
  color: #b9f5d6;
  border-color: var(--green);
}

.chip.chant {
  color: #e3d2ff;
  border-color: #8a6ce0;
}

#log-panel {
  height: 132px;
  margin: 0 16px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 16, 23, 0.9);
  overflow: hidden;
}

#log-list {
  height: 100%;
  padding: 10px 12px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.7;
}

.log-line {
  color: #aeb8c9;
}

.log-line.log-win,
.log-line.log-unlock {
  color: var(--gold);
}

.log-line.log-damage {
  color: #ffd0d6;
}

.log-line.log-heal {
  color: #b9f5d6;
}

.log-line.log-domain,
.log-line.log-control {
  color: #cfe3ff;
}

.log-line.log-miss {
  color: #7f8aa0;
}

.log-line.log-error {
  color: #ff9aa8;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(8, 10, 15, 0.78);
  backdrop-filter: blur(5px);
}

.overlay-card {
  width: min(420px, 94vw);
  text-align: center;
  padding: 34px 26px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

.overlay-card h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

.overlay-card p {
  color: var(--dim);
  font-size: 13px;
  margin-bottom: 20px;
}

.overlay-icon {
  width: 58px;
  height: 58px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #ff8a97, #a3122e 72%);
  color: #fff;
  font-size: 28px;
  font-weight: 900;
}

.overlay-icon.winner {
  background: radial-gradient(circle at 35% 28%, #ffe3a0, #b8861f 72%);
  box-shadow: 0 0 26px rgba(231, 196, 107, 0.5);
}

.overlay-icon.domain {
  background: radial-gradient(circle at 35% 28%, #c9b4ff, #5133a8 72%);
  box-shadow: 0 0 26px rgba(169, 139, 255, 0.5);
}

.overlay-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.rules-card {
  width: min(680px, 94vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

.rules-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.rules-head h2 {
  font-size: 18px;
}

.rules-head button {
  min-height: 32px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.rules-body {
  padding: 16px 20px 22px;
  overflow-y: auto;
}

.rules-body h3 {
  margin: 14px 0 6px;
  color: var(--gold);
  font-size: 14px;
}

.rules-body h3:first-child {
  margin-top: 0;
}

.rules-body p {
  color: #c2cadb;
  font-size: 13px;
  line-height: 1.8;
}

@media (max-width: 900px) {
  #layout {
    flex-direction: column;
    align-items: center;
  }

  #board-wrap {
    width: min(96vw, 640px);
  }

  #panel {
    width: min(94vw, 560px);
  }

  #topbar {
    padding: 0 10px;
  }

  .brand {
    font-size: 17px;
  }

  .top-btn {
    padding: 0 8px;
    font-size: 12px;
  }

  #turn-info {
    font-size: 12px;
  }

  .token .glyph {
    font-size: 11px;
  }
}

@media (max-width: 560px) {
  .mode-box {
    grid-template-columns: 1fr;
  }

  .start-card {
    padding: 30px 20px 26px;
  }

  .start-title {
    font-size: 34px;
  }

  #log-panel {
    height: 110px;
    margin: 0 10px 10px;
  }

  .online-box {
    flex-direction: column;
  }
}
