:root {
  --paper: #f3ecdf;
  --paper-2: #e7dcc8;
  --ink: #241c16;
  --muted: #6d6256;
  --line: #ddcbb4;
  --green: #1f6b4a;
  --red: #c24b2e;
  --blue: #2456a6;
  --gold: #a56b12;
  --shadow: 0 10px 30px rgba(36, 28, 22, 0.08);
  --sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", "Songti SC", "STSong", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #fff6e8;
  color: #243044;
  font-family: "Yuanti SC", "PingFang SC", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}
button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--red); }
[hidden] { display: none !important; }

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  background: #241848;
  touch-action: none;
}
body.fighting #stage,
body.result #stage { display: block; }

#ui {
  width: min(440px, 100%);
  min-height: 100%;
  margin: 0 auto;
  overflow: auto;
  background: #fff6e8;
}
body.fighting #ui,
body.result #ui { display: none; }

.float {
  position: fixed;
  z-index: 4;
  top: calc(12px + env(safe-area-inset-top));
  border: 1.5px solid var(--ink);
  background: rgba(243, 236, 223, 0.92);
  border-radius: 999px;
  padding: 8px 14px;
}
#quit { left: 12px; }
#fast { right: 12px; }
body.fighting #quit,
body.result #quit,
body.fighting #fast,
body.result #fast {
  top: 46px;
  background: #fff;
  color: #2a2448;
  border: 0;
  font-weight: 800;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.22);
}

#title, #draw {
  width: 100%;
  margin: 0 auto;
  padding: calc(22px + env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom));
}

#title { text-align: center; }
#title .hero { padding: 8px 6px 0; }
.langs {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 0 0 12px;
}
.langs a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 999px;
}
.langs a[aria-current="page"] {
  color: #243044;
  background: #fff;
  box-shadow: 0 0 0 1.5px #243044;
}
#title h1 {
  margin: 0;
  font-family: "Arial Rounded MT Bold", "Yuanti SC", "Hiragino Maru Gothic ProN", "PingFang SC", sans-serif;
  font-weight: 900;
  font-size: clamp(32px, 8.6vw, 46px);
  line-height: 1.05;
  letter-spacing: 0;
  color: #ff4b4b;
  -webkit-text-stroke: 6px #243044;
  paint-order: stroke fill;
  text-shadow: 3px 3px 0 #243044;
}
#title h1 span { display: block; }
#title .lead {
  margin: 14px 0 0;
  color: #243044;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.65;
}
#title .record {
  margin: 12px 0 0;
  color: #e3a31a;
  font-weight: 800;
  font-size: 16px;
}
.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 13px;
  letter-spacing: 0.16em;
}
h1, h2, .sheet h2 {
  font-family: var(--serif);
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0;
}
h1 { font-size: 48px; line-height: 1.05; }
h2, .sheet h2 { font-size: 28px; line-height: 1.2; }
.lead { font-size: 17px; margin: 12px 0 0; }
.caption { color: var(--muted); text-align: center; margin: 8px 0 18px; font-size: 13px; }

.actions, .row { display: flex; flex-wrap: wrap; gap: 8px; }
.actions { margin: 18px 0; }
.row button, .sheet > .main, #fight, #fightfriend { flex: 1; }
#title .actions {
  flex-direction: column;
  gap: 12px;
  margin: 18px 4px 20px;
}
#title .actions button { width: 100%; }

button.main, a.main {
  display: inline-grid;
  place-items: center;
  text-decoration: none;
  background: var(--ink);
  color: var(--paper);
  border: 0;
  border-radius: 999px;
  padding: 13px 16px;
  font-weight: 700;
}
button.ghost {
  background: transparent;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  padding: 12px 14px;
}
button:disabled { opacity: 0.38; cursor: default; }
button.main:active, button.ghost:active { transform: translateY(1px); }
#title button.main,
#title button.ghost {
  border: 3px solid #243044;
  border-radius: 16px;
  box-shadow: 0 4px 0 #243044;
  padding: 14px 16px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
#title button.main {
  background: #ff4d4d;
  color: #fff;
}
#title button.ghost {
  background: #fff;
  color: #243044;
}
#title button.main:active,
#title button.ghost:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #243044;
}

