:root {
  color-scheme: light;
  --ink: #201711;
  --muted: #7a6b61;
  --paper: #f7f1e8;
  --panel: #fffaf2;
  --line: #9f6a3c;
  --red: #b52922;
  --black: #202020;
  --green: #426b5b;
  --gold: #c99445;
  --shadow: 0 18px 60px rgba(42, 31, 19, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(247, 241, 232, 0.94), rgba(237, 244, 239, 0.9)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cg fill='none' stroke='%23b89465' stroke-opacity='.18'%3E%3Cpath d='M0 30h180M0 90h180M0 150h180M30 0v180M90 0v180M150 0v180'/%3E%3C/g%3E%3C/svg%3E");
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  padding: 0 18px;
  background: var(--green);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(66, 107, 91, 0.18);
}

button:hover {
  filter: brightness(1.04);
}

button:active {
  transform: translateY(1px);
}

button[aria-pressed="true"] {
  background: var(--gold);
  color: #27180d;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0;
  display: grid;
  grid-template-columns: minmax(560px, 740px) minmax(300px, 380px);
  gap: 24px;
  align-items: center;
}

.app-shell.coach-closed {
  grid-template-columns: minmax(560px, 760px);
  justify-content: center;
}

.board-zone,
.companion-panel {
  background: rgba(255, 250, 242, 0.92);
  border: 1px solid rgba(159, 106, 60, 0.22);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.board-zone {
  padding: 22px;
}

.topbar,
.companion-head,
.controls,
.score-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.controls {
  flex-wrap: wrap;
}

.starter-control {
  min-height: 46px;
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(66, 107, 91, 0.22);
  border-radius: 8px;
  background: rgba(237, 244, 239, 0.82);
}

.starter-btn {
  min-height: 36px;
  padding: 0 12px;
  box-shadow: none;
  color: var(--green);
  background: transparent;
}

.starter-btn.active {
  color: #fff9e9;
  background: var(--green);
}

.player-status {
  min-height: 44px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--green);
  font-weight: 900;
}

.player-status strong {
  color: var(--gold);
}

.player-status span:last-child {
  color: var(--muted);
}

.top-actions,
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.profile-button,
.user-chip button {
  min-height: 34px;
  padding: 0 12px;
}

.user-chip {
  min-height: 44px;
  padding: 6px 8px 6px 12px;
  border: 1px solid rgba(66, 107, 91, 0.22);
  border-radius: 8px;
  background: rgba(237, 244, 239, 0.82);
  color: var(--green);
  font-weight: 900;
}

.user-chip strong {
  color: var(--gold);
}

.user-chip button {
  background: rgba(66, 107, 91, 0.12);
  color: var(--green);
  box-shadow: none;
}

.admin-link {
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--green);
  background: rgba(66, 107, 91, 0.12);
  text-decoration: none;
  font-size: 13px;
}

.admin-link[hidden] {
  display: none;
}

.opponent-stage {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 6px;
}

.role-arrow {
  min-width: 34px;
  min-height: 52px;
  padding: 0;
  border: 1px solid rgba(159, 106, 60, 0.18);
  background: rgba(255, 250, 242, 0.68);
  color: rgba(66, 107, 91, 0.72);
  box-shadow: none;
  font-size: 24px;
  line-height: 1;
}

.role-arrow:hover {
  background: rgba(237, 244, 239, 0.9);
  color: var(--green);
}

.opponent-card {
  min-height: 150px;
  display: grid;
  grid-template-columns: minmax(110px, 1fr) 168px minmax(130px, 1fr);
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.72);
}

.opponent-avatar,
.avatar {
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(237, 244, 239, 0.74);
  color: var(--green);
  font-weight: 900;
  font-family: serif;
}

.opponent-avatar {
  justify-self: center;
  width: 158px;
  height: 138px;
  font-size: 48px;
  box-shadow: none;
  overflow: hidden;
}

.opponent-avatar.laogao,
.avatar.laogao {
  background: #426b5b;
}

.opponent-avatar.jiexi,
.avatar.jiexi {
  background: #8f3f59;
}

.opponent-avatar.qingjie,
.avatar.qingjie {
  background: #425f85;
}

.opponent-avatar.tongmei,
.avatar.tongmei {
  background: #6d5fa8;
}

