:root {
  --ink: #5e3828;
  --ink-soft: #7c5946;
  --paper: rgba(255, 246, 224, 0.9);
  --paper-strong: rgba(255, 250, 235, 0.97);
  --cream: #fff8e9;
  --almond: #f5dfba;
  --camel: #c99663;
  --tea: #8d5d3f;
  --tea-deep: #68402e;
  --peach: #ee9367;
  --peach-soft: #ffd0b7;
  --gold: #e7bd58;
  --jade: #65cfa3;
  --jade-bright: #7cf06f;
  --crystal: #8fcde7;
  --rose-gray: #c9a2a0;
  --line: rgba(132, 82, 49, 0.38);
  --line-strong: rgba(112, 66, 43, 0.62);
  --shadow: rgba(117, 74, 46, 0.18);
  --shadow-soft: rgba(167, 110, 68, 0.14);
  color-scheme: light;
  font-family: "STKaiti", "KaiTi", "FZKai-Z03", "Songti SC", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: #f7e0b8;
}

body {
  overflow: hidden;
  color: var(--ink);
  touch-action: manipulation;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  filter: saturate(0.72);
}

.hidden {
  display: none !important;
}

.shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 8%, rgba(255, 242, 205, 0.9), transparent 28%),
    radial-gradient(circle at 78% 82%, rgba(131, 215, 183, 0.22), transparent 30%),
    linear-gradient(180deg, #f6dbad 0%, #fdeed1 100%);
}

.view {
  position: relative;
  width: min(100vw, 480px);
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background-image:
    linear-gradient(180deg, rgba(255, 246, 221, 0.08), rgba(255, 241, 209, 0.3) 56%, rgba(248, 222, 185, 0.72)),
    url("assets/xianxia-card-bg.png");
  background-size: cover;
  background-position: center top;
  box-shadow: 0 0 0 1px rgba(128, 77, 43, 0.16), 0 26px 76px rgba(119, 75, 41, 0.28);
}

.view::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.28;
  background:
    radial-gradient(circle at 50% 42%, transparent 0 36%, rgba(255, 251, 237, 0.36) 68%),
    repeating-linear-gradient(0deg, rgba(119, 75, 41, 0.035) 0 1px, transparent 1px 5px);
  mix-blend-mode: multiply;
}

.start-view {
  padding: max(22px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: minmax(148px, 25dvh) 1fr auto;
  align-items: end;
}

.scene-light {
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 238, 196, 0.58), transparent 24%),
    radial-gradient(circle at 82% 32%, rgba(143, 205, 231, 0.2), transparent 26%),
    linear-gradient(180deg, rgba(255, 250, 231, 0), rgba(248, 221, 181, 0.38) 76%, rgba(179, 115, 66, 0.22));
}

.brand {
  align-self: start;
  text-align: center;
  padding-top: 4px;
}

.seal {
  display: inline-grid;
  place-items: center;
  min-width: 90px;
  min-height: 32px;
  margin: 0 0 8px;
  border: 2px solid rgba(143, 85, 49, 0.58);
  border-radius: 999px;
  background:
    linear-gradient(180deg, #fff3d5, #f5bf78),
    var(--almond);
  color: #81452f;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.55), 0 5px 12px var(--shadow);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  color: #7d452e;
  font-size: clamp(48px, 16vw, 74px);
  line-height: 0.95;
  text-shadow:
    0 2px 0 #fff9e5,
    0 4px 0 rgba(179, 112, 67, 0.2),
    0 8px 18px rgba(139, 82, 47, 0.18);
}

.tagline {
  margin-top: 12px;
  color: #815742;
  font-size: 17px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75);
}

.card-fan {
  position: absolute;
  left: 50%;
  bottom: clamp(206px, 31dvh, 268px);
  width: min(282px, 70vw);
  height: 164px;
  transform: translateX(-50%);
  pointer-events: none;
}