.card {
  background: rgba(255, 252, 247, 0.72);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
}
#title .rules {
  background: #f6edd8;
  border: 0;
  border-radius: 22px;
  box-shadow: none;
  text-align: left;
  padding: 18px 16px 8px;
}
.rules h2 { margin: 16px 0 6px; font-size: 22px; }
#title .rules h2 {
  margin: 14px 0 8px;
  color: #ff5a5a;
  font-family: "Yuanti SC", "PingFang SC", sans-serif;
  font-size: 18px;
  font-weight: 800;
}
.rules h2:first-child { margin-top: 0; }
.rules p { margin: 0 0 8px; }
#title .rules p { color: #243044; font-weight: 650; }
#title .rules b { color: #3b82c4; font-weight: 800; }
.rules dl { margin: 0; }
.rules dl div {
  display: grid;
  grid-template-columns: 5.2em 1fr;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
#title .rules dl div {
  display: flex;
  gap: 10px;
  padding: 7px 0;
  border-top: 0;
  align-items: flex-start;
}
#title .rules dt { flex: 0 0 6.5em; }
#title .rules dd { flex: 1 1 auto; min-width: 0; }
.rules dt { font-weight: 700; }
.rules dd { margin: 0; color: var(--muted); }
#title .rules dt { color: #3b82c4; font-weight: 800; }
#title .rules dd { min-width: 0; color: #243044; font-weight: 650; }

#demo, #friendprev, #pad {
  width: 100%;
  border-radius: 16px;
  background: #fffaf3;
  border: 1px solid var(--line);
  touch-action: none;
  display: block;
}
#demo { height: 280px; }
#friendprev { height: 180px; margin: 8px 0 12px; }
#friendbox { margin-bottom: 14px; }

body.drawing { background: #161033; }
body.drawing #ui {
  width: min(480px, 100%);
  max-width: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(ellipse at 50% 12%, #3a2d86 0%, rgba(22, 16, 51, 0) 52%),
    #161033;
}
#draw {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto auto auto auto auto;
  align-content: safe center;
  gap: 10px;
  max-width: 100%;
  overflow-x: clip;
  color: #fff;
}
#draw > * { min-width: 0; }
#draw .tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 4px 0 0;
}
#draw .tab {
  border: 1.5px solid rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 800;
}
#draw .tab.on {
  background: #7b68f6;
  border-color: #7b68f6;
  color: #fff;
}
#draw .tab.done::after { content: " ✓"; }
#draw .hint {
  min-height: 1.4em;
  margin: 0;
  color: #ffe56a;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
}
.pad-frame {
  width: min(100%, 420px);
  height: min(420px, 46dvh);
  justify-self: center;
  border-radius: 22px;
  box-shadow: 0 0 0 2px #79d2ff, 0 0 22px rgba(90, 180, 255, 0.7);
  overflow: hidden;
  background: #10163a;
}
#draw #pad {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}
#draw .draw-note {
  margin: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.88);
  font-size: 13px;
}
#draw .stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 18px;
}
#draw .stats div {
  display: grid;
  grid-template-columns: 2.4em 1fr auto;
  gap: 6px;
  align-items: center;
  font-size: 13px;
}
#draw .stats span,
#draw .stats em { color: #fff; font-style: normal; font-variant-numeric: tabular-nums; }
#draw .stats i {
  display: block;
  height: 8px;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 99px;
  overflow: hidden;
}
#draw .stats b {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: #f0b429;
}
#b-hp b { background: linear-gradient(90deg, #f6c14a, #ef7a22); }
#b-punch b { background: linear-gradient(90deg, #8cbcff, #3d6dff); }
#b-reach b { background: linear-gradient(90deg, #f0b429, #e07a20); }
#b-speed b { background: linear-gradient(90deg, #ffe56a, #f0b429); }

