:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f1ea;
  color: #202020;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

button,
input {
  font: inherit;
}

button {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  background: #fffaf0;
  color: #202020;
  cursor: pointer;
  padding: 0.55rem 0.75rem;
  touch-action: manipulation;
  user-select: none;
}

button:hover {
  background: #fff0c8;
}

input {
  border: 1px solid #8a8174;
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  width: 100%;
}

.app {
  min-height: 100vh;
}

.topbar {
  align-items: end;
  background: #28231d;
  color: #fff8eb;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  padding: 1rem clamp(1rem, 4vw, 2rem);
}

.topbar h1 {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  margin: 0;
}

.topbar p {
  margin: 0.25rem 0 0;
}

.rules-disclosure {
  margin-top: 0.6rem;
  max-width: 48rem;
}

.rules-disclosure summary {
  cursor: pointer;
  display: inline-block;
  font-weight: 700;
  touch-action: manipulation;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

.rules-text {
  color: #fff8eb;
  display: grid;
  gap: 0.45rem;
  line-height: 1.55;
  margin-top: 0.55rem;
}

.rules-text p {
  margin: 0;
}

.connection {
  align-items: end;
  display: grid;
  gap: 0.75rem;
  grid-template-columns: minmax(9rem, 14rem);
  width: min(100%, 14rem);
}

.connection label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.86rem;
}

.layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(17rem, 22rem) minmax(0, 1fr);
  padding: 1rem clamp(1rem, 4vw, 2rem) 2rem;
}

.sidebar {
  display: grid;
  gap: 1rem;
}

.panel {
  background: #fffdf8;
  border: 1px solid #d2c7b4;
  border-radius: 8px;
  padding: 0.85rem;
}

.panel h2 {
  font-size: 1rem;
  margin: 0;
}

.panel-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.room-list,
.player-list {
  display: grid;
  gap: 0.5rem;
}

.room-button,
.player-row {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.room-button {
  text-align: left;
}

.room-button small,
.player-row small {
  color: #665d52;
}

.room-actions {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 0.75rem;
}

.chat-panel {
  min-height: 16rem;
}

.chat-log {
  background: #f7f2e8;
  border-radius: 6px;
  height: 12rem;
  overflow: auto;
  padding: 0.6rem;
}

.chat-line {
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.chat-line.system {
  color: #6b5d49;
}

.chat-form {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: 1fr auto;
  margin-top: 0.6rem;
}

.board-area {
  min-width: 0;
}

.game-summary {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.game-controls {
  align-items: center;
  display: flex;
  gap: 1rem;
}

.game-summary span {
  color: #5d5146;
  margin-left: 0.75rem;
}

.setting-toggle {
  align-items: center;
  color: #4d463e;
  display: flex;
  gap: 0.4rem;
  white-space: nowrap;
}

.setting-toggle input {
  width: auto;
}

.message-line {
  background: #fffdf8;
  border: 1px solid #d2c7b4;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  min-height: 2.4rem;
  padding: 0.6rem 0.8rem;
}

.board {
  --board-size: 19;
  --board-margin: 6%;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  aspect-ratio: 1;
  background: #d6a35f;
  border: 2px solid #6a4a28;
  max-height: calc(100vh - 12rem);
  max-width: min(100%, calc(100vh - 12rem));
  min-height: 20rem;
  position: relative;
  touch-action: manipulation;
  user-select: none;
}

.board-grid,
.board-points {
  inset: var(--board-margin);
  position: absolute;
}

.board-grid svg {
  display: block;
  height: 100%;
  overflow: visible;
  width: 100%;
}

.board-grid line {
  shape-rendering: geometricPrecision;
  stroke: #6f4f2b;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.star-point {
  fill: #111;
  stroke: none;
}

.cell {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 999px;
  display: flex;
  height: calc(100% / var(--board-size));
  justify-content: center;
  padding: 0;
  position: absolute;
  touch-action: manipulation;
  transform: translate(-50%, -50%);
  user-select: none;
  width: calc(100% / var(--board-size));
}

.cell:hover {
  background: rgb(255 255 255 / 0.2);
}

.cell::before {
  border-radius: 999px;
  content: "";
  display: none;
  height: 86%;
  width: 86%;
}

.cell.black::before {
  background: #111;
  box-shadow: 0 0 0 1px #000;
  display: block;
}

.cell.white::before {
  background: #f5f5f5;
  box-shadow: 0 0 0 1px #777;
  display: block;
}

.cell.last::after,
.cell.pending::after {
  border-radius: 999px;
  content: "";
  pointer-events: none;
  position: absolute;
}

.cell.last::after {
  border: 2px solid #db2a1f;
  height: 42%;
  width: 42%;
}

.cell.pending::after {
  border: 2px solid #2563eb;
  height: 86%;
  width: 86%;
}

.move-log {
  background: #fffdf8;
  border: 1px solid #d2c7b4;
  border-radius: 8px;
  color: #4d463e;
  display: grid;
  gap: 0.25rem;
  grid-template-columns: repeat(auto-fill, minmax(5.8rem, 1fr));
  margin-top: 0.75rem;
  max-height: 9rem;
  overflow: auto;
  padding: 0.55rem;
}

@media (max-width: 860px) {
  .topbar,
  .layout {
    display: grid;
  }

  .connection,
  .layout {
    grid-template-columns: 1fr;
  }

  .game-summary,
  .game-controls {
    align-items: start;
    display: grid;
  }

  .board {
    max-height: none;
    max-width: 100%;
    min-height: auto;
  }
}