.spirit-card {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 92px;
  height: 132px;
  border: 2px solid rgba(131, 83, 50, 0.5);
  border-radius: 18px;
  background:
    radial-gradient(circle at 50% 26%, rgba(255, 255, 229, 0.92) 0 6px, transparent 7px),
    linear-gradient(160deg, #fff7df, #b9ead0 48%, #6cc7a5);
  box-shadow:
    inset 0 0 0 6px rgba(255, 249, 224, 0.58),
    0 12px 24px rgba(130, 82, 47, 0.24);
}

.spirit-card::after {
  content: "";
  position: absolute;
  inset: 22px 18px;
  border: 2px solid rgba(128, 82, 50, 0.26);
  border-radius: 999px 999px 18px 18px;
  background:
    radial-gradient(circle at 50% 34%, rgba(255, 242, 166, 0.5), transparent 26%),
    linear-gradient(180deg, transparent, rgba(255, 185, 128, 0.34));
}

.card-left {
  transform: translateX(-98%) rotate(-14deg);
}

.card-mid {
  z-index: 2;
  transform: translateX(-50%) translateY(-18px);
}

.card-right {
  transform: translateX(-2%) rotate(14deg);
}

.start-panel,
.enemy-panel,
.log-panel,
.modal-sheet {
  border: 2px solid var(--line);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.52), rgba(255, 242, 211, 0.2) 32%),
    radial-gradient(circle at 100% 0%, rgba(255, 205, 151, 0.18), transparent 34%),
    var(--paper);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.7),
    inset 0 -5px 16px rgba(179, 113, 67, 0.08),
    0 14px 30px var(--shadow);
  backdrop-filter: blur(8px);
}

.start-panel {
  width: 100%;
  padding: 16px;
}

.name-field {
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 14px;
  border: 2px solid rgba(135, 82, 48, 0.32);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 244, 217, 0.74)),
    #fff3d2;
  box-shadow: inset 0 2px 8px rgba(156, 99, 58, 0.08);
}

.name-field span {
  color: var(--tea);
  font-size: 15px;
  font-weight: 700;
}

.name-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 18px;
}

.name-field input::placeholder {
  color: rgba(105, 65, 44, 0.42);
}

.menu-actions,
.action-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.primary-action,
.secondary-action,
.icon-action,
.mini-button,
.close-button {
  position: relative;
  min-height: 46px;
  overflow: hidden;
  border-radius: 17px;
  border: 2px solid rgba(126, 75, 45, 0.34);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.6),
    0 7px 14px rgba(152, 96, 57, 0.15);
}

.primary-action {
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.34), transparent),
    linear-gradient(180deg, #fff0ba 0%, #f7b171 46%, #baf2be 100%);
  background-size: 220% 100%, 100% 100%;
  color: #6a3828;
  font-size: 20px;
  font-weight: 800;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
  animation: glint 3.4s ease-in-out infinite;
}

.secondary-action,
.icon-action,
.mini-button,
.close-button {
  background:
    linear-gradient(180deg, #fff9e6, #f1d0a3),
    var(--almond);
  color: #744531;
  font-weight: 700;
}

.primary-action:active,
.secondary-action:active,
.icon-action:active,
.mini-button:active,
.game-card:active {
  transform: translateY(1px) scale(0.992);
}

.quick-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.game-view {
  padding: max(12px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto minmax(156px, 23dvh) minmax(74px, 10dvh) 1fr auto;
  gap: 9px;
}

.topbar {
  display: grid;
  grid-template-columns: 66px 1fr 66px;
  align-items: center;
  gap: 8px;
}

.topbar div {
  min-width: 0;
  text-align: center;
  padding: 6px 10px;
  border: 2px solid rgba(119, 72, 44, 0.25);
  border-radius: 18px;
  background: rgba(255, 250, 233, 0.72);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.65);
}

.topbar strong,
.topbar span {
  display: block;
}

.topbar strong {
  color: #7a442e;
  font-size: 18px;
  line-height: 1.1;
}

.topbar span {
  color: rgba(112, 74, 52, 0.76);
  font-size: 13px;
}

.mini-button {
  min-height: 42px;
  font-size: 14px;
}

.resource-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.resource-strip div {
  min-width: 0;
  min-height: 52px;
  padding: 7px 6px;
  border: 2px solid rgba(137, 83, 47, 0.24);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(255, 236, 197, 0.7)),
    #f7ddb2;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.72),
    0 6px 12px rgba(142, 91, 53, 0.1);
  text-align: center;
}

