[hidden] { display: none !important; }
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%; height: 100%;
  background: #1c120c;
  color: #f3e6c8;
  font-family: -apple-system, "PingFang SC", "Noto Sans SC", "Segoe UI", sans-serif;
  overflow: hidden;
  user-select: none;
}
#loading {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, #3a2418 0%, #140c08 70%);
  z-index: 40;
  padding: 24px;
  text-align: center;
}
#loading.fade { opacity: 0; pointer-events: none; transition: opacity 0.5s ease; }
#loading h1 {
  font-family: "Songti SC", "Noto Serif SC", serif;
  font-size: clamp(28px, 8vw, 42px);
  letter-spacing: 0.12em;
  font-weight: 700;
}
.mist { width: min(86vw, 420px); height: auto; margin-bottom: 18px; }
.tagline { margin-top: 10px; color: #d7c39a; font-size: 15px; max-width: 280px; }
#loadStatus { margin-top: 28px; color: #a89070; font-size: 13px; }

#app {
  height: 100dvh;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: hidden;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.stage {
  width: min(96vw, 720px);
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}
.seat {
  width: 100%;
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 8px;
  border-radius: 12px;
  border: 2px solid transparent;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.seat.turn {
  background: rgba(232, 196, 114, 0.18);
  border-color: #e8c472;
  box-shadow: 0 0 14px rgba(232, 196, 114, 0.35);
}
.seat.turn .name { color: #ffe9a8; }
.seat.turn .clock {
  color: #ffe08a;
  font-weight: 800;
}
.seat.you {
  grid-template-columns: 52px 1fr auto auto;
}
.coin-chip {
  min-width: 52px;
  width: auto !important;
  margin: 0 !important;
  padding: 6px 10px !important;
  border-radius: 999px;
  background: #5c3a14;
  border: 1px solid #e8c472;
  color: #ffe9a8;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.2;
}
.coin-chip::before {
  content: "● ";
  color: #e8c472;
}
.seat.turn .avatar {
  box-shadow: 0 0 0 3px #e8c472;
}
.avatar {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: #3a2418;
  border: 2px solid #c4a056;
  font-family: "Songti SC", serif;
  font-size: 20px;
}
.avatar.self { border-color: #b0161c; }
.name { font-weight: 700; font-size: 15px; }
.sub { font-size: 12px; color: #d4b888; margin-top: 2px; }
.clock {
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  color: #f0d9a0;
  min-width: 64px;
  text-align: right;
}
.clock.low { color: #ff7a4a; font-weight: 800; }

#board {
  width: auto;
  max-width: 100%;
  max-height: calc(100dvh - 238px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  height: auto;
  aspect-ratio: 720 / 800;
  touch-action: none;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.32));
}
#status {
  min-height: 1.4em;
  margin: 6px 0 2px;
  font-size: 14px;
  color: #ffe8c4;
  text-align: center;
}
.arena-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  width: 100%;
  margin-top: 4px;
}
.ready-timer {
  width: 100%;
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  color: #e8c472;
  letter-spacing: 0.08em;
}
button {
  border: 0;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 700;
  color: #fff8e8;
  background: #5c3a22;
  font-family: inherit;
  min-height: 44px;
  cursor: pointer;
}
button.primary { background: linear-gradient(180deg, #ad3428, #7f1d18); box-shadow: 0 4px 14px rgba(176, 22, 28, 0.28); }
#btnReady { min-width: min(78vw, 280px); font-size: 17px; }
button:disabled { opacity: 0.45; }
.dock {
  display: flex;
  gap: 6px;
  width: 100%;
  margin-top: 8px;
}
.dock button {
  flex: 1;
  background: #2e1c14;
  font-size: 12px;
  font-weight: 600;
  padding: 10px 5px;
  color: #e6d2aa;
  line-height: 1.2;
  white-space: normal;
}

.sheet {
  position: fixed; inset: 0;
  background: rgba(12, 8, 6, 0.78);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  z-index: 30;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet h2 {
  font-family: "Songti SC", "Noto Serif SC", serif;
  font-size: 32px;
  margin-bottom: 8px;
}
.sheet > * { width: min(96vw, 420px); text-align: center; }
.result-card { width: min(96vw, 420px); }
.deltas { display: flex; gap: 16px; justify-content: center; margin: 12px 0; color: #e8c472; font-weight: 700; }
.sheet-actions, .sheet button { width: min(96vw, 420px); margin-top: 8px; }
.menu-overlay {
  justify-content: flex-end;
  padding: 0;
  background: rgba(10, 6, 4, 0.72);
  z-index: 40;
}
.menu-overlay > * { width: 100%; max-width: none; text-align: left; }
.menu-card {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  height: min(92vh, 820px);
  background: #1a120e;
  border: 1px solid #5a3f28;
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.menu-head {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  align-items: center;
  column-gap: 10px;
  padding: 10px 14px;
  background: #211610;
  border-bottom: 1px solid #4a3424;
  position: sticky;
  top: 0;
  z-index: 2;
}
.menu-head-side { width: 36px; height: 36px; }
.menu-head h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.12em;
  color: #e8c472;
  text-align: center;
  line-height: 36px;
}
.menu-x {
  width: 36px !important;
  height: 36px;
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 50%;
  background: #8a241c;
  color: #fff4e8;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 36px;
}
.menu-x svg { width: 16px; height: 16px; }
.menu-scroll {
  flex: 1 1 auto;
  overflow: auto;
  padding: 8px 14px calc(20px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}
.menu-scroll { scrollbar-color: #78552f #211610; scrollbar-width: thin; }
.menu-scroll::-webkit-scrollbar { width: 8px; }
.menu-scroll::-webkit-scrollbar-track { background: #211610; }
.menu-scroll::-webkit-scrollbar-thumb { background: #78552f; border-radius: 8px; }
.menu-lang {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #2a1c14;
  border: 1px solid #4a3424;
  border-radius: 12px;
  padding: 10px 12px;
  margin: 8px 0 4px;
  color: #f3e6c8;
}
.menu-lang select {
  min-width: 140px;
  background: #1c120c;
  border-color: #6a4a30;
}
.menu-toggle {
  width: auto !important;
  min-width: 72px;
  margin: 0 !important;
  padding: 8px 12px !important;
  background: #8a241c;
  font-size: 13px;
}
.menu-group {
  margin: 16px 4px 8px;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #c4a056;
  width: auto !important;
  text-align: left;
}
.menu-item {
  width: 100% !important;
  margin: 0 0 8px !important;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: #2a1c14;
  border: 1px solid #4a3424;
  color: #f3e6c8;
  font-weight: 600;
  padding: 13px 14px !important;
}
.menu-item-coin { border-color: #7a5a28; }
.menu-ico {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #e8c472;
}
.menu-ico svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.cosmetic-item { gap: 10px; }
.cosmetic-swatch { flex: 0 0 40px; width: 40px; height: 40px; box-shadow: 0 2px 8px #0005; }
.swatch-board { border-radius: 8px; border: 4px solid #8d5c2d; background: #e8c472; }
.swatch-piece { border-radius: 50%; border: 3px double #8a241c; background: radial-gradient(circle at 32% 25%,#fff8df,#d7bc86); }
.swatch-bamboo { border-color:#6b8f3c;background:#d5e8a8; }
.swatch-redwood { border-color:#8a241c;background:#e8a070; }
.swatch-marble { border-color:#6a6a72;background:#d8d4cc; }
.swatch-ink { border-color:#2a2a32;background:#c8c0a8; }
.swatch-palace { border-color:#c4a056;background:#f0d9a0; }
.swatch-snow { border-color:#8aa0b4;background:#eef4f8; }
.swatch-obsidian { border-color:#11141b;background:#343b48; }
.swatch-royal_blue { border-color:#152d57;background:#d6e4f2; }
.swatch-sakura { border-color:#7f4058;background:#f4d9d8; }
.swatch-neon { border-color:#745cff;background:linear-gradient(135deg,#202840,#64f3ff); }
.swatch-jade { border-color:#3d8055;background:#bfe7c9; }
.swatch-bronze { border-color:#76501f;background:#c89445; }
.swatch-porcelain { border-color:#8299aa;background:#f4f5f2; }
.swatch-ebony { border-color:#07090c;background:#252a31; }
.swatch-ruby { border-color:#5b0b16;background:#b52431; }
.swatch-ivory { border-color:#a99770;background:#eadfbf; }
.swatch-crystal { border-color:#448fae;background:#aee9f5;box-shadow:0 0 10px #64d9ff88; }
.row {
  display: flex; align-items: center; justify-content: space-between;
  background: #2a1c14; padding: 12px; border-radius: 10px; margin: 12px 0;
  text-align: left;
}
select {
  background: #1c120c;
  color: #f3e6c8;
  border: 1px solid #5c3a22;
  border-radius: 8px;
  padding: 8px;
  font-size: 14px;
}
.ai-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: #24160f;
  border-top: 1px solid #4a3424;
  z-index: 12;
}
.ai-bar button {
  min-width: 0;
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  padding: 7px 4px;
  line-height: 1.25;
  white-space: normal;
}
.ai-bar #btnBackArena {
  grid-column: 1 / -1;
  font-size: 12px;
  padding: 8px 10px;
}
#btnUndo { background: #5c3a1c; }
#btnDiff, #btnSide { background: #1c4e5c; }
body.ai-mode #stage {
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}
.connection-banner {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  width: min(92vw, 420px);
  padding: 10px 14px;
  border: 1px solid #d98b45;
  border-radius: 12px;
  background: rgba(74, 37, 20, 0.96);
  color: #fff1d0;
  text-align: center;
  font-size: 13px;
  box-shadow: 0 8px 24px #0008;
}

@media (orientation: landscape) and (min-width: 700px) {
  #app { align-items: center; padding: 8px max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left)); }
  .stage {
    width: min(100%, 1180px);
    height: min(100%, 820px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(290px, 360px);
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    column-gap: clamp(16px, 3vw, 42px);
    align-items: center;
  }
  #board {
    grid-column: 1;
    grid-row: 1 / -1;
    justify-self: end;
    width: auto;
    height: min(calc(100dvh - 16px), 800px);
    max-width: 100%;
    max-height: 100%;
  }
  #oppSeat { grid-column: 2; grid-row: 1; }
  #status { grid-column: 2; grid-row: 2; align-self: end; margin-bottom: 16px; font-size: 16px; }
  .arena-actions { grid-column: 2; grid-row: 3; }
  .dock { grid-column: 2; grid-row: 4; }
  #youSeat { grid-column: 2; grid-row: 5; }
  .dock button { font-size: 13px; }
  .ai-bar {
    left: auto;
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    width: min(360px, 34vw);
    border: 1px solid #4a3424;
    border-radius: 14px;
  }
  body.ai-mode #stage { padding-bottom: 0; }
  body.ai-mode #youSeat { margin-bottom: 122px; }
}

@media (max-height: 680px) and (orientation: portrait) {
  .seat { padding-block: 4px; }
  .avatar { width: 42px; height: 42px; }
  #board { max-height: calc(100dvh - 210px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  .dock { margin-top: 4px; }
}
.panel { justify-content: flex-start; overflow: auto; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-head h2 { font-size: 22px; margin: 0; text-align: left; }
.panel-head button { width: auto; margin: 0; padding: 8px 12px; }
.panel-body { text-align: left; max-height: 70vh; overflow: auto; padding-bottom: 24px; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: #2a1c14; padding: 10px 12px; border-radius: 10px; margin: 8px 0; text-align: left;
}
.list-item button { width: auto; margin: 0; padding: 8px 10px; font-size: 13px; }
.muted { color: #b89a72; font-size: 13px; }
.chat-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  width: 100%;
  padding: 8px 4px;
  margin-top: 4px;
  background: #24160f;
  border: 1px solid #4a3424;
  border-radius: 10px;
}
.chat-bar[hidden] { display: none !important; }
.chat-bar button { width: auto; padding: 8px 10px; font-size: 12px; background: #3a2418; }
.progress { height: 6px; background: #3a2418; border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress > span { display: block; height: 100%; background: #c4a056; }
.toast { position: fixed; top: 18%; left: 50%; transform: translateX(-50%); background: #2a1c14; padding: 10px 16px; border-radius: 8px; z-index: 50; }
.share-overlay {
  z-index: 45;
  justify-content: center;
  gap: 12px;
}
.share-overlay > * { width: min(92vw, 400px); }
.share-overlay button { width: auto; margin-top: 0; }
.share-card {
  position: relative;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 20%, #5a3a1c 0%, #1c100c 62%);
  border: 1px solid #e8c472;
  border-radius: 22px;
  padding: 28px 18px 20px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
}
.share-burst { position: absolute; inset: 0; pointer-events: none; }
.spark {
  position: absolute;
  color: #e8c472;
  font-size: 14px;
  opacity: 0.85;
  animation: sparkle 2.4s ease-in-out infinite;
}
.s1 { top: 8%; left: 10%; transform: rotate(-18deg); }
.s2 { top: 14%; right: 12%; font-size: 18px; animation-delay: .2s; }
.s3 { top: 28%; left: 6%; font-size: 11px; }
.s4 { top: 36%; right: 8%; transform: rotate(22deg); animation-delay: .4s; }
.s5 { bottom: 22%; left: 12%; }
.s6 { bottom: 18%; right: 10%; font-size: 16px; animation-delay: .6s; }
.s7 { top: 48%; left: 14%; font-size: 10px; }
.s8 { top: 52%; right: 16%; }
.s9 { bottom: 32%; left: 22%; animation-delay: .3s; }
.s10 { bottom: 28%; right: 24%; transform: rotate(-12deg); }
@keyframes sparkle {
  0%, 100% { opacity: 0.35; transform: scale(0.85) rotate(var(--r, 0deg)); }
  50% { opacity: 1; transform: scale(1.15) rotate(var(--r, 0deg)); }
}
.share-trophy { margin: 0 auto 8px; filter: drop-shadow(0 0 12px rgba(232,196,114,0.55)); }
.share-kicker {
  color: #e8c472;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 8px;
}
.share-name {
  font-family: "Songti SC", "Noto Serif SC", serif;
  font-size: 28px;
  letter-spacing: 0.18em;
  color: #fff4d6;
  margin: 0 8px 8px;
  line-height: 1.35;
}
.share-name span {
  display: inline-block;
  transform: rotate(var(--r, 0deg)) translateY(var(--y, 0px));
}
.share-headline { color: #f3e6c8; font-size: 15px; margin-bottom: 16px; }
.share-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.share-stats > div {
  background: rgba(28,16,12,0.55);
  border: 1px solid #6a4a28;
  border-radius: 12px;
  padding: 10px 6px;
}
.share-stat-ico {
  display: block;
  width: 22px;
  height: 22px;
  margin: 0 auto 4px;
  color: #e8c472;
}
.share-stat-ico svg { width: 22px; height: 22px; }
.share-stats b { display: block; font-size: 13px; color: #ffe9a8; }
.share-stats small { color: #c4a056; font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; }
.share-delta { color: #e8c472; font-weight: 800; margin-bottom: 4px; }
.share-brand {
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 14px;
  font-weight: 800;
  color: #e8c472;
  margin: 0 0 10px;
  text-shadow: 0 0 16px rgba(232,196,114,0.45);
}
.share-platforms {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  width: min(92vw, 400px);
}
.share-app {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: transparent !important;
  color: #e6d2aa;
  font-size: 10px;
  font-weight: 700;
  padding: 4px !important;
}
.share-app-ico {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.share-app-ico svg { width: 22px; height: 22px; }
.share-app-ico.wa { background: #25D366; color: #fff; }
.share-app-ico.fb { background: #1877F2; color: #fff; }
.share-app-ico.sms { background: #5c8a3c; color: #fff; }
.share-app-ico.copy { background: #5c3a22; color: #f3e6c8; }
.share-app-ico.more { background: #8a241c; color: #fff; }
#btnCloseShare { width: min(92vw, 400px) !important; background: #5c3a22; }
input[type=text], input[type=email], input[type=password] {
  width: 100%; background: #1c120c; color: #f3e6c8; border: 1px solid #5c3a22; border-radius: 8px; padding: 10px; margin: 6px 0;
}
