:root {
  --bg0: #080f1f;
  --bg1: #0f1a35;
  --bg2: #1c2f59;
  --panel: #0f1d35dd;
  --panel-soft: #122445cc;
  --line: #3e5a8a;
  --text: #eef4ff;
  --muted: #9cb0d3;
  --enemy: #e25d6e;
  --self: #5cd2ff;
  --accent: #73ffba;
  --warn: #ffb35c;
  --shadow: 0 10px 24px #02050f88;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: "Segoe UI", "Noto Sans JP", sans-serif;
  color: var(--text);
  background:
    radial-gradient(120vw 80vh at 10% -20%, #d7ecff 0%, transparent 55%),
    radial-gradient(120vw 80vh at 90% 120%, #7db6ff55 0%, transparent 60%),
    linear-gradient(180deg, #d8e8ff 0%, #9fc3f7 45%, #78a9ef 100%);
}

.app {
  max-width: 820px;
  margin: 0 auto;
  padding: 8px 8px 0;
  perspective: 1200px;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.hud {
  border: 1px solid #7ea5de;
  background: linear-gradient(180deg, #ffffffd9 0%, #dceafecc 100%);
  border-radius: 16px;
  padding: 10px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.hud-row.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.player-chip {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.06em;
  border: 1px solid #6e86b0;
}

.player-chip.enemy {
  color: #ffd9df;
  border-color: #db7481;
  background: #5b2130aa;
}

.turn-phase {
  display: grid;
  gap: 2px;
  text-align: right;
}

#turnLabel {
  font-size: 0.8rem;
  color: #36588d;
}

#phaseLabel {
  font-size: 0.92rem;
  font-weight: 700;
  color: #2c79c7;
}

.gauges {
  margin-top: 8px;
  display: grid;
  gap: 8px;
}

.gauge-block label {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  margin-bottom: 3px;
  color: #eaf3ff;
}

.gauge {
  height: 9px;
  border-radius: 999px;
  background: #091124;
  border: 1px solid #37537e;
  overflow: hidden;
}

.fill {
  height: 100%;
  width: 0;
  transition: width 220ms ease;
}

.enemy-fill {
  background: linear-gradient(90deg, #e25d6e 0%, #f395a2 100%);
}

.self-fill {
  background: linear-gradient(90deg, #57bfff 0%, #77f2ff 100%);
}

.resource-row {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.res {
  border: 1px solid #45679e;
  border-radius: 10px;
  background: #0d1932;
  font-size: 0.72rem;
  color: var(--muted);
  padding: 6px 8px;
}

.res strong {
  float: right;
  color: #ecf4ff;
  font-size: 0.9rem;
}

.assist-row {
  margin-top: 6px;
}

.res-btn {
  border: 1px solid #6abca3;
  border-radius: 10px;
  font-size: 0.68rem;
  color: #d9ffef;
  background: linear-gradient(180deg, #2b5d4c 0%, #23463b 100%);
  font-weight: 700;
}

.board {
  margin-top: 10px;
  display: grid;
  gap: 10px;
  position: relative;
  padding: 10px 6px 18px;
  border-radius: 22px;
  background:
    radial-gradient(circle at 50% 52%, #f6fbff 0 21%, transparent 22%),
    radial-gradient(circle at 50% 52%, #ebf4ff 0 35%, transparent 36%),
    radial-gradient(circle at 50% 52%, #d9e9ff 0 49%, transparent 50%),
    linear-gradient(180deg, #b9d7ff88 0%, #8eb9f588 100%);
  transform-style: preserve-3d;
  transform: rotateX(10deg) translateZ(0);
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 250px;
}

.board.shake {
  animation: boardShake 220ms linear;
}

.field {
  border: 1px solid #8db4ea;
  background: linear-gradient(180deg, #ffffffbf 0%, #e8f2ffbf 100%);
  border-radius: 14px;
  padding: 8px;
  box-shadow: var(--shadow);
  transform: translateZ(12px);
}

.field h3 {
  margin: 0 0 7px;
  font-size: 0.82rem;
  color: #436ca8;
}

.pit-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.pit {
  border: 1px solid #9ec0ef;
  border-radius: 10px;
  min-height: 128px;
  padding: 6px;
  background: linear-gradient(180deg, #fafdff 0%, #eaf2ff 100%);
  position: relative;
  transform: translateZ(6px);
}

.pit.third {
  border-color: #6f6bb5;
  background: linear-gradient(180deg, #251e53 0%, #16143d 100%);
}

.pit h4 {
  margin: 0 0 6px;
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  color: #5c80b8;
}

.units {
  display: grid;
  gap: 5px;
  position: relative;
}

.units.env-heat {
  box-shadow: inset 0 0 0 1px #d17b56, 0 0 12px #c66d3b66;
  border-radius: 8px;
}

.units.env-cold {
  box-shadow: inset 0 0 0 1px #66a8d6, 0 0 12px #4e9ddf66;
  border-radius: 8px;
}

.units.flash-hot {
  animation: pitFlashHot 220ms ease;
}

.units.flash-cold {
  animation: pitFlashCold 220ms ease;
}

.unit {
  border: 1px solid #8eb2e6;
  border-radius: 8px;
  background: #ffffff;
  color: #2d3f63;
  padding: 5px;
  font-size: 0.67rem;
  text-align: left;
  line-height: 1.28;
}

.unit.enemy {
  border-color: #a46474;
}

.unit.selected {
  outline: 2px solid #ffd567;
  transform: translateY(-1px);
}

.unit .flags {
  margin-top: 3px;
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

.flag {
  font-size: 0.56rem;
  border: 1px solid #5f7cb0;
  color: #dbe8ff;
  border-radius: 999px;
  padding: 1px 4px;
}

.flag.hot {
  border-color: #e19a68;
  color: #ffd7b7;
}

.flag.cold {
  border-color: #70b9e4;
  color: #c9edff;
}

.flag.debuff {
  border-color: #d07cb2;
  color: #ffd5f1;
}

.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(198px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #f8fbffef 0%, #deecffef 100%);
  border-top: 1px solid #99bae9;
  padding: 8px max(10px, env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  z-index: 20;
  box-shadow: 0 -10px 28px #01040d9e;
  max-width: 820px;
  margin: 0 auto;
}

#drawBtn,
#attackBtn,
#nextPhaseBtn {
  display: none;
}

button {
  border: 1px solid #79a6df;
  border-radius: 999px;
  color: #2f4c7a;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 10px 4px;
  background: linear-gradient(180deg, #ffffff 0%, #ddecff 100%);
}

button:hover {
  filter: brightness(1.07);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.46;
}

#attackBtn {
  background: linear-gradient(180deg, #b36d3e 0%, #8f4f22 100%);
  border-color: #da955f;
}

#useItemBtn {
  background: linear-gradient(180deg, #3f8c73 0%, #2c6a58 100%);
  border-color: #66b198;
}

.hand-wrap,
.assist-wrap,
.log-wrap {
  margin-top: 10px;
  border: 1px solid #496da7;
  border-radius: 14px;
  background: var(--panel-soft);
  box-shadow: var(--shadow);
  padding: 8px;
}

.assist-wrap,
.log-wrap {
  flex: 0 0 auto;
}

.hand-wrap {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(820px, 100%);
  z-index: 25;
  border-radius: 16px 16px 0 0;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #f7fbffef 0%, #dcebffef 100%);
  touch-action: pan-x;
  box-shadow: 0 -10px 22px #2e4a7e2a;
}

.assist-wrap,
.log-wrap {
  display: none;
}

.hand-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}

.hand-title h3,
.assist-wrap h3,
.log-wrap h3 {
  margin: 0;
  font-size: 0.8rem;
}

#selectionInfo {
  margin: 0;
  font-size: 0.64rem;
  color: #a9bddf;
}

.hand {
  margin-top: 6px;
  position: relative;
  height: 188px;
  overflow-x: auto;
  overflow-y: hidden;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 6px 4px;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
}

.card {
  width: 106px;
  min-height: 156px;
  position: relative;
  border: 1px solid #8bb2e6;
  border-radius: 14px;
  padding: 8px;
  color: #2f4b75;
  text-align: left;
  background:
    radial-gradient(circle at 80% 10%, #8bb6f255 0%, transparent 40%),
    linear-gradient(180deg, #ffffff 0%, #e8f3ff 100%);
  box-shadow: 0 8px 16px #3862a133;
  transition: transform 120ms ease, box-shadow 120ms ease;
  touch-action: pan-x;
  transform: rotate(var(--tilt, 0deg)) rotateX(4deg);
  transform-origin: center center;
  overflow: hidden;
  flex: 0 0 auto;
}

.card.item {
  border-color: #6dbd9f;
  background: linear-gradient(180deg, #164d41 0%, #10362d 100%);
}

.card small {
  display: block;
  opacity: 0.9;
  margin-top: 3px;
  font-size: 0.58rem;
}

.card.selected {
  outline: 2px solid #ffe487;
}

.card.dragging {
  opacity: 0.3;
}

.card.enter-pop {
  animation: cardPop 320ms ease;
}

.card:active {
  transform: translateY(-2px) rotate(var(--tilt, 0deg)) scale(1.01);
  box-shadow: 0 12px 24px #00000066;
}

.card .card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.58rem;
  opacity: 0.95;
}

.card .card-atom {
  margin: 6px auto 6px;
  width: 50px;
  height: 50px;
  border-radius: 999px;
  border: 1px solid #93b4e0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.16rem;
  font-weight: 800;
  background: radial-gradient(circle at 30% 28%, #ffffff 0%, #e8f3ff 55%, #c4dbf7 100%);
}

.card .card-section {
  margin-top: 6px;
  border-top: 1px solid #7ea2db66;
  padding-top: 4px;
  font-size: 0.56rem;
  line-height: 1.3;
}

.card.item .card-atom {
  border-color: #86d9ba;
  background: radial-gradient(circle at 30% 28%, #b2f0d733 0%, #6ec8a422 55%, #2d7f6633 100%);
}

.drag-ghost {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  min-width: 92px;
  border: 1px solid #94b4e7;
  border-radius: 14px;
  padding: 8px;
  color: #f2f8ff;
  background: linear-gradient(180deg, #24519a 0%, #163666 100%);
  box-shadow: 0 16px 30px #00000088;
  transform: translate(-50%, -50%) rotate(-2deg);
}

.pit.drop-target .units {
  outline: 2px dashed #ffe08b;
  border-radius: 10px;
}

.assist-list {
  margin-top: 7px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.assist-pill {
  border: 1px solid #5f8ec6;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.63rem;
  background: #0d1f3e;
}

.combine-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.combine-burst span {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #9ce3ff;
  animation: burstFly 420ms ease forwards;
}

.unit.combine-enter {
  animation: combineMerge 360ms ease;
}

.combine-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.combine-lines span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 42px;
  transform-origin: center center;
  background: linear-gradient(180deg, #d6f2ff 0%, #7ec7ff 100%);
  animation: mergeLine 300ms ease forwards;
}

@keyframes pitFlashHot {
  0% { background: #ff8a4f66; }
  100% { background: transparent; }
}

@keyframes pitFlashCold {
  0% { background: #6dc9ff66; }
  100% { background: transparent; }
}

@keyframes cardPop {
  0% { transform: translateY(10px) scale(0.94); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes combineMerge {
  0% { transform: scale(0.85); filter: brightness(1.9); }
  100% { transform: scale(1); filter: brightness(1); }
}

@keyframes burstFly {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.6); opacity: 0; }
}

@keyframes mergeLine {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--rot)) scaleY(0.2); }
  100% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--rot)) scaleY(1.1); }
}

@keyframes boardShake {
  0% { transform: translate(0, 0); }
  20% { transform: translate(2px, -1px); }
  40% { transform: translate(-2px, 1px); }
  60% { transform: translate(2px, 1px); }
  80% { transform: translate(-1px, -1px); }
  100% { transform: translate(0, 0); }
}

.log {
  margin-top: 7px;
  max-height: 170px;
  overflow-y: auto;
  display: grid;
  gap: 4px;
}

.log p {
  margin: 0;
  border-radius: 8px;
  padding: 5px 7px;
  font-size: 0.67rem;
  background: #09152b;
  border: 1px solid #294a7f;
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 30;
  background: #020712d6;
}

.overlay.show {
  display: flex;
}

.modal {
  width: min(520px, 100%);
  border: 1px solid #5b80ba;
  border-radius: 16px;
  padding: 14px;
  background: linear-gradient(180deg, #172f5d 0%, #0f1f3f 100%);
  box-shadow: 0 24px 44px #0000009b;
}

.modal h2 {
  margin: 0;
  font-size: 1rem;
}

.modal p {
  margin: 6px 0;
  font-size: 0.72rem;
  color: #c5d7f4;
}

.atom-choices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin: 8px 0;
}

.atom-chip {
  border: 1px solid #6b8fc6;
  border-radius: 10px;
  padding: 10px 0;
  text-align: center;
  color: #e8f1ff;
  background: #11264a;
  font-weight: 700;
}

.atom-chip.selected {
  border-color: #89ebc5;
  background: #173e36;
  color: #d4fff0;
}

#startGameBtn {
  width: 100%;
  margin-top: 8px;
}

.card-preview-modal p {
  white-space: pre-wrap;
  line-height: 1.45;
}

@media (max-width: 540px) {
  .app { padding: 8px 8px 0; }

  .pit {
    min-height: 116px;
  }

  .card { width: 96px; min-height: 146px; }
  .hand { height: 178px; }
  .action-bar { bottom: calc(188px + env(safe-area-inset-bottom)); }
  .board { padding-bottom: 236px; }
}