.opponent-avatar.fengzai,
.avatar.fengzai {
  background: #b26b34;
}

.opponent-info {
  min-width: 0;
  text-align: right;
}

.opponent-info h1 {
  font-size: 24px;
}

.opponent-side-note {
  min-width: 0;
  display: grid;
  gap: 8px;
  justify-items: start;
}

.opponent-side-note span {
  display: block;
  color: #6d5a4b;
  font-size: 14px;
  font-weight: 800;
}

.opponent-side-note strong {
  display: block;
  max-width: 160px;
  padding: 8px 10px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(237, 244, 239, 0.96), rgba(255, 246, 220, 0.9));
  color: #426b5b;
  font-size: 13px;
  font-weight: 900;
  text-align: center;
}

.level-control,
.level-btn {
  display: none;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 34px;
}

h2 {
  font-size: 24px;
}

.status-pill,
.mood {
  border: 1px solid rgba(66, 107, 91, 0.26);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--green);
  background: rgba(237, 244, 239, 0.86);
  font-weight: 800;
}

.board-wrap {
  margin: 18px auto 22px;
  width: min(100%, 630px);
  aspect-ratio: 9 / 10;
  padding: 32px;
  border-radius: 8px;
  background: #c9914c;
  box-shadow: inset 0 0 0 2px rgba(79, 39, 12, 0.2), 0 10px 30px rgba(69, 38, 15, 0.16);
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  border: 3px solid #6f3a17;
  background: #efbf75;
  overflow: hidden;
}

.grid-line {
  position: absolute;
  background: #753d19;
  pointer-events: none;
  z-index: 1;
}

.grid-line.vertical {
  width: 2px;
  transform: translateX(-1px);
}

.grid-line.horizontal {
  height: 2px;
  transform: translateY(-1px);
}

.palace-line {
  position: absolute;
  height: 2px;
  background: #753d19;
  transform-origin: left center;
  pointer-events: none;
  z-index: 1;
}

.river {
  position: absolute;
  left: 7%;
  top: 43%;
  width: 86%;
  height: 9.556%;
  display: grid;
  place-items: center;
  color: rgba(96, 52, 21, 0.72);
  font-size: clamp(18px, 4vw, 34px);
  font-family: serif;
  font-weight: 800;
  pointer-events: none;
  z-index: 2;
}

.river span {
  display: inline-flex;
  gap: min(9vw, 76px);
  transform: translateY(2%);
}

.piece {
  position: absolute;
  width: min(10.2%, 56px);
  height: auto;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid currentColor;
  border-radius: 999px;
  background: radial-gradient(circle at 35% 28%, #fff7df, #e1b66b 72%);
  box-shadow: 0 4px 10px rgba(55, 31, 15, 0.28);
  font-family: "STSong", "Songti SC", "Noto Serif CJK SC", "SimSun", serif;
  font-size: clamp(18px, 4.2vw, 31px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
  text-indent: 0;
  transform: translate(-50%, -50%);
  cursor: pointer;
  user-select: none;
  z-index: 4;
  appearance: none;
  -webkit-appearance: none;
  padding: 0;
}

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

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

.piece.selected {
  outline: 4px solid rgba(255, 238, 141, 0.88);
}

.hint-dot {
  position: absolute;
  width: min(4.2%, 24px);
  aspect-ratio: 1;
  border-radius: 999px;
  background: rgba(66, 107, 91, 0.65);
  transform: translate(-50%, -50%);
  z-index: 3;
  pointer-events: none;
}

.last-move {
  position: absolute;
  width: min(8.4%, 48px);
  aspect-ratio: 1;
  border: 4px solid rgba(255, 244, 166, 0.95);
  border-radius: 999px;
  transform: translate(-50%, -50%);
  z-index: 2;
  pointer-events: none;
  animation: movePulse 1.35s ease-out 2;
}

.last-move.from {
  border-color: rgba(66, 107, 91, 0.72);
}

.move-line {
  position: absolute;
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(66, 107, 91, 0.15), rgba(255, 244, 166, 0.95));
  transform-origin: left center;
  z-index: 2;
  pointer-events: none;
  animation: lineFlash 1.4s ease-out 1;
}

@keyframes movePulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 244, 166, 0.95);
  }
  100% {
    box-shadow: 0 0 0 16px rgba(255, 244, 166, 0);
  }
}

