:root {
  --ink: #151515;
  --paper: #fffaf0;
  --pink: #ff4fa3;
  --red: #ef4b46;
  --blue: #4da7ff;
  --green: #7ad52f;
  --yellow: #ffd32f;
  --purple: #a06bed;
  --muted: #efe9dc;
  font-family: "Kaiti SC", "STKaiti", "FZKai-Z03", "PingFang SC", system-ui, sans-serif;
  color: var(--ink);
  background: #d8d2c6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,.8) 0 1px, transparent 1.5px) 0 0 / 7px 7px,
    #d8d2c6;
}

button { font: inherit; color: inherit; }

.game-shell {
  position: relative;
  width: min(100%, 520px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  overflow: hidden;
  background:
    radial-gradient(circle at 8% 14%, rgba(255,79,163,.09) 0 3px, transparent 4px),
    radial-gradient(circle at 89% 31%, rgba(77,167,255,.1) 0 2px, transparent 3px),
    repeating-linear-gradient(8deg, transparent 0 33px, rgba(26,26,26,.018) 34px 35px),
    var(--paper);
  box-shadow: 0 0 50px rgba(0,0,0,.25);
}

.masthead {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 78px;
  margin-bottom: 5px;
}

.masthead h1 {
  margin: 0;
  transform: rotate(-2deg);
  font-size: clamp(40px, 12vw, 64px);
  line-height: .95;
  font-family: "Kaiti SC", "STKaiti", cursive;
  font-weight: 1000;
  letter-spacing: -5px;
  text-shadow: 1px 2px 0 rgba(0,0,0,.08);
}

.masthead h1::after {
  content: "";
  position: absolute;
  height: 7px;
  left: 12%; right: -3%; bottom: -9px;
  background: var(--pink);
  border-radius: 50%;
  transform: rotate(3deg) skewX(-18deg);
}

.masthead h1 span { color: var(--pink); margin-left: 7px; }

.round-note {
  position: absolute;
  top: 0; right: -5px;
  padding: 8px 10px;
  background: white;
  border: 2px solid #e8e0d3;
  font-weight: 900;
  transform: rotate(3deg);
  box-shadow: 3px 5px 0 rgba(0,0,0,.09);
}

.round-note::before {
  content: "";
  position: absolute;
  width: 38px; height: 12px;
  top: -9px; left: 28%;
  background: rgba(122,213,47,.78);
  transform: rotate(-5deg);
}

.round-note strong { color: var(--pink); font-size: 24px; }

.icon-button {
  position: absolute;
  left: -2px; top: 5px;
  width: 34px; height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--pink);
  font-size: 20px;
  font-weight: 1000;
  cursor: pointer;
}