.resource-strip span,
.resource-strip strong {
  display: block;
}

.resource-strip span {
  color: rgba(105, 65, 44, 0.68);
  font-size: 12px;
}

.resource-strip strong {
  margin-top: 3px;
  color: #84502f;
  font-size: 16px;
}

.enemy-panel {
  position: relative;
  padding: 15px;
  overflow: hidden;
  background:
    radial-gradient(circle at 90% 18%, rgba(124, 240, 111, 0.16), transparent 28%),
    radial-gradient(circle at 16% 100%, rgba(238, 147, 103, 0.16), transparent 30%),
    linear-gradient(180deg, rgba(255, 250, 236, 0.92), rgba(249, 225, 190, 0.9));
}

.enemy-panel::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px dashed rgba(137, 83, 47, 0.17);
  border-radius: 17px;
  pointer-events: none;
}

.enemy-panel.boss {
  border-color: rgba(238, 147, 103, 0.7);
}

.enemy-copy span {
  color: #b57932;
  font-size: 13px;
  font-weight: 700;
}

.enemy-copy h2 {
  margin-top: 4px;
  color: #7c432e;
  font-size: clamp(28px, 8vw, 38px);
  line-height: 1.05;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.72);
}

.enemy-copy p {
  margin-top: 6px;
  max-width: 70%;
  color: rgba(100, 62, 43, 0.74);
  font-size: 14px;
}

.intent-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  max-width: 43%;
  padding: 8px 10px;
  border: 2px solid rgba(139, 80, 47, 0.36);
  border-radius: 15px;
  background:
    linear-gradient(180deg, #fff5d5, #ffd1b6),
    var(--peach-soft);
  color: #7d3e2c;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.55), 0 5px 10px rgba(166, 95, 55, 0.12);
  font-size: 13px;
  font-weight: 700;
  text-align: right;
}

.bar {
  position: absolute;
  left: 15px;
  right: 15px;
  bottom: 45px;
  height: 12px;
  overflow: hidden;
  border: 2px solid rgba(129, 78, 47, 0.28);
  border-radius: 999px;
  background: rgba(255, 250, 232, 0.8);
  box-shadow: inset 0 2px 5px rgba(139, 84, 50, 0.12);
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ee7e64, #ffd06e);
  transition: width 180ms ease;
}

.enemy-stats {
  position: absolute;
  left: 15px;
  right: 15px;
  bottom: 12px;
  display: flex;
  gap: 6px;
  overflow: hidden;
}

.enemy-stats span {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid rgba(110, 191, 154, 0.36);
  border-radius: 999px;
  background: rgba(255, 252, 236, 0.74);
  color: rgba(94, 56, 40, 0.7);
  font-size: 12px;
}

.enemy-stats strong {
  color: var(--tea-deep);
}

.log-panel {
  padding: 10px 12px;
  overflow: hidden;
  color: rgba(94, 56, 40, 0.78);
  font-size: 13px;
  line-height: 1.35;
}

.log-panel p + p {
  margin-top: 3px;
}

.hand {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 9px;
  padding: 1px 1px 4px;
  scrollbar-color: rgba(157, 99, 60, 0.5) rgba(255, 246, 221, 0.42);
}

.game-card {
  min-width: 0;
  min-height: 132px;
  padding: 13px 11px 11px;
  border: 2px solid rgba(132, 82, 49, 0.34);
  border-radius: 20px;
  background:
    radial-gradient(circle at 84% 0%, rgba(124, 207, 163, 0.18), transparent 34%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 239, 205, 0.9)),
    #fff1cf;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.72),
    inset 0 -7px 16px rgba(190, 123, 78, 0.08),
    0 9px 16px rgba(132, 82, 49, 0.16);
  text-align: left;
}

.game-card::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(128, 79, 48, 0.13);
  border-radius: 15px;
  pointer-events: none;
}

.game-card strong,
.game-card em,
.game-card span:not(.card-cost) {
  display: block;
}

.game-card strong {
  padding-right: 31px;
  color: #75442f;
  font-size: 19px;
  line-height: 1.05;
}

.game-card em {
  margin-top: 5px;
  color: #ba7b33;
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
}

