:root {
  color-scheme: dark;
  --bg: #11151b;
  --panel: #1a2028;
  --panel-2: #232b34;
  --line: #3c4652;
  --text: #f5f3ec;
  --muted: #aeb8c4;
  --orange: #f28a18;
  --orange-2: #cf6a07;
  --stone: #a9aaa4;
  --stone-dark: #777b78;
  --blue: #3ba7ff;
  --yellow: #e0c25b;
  --red: #9a2027;
  --purple: #7b42ff;
  --green: #55c780;
  --focus: #f8f2d0;
  --bad: #ff6670;
  --good: #6fe094;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 12%, rgba(74, 98, 118, 0.28), transparent 28rem),
    linear-gradient(135deg, #10141a 0%, #18212a 48%, #11151b 100%);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: clamp(16px, 3vw, 34px);
  display: grid;
  place-items: center;
}

.trainer {
  width: min(1180px, 100%);
  display: grid;
  grid-template-columns: minmax(270px, 330px) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.panel {
  min-height: 680px;
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(26, 32, 40, 0.94);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
}

.brand {
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.65rem, 2.4vw, 2.25rem);
  line-height: 1.1;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

select {
  width: 100%;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 13px;
  outline: none;
}

select:focus-visible,
button:focus-visible {
  outline: 3px solid rgba(248, 242, 208, 0.4);
  outline-offset: 2px;
}

.party-panel {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.panel-label {
  color: var(--muted);
  font-size: 0.78rem;
}

.party-list {
  display: grid;
  gap: 7px;
}

.party-row {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 7px;
  background: #121921;
}

.party-row.is-current {
  border-color: rgba(248, 242, 208, 0.7);
  box-shadow: inset 0 0 0 1px rgba(248, 242, 208, 0.18);
}

.party-role {
  min-width: 48px;
  display: flex;
  align-items: center;
  color: var(--text);
  font-weight: 900;
}

.role-mark {
  position: relative;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
}

.role-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 7px rgba(0, 0, 0, 0.32));
}

.role-mark-label {
  position: absolute;
  right: -10px;
  bottom: -4px;
  min-width: 23px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.74);
  background: rgba(14, 19, 25, 0.94);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 0.64rem;
  font-weight: 950;
  line-height: 1;
}

.party-debuff {
  min-width: 74px;
  padding: 5px 9px;
  border-radius: 999px;
  color: #10151b;
  font-size: 0.86rem;
  text-align: center;
}

.party-row[data-debuff="bubble"] .party-debuff {
  background: var(--blue);
}

.party-row[data-debuff="bind"] .party-debuff {
  background: var(--yellow);
}