.icon-button.muted { color: #aaa; text-decoration: line-through; }

.opponents {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin: 8px 4px 14px;
}

.opponent {
  position: relative;
  min-width: 0;
  padding: 7px 6px 8px;
  border: 2px solid transparent;
  border-radius: 4px;
  background: #fff;
  box-shadow: 2px 4px 0 rgba(0,0,0,.14);
  cursor: pointer;
  transition: transform .16s ease, border-color .16s ease;
}

.opponent:nth-child(1) { transform: rotate(-2deg); }
.opponent:nth-child(2) { transform: translateY(3px) rotate(1deg); }
.opponent:nth-child(3) { transform: rotate(2deg); }
.opponent:hover { transform: translateY(-3px) rotate(0); }
.opponent.selected { border-color: var(--pink); transform: translateY(-5px) rotate(0); }
.opponent.broken { filter: grayscale(.7); opacity: .58; cursor: not-allowed; }
.opponent.broken::after {
  content: "已破防";
  position: absolute; inset: 35% -4px auto;
  padding: 3px;
  background: var(--ink); color: white;
  font-weight: 900; transform: rotate(-8deg);
}

.avatar {
  width: 66px; height: 66px;
  margin: 0 auto 3px;
  border-radius: 50%;
  background-image: url("assets/generated/bean-avatar-sheet.png");
  background-size: 200% 200%;
  background-repeat: no-repeat;
  background-color: #fffdf5;
}

.avatar-red { background-position: 0 0; }
.avatar-yellow { background-position: 100% 0; }
.avatar-green { background-position: 0 100%; }
.avatar-blue { background-position: 100% 100%; }

.opponent strong {
  display: block;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
}

.opponent .stage {
  display: inline-block;
  margin-top: 3px;
  padding: 1px 6px;
  border-radius: 2px;
  color: white;
  font-size: 12px;
  font-weight: 900;
}

.meter {
  height: 9px;
  margin-top: 5px;
  overflow: hidden;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  background: #eee9df;
}

.meter i { display: block; width: 0; height: 100%; transition: width .35s ease; }

.topic-card {
  position: relative;
  margin: 3px 24px 10px;
  padding: 14px 18px 20px;
  background: #ffdd64;
  border: 2px solid #e1bd38;
  transform: rotate(-1deg);
  box-shadow: 4px 5px 0 rgba(0,0,0,.12);
}

.topic-card::before {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: .16;
  background: repeating-linear-gradient(0deg, transparent 0 22px, #9f8d60 23px 24px);
}

.tape { position: absolute; width: 74px; height: 18px; top: -12px; left: -22px; opacity: .78; transform: rotate(-7deg); }
.tape-pink { background: var(--pink); }
.topic-label { position: relative; font-weight: 1000; text-decoration: underline 4px var(--pink); }

.topic-card h2 {
  position: relative;
  width: 85%;
  margin: 12px auto 3px;
  font-size: clamp(27px, 7.5vw, 39px);
  line-height: 1.25;
  text-align: center;
  font-weight: 1000;
}

.topic-stamp {
  position: absolute;
  right: -15px; top: 17px;
  padding: 5px 10px;
  border: 4px double #c94033;
  border-radius: 50%;
  color: #c94033;
  font-weight: 1000;
  text-align: center;
  line-height: 1.05;
  transform: rotate(10deg);
  opacity: .9;
}

.doodle { position: absolute; font-weight: 1000; font-size: 21px; }
.doodle-left { left: -28px; bottom: 10px; transform: rotate(-25deg); }
.doodle-right { right: -29px; bottom: 5px; color: var(--pink); transform: rotate(18deg); }

.argument-track {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 73px;
  margin: 0 -4px 5px;
  padding-bottom: 19px;
}

.speech {
  max-width: 29%;
  padding: 8px 8px;
  border: 2px solid;
  background: white;
  font-size: clamp(14px, 4vw, 19px);
  font-weight: 1000;
  white-space: nowrap;
  box-shadow: 2px 3px 0 rgba(0,0,0,.1);
  transition: transform .2s ease;
}

.speech-blue { border-color: var(--blue); transform: rotate(-3deg); }
.speech-pink { border-color: var(--pink); transform: rotate(2deg); }
.speech-green { border-color: var(--green); transform: rotate(-1deg); }
.argument-track > span { font-size: 22px; font-weight: 1000; }
.loop-note { position: absolute; bottom: -1px; font-size: 15px; font-weight: 900; transform: rotate(-3deg); }

.turn-banner {
  width: fit-content;
  max-width: 92%;
  margin: 1px auto 7px;
  padding: 5px 15px;
  background: var(--ink);
  color: white;
  font-size: 14px;
  font-weight: 900;
  transform: rotate(.5deg);
}

.hand-section { position: relative; }

.hand {
  display: grid;
  grid-template-columns: repeat(5, minmax(64px, 1fr));
  gap: 6px;
  align-items: end;
  min-height: 143px;
  padding: 4px 0 1px;
}

.card {
  position: relative;
  min-width: 0;
  height: 128px;
  padding: 8px 4px 5px;
  border: 2px solid var(--card-color);
  border-radius: 5px;
  background: #fff;
  box-shadow: 2px 4px 0 rgba(0,0,0,.16);
  cursor: pointer;
  overflow: hidden;
  transition: transform .16s ease, box-shadow .16s ease;
}

.card:nth-child(odd) { transform: rotate(-1.2deg); }
.card:nth-child(even) { transform: rotate(1deg); }
.card:hover, .card.selected {
  transform: translateY(-9px) rotate(0);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--card-color) 26%, transparent), 3px 7px 0 rgba(0,0,0,.16);
}

.card .cost {
  position: absolute; top: 3px; right: 4px;
  color: var(--card-color); font-weight: 1000; font-size: 12px;
}

.card strong { display: block; font-size: clamp(13px, 3.4vw, 17px); line-height: 1.05; white-space: nowrap; }
.card .card-face {
  display: grid;
  place-items: center;
  width: 100%;
  height: 67px;
  overflow: hidden;
  font-family: "PingFang SC", system-ui, sans-serif;
  font-size: clamp(25px, 8.5vw, 40px);
  font-weight: 1000;
  line-height: 1;
  white-space: nowrap;
}
.card small { display: block; overflow: hidden; font-size: 10px; line-height: 1.1; height: 22px; }

.card-detail {
  min-height: 23px;
  padding: 4px 8px 2px;
  color: #585047;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.play-button {
  display: block;
  position: relative;
  width: 75%;
  margin: 3px auto 10px;
  padding: 9px 15px 10px;
  border: 3px solid var(--ink);
  border-radius: 8px 18px 8px 16px;
  background: var(--green);
  box-shadow: 4px 5px 0 var(--ink);
  font-size: clamp(26px, 8vw, 40px);
  font-weight: 1000;
  letter-spacing: 4px;
  cursor: pointer;
  transform: rotate(-1deg);
  transition: transform .12s ease;
}

.play-button:not(:disabled):active { transform: translate(4px, 5px) rotate(-1deg); box-shadow: none; }
.play-button:disabled { filter: grayscale(.7); opacity: .55; cursor: not-allowed; }

.player-bar {
  display: grid;
  grid-template-columns: 58px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  background: rgba(255,255,255,.86);
  border-top: 2px dashed var(--ink);
}