@keyframes lineFlash {
  0% {
    opacity: 0;
    transform: scaleX(0) rotate(var(--angle));
  }
  100% {
    opacity: 1;
    transform: scaleX(1) rotate(var(--angle));
  }
}

.companion-panel {
  height: min(760px, calc(100vh - 48px));
  padding: 22px;
  display: grid;
  grid-template-rows: auto auto auto auto 1fr auto;
  gap: 16px;
}

.companion-panel.coach-hidden {
  display: none;
}

.avatar {
  width: 58px;
  height: 58px;
  font-size: 30px;
  overflow: hidden;
}

.opponent-avatar.has-image,
.avatar.has-image {
  background: transparent;
  box-shadow: none;
}

.opponent-avatar img,
.avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: 50% 30%;
}

.opponent-avatar.has-image img {
  transform: scale(1.04);
}

.avatar.has-image img {
  transform: scale(1.22);
}

.mood {
  justify-content: center;
  text-align: center;
}

.source-pill {
  width: 18px;
  height: 18px;
  margin: -8px auto 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.source-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #b7a99e;
  box-shadow: 0 0 0 3px rgba(183, 169, 158, 0.16);
}

.source-dot.online {
  background: #2f9e68;
  box-shadow: 0 0 0 3px rgba(47, 158, 104, 0.16);
}

.source-dot.offline {
  background: #c6953d;
  box-shadow: 0 0 0 3px rgba(198, 149, 61, 0.14);
}

.panel-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 5px;
  border-radius: 8px;
  background: rgba(237, 244, 239, 0.7);
}

.panel-tab {
  min-height: 36px;
  background: transparent;
  color: var(--green);
  box-shadow: none;
}

.panel-tab.active {
  background: var(--green);
  color: #fff;
}

.panel-view {
  min-height: 0;
  display: none;
}

.panel-view.active {
  display: block;
  overflow: hidden;
}

.message-log {
  height: 100%;
  overflow: auto;
  padding-right: 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  border-radius: 8px;
  padding: 12px 13px;
  background: #f4eadb;
  line-height: 1.55;
  color: #33251b;
  border-left: 4px solid rgba(66, 107, 91, 0.45);
}

.message::before {
  content: "对局";
  display: block;
  margin-bottom: 4px;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
}

.message.system {
  background: #f4eadb;
  color: #33251b;
  font-weight: 500;
  border-left-color: rgba(66, 107, 91, 0.45);
}

.analysis-card {
  display: grid;
  gap: 10px;
  padding: 13px;
  border: 1px solid rgba(66, 107, 91, 0.24);
  border-left: 4px solid var(--green);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 8px 20px rgba(45, 55, 48, 0.06);
}

.analysis-card.warning {
  border-left-color: var(--gold);
}

.analysis-card.danger {
  border-left-color: var(--red);
}

