:root {
  --bg: #1a1510;
  --panel: #2a2118;
  --ink: #f3e6d0;
  --muted: #a89070;
  --red: #c23b22;
  --black: #1e1a16;
  --line: #6b4e2e;
  --wood: #c4a574;
  --wood-dark: #8b6914;
  --accent: #d4a017;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100dvh;
  font-family: "Songti SC", "SimSun", "Noto Serif SC", serif;
  background:
    radial-gradient(ellipse at 30% 0%, #3a2a18 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, #2a1810 0%, transparent 45%),
    var(--bg);
  color: var(--ink);
}

#app {
  max-width: 420px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.top h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.sub {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.panel { margin-top: 1.5rem; }

.hidden { display: none !important; }

.btn {
  appearance: none;
  border: 1px solid #5a4030;
  background: var(--panel);
  color: var(--ink);
  padding: 0.7rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  border-radius: 6px;
  cursor: pointer;
}

.btn.primary {
  width: 100%;
  background: linear-gradient(180deg, #b8860b, #8b6914);
  border-color: #6b5010;
  color: #1a1208;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.btn.danger { border-color: #8a3030; color: #e8a0a0; }

.btn:active { transform: scale(0.98); }

.row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.row input {
  flex: 1;
  padding: 0.7rem 0.75rem;
  border-radius: 6px;
  border: 1px solid #5a4030;
  background: #120e0a;
  color: var(--ink);
  font-size: 1rem;
  font-family: ui-monospace, monospace;
  letter-spacing: 0.06em;
}

.hint {
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}

#board-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  touch-action: none;
}

#check-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(176, 28, 18, 0.94);
  color: #ffe9c0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.4em;
  text-indent: 0.4em;
  padding: 0.35rem 1.2rem;
  border-radius: 999px;
  box-shadow: 0 0 20px rgba(255, 60, 40, 0.75);
  animation: check-pulse 0.9s ease-in-out infinite;
  z-index: 5;
  pointer-events: none;
}

@keyframes check-pulse {
  0%, 100% { transform: translateX(-50%) scale(1); opacity: 1; }
  50% { transform: translateX(-50%) scale(1.07); opacity: 0.82; }
}

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 6, 4, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

#overlay.hidden { display: none; }

.modal {
  width: min(88%, 320px);
  background: linear-gradient(180deg, #32281a, #241c12);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.5rem 1.25rem 1.25rem;
  text-align: center;
  box-shadow: 0 14px 44px rgba(0,0,0,0.65);
}

.modal h2 {
  color: var(--accent);
  font-size: 1.3rem;
  letter-spacing: 0.18em;
  text-indent: 0.18em;
}

.modal .result {
  font-size: 1.7rem;
  font-weight: 700;
  margin: 0.7rem 0 0.25rem;
}

.modal .result.win { color: #ffd76a; text-shadow: 0 0 14px rgba(255, 190, 60, 0.45); }
.modal .result.lose { color: #d8c8a8; }

.modal .reason {
  color: var(--muted);
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.15rem;
}

.modal-actions .btn { flex: 1; }

.modal .hint {
  margin-top: 0.6rem;
  min-height: 1.25em;
  font-size: 0.8rem;
  color: var(--muted);
}

.modal .btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

#board {
  width: min(100%, 360px);
  height: auto;
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}

.actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.9rem;
  flex-wrap: wrap;
}

.actions .btn { flex: 1; min-width: 5rem; }

.msg {
  max-width: 420px;
  margin: 0.75rem auto;
  padding: 0 1rem;
  min-height: 1.4em;
  color: var(--accent);
  font-size: 0.95rem;
  text-align: center;
}

.voice-bar {
  margin-top: 0.9rem;
  text-align: center;
}

.ptt {
  width: 100%;
  padding: 0.95rem 1rem;
  font-size: 1.05rem;
  font-family: inherit;
  letter-spacing: 0.15em;
  text-indent: 0.15em;
  border-radius: 999px;
  border: 1px solid #6b4e2e;
  background: linear-gradient(180deg, #3a2f1e, #2a2118);
  color: var(--ink);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.ptt.talking {
  background: linear-gradient(180deg, #b8860b, #8b6914);
  border-color: #6b5010;
  color: #1a1208;
  font-weight: 700;
  animation: ptt-pulse 0.8s ease-in-out infinite;
}

.ptt:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

@keyframes ptt-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.remote-talk {
  margin-bottom: 0.55rem;
  font-size: 0.9rem;
  color: #ffd76a;
  animation: rtalk-pulse 1s ease-in-out infinite;
}

@keyframes rtalk-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
