* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #2a1c16; }
[hidden] { display: none !important; }
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #f0e8dc; user-select: none; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
#stage {
  position: fixed; inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#game { width: 100%; height: 100%; display: block; }

/* —— Hit zones (aligned to table) —— */
.hits {
  position: fixed; left: 8%; right: 8%; height: clamp(64px, 12vh, 110px);
  z-index: 15; pointer-events: none;
}
.row-ai { top: clamp(16%, 20vh, 26%); }
.row-player { top: clamp(36%, 42vh, 48%); }
.hit-minion {
  pointer-events: auto; position: absolute; top: 10%;
  width: clamp(48px, 8vw, 72px); height: 80%;
  transform: translateX(-50%); background: transparent;
  border: 2px solid transparent; cursor: pointer; border-radius: 10px;
}
.hit-minion:hover, .hit-minion:focus-visible {
  border-color: rgba(255, 200, 80, .55); background: rgba(255,200,80,.08); outline: none;
}
.hit-minion.can-atk { border-color: rgba(80,255,140,.7) !important; box-shadow: 0 0 12px rgba(80,255,140,.4); }
.hit-minion.selected {
  border-color: rgba(255,200,80,.95) !important;
  background: rgba(255,180,60,.16);
  box-shadow: 0 0 14px rgba(255,180,60,.45);
}
.hit-minion.valid-target { border-color: rgba(255,90,70,.85) !important; background: rgba(255,60,60,.14); }
.hit-hero {
  position: fixed; z-index: 16;
  width: clamp(64px, 11vw, 88px); height: clamp(64px, 11vw, 88px);
  border-radius: 50%; border: 3px solid rgba(255,200,120,.55);
  cursor: pointer; left: 50%; transform: translateX(-50%);
  background-size: cover; background-position: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.45), inset 0 0 0 2px rgba(0,0,0,.25);
}
.hit-hero.ai {
  top: clamp(4%, 6vh, 10%);
  border-color: rgba(100,180,230,.7);
  background-image: url("../assets/arts/hero_ai.webp");
}
.hit-hero.player {
  bottom: calc(var(--hand-h, 148px) + 58px);
  border-color: rgba(240,140,70,.75);
  background-image: url("../assets/arts/hero_player.webp");
}
.hit-hero:hover, .hit-hero:focus-visible { filter: brightness(1.12); outline: none; }
.hit-hero.valid-target { border-color: rgba(255,100,80,.95) !important; box-shadow: 0 0 16px rgba(255,80,60,.5); }

/* —— HUD —— */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
#bottombar {
  position: absolute; left: 0; right: 0;
  bottom: calc(var(--hand-h, 148px) + 4px);
  display: flex; gap: 8px; align-items: center; flex-wrap: nowrap;
  padding: 8px 12px; pointer-events: auto; font-size: 13px; font-weight: 700;
  background: transparent;
  z-index: 2;
}
#topbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 8px 12px; pointer-events: auto; font-size: 13px; font-weight: 700;
  background: transparent;
}
#bottombar .btn { flex: 0 0 auto; }
#btn-end { margin-left: auto; }
#hp-ai, #hp-player {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px;
  background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.08);
}
#hp-ai { color: #80c0e8; }
#hp-player { color: #f0a060; }
#hp-ai::before, #hp-player::before {
  content: ""; width: 22px; height: 22px; border-radius: 50%;
  background-size: cover; background-position: center; flex-shrink: 0;
}
#hp-ai::before { background-image: url("../assets/arts/hero_ai.webp"); }
#hp-player::before { background-image: url("../assets/arts/hero_player.webp"); }
#turn-label { margin-left: auto; color: #ffe0a0; font-size: 12px; }
#deck-count { color: #a89070; font-size: 12px; }
#log {
  position: absolute; right: 10px; top: 44px; width: min(220px, 28vw);
  font-size: 11px; color: #b0a090; line-height: 1.45; text-align: right;
  text-shadow: 0 1px 3px #000; max-height: 28vh; overflow: hidden;
  pointer-events: none;
}
#tip {
  position: absolute; left: 50%; top: 36%; transform: translate(-50%, -50%);
  font-size: clamp(13px, 2.4vw, 15px); color: #ffe8b0; text-shadow: 0 2px 8px #000;
  min-height: 1.2em; padding: 6px 12px; border-radius: 8px;
  background: rgba(0,0,0,.35); pointer-events: none; max-width: 90vw; text-align: center;
}
#tip:empty { display: none; }