.game-card span:not(.card-cost) {
  margin-top: 9px;
  color: rgba(88, 54, 39, 0.78);
  font-size: 13px;
  line-height: 1.3;
}

.card-cost {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid rgba(117, 72, 45, 0.32);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.9), transparent 22%),
    linear-gradient(180deg, #bdf0d4, #65cfa3);
  color: #4b583c;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5), 0 3px 7px rgba(102, 73, 49, 0.15);
  font-size: 14px;
  font-weight: 800;
}

.rarity-uncommon {
  border-color: rgba(90, 180, 139, 0.58);
}

.rarity-rare {
  border-color: rgba(112, 180, 211, 0.68);
  background:
    radial-gradient(circle at 18% 0%, rgba(143, 205, 231, 0.3), transparent 34%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(227, 246, 244, 0.92)),
    #e9f8f4;
}

.empty-hand {
  grid-column: 1 / -1;
  min-height: 112px;
  display: grid;
  place-items: center;
  border: 2px dashed rgba(136, 84, 50, 0.25);
  border-radius: 20px;
  color: rgba(94, 56, 40, 0.62);
  background: rgba(255, 250, 235, 0.58);
}

.combat-actions {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 8px;
}

.wide {
  width: 100%;
}

.modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  align-items: end;
  padding: 14px;
  background: rgba(109, 69, 42, 0.22);
  backdrop-filter: blur(2px);
}

.modal-sheet {
  width: 100%;
  max-height: min(82dvh, 720px);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.76), rgba(255, 239, 204, 0.82)),
    var(--paper-strong);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 15px 11px;
  border-bottom: 2px solid rgba(141, 92, 55, 0.14);
}

.modal-header span {
  color: #ad7030;
  font-size: 12px;
  font-weight: 800;
}

.modal-header h2 {
  color: #75442f;
  font-size: 24px;
}

.close-button {
  width: 40px;
  height: 40px;
  min-height: 40px;
  font-size: 25px;
}

.modalBody {
  overflow-y: auto;
  padding: 14px;
}

.modal-copy {
  margin-bottom: 13px;
  color: rgba(94, 56, 40, 0.74);
  font-size: 14px;
  line-height: 1.45;
}

.modalBody h3 {
  margin: 14px 0 8px;
  color: #9a622e;
  font-size: 16px;
}

.reward-grid,
.compact-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.reward-grid {
  margin-bottom: 10px;
}

.compact-grid .game-card {
  min-height: 116px;
}

.settings-list {
  display: grid;
  gap: 10px;
}

.settings-list label,
.result-grid span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
  padding: 10px 12px;
  border: 2px solid rgba(132, 82, 49, 0.22);
  border-radius: 16px;
  background: rgba(255, 250, 235, 0.72);
}

.settings-list input {
  width: 44px;
  height: 24px;
  accent-color: var(--jade);
}

.result-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 74px);
  z-index: 20;
  width: max-content;
  max-width: calc(100% - 36px);
  padding: 10px 14px;
  border: 2px solid rgba(124, 76, 46, 0.24);
  border-radius: 999px;
  background: rgba(255, 248, 229, 0.92);
  color: #744531;
  box-shadow: 0 10px 24px var(--shadow);
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

body.reduced-motion *,
body.reduced-motion *::before,
body.reduced-motion *::after {
  animation: none !important;
  transition-duration: 0.01ms !important;
}

@keyframes glint {
  0%,
  35% {
    background-position: -170% 0, 0 0;
  }
  75%,
  100% {
    background-position: 170% 0, 0 0;
  }
}

@media (max-height: 720px) {
  .start-view {
    grid-template-rows: 128px 1fr auto;
  }

  h1 {
    font-size: 46px;
  }

  .card-fan {
    bottom: 188px;
    transform: translateX(-50%) scale(0.86);
  }

  .game-view {
    grid-template-rows: auto auto minmax(132px, 21dvh) 66px 1fr auto;
    gap: 7px;
  }

  .game-card {
    min-height: 118px;
  }
}

@media (min-width: 481px) {
  body {
    background:
      radial-gradient(circle at center, rgba(255, 246, 220, 0.62), transparent 36%),
      #f2d2a2;
  }

  .view {
    height: min(100dvh, 920px);
  }
}