.self-avatar { width: 52px; height: 52px; margin: 0; }
.self-status { min-width: 0; font-size: 15px; }
.self-status b { color: var(--pink); font-size: 20px; }
.meter-self { height: 10px; }
.meter-self i { background: var(--pink); }
.deck-count { font-size: 13px; font-weight: 900; white-space: nowrap; }
.deck-count strong { color: var(--green); font-size: 25px; }
.mini-cards { display: inline-block; width: 18px; height: 23px; border: 2px solid #2679cc; background: var(--blue); transform: rotate(-5deg); vertical-align: middle; }

.toast {
  position: fixed;
  z-index: 20;
  left: 50%; top: 48%;
  max-width: min(86vw, 410px);
  padding: 13px 20px;
  border: 3px solid var(--ink);
  background: white;
  box-shadow: 5px 6px 0 var(--ink);
  font-size: 18px;
  font-weight: 1000;
  text-align: center;
  transform: translate(-50%, -50%) rotate(-2deg) scale(.8);
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s, transform .16s;
}

.toast.show { opacity: 1; transform: translate(-50%, -50%) rotate(-2deg) scale(1); }

.result-dialog {
  width: min(88vw, 390px);
  padding: 27px 24px 22px;
  border: 4px solid var(--ink);
  border-radius: 8px 22px 7px 17px;
  background: var(--paper);
  box-shadow: 8px 10px 0 var(--ink);
  text-align: center;
  transform: rotate(-1deg);
}

.result-dialog::backdrop { background: rgba(21,21,21,.68); backdrop-filter: blur(2px); }
.result-dialog h2 { margin: 8px 0; font-size: 34px; }
.result-dialog p { margin: 0 0 17px; font-weight: 800; }
.result-dialog button { padding: 10px 24px; border: 2px solid var(--ink); background: var(--green); font-weight: 1000; box-shadow: 3px 4px 0 var(--ink); cursor: pointer; }
.result-sticker { display: grid; place-items: center; width: 70px; height: 70px; margin: 0 auto; border: 4px solid var(--red); border-radius: 50%; color: var(--red); font-size: 38px; font-weight: 1000; transform: rotate(-12deg); }

.shake { animation: shake .32s ease; }
@keyframes shake { 20% { transform: translateX(-5px) rotate(-1deg); } 40% { transform: translateX(5px) rotate(1deg); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }

@media (max-width: 380px) {
  .game-shell { padding-left: 10px; padding-right: 10px; }
  .masthead { min-height: 68px; }
  .masthead h1 { font-size: 42px; }
  .avatar { width: 56px; height: 56px; }
  .opponents { gap: 5px; }
  .opponent { padding-inline: 3px; }
  .topic-card { margin-inline: 19px; padding-inline: 11px; }
  .hand { gap: 3px; grid-template-columns: repeat(5, minmax(55px, 1fr)); }
  .card { height: 117px; padding-inline: 2px; }
  .card .card-face { height: 60px; font-size: clamp(23px, 8vw, 32px); }
  .player-bar { grid-template-columns: 50px 1fr; }
  .deck-count { grid-column: 2; }
}

@media (min-width: 840px) {
  body { padding: 24px; }

  .game-shell {
    display: grid;
    grid-template-columns: minmax(300px, .8fr) minmax(460px, 1.2fr);
    grid-template-areas:
      "header header"
      "opponents turn"
      "topic hand"
      "argument hand"
      "status action";
    gap: 12px 28px;
    align-content: center;
    width: min(100%, 1180px);
    min-height: calc(100dvh - 48px);
    padding: 22px 30px;
    border-radius: 3px;
  }

  .masthead { grid-area: header; margin-bottom: 2px; }
  .masthead h1 { font-size: clamp(54px, 6vw, 76px); }
  .opponents { grid-area: opponents; margin: 0 4px; align-self: end; }
  .topic-card { grid-area: topic; margin: 4px 20px; align-self: center; }
  .topic-card h2 { font-size: clamp(28px, 3.2vw, 42px); }
  .argument-track { grid-area: argument; margin: 0; align-self: start; }
  .speech { font-size: clamp(14px, 1.7vw, 19px); }

  .turn-banner {
    grid-area: turn;
    align-self: end;
    margin: 0 auto;
    font-size: 16px;
  }

  .hand-section {
    grid-area: hand;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .hand {
    min-height: 210px;
    gap: 9px;
  }

  .card {
    height: 190px;
    padding: 12px 7px 8px;
  }

  .card strong { font-size: clamp(15px, 1.6vw, 20px); }
  .card .card-face { height: 103px; font-size: clamp(34px, 4vw, 52px); }
  .card small { height: 39px; font-size: 12px; line-height: 1.25; }
  .card-detail { min-height: 28px; font-size: 15px; }

  .play-button {
    grid-area: action;
    align-self: start;
    width: min(78%, 430px);
    margin: 0 auto;
    font-size: clamp(29px, 3vw, 42px);
  }

  .player-bar {
    grid-area: status;
    align-self: start;
    margin-top: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
