body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #2a2520;
  color: #eee;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
  box-sizing: border-box;
}

h1 {
  margin: 0 0 16px 0;
  font-weight: 500;
  font-size: 1.7em;
  letter-spacing: 0.02em;
}

h2 {
  margin: 0 0 12px 0;
  font-weight: 500;
  font-size: 1.3em;
}

h3 {
  margin: 8px 0 4px 0;
  font-size: 0.95em;
  color: #d8c5a8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ===== Screens ===== */
.screen { display: none; }
.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 540px;
}
#screen-game.active {
  max-width: 100%;
}

.lead {
  text-align: center;
  color: #c8b89e;
  line-height: 1.5;
  margin: 4px 0 24px;
}

.screen-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.hint {
  color: #908070;
  font-size: 0.85em;
  margin-top: 14px;
  text-align: center;
}

/* ===== Buttons ===== */
button, select {
  padding: 9px 16px;
  font-size: 0.95em;
  border-radius: 6px;
  border: 1px solid #6a5a48;
  background: #4a3f33;
  color: #eee;
  cursor: pointer;
  font-family: inherit;
}

button:hover:not(:disabled) { background: #5a4d3f; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.primary-btn {
  background: #c87a3a;
  border-color: #d89050;
  font-weight: 600;
}
.primary-btn:hover:not(:disabled) { background: #d8884a; }

.secondary-btn { /* default styling */ }

.success-btn {
  background: #3a8a3a;
  border-color: #4caf4c;
}
.success-btn:hover:not(:disabled) { background: #4aaa4a; }

.danger-btn {
  background: #8a3a3a;
  border-color: #c04c4c;
}
.danger-btn:hover:not(:disabled) { background: #a04a4a; }

/* ===== Forms / lobby ===== */
.form-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 10px 0;
}

.invite-row {
  display: flex;
  gap: 8px;
  width: 100%;
  margin: 8px 0 16px;
}

#invite-link {
  flex: 1;
  padding: 9px 12px;
  border-radius: 6px;
  border: 1px solid #6a5a48;
  background: #1f1c18;
  color: #f8e8c8;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.9em;
}

.lobby-players {
  width: 100%;
  background: #3a2f24;
  border-radius: 8px;
  padding: 12px 16px;
  margin: 8px 0;
}

#player-list {
  margin: 0;
  padding-left: 22px;
  color: #d0c2a8;
}

#player-list li {
  padding: 3px 0;
}

.knock-box {
  width: 100%;
  background: #4a3a2a;
  border: 1px solid #c87a3a;
  border-radius: 8px;
  padding: 14px 16px;
  margin: 10px 0;
  text-align: center;
}

.knock-box p { margin: 0 0 10px 0; }
.knock-box button { margin: 0 4px; }

#lobby-status, #guest-status {
  color: #c8b89e;
  margin: 4px 0 8px;
  text-align: center;
}

/* ===== Game screen ===== */
.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.status-row {
  display: flex;
  gap: 14px;
  align-items: center;
  margin: 8px 0 16px;
  font-size: 1.05em;
}

#status { font-weight: 600; }

#status-chip {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #888;
  border: 2px solid #222;
  vertical-align: middle;
}

#move-info {
  color: #aaa;
  font-size: 0.9em;
}

.play-area {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  width: 100%;
  max-width: 960px;
  justify-content: center;
}

.sidebar {
  width: 240px;
  background: #3a2f24;
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

.sidebar h2 {
  margin: 0 0 10px 0;
  font-size: 1em;
  font-weight: 600;
  color: #d8c5a8;
  border-bottom: 1px solid #5a4a38;
  padding-bottom: 6px;
}

#history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 60vh;
  overflow-y: auto;
  font-size: 0.9em;
}

#history-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid #4a3d2c;
  color: #d0c2a8;
}

#history-list li:last-child { border-bottom: none; }

.history-chip {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ===== Chat panel ===== */
#chat-panel {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #5a4a38;
}

#chat-panel h2 {
  margin: 0 0 8px 0;
  font-size: 1em;
  font-weight: 600;
  color: #d8c5a8;
  border-bottom: none;
  padding-bottom: 0;
}

#chat-list {
  list-style: none;
  padding: 0;
  margin: 0 0 8px 0;
  max-height: 180px;
  overflow-y: auto;
  font-size: 0.9em;
}

#chat-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 0;
  color: #e0d2b8;
  word-break: break-word;
}

#chat-list li .history-chip {
  margin-top: 5px;
}

.chat-input-row {
  display: flex;
  gap: 6px;
}

#chat-input {
  flex: 1;
  padding: 7px 10px;
  border-radius: 5px;
  border: 1px solid #6a5a48;
  background: #1f1c18;
  color: #f0e0c0;
  font-family: inherit;
  font-size: 0.9em;
  min-width: 0;
}

#btn-send-chat {
  padding: 7px 12px;
  font-size: 0.9em;
}

/* ===== Mobile ===== */
@media (max-width: 720px) {
  body { padding: 12px; }
  h1 { font-size: 1.4em; }
  .play-area {
    flex-direction: column;
    align-items: center;
  }
  .sidebar {
    width: 100%;
    max-width: 600px;
  }
  #history-list { max-height: 160px; }
  #chat-list   { max-height: 140px; }
  #board-svg   { max-width: 95vw; }
  .controls    { gap: 6px; }
  button       { padding: 10px 12px; } /* touch-friendly */
}

@media (max-width: 420px) {
  h1 { font-size: 1.2em; margin-bottom: 8px; }
  .controls { font-size: 0.9em; }
}
