:root {
  color-scheme: light;
  --bg: #c3925c;
  --wood: #e6bf7b;
  --wood-dark: #c89453;
  --frame: #9b6738;
  --line: rgba(86, 54, 24, 0.56);
  --text: #342110;
  --muted: #6f5438;
  --button: #b87836;
  --danger: #a34734;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  background:
    linear-gradient(rgba(96, 60, 29, 0.08), rgba(96, 60, 29, 0.08)),
    linear-gradient(180deg, #b7844f, var(--bg));
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

.hidden {
  display: none !important;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 48px 40px 1fr 64px;
  padding: env(safe-area-inset-top, 0) 12px env(safe-area-inset-bottom, 0);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: #fff6e2;
}

.top-item {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 15px;
}

.turn-text {
  text-align: center;
}

.copy-btn,
.tool-btn,
.overlay-actions button,
.ghost {
  min-height: 38px;
  border-radius: 12px;
  background: var(--button);
  color: #fff8ec;
  padding: 0 14px;
}

.players-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.player-chip {
  min-width: 0;
  min-height: 32px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 10px;
  color: #fff7e4;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.black-chip {
  background: rgba(39, 27, 17, 0.44);
}

.white-chip {
  background: rgba(98, 71, 40, 0.38);
}

.board-wrap {
  display: grid;
  place-items: center;
  min-height: 0;
}

.board-canvas {
  width: min(calc(100vw - 24px), calc(100vh - 128px), 760px);
  height: min(calc(100vw - 24px), calc(100vh - 128px), 760px);
  display: block;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(126, 77, 28, 0.04) 0,
      rgba(126, 77, 28, 0.04) 12px,
      rgba(255, 255, 255, 0.03) 12px,
      rgba(255, 255, 255, 0.03) 24px
    ),
    linear-gradient(180deg, var(--wood), var(--wood-dark));
  border-radius: 22px;
  border: 4px solid rgba(94, 59, 28, 0.34);
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: center;
}

.tool-btn.danger {
  background: var(--danger);
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(39, 25, 14, 0.42);
}

.overlay-card {
  width: min(100%, 360px);
  border-radius: 18px;
  background: rgba(249, 240, 220, 0.96);
  padding: 20px;
  display: grid;
  gap: 14px;
}

.overlay-card h1,
.overlay-status,
.field span {
  margin: 0;
}

.overlay-card h1 {
  font-size: 28px;
  text-align: center;
}

.overlay-status {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  min-height: 20px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--muted);
  font-size: 14px;
}

.field input {
  width: 100%;
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(118, 84, 52, 0.18);
  background: #fffdf9;
  color: var(--text);
  padding: 0 12px;
}

.overlay-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.created-room-info {
  border-radius: 14px;
  background: rgba(230, 191, 123, 0.28);
  padding: 12px;
  text-align: center;
}

.created-room-label,
.created-room-code {
  margin: 0;
}

.created-room-label {
  color: var(--muted);
  font-size: 13px;
}

.created-room-code {
  margin-top: 6px;
  font-size: 28px;
  letter-spacing: 0.12em;
  color: var(--text);
}

.overlay-actions .primary {
  background: #d28c34;
}

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(118, 84, 52, 0.2);
}

@media (max-width: 640px) {
  .app {
    grid-template-rows: 48px 40px 1fr 60px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .top-item,
  .copy-btn {
    font-size: 13px;
  }

  .board-canvas {
    width: min(calc(100vw - 16px), calc(100vh - 124px));
    height: min(calc(100vw - 16px), calc(100vh - 124px));
    border-radius: 18px;
  }

  .toolbar {
    gap: 8px;
  }
}