#mana-wrap { display: flex; flex-direction: column; gap: 3px; }
#mana-crystals { display: flex; gap: 3px; flex-wrap: wrap; max-width: 150px; }
#mana-crystals i {
  width: 11px; height: 11px; border-radius: 50%;
  background: #1a3040; border: 1px solid #3a6080; display: inline-block;
}
#mana-crystals i.on {
  background: radial-gradient(circle at 35% 35%, #a0e0ff, #2060a0);
  border-color: #80d0ff; box-shadow: 0 0 6px #40a0ff;
}
#mana {
  position: relative; width: 110px; height: 12px; background: #1a2830;
  border: 1px solid #3a6080; overflow: hidden; border-radius: 2px;
}
#mana-fill {
  display: block; height: 100%; width: 10%;
  background: linear-gradient(90deg, #2060a0, #60c0ff);
}
#mana-text {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 10px; color: #e8f4ff;
}

/* —— Hand —— */
#hand-bar {
  --hand-h: 148px;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; gap: 6px; justify-content: center; align-items: flex-end;
  flex-wrap: nowrap; overflow-x: auto; overflow-y: visible;
  padding: 10px 12px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(42,28,22,.92), rgba(42,28,22,.45) 55%, transparent);
  height: var(--hand-h); pointer-events: auto;
  scrollbar-width: thin; scrollbar-color: #6a4830 transparent;
  -webkit-overflow-scrolling: touch;
}
.hand-card {
  flex: 0 0 auto;
  width: 100px; padding: 0 0 5px;
  background: #2a1c14; border: 1px solid #6a4830; color: #f0e0c8;
  font-family: inherit; cursor: pointer; text-align: left; position: relative;
  overflow: hidden; border-radius: 6px 6px 4px 4px;
  transition: transform .1s ease-out, border-color .1s ease-out, opacity .1s ease-out;
  will-change: transform;
}
.hand-card .art {
  display: block; width: 100%; height: 52px; object-fit: cover;
  background: #3a2818; pointer-events: none;
  content-visibility: auto;
}
.hand-card .cost {
  position: absolute; left: 4px; top: 4px; width: 22px; height: 22px;
  border-radius: 50%; background: #3080c0; color: #fff; font-style: normal;
  font-size: 11px; font-weight: 800; display: grid; place-items: center; z-index: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.hand-card b { display: block; font-size: 11px; margin: 4px 6px 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hand-card small {
  display: block; color: #a89070; font-size: 9px; margin: 0 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 88px;
}
.hand-card.on { border-color: #ffc060; box-shadow: 0 0 0 2px #ffc060; transform: translateY(-8px); }
.hand-card.dim { opacity: 0.42; }
.hand-card:active { transform: translateY(-4px) scale(0.98); }

.btn {
  padding: 10px 14px; font-size: 13px; font-weight: 700; background: #3a2818; color: #f0e0c8;
  border: 1px solid #6a4830; cursor: pointer; font-family: inherit; text-decoration: none;
  display: inline-block; border-radius: 4px; min-height: 40px;
}
.btn.primary { background: #8a4020; border-color: #e08040; }
.btn.glow { background: #2a3048; border-color: #7090c0; }
.btn.glow.used { opacity: 0.4; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* —— Card inspect (detail + 3D spin) —— */
.inspect-overlay {
  z-index: 60;
  background: radial-gradient(ellipse at center, rgba(80,48,28,.55), rgba(28,16,12,.78));
}
.inspect-card {
  width: min(200px, 48vw);
  aspect-ratio: 5 / 7;
  transform-style: preserve-3d;
  animation: inspect-spin 4.2s ease-in-out infinite;
  border-radius: 10px;
  box-shadow: 0 18px 40px rgba(0,0,0,.45), 0 0 0 2px rgba(255,190,100,.4);
}
.inspect-card img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 10px;
  background: #3a2818; display: block;
}
@keyframes inspect-spin {
  0% { transform: rotateY(-18deg) rotateX(6deg); }
  50% { transform: rotateY(18deg) rotateX(4deg); }
  100% { transform: rotateY(-18deg) rotateX(6deg); }
}
.inspect-name {
  font-size: 20px; font-weight: 800; color: #ffe0b0; text-align: center;
}
.inspect-stats {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}
.inspect-stats span {
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.1);
  color: #e8d8c8;
}
.inspect-stats .cost { color: #9fd8ff; border-color: #4080b0; }
.inspect-stats .atk { color: #ffd257; border-color: #a08020; }
.inspect-stats .hp { color: #ff9080; border-color: #a04040; }
.inspect-stats .type { color: #c0b0a0; }
.inspect-text {
  font-size: 14px; line-height: 1.7; color: #d0c0b0; text-align: center;
  min-height: 1.5em;
}
.inspect-actions {
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
}
.inspect-actions .btn { min-width: 110px; }

.overlay[hidden] { display: none; }
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: radial-gradient(ellipse at center, rgba(60,30,16,.85), rgba(8,4,4,.96));
  overflow-y: auto; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.panel {
  width: min(520px, 94vw); background: #1a120e; border: 1px solid #5a3820;
  border-top: 3px solid #e08040; padding: 22px 24px;
}
.logo {
  font-size: clamp(22px, 5vw, 34px); font-weight: 900; letter-spacing: .06em;
  background: linear-gradient(90deg, #ffb060, #e05030); -webkit-background-clip: text;
  background-clip: text; color: transparent;
}
.logo.sm { font-size: 20px; }
.sub { color: #a07050; font-size: 13px; margin: 4px 0 12px; }
.intro { font-size: 13.5px; line-height: 1.85; color: #c8b0a0; margin-bottom: 14px; }
.menu-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.help-body { font-size: 13.5px; line-height: 1.9; color: #c8b0a0; }
.help-body b { color: #ffb060; }
.help-body p { margin-bottom: 8px; }
.board { margin: 8px 0; max-height: 150px; overflow-y: auto; }
.board-row { display: flex; gap: 8px; padding: 4px 6px; font-size: 12px; border-bottom: 1px solid #2a1c14; }
.board-rank { color: #e08040; font-weight: 800; width: 28px; }
.board-score { margin-left: auto; color: #ffd257; font-weight: 700; }
.board-empty { color: #6a5a50; font-size: 12px; padding: 8px; }
.submit-row { display: flex; gap: 8px; margin: 10px 0 4px; flex-wrap: wrap; }
#player-name {
  flex: 1; min-width: 140px; padding: 10px; background: #221810; border: 1px solid #5a3820;
  color: #f0e8dc; font-family: inherit; font-size: 16px;
}
#submit-status { font-size: 12px; color: #a07050; min-height: 18px; }

/* —— Desktop wide —— */
@media (min-width: 901px) {
  :root { --hand-h: 156px; }
  #hand-bar { height: var(--hand-h); justify-content: center; padding-bottom: 16px; }
  .hand-card { width: 110px; }
  .hand-card .art { height: 60px; }
  .hand-card:hover { transform: translateY(-10px); border-color: #c09060; }
  .hits { left: 18%; right: 18%; }
  .hit-minion { width: clamp(56px, 6.5vw, 78px); }
  .hit-hero.player { bottom: calc(var(--hand-h) + 58px); }
}

/* —— Tablet / small laptop —— */
@media (max-width: 900px) and (min-width: 601px) {
  :root { --hand-h: 128px; }
  .hits { left: 10%; right: 10%; }
  #log { width: min(180px, 24vw); font-size: 10px; }
}

/* —— Phone portrait —— */
@media (max-width: 600px) {
  :root { --hand-h: 128px; }
  body { touch-action: manipulation; }
  #topbar {
    font-size: 11px; gap: 6px; padding: 6px 8px;
    justify-content: space-between;
  }
  #turn-label { margin-left: 0; }
  #bottombar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "hp mana"
      "power end";
    gap: 6px; padding: 6px 8px;
    bottom: calc(var(--hand-h) + 2px);
    align-items: center;
  }
  #bottombar.targeting {
    grid-template-areas:
      "hp mana"
      "power end"
      "cancel cancel";
  }
  #hp-player { grid-area: hp; justify-self: start; }
  #mana-wrap { grid-area: mana; justify-self: end; }
  #btn-power { grid-area: power; width: 100%; }
  #btn-end { grid-area: end; width: 100%; margin-left: 0; }
  #btn-cancel { grid-area: cancel; width: 100%; }
  #hp-ai, #hp-player { padding: 3px 8px; font-size: 11px; }
  #hp-ai::before, #hp-player::before { width: 18px; height: 18px; }
  #deck-count { display: none; }
  #log { display: none; }
  #tip { top: 30%; font-size: 13px; padding: 5px 10px; }
  #mana { width: 88px; }
  #mana-crystals { max-width: 100px; }
  #mana-crystals i { width: 9px; height: 9px; }
  .btn {
    padding: 8px 10px; font-size: 12px; min-height: 44px; min-width: 44px;
  }
  #hand-bar {
    height: var(--hand-h);
    justify-content: flex-start;
    padding: 8px 8px calc(12px + env(safe-area-inset-bottom));
    scroll-snap-type: x proximity;
  }
  .hand-card {
    width: 78px; scroll-snap-align: center;
  }
  .hand-card .art { height: 44px; }
  .hand-card b { font-size: 10px; margin: 3px 4px 0; }
  .hand-card small { font-size: 8px; margin: 0 4px; max-width: 70px; }
  .hand-card .cost { width: 20px; height: 20px; font-size: 10px; }
  .hits { left: 2%; right: 2%; height: clamp(72px, 14vh, 100px); }
  .row-ai { top: 16%; }
  .row-player { top: 40%; }
  .hit-minion {
    width: clamp(44px, 12vw, 58px); height: 85%;
    border-width: 2.5px;
  }
  .hit-hero {
    width: 52px; height: 52px;
  }
  .hit-hero.ai { top: 5%; }
  .hit-hero.player { bottom: calc(var(--hand-h) + 108px); }
  .panel { padding: 18px 16px; }
  .menu-row .btn { flex: 1 1 40%; text-align: center; }
}

/* —— Phone landscape —— */
@media (max-height: 480px) and (orientation: landscape) {
  :root { --hand-h: 96px; }
  #topbar { padding: 4px 8px; }
  #bottombar { padding: 4px 8px; gap: 6px; }
  #log { display: none; }
  #mana-crystals { display: none; }
  .hand-card { width: 70px; }
  .hand-card .art { height: 36px; }
  .hand-card small { display: none; }
  .row-ai { top: 12%; }
  .row-player { top: 38%; }
  .hits { height: 18vh; }
  .hit-hero.player { bottom: calc(var(--hand-h) + 40px); }
  .btn { min-height: 36px; padding: 6px 10px; }
}

/* coarse pointer: bigger targets always */
@media (pointer: coarse) {
  .hit-minion { min-width: 48px; min-height: 56px; }
  .hand-card { min-height: 88px; }
  .btn { min-height: 44px; }
}
