:root {
  color-scheme: light;
  --ink: #20170f;
  --muted: #74624f;
  --panel: #fff8ec;
  --panel-strong: #f1d7ae;
  --wood: #d79b5e;
  --wood-dark: #8b5530;
  --line: #6c4228;
  --red: #a33425;
  --black: #17120d;
  --green: #2f6b50;
  --shadow: 0 18px 40px rgba(52, 34, 18, 0.18);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(80, 50, 31, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, #f8efe0 0%, #e9c58d 100%);
  background-size: 38px 38px, auto;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(420px, 1fr);
  gap: 24px;
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 20px 0 24px;
  align-items: center;
}

.app-shell[hidden] {
  display: none;
}

.table-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  background: rgba(255, 248, 236, 0.94);
  border: 1px solid rgba(108, 66, 40, 0.22);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

.brand-row p,
.seat-label,
.status-box span {
  color: var(--muted);
  font-size: 13px;
}

.server-dot {
  width: 12px;
  height: 12px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(47, 107, 80, 0.12);
}

.player-strip,
.status-box,
.action-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.player-strip {
  padding: 10px 12px;
  background: #fff;
  border: 1px solid rgba(108, 66, 40, 0.16);
  border-radius: 6px;
}

.player-strip[hidden] {
  display: none;
}

.player-name-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.spectator-badge {
  padding: 2px 9px;
  color: #fff;
  background: var(--muted);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.ghost-btn {
  padding: 6px 10px;
  color: var(--muted);
  background: transparent;
}

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

.seat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(108, 66, 40, 0.2);
  border-radius: 6px;
  background: #fffaf2;
}

.seat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.seat-timer-track {
  position: relative;
  height: 14px;
  overflow: hidden;
  background: rgba(108, 66, 40, 0.14);
  border-radius: 999px;
}

.seat-timer-fill {
  height: 100%;
  background: var(--green);
  transition: width 0.2s linear, background-color 0.2s linear;
}

.seat-timer-fill.is-low {
  background: var(--red);
}

.seat-timer-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
}

.seat strong {
  display: block;
  margin-top: 3px;
  font-size: 17px;
}

.red-seat strong {
  color: var(--red);
}

.black-seat strong {
  color: var(--black);
}

.seat-btn,
.action-row button,
.login-card button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 6px;
  color: #fff;
  background: var(--wood-dark);
}

.kick-row {
  display: flex;
  justify-content: flex-end;
}

.kick-row[hidden] {
  display: none;
}

.kick-btn {
  min-height: 34px;
  padding: 0 12px;
  color: #fff;
  background: var(--red);
  border-radius: 6px;
}

.timer-settings {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid rgba(108, 66, 40, 0.16);
  border-radius: 6px;
  font-size: 13px;
  color: var(--muted);
}

.timer-options {
  display: flex;
  gap: 6px;
}

.timer-options button {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--muted);
  background: #f1d7ae;
}

.timer-options button.is-active {
  color: #fff;
  background: var(--wood-dark);
}

.score-box {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 10px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid rgba(108, 66, 40, 0.16);
  border-radius: 6px;
  font-size: 14px;
}

.score-side {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-weight: 700;
}

.red-side {
  color: var(--red);
}

.black-side {
  color: var(--black);
}

.score-side strong {
  font-size: 18px;
}

.score-sep {
  color: var(--muted);
  font-size: 12px;
}

.status-box {
  padding: 12px;
  background: #f6e4c7;
  border-radius: 6px;
}

.action-row {
  flex-wrap: wrap;
}

.action-row .accept-btn {
  background: var(--green);
}

.reset-status-line {
  margin-top: -6px;
  color: var(--muted);
  font-size: 13px;
}

.spectator-line {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.move-card,
.invite-box {
  padding: 12px;
  background: #fffaf2;
  border: 1px solid rgba(108, 66, 40, 0.16);
  border-radius: 6px;
}

.move-card[open],
.invite-box[open] {
  display: grid;
  gap: 8px;
}

.collapsible-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
}

.collapsible-summary::-webkit-details-marker {
  display: none;
}

.collapsible-summary h2 {
  font-size: 16px;
}

.collapsible-summary .chevron {
  color: var(--muted);
  transition: transform 0.15s ease;
}

details[open] .collapsible-summary .chevron {
  transform: rotate(180deg);
}

.invite-actions {
  display: flex;
  justify-content: flex-end;
}

.invite-box input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(108, 66, 40, 0.2);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
}

.invite-box p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.move-card ol {
  display: grid;
  gap: 6px;
  max-height: 210px;
  margin: 0;
  padding-left: 20px;
  overflow: auto;
  color: var(--muted);
  font-size: 14px;
}

.board-panel {
  display: grid;
  gap: 12px;
  justify-items: center;
}

.fx-flash {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
}

.fx-flash.is-active {
  animation: fx-flash-pop 1.6s ease-out forwards;
}

.fx-flash-burst {
  position: absolute;
  width: 72%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(255, 217, 130, 0.95) 0%,
    rgba(240, 122, 40, 0.9) 32%,
    rgba(191, 42, 22, 0.7) 58%,
    rgba(191, 42, 22, 0) 76%
  );
}

.fx-flash-burst.is-loss {
  background: radial-gradient(
    circle,
    rgba(210, 220, 230, 0.95) 0%,
    rgba(110, 130, 150, 0.9) 32%,
    rgba(40, 50, 70, 0.7) 58%,
    rgba(40, 50, 70, 0) 76%
  );
}

.fx-flash-char {
  position: relative;
  font-family: "Songti TC", "STSong", "Noto Serif CJK TC", serif;
  font-size: clamp(64px, 20vw, 200px);
  font-weight: 900;
  color: #fffaf0;
  text-shadow:
    0 0 14px rgba(255, 210, 140, 0.9),
    0 0 34px rgba(200, 50, 20, 0.85),
    0 3px 0 rgba(110, 20, 10, 0.9);
}