.analysis-card-head,
.analysis-score,
.analysis-best,
.analysis-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.analysis-card-head > div {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.analysis-card-head span,
.analysis-score span,
.analysis-best span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.analysis-card-head strong {
  font-size: 16px;
}

.analysis-card-head b {
  color: var(--green);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.analysis-card.warning .analysis-card-head b,
.analysis-card.danger .analysis-card-head b {
  color: var(--red);
}

.analysis-score,
.analysis-best {
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(237, 244, 239, 0.72);
}

.analysis-score strong,
.analysis-best strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.analysis-card p {
  margin: 0;
  color: #4f443b;
  font-size: 13px;
  line-height: 1.5;
}

.analysis-tags {
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.analysis-tags:empty {
  display: none;
}

.analysis-tags span {
  padding: 4px 7px;
  border-radius: 999px;
  color: var(--green);
  background: var(--green-soft, rgba(237, 244, 239, 0.86));
  font-size: 11px;
  font-weight: 800;
}

.analysis-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.analysis-actions button {
  min-height: 34px;
  padding: 0 6px;
  color: var(--green);
  background: rgba(66, 107, 91, 0.1);
  box-shadow: none;
  font-size: 12px;
}

.analysis-actions button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.analysis-detail {
  padding: 10px;
  border-left: 3px solid rgba(201, 148, 69, 0.72);
  background: rgba(255, 246, 220, 0.72);
  color: #45372c;
  font-size: 12px;
  line-height: 1.65;
}

.analysis-detail[hidden] {
  display: none;
}

.review-list {
  height: 100%;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 4px;
}

.empty-review {
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  background: #f4eadb;
  color: var(--muted);
  line-height: 1.5;
  font-weight: 700;
}

.review-item {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(159, 106, 60, 0.22);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.88);
}

.review-item.active {
  border-color: rgba(201, 148, 69, 0.88);
  background: rgba(255, 246, 220, 0.96);
  box-shadow: 0 8px 20px rgba(201, 148, 69, 0.14);
}

.review-step {
  color: var(--green);
  font-weight: 900;
}

.review-main {
  min-width: 0;
}

.review-main strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
}

.review-main span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.review-delta {
  color: var(--red);
  font-weight: 900;
}

.review-delta.up {
  color: #2f7f5f;
}

.score-strip {
  padding-top: 14px;
  border-top: 1px solid rgba(159, 106, 60, 0.22);
}

.score-strip div {
  min-width: 72px;
  display: grid;
  gap: 3px;
  text-align: center;
}

.score-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.score-strip strong {
  font-size: 24px;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .companion-panel {
    height: auto;
    min-height: 420px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100vw - 16px, 540px);
    padding: 8px 0;
  }

  .board-zone,
  .companion-panel {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  .opponent-stage {
    grid-template-columns: 28px minmax(0, 1fr) 28px;
    gap: 4px;
  }

  .role-arrow {
    min-width: 28px;
    min-height: 44px;
    font-size: 20px;
  }

  .opponent-card {
    grid-template-columns: minmax(0, 1fr) 112px minmax(0, 1fr);
    gap: 6px;
    padding: 8px 6px;
    min-height: 118px;
  }

  .opponent-avatar {
    width: 112px;
    height: 104px;
    font-size: 34px;
  }

  .opponent-info h1 {
    font-size: 20px;
  }

  .opponent-side-note span,
  .opponent-side-note strong {
    font-size: 12px;
  }

  .opponent-side-note strong {
    max-width: none;
  }

  h1 {
    font-size: 27px;
  }

  .board-wrap {
    margin: 14px auto 18px;
    padding: 20px;
  }

  .board {
    border-width: 2px;
  }

  .piece {
    width: min(8.4%, 34px);
    height: auto;
    min-height: 0;
    border-width: 1.25px;
    box-shadow: 0 2px 6px rgba(55, 31, 15, 0.22);
    font-size: 15px;
  }

  .river {
    font-size: 20px;
  }

  .last-move {
    width: min(6.4%, 27px);
    border-width: 2.5px;
  }

  .hint-dot {
    width: min(2.9%, 12px);
  }

  .controls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .starter-control {
    min-height: 54px;
  }

  .starter-btn {
    min-height: 44px;
    padding: 0 6px;
  }

  button {
    padding: 0 8px;
  }
}

.voice-player {
  width: 100%;
  height: 36px;
  margin-top: 10px;
  display: block;
}

.volume-control {
  display: grid;
  grid-template-columns: auto 1fr 48px;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(66, 107, 91, 0.22);
  border-radius: 8px;
  background: rgba(237, 244, 239, 0.7);
  color: var(--green);
  font-weight: 800;
}

.volume-control input {
  width: 100%;
  accent-color: var(--green);
}

.auth-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(32, 23, 17, 0.34);
  backdrop-filter: blur(8px);
}

.auth-backdrop[hidden],
.auth-card label[hidden] {
  display: none;
}

.auth-card {
  width: min(360px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border-radius: 8px;
  border: 1px solid rgba(159, 106, 60, 0.28);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 5px;
  border-radius: 8px;
  background: rgba(237, 244, 239, 0.7);
}

.auth-tab {
  min-height: 36px;
  background: transparent;
  color: var(--green);
  box-shadow: none;
}

.auth-tab.active {
  background: var(--green);
  color: #fff;
}

.auth-card h2 {
  margin: 0;
}

.auth-card label {
  display: grid;
  gap: 6px;
  color: var(--green);
  font-weight: 900;
}

.auth-card input {
  min-height: 42px;
  border: 1px solid rgba(66, 107, 91, 0.24);
  border-radius: 8px;
  padding: 0 12px;
  background: #fffdf8;
  color: var(--ink);
  font: inherit;
}

.auth-note {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