.party-row[data-debuff="none"] .party-debuff {
  background: #3a4551;
  color: var(--muted);
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.stat {
  min-height: 75px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: #151b22;
  padding: 12px;
  display: grid;
  align-content: center;
  gap: 6px;
}

.stat span {
  color: var(--muted);
  font-size: 0.76rem;
}

.stat strong {
  font-size: 1rem;
}

.stepper {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}

.step {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #141a21;
  color: var(--muted);
}

.step span {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 800;
}

.step b {
  font-size: 0.94rem;
}

.step.is-active {
  border-color: rgba(248, 242, 208, 0.58);
  background: #222933;
  color: var(--text);
}

.timer-panel {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.timer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.82rem;
}

.timer-top strong {
  color: var(--text);
  font-size: 1.08rem;
}

.timer-bar {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #101820;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.timer-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--good), #4a89e8);
  transition: width 90ms linear;
}

.timer-fill.is-low {
  background: linear-gradient(90deg, var(--bad), #f0b84a);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

button {
  min-height: 45px;
  border: 0;
  border-radius: 7px;
  color: var(--text);
  cursor: pointer;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.primary {
  background: linear-gradient(180deg, #4a89e8, #2e65b7);
}

.ghost {
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.notice {
  min-height: 74px;
  margin: 0;
  padding: 13px 14px;
  border-radius: 8px;
  background: #111820;
  color: var(--muted);
  line-height: 1.6;
}

.notice.is-good {
  color: var(--good);
}

.notice.is-bad {
  color: var(--bad);
}

.copyright {
  margin: 10px 0 0;
  color: rgba(174, 184, 196, 0.72);
  font-size: 0.68rem;
  line-height: 1.45;
}

.board-wrap {
  min-height: 680px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(22, 28, 36, 0.84);
  padding: clamp(14px, 2vw, 24px);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
}

.board-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 36px;
  color: var(--muted);
}

.board-meta span:first-child {
  color: var(--text);
  font-weight: 800;
}

.board {
  position: relative;
  width: min(100%, 660px);
  aspect-ratio: 1 / 1;
  align-self: center;
  justify-self: center;
  overflow: hidden;
  border: 4px solid #363d43;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.07) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.07) 1px, transparent 1px),
    radial-gradient(circle at center, #ff9d1f 0%, var(--orange) 58%, var(--orange-2) 100%);
  background-size:
    12.5% 12.5%,
    12.5% 12.5%,
    cover;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.12),
    0 22px 55px rgba(0, 0, 0, 0.28);
}

.crystal-safe-area {
  position: absolute;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent 46%),
    linear-gradient(180deg, var(--stone), var(--stone-dark));
  border: 1px solid rgba(255, 255, 255, 0.28);
  opacity: 0.9;
  z-index: 1;
  pointer-events: none;
}

.grid-line {
  position: absolute;
  background: rgba(31, 40, 50, 0.18);
  pointer-events: none;
  z-index: 2;
}

.grid-x {
  left: 50%;
  top: 0;
  width: 2px;
  height: 100%;
}

.grid-y {
  top: 50%;
  left: 0;
  width: 100%;
  height: 2px;
}

.orbit {
  position: absolute;
  left: 19%;
  top: 19%;
  width: 62%;
  height: 62%;
  border: 2px dashed rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  pointer-events: none;
  z-index: 3;
}

.whale {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 76px;
  height: 76px;
  transform: translate(-50%, -50%);
  border-radius: 45% 45% 52% 52%;
  background:
    radial-gradient(circle at 50% 58%, #5d27c9 0 34%, transparent 36%),
    linear-gradient(145deg, #9659ff, #4d2498);
  border: 3px solid rgba(255, 255, 255, 0.24);
  box-shadow: 0 12px 28px rgba(74, 18, 156, 0.46);
  display: grid;
  place-items: center;
  z-index: 4;
}

.whale::before,
.whale::after {
  content: "";
  position: absolute;
  top: 7px;
  width: 28px;
  height: 28px;
  background: #7b42ff;
  border-radius: 6px 22px 8px 20px;
}

.whale::before {
  left: -12px;
  transform: rotate(-24deg);
}

.whale::after {
  right: -12px;
  transform: scaleX(-1) rotate(-24deg);
}

.whale span {
  position: relative;
  z-index: 1;
  font-weight: 900;
  font-size: 0.88rem;
}

.zaratan,
.player-token,
.move-point {
  position: absolute;
  transform: translate(-50%, -50%);
}

.zaratan {
  width: 50px;
  height: 50px;
  border: 0;
  background: transparent;
  padding: 0;
  display: grid;
  place-items: center;
  z-index: 5;
}

.zaratan::before {
  content: "";
  width: 38px;
  height: 38px;
  clip-path: polygon(50% 4%, 94% 30%, 82% 88%, 50% 73%, 18% 88%, 6% 30%);
  background:
    radial-gradient(circle at 50% 38%, #ffd1c8 0 12%, transparent 14%),
    linear-gradient(180deg, #c9373c, #6e1219);
  border: 2px solid #ffe2d7;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.32));
}

.enemy-debuff {
  position: absolute;
  right: -5px;
  bottom: -4px;
  min-width: 24px;
  height: 24px;
  padding: 0 5px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.82);
  display: grid;
  place-items: center;
  color: #11161d;
  font-size: 0.74rem;
  font-weight: 950;
  z-index: 2;
}

.zaratan[data-debuff="bubble"] .enemy-debuff {
  background: var(--blue);
}

.zaratan[data-debuff="bind"] .enemy-debuff {
  background: var(--yellow);
}

.zaratan[data-debuff="none"] {
  cursor: default;
}

.zaratan:hover::after,
.move-point:hover::after {
  content: "";
  position: absolute;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.72);
}

.zaratan.is-selected::after,
.move-point.is-selected::after {
  content: "";
  position: absolute;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: 4px solid var(--focus);
  box-shadow: 0 0 18px rgba(248, 242, 208, 0.44);
}

.zaratan.is-correct::after,
.move-point.is-correct::after {
  content: "";
  position: absolute;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 4px solid var(--good);
}

.zaratan.is-wrong::after,
.move-point.is-wrong::after {
  content: "";
  position: absolute;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 4px solid var(--bad);
}

.player-token {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.76);
  background: rgba(15, 21, 28, 0.9);
  color: var(--text);
  display: grid;
  place-items: center;
  font-weight: 950;
  z-index: 8;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.34);
  transition:
    left 220ms ease,
    top 220ms ease;
}

.player-token .role-mark {
  width: 39px;
  height: 39px;
}

.player-token.is-hidden {
  display: none;
}

.move-point {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  border: 3px solid rgba(111, 224, 148, 0.72);
  background: rgba(17, 24, 32, 0.34);
  z-index: 3;
  cursor: pointer;
}

.board.is-idle .zaratan,
.board.is-result .zaratan,
.board:not(.is-return) .zaratan[data-debuff="none"],
.board:not(.is-safe) .move-point {
  pointer-events: none;
}

.board.is-idle .zaratan,
.board.is-result .zaratan,
.board:not(.is-safe) .move-point {
  opacity: 0.48;
}

.board.is-safe .zaratan {
  pointer-events: none;
}

.board.is-safe .zaratan {
  opacity: 0.72;
}

.board.is-result .move-point {
  pointer-events: none;
}

.board.is-safe .move-point {
  z-index: 7;
}

.move-point::before {
  content: "安";
  position: absolute;
  left: 50%;
  top: 50%;
  width: auto;
  height: auto;
  border: 0;
  color: #f8f2d0;
  font-size: 0.95rem;
  font-weight: 950;
  transform: translate(-50%, -50%);
}

.celebration-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
}

.celebration-layer.is-active {
  opacity: 1;
}

.celebration-layer::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 24%;
  aspect-ratio: 1 / 1;
  border: 5px solid rgba(248, 242, 208, 0.72);
  border-radius: 50%;
  box-shadow:
    0 0 28px rgba(248, 242, 208, 0.4),
    inset 0 0 22px rgba(111, 224, 148, 0.26);
  transform: translate(-50%, -50%) scale(0.4);
  animation: celebration-ring 900ms ease-out forwards;
}

.celebration-message {
  position: relative;
  z-index: 2;
  min-width: 210px;
  padding: 12px 18px;
  border: 2px solid rgba(248, 242, 208, 0.86);
  border-radius: 999px;
  background:
    linear-gradient(135deg, rgba(17, 24, 32, 0.9), rgba(35, 43, 52, 0.72)),
    radial-gradient(circle at 50% 20%, rgba(111, 224, 148, 0.28), transparent 60%);
  color: #fff8c9;
  display: grid;
  place-items: center;
  gap: 1px;
  text-align: center;
  box-shadow:
    0 16px 36px rgba(0, 0, 0, 0.34),
    0 0 24px rgba(248, 242, 208, 0.24);
  animation: celebration-pop 2200ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.celebration-message strong {
  font-size: clamp(1.42rem, 4vw, 2.3rem);
  line-height: 1.05;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.38);
}

.celebration-message span {
  color: var(--good);
  font-size: clamp(0.74rem, 1.6vw, 0.9rem);
  font-weight: 900;
}

.celebration-piece {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  background: var(--bg);
  box-shadow: 0 0 10px color-mix(in srgb, var(--bg) 70%, transparent);
  transform: translate(-50%, -50%);
  animation: celebration-burst 1600ms cubic-bezier(0.12, 0.82, 0.18, 1) var(--delay) forwards;
}

@keyframes celebration-pop {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.76);
  }

  18% {
    opacity: 1;
    transform: translateY(0) scale(1.08);
  }

  82% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  100% {
    opacity: 0;
    transform: translateY(-10px) scale(0.96);
  }
}