#draw .row.tight {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(4.5em, max-content));
  justify-content: center;
  width: 100%;
  max-width: 100%;
  gap: 8px;
}
#draw .row.tight button.ghost {
  background: #fff;
  color: #2a2448;
  border: 0;
  border-radius: 999px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
  font-weight: 800;
  font-size: 13px;
  padding: 7px 12px;
  white-space: nowrap;
}
#draw #fight.main {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0;
  background: #ff4d57;
  color: #fff;
  border: 0;
  border-radius: 16px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.22);
  padding: 10px 16px 12px;
  font-size: 22px;
  font-weight: 800;
}
#draw #fight small {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
}
#draw #fight:disabled { opacity: 0.45; }
@media (max-width: 430px) {
  #draw .row.tight { grid-template-columns: repeat(3, max-content); }
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(36, 28, 22, 0.42);
}
.sheet {
  width: min(420px, 100%);
  max-height: min(86dvh, 760px);
  overflow: auto;
  background: var(--paper);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.sheet p { margin: 8px 0 14px; }
.sheet .row { margin-top: 10px; }
.pips { display: flex; gap: 6px; margin: 4px 0 12px; flex-wrap: wrap; justify-content: center; }
.pips i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  display: block;
}
.pips i.on { background: var(--red); border-color: var(--red); }
.pips span {
  border: 1.5px solid #ddd4c8;
  background: #f6f1ea;
  color: #8d8478;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
}
.pips span.done { background: #ffe7a3; color: #6d5010; border-color: #e3c56a; }
.pips span.now { background: #fff; color: #243044; border-color: #ff4d57; box-shadow: 0 0 0 1px #ff4d57; }

body.result #result { background: transparent; }
#result .sheet {
  background: #fff7ea;
  border: 3px solid #243044;
  border-radius: 22px;
  box-shadow: 0 8px 0 #1a1428;
  text-align: center;
  padding: 22px 18px 14px;
}
#result .eyebrow { display: none; }
#result #r-title { font-size: 40px; line-height: 1.15; }
body.won #r-title {
  color: #f0b429;
  -webkit-text-stroke: 5px #243044;
  paint-order: stroke fill;
  text-shadow: 2px 2px 0 #243044;
}
body.lost #r-title { color: #3b82f6; font-weight: 900; }
#result .sheet p { margin: 6px 0; color: #243044; font-weight: 750; font-size: 14px; }
#result .main {
  width: 100%;
  margin-top: 10px;
  background: #ff4d57;
  color: #fff;
  border: 0;
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12);
  font-size: 18px;
  font-weight: 800;
}
#result .row { flex-direction: column; margin-top: 8px; }
#result .ghost {
  width: 100%;
  background: #fff;
  color: #243044;
  border: 2px solid #243044;
  border-radius: 14px;
  font-weight: 800;
}
#result .textlink {
  margin-top: 8px;
  background: transparent;
  border: 0;
  color: #6d6256;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 120px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fffaf3;
  padding: 10px;
  resize: vertical;
}
#certimg { width: 100%; border-radius: 12px; background: white; }
.slot {
  display: grid;
  grid-template-columns: 72px 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.slot canvas { width: 72px; height: 54px; background: #fffaf3; border-radius: 8px; }
.nick-row { display: flex; gap: 8px; align-items: center; }
.nick-row input {
  flex: 1;
  min-width: 0;
  border-radius: 999px;
  border: 1.5px solid #243044;
  background: #fff;
  padding: 8px 12px;
}
.board-row {
  display: grid;
  grid-template-columns: 28px 72px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-top: 1px solid var(--line);
}
.board-row.mine { background: #fff4d4; border-radius: 12px; }
.board-row b { font-size: 18px; text-align: center; }
.board-row canvas { width: 72px; height: 54px; background: #fffaf3; border-radius: 8px; }
.board-row strong, .board-row span { display: block; overflow-wrap: anywhere; }
.board-row span { color: #6d6256; font-size: 13px; }
#boardlist .empty { color: #6d6256; margin: 12px 0; }
.slot button { padding: 8px 10px; }
footer { color: #8a8174; font-size: 12px; margin-top: 16px; text-align: center; }
footer p { margin: 0; overflow-wrap: anywhere; }
#title footer a { color: #e07a4a; }

@media (min-width: 820px) {
  body { background: #1b2140; }
  #ui { min-height: 100%; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.04); }
}