.fx-flash-char.is-loss {
  text-shadow:
    0 0 14px rgba(190, 205, 220, 0.9),
    0 0 34px rgba(60, 70, 100, 0.85),
    0 3px 0 rgba(20, 25, 40, 0.9);
}

@keyframes fx-flash-pop {
  0% {
    opacity: 0;
    transform: scale(0.4);
  }
  15% {
    opacity: 1;
    transform: scale(1.08);
  }
  25% {
    transform: scale(1);
  }
  70% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.05);
  }
}

.board-frame {
  width: min(760px, calc(100vw - 420px));
  padding: clamp(18px, 3vw, 30px);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 28%),
    var(--wood);
  border: 6px solid #a66a3c;
  border-radius: 8px;
  box-shadow: var(--shadow), inset 0 0 0 3px rgba(255, 233, 187, 0.4);
}

.board-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 8 / 9;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 246, 211, 0.55), transparent 34%),
    #e6bd78;
  border: 2px solid var(--line);
  user-select: none;
}

.board-lines,
.pieces-layer {
  position: absolute;
  inset: 0;
}

.board-lines {
  overflow: visible;
  opacity: 0.95;
}

.board-lines path {
  fill: none;
  stroke: var(--line);
  stroke-width: 0.045;
  stroke-linecap: round;
  stroke-linejoin: round;
  shape-rendering: geometricPrecision;
}

.river {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  color: rgba(87, 57, 35, 0.52);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(22px, 5vw, 46px);
  font-weight: 700;
  letter-spacing: 0;
  pointer-events: none;
}

.river-left {
  left: 20%;
}

.river-right {
  right: 20%;
}

.piece {
  position: absolute;
  display: grid;
  place-items: center;
  width: clamp(34px, 7.2vw, 62px);
  aspect-ratio: 1;
  translate: -50% -50%;
  transition: left 0.3s ease, top 0.3s ease;
  color: var(--black);
  background:
    radial-gradient(circle at 32% 24%, #fff3c4 0 18%, transparent 19%),
    radial-gradient(circle, #f6d48b 0 55%, #d08a43 56% 70%, #8b5530 72% 74%, #f5d28a 76%);
  border: 2px solid rgba(98, 55, 29, 0.56);
  border-radius: 999px;
  box-shadow: 0 8px 13px rgba(68, 38, 18, 0.28);
  font-family: "Songti TC", "STSong", "Noto Serif CJK TC", serif;
  font-size: clamp(22px, 4.5vw, 39px);
  font-weight: 900;
  line-height: 1;
}

.piece.red {
  color: var(--red);
}

.piece.is-movable {
  outline: 3px solid rgba(47, 107, 80, 0.14);
}

.piece.is-selected {
  outline: 4px solid #2f6b50;
  outline-offset: 3px;
  z-index: 5;
}

.message-line {
  min-height: 24px;
  margin: 0;
  color: var(--green);
  font-weight: 650;
}

.message-line.is-error {
  color: #9f2e20;
}

.login-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(32, 23, 15, 0.42);
  backdrop-filter: blur(4px);
}

.login-overlay[hidden] {
  display: none;
}

.login-card {
  display: grid;
  gap: 12px;
  width: min(360px, 100%);
  padding: 20px;
  background: var(--panel);
  border: 1px solid rgba(108, 66, 40, 0.24);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card h2 {
  font-size: 22px;
}

.login-card label {
  color: var(--muted);
  font-size: 14px;
}

.login-card input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(108, 66, 40, 0.32);
  border-radius: 6px;
  background: #fff;
}

.dialog-message {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.login-card .ghost-btn {
  background: transparent;
  color: var(--muted);
}

.login-error {
  margin: -4px 0 0;
  color: #9f2e20;
  font-size: 13px;
  font-weight: 650;
}

.lobby-shell {
  width: min(720px, calc(100vw - 32px));
  margin: 24px auto;
}

.lobby-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  background: rgba(255, 248, 236, 0.94);
  border: 1px solid rgba(108, 66, 40, 0.22);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.back-to-lobby-link {
  align-self: flex-start;
  padding: 0;
  color: var(--muted);
  background: transparent;
}

.lobby-panel h2 {
  font-size: 22px;
}

.lobby-hint {
  color: var(--muted);
  font-size: 14px;
}

.lobby-table-list {
  display: grid;
  gap: 12px;
}

.lobby-table-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: #fffaf2;
  border: 1px solid rgba(108, 66, 40, 0.2);
  border-radius: 6px;
}

.lobby-table-card h3 {
  margin: 0 0 4px;
  font-size: 17px;
}

.lobby-table-seats {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.lobby-table-status {
  padding: 3px 10px;
  border-radius: 999px;
  color: #fff;
  background: var(--green);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.lobby-table-status.is-full {
  background: var(--red);
}

.lobby-enter-btn {
  min-height: 36px;
  padding: 0 16px;
  border-radius: 6px;
  color: #fff;
  background: var(--wood-dark);
  white-space: nowrap;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(720px, calc(100vw - 24px));
    padding: 12px 0 24px;
  }

  .table-panel {
    order: 2;
  }

  .board-panel {
    order: 1;
  }

  .board-frame {
    width: min(100%, 680px);
  }
}

@media (max-width: 520px) {
  .board-frame {
    padding: 16px;
    border-width: 4px;
  }

  .piece {
    width: clamp(28px, 9vw, 42px);
    font-size: clamp(18px, 6vw, 28px);
  }

  h1 {
    font-size: 23px;
  }
}