@keyframes celebration-ring {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.34);
  }

  18% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.6);
  }
}

@keyframes celebration-burst {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.45) rotate(0deg);
  }

  14% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(0.78)
      rotate(calc(var(--turn) * 260deg));
  }
}

@media (max-width: 860px) {
  .app-shell {
    padding: 10px;
    place-items: start center;
  }

  .trainer {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .panel,
  .board-wrap {
    min-height: auto;
  }

  .panel {
    padding: 14px;
  }

  .brand {
    margin-bottom: 12px;
  }

  h1 {
    font-size: 1.55rem;
  }

  .field,
  .party-panel,
  .stat-grid,
  .stepper,
  .timer-panel,
  .actions {
    margin-bottom: 10px;
  }

  .party-list {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .party-row {
    min-height: 36px;
    padding: 6px 8px;
  }

  .party-role {
    min-width: 42px;
  }

  .role-mark {
    width: 30px;
    height: 30px;
  }

  .role-mark-label {
    right: -9px;
    min-width: 21px;
    height: 17px;
    font-size: 0.6rem;
  }

  .party-debuff {
    min-width: 64px;
    padding: 4px 8px;
    font-size: 0.8rem;
  }

  .stat-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .stat {
    min-height: 54px;
    padding: 7px 8px;
  }

  .stat span {
    font-size: 0.68rem;
  }

  .stat strong {
    min-width: 0;
    overflow-wrap: anywhere;
    font-size: 0.82rem;
    line-height: 1.25;
  }

  .stepper {
    gap: 6px;
  }

  .step {
    min-height: 38px;
    gap: 6px;
    padding: 6px 7px;
  }

  .step span {
    width: 23px;
    height: 23px;
    font-size: 0.86rem;
  }

  .step b {
    font-size: 0.82rem;
  }

  .timer-panel {
    gap: 6px;
  }

  .timer-bar {
    height: 9px;
  }

  .actions {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  button {
    min-height: 44px;
  }

  .notice {
    min-height: 50px;
    padding: 10px 12px;
    font-size: 0.9rem;
    line-height: 1.45;
  }

  .copyright {
    margin-top: 8px;
    font-size: 0.64rem;
  }

  .board-wrap {
    padding: 10px;
    gap: 8px;
  }

  .board-meta {
    min-height: 28px;
    font-size: 0.86rem;
  }

  .board {
    width: min(100%, 430px);
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 6px;
  }

  .panel,
  .board-wrap {
    padding: 8px;
  }

  .brand,
  .stat-grid,
  .stepper {
    display: none;
  }

  select {
    padding: 9px 11px;
  }

  .field,
  .party-panel,
  .timer-panel,
  .actions {
    margin-bottom: 8px;
  }

  .panel-label,
  .field {
    font-size: 0.76rem;
  }

  .party-row {
    min-height: 34px;
  }

  .party-debuff {
    min-width: 58px;
    font-size: 0.76rem;
  }

  .actions {
    grid-template-columns: 1fr 1fr;
  }

  .notice {
    min-height: 42px;
    padding: 8px 10px;
    font-size: 0.84rem;
  }

  .copyright {
    margin-top: 6px;
    font-size: 0.58rem;
  }

  .board-wrap {
    gap: 6px;
  }

  .board-meta {
    min-height: 24px;
    font-size: 0.78rem;
  }

  .whale {
    width: 54px;
    height: 54px;
  }

  .zaratan {
    width: 48px;
    height: 48px;
  }

  .zaratan::before {
    width: 34px;
    height: 34px;
  }

  .enemy-debuff {
    min-width: 23px;
    height: 23px;
    font-size: 0.7rem;
  }

  .move-point {
    width: 58px;
    height: 58px;
  }

  .player-token {
    width: 46px;
    height: 46px;
  }

  .player-token .role-mark {
    width: 36px;
    height: 36px;
  }

  .celebration-message {
    min-width: 174px;
    padding: 10px 14px;
  }

}

@media (max-width: 380px) {
  .board {
    width: min(100%, 310px);
  }

  .move-point {
    width: 54px;
    height: 54px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .celebration-layer::before,
  .celebration-piece {
    display: none;
  }

  .celebration-message {
    animation: none;
  }
}
