* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(160deg, #f4ecdc, #e2d3b4);
  color: #3b2a14;
}

header {
  text-align: center;
  padding: 16px 0 4px;
}

header h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 4px;
}

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 12px;
}

.hidden {
  display: none !important;
}

.card {
  background: rgba(255, 255, 255, 0.75);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(80, 50, 10, 0.15);
  padding: 16px;
}

button {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid #b89560;
  background: #fff8ea;
  color: #3b2a14;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #f5e6c8;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: #8b5a2b;
  border-color: #8b5a2b;
  color: #fff;
}

button.primary:hover:not(:disabled) {
  background: #74481f;
}

button.big {
  width: 100%;
  padding: 12px;
  font-size: 18px;
}

button.small {
  padding: 4px 10px;
  font-size: 13px;
}

input {
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #b89560;
  background: #fff;
  min-width: 0;
}

.lobby {
  max-width: 420px;
  margin: 40px auto;
  text-align: center;
}

.divider {
  margin: 14px 0;
  color: #9a8160;
}

.join-row {
  display: flex;
  gap: 8px;
}

.join-row input {
  flex: 1;
}

select {
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #b89560;
  background: #fff;
  color: #3b2a14;
}

.ai-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-form label {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-form label span {
  width: 3em;
  text-align: left;
}

.ai-form select {
  flex: 1;
}

.game {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: center;
}

.board-wrap {
  flex: 1 1 auto;
  max-width: 640px;
  width: 100%;
}

#board {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(80, 50, 10, 0.3);
  touch-action: manipulation;
  cursor: pointer;
}

.panel {
  flex: 0 0 280px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.room-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.conn {
  font-size: 13px;
  color: #9a8160;
}

.conn.ok {
  color: #2e7d32;
}

.conn.bad {
  color: #c62828;
}

.players {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 2px solid transparent;
  background: rgba(255, 248, 234, 0.8);
}

.player.active {
  border-color: #e0a030;
  background: #fff3d6;
}

.player .pname {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #bbb;
}

.player .dot.on {
  background: #43a047;
}

.stone {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.stone.black {
  background: radial-gradient(circle at 35% 35%, #666, #000);
}

.stone.white {
  background: radial-gradient(circle at 35% 35%, #fff, #ccc);
  border: 1px solid #aaa;
}

.status {
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  padding: 8px 0;
}

.meta {
  font-size: 13px;
  color: #6d5535;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  background: rgba(40, 25, 5, 0.88);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 10;
}

@media (max-width: 760px) {
  .game {
    flex-direction: column;
    align-items: stretch;
  }

  .panel {
    flex: none;
  }
}
