:root {
  --bg: #2a1a10;
  --bg2: #3b2414;
  --panel: #f7efe2;
  --ink: #2b1d12;
  --muted: #7a6654;
  --light: #f0d9b5;
  --dark: #8b5a2b;
  --sel: #f6e05e;
  --target: #48bb78;
  --last: #c08a3e;
  --accent: #b7791f;
  --whats: #25d366;
  --radius: 10px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg) radial-gradient(circle at 50% 0%, #4a2e1a, var(--bg) 70%) fixed;
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; color: #f7e7cf;
}
.topbar h1 { margin: 0; font-size: 1.5rem; letter-spacing: .5px; }
.icon-btn { background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: inherit; }

.layout {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 0 16px 24px;
}
.board-area { width: 100%; max-width: min(92vh - 120px, 640px); }

.board {
  display: grid; grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1; width: 100%;
  border: 8px solid #5a3519; border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  touch-action: manipulation; user-select: none;
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; }
.sq.l { background: var(--light); }
.sq.d { background: var(--dark); cursor: pointer; }
.sq.last { background: var(--last); }
.sq.sel { background: var(--sel); }
.sq .coord { position: absolute; font-size: 10px; font-weight: 600; pointer-events: none; }
.sq.l .coord { color: rgba(90, 53, 25, .7); }
.sq.d .coord, .sq.last .coord, .sq.sel .coord { color: rgba(255, 245, 230, .7); }
.sq .coord.r { top: 2px; left: 3px; }
.sq .coord.c { bottom: 1px; right: 3px; }
.sq .dot { width: 30%; height: 30%; border-radius: 50%; background: var(--target); opacity: .9; }

.piece {
  position: relative;
  width: 78%; height: 78%; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 2px 4px 0 rgba(0,0,0,.45);
  transition: transform .12s;
}
.piece.w { background: radial-gradient(circle at 35% 30%, #fff, #e6e6e6 60%, #c9c9c9); border: 3px solid #9a9a9a; }
.piece.b { background: radial-gradient(circle at 35% 30%, #555, #2b2b2b 60%, #111); border: 3px solid #000; }
.piece::before {
  content: ""; width: 58%; height: 58%; border-radius: 50%;
  border: 1px solid rgba(0,0,0,.25);
}
.piece.b::before { border-color: rgba(255,255,255,.18); }
.piece.k::after {
  content: "♛"; position: absolute; font-size: min(5vw, 30px); color: #d4a017;
  text-shadow: 0 1px 1px rgba(0,0,0,.5);
}
.sq.sel .piece { transform: scale(1.06); }

.status {
  color: #f7e7cf; text-align: center; margin: 10px 0 0; min-height: 1.4em; font-weight: 600;
}

.side {
  width: 100%; max-width: 640px;
  background: var(--panel); border-radius: var(--radius); padding: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
}
.info { display: grid; grid-template-columns: 1fr; gap: 3px; margin: 0 0 12px; font-size: .95rem; }
.info div { display: flex; gap: 6px; min-width: 0; }
.info dt { color: var(--muted); flex: none; width: 6.5em; }
.info dt::after { content: ":"; }
.info dd { margin: 0; font-weight: 600; min-width: 0; }

.buttons { display: flex; flex-direction: column; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 .wide, .wide { grid-column: 1 / -1; width: 100%; }
.nav { display: flex; gap: 8px; }
.nav button { flex: 1; }

button, .btn, select, input {
  font: inherit; border-radius: 8px;
}
button, .btn {
  border: 1px solid #c9b79e; background: #fffaf2; color: var(--ink);
  padding: 10px 12px; cursor: pointer; text-align: center; text-decoration: none;
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
}
button:hover:not(:disabled), .btn:hover { background: #fff; border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.whats, .btn.whats { background: var(--whats); color: #0b3b1e; border-color: #1ebe5a; font-weight: 600; }
button.link { background: none; border: 0; color: var(--muted); text-decoration: underline; min-height: 32px; }
select, input { border: 1px solid #c9b79e; padding: 8px; background: #fff; color: var(--ink); }

.hint { color: var(--muted); font-size: .9rem; margin: 4px 0; }

.room { border-top: 1px solid #e3d5c0; padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.room h2 { font-size: .95rem; margin: 4px 0 0; color: var(--muted); font-weight: 600; }
.room h2 small { font-weight: 400; }
.room .seat { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 600; }
.room .seat .mini { width: 20px; height: 20px; flex: none; }
.room ol { margin: 0; padding-left: 1.6em; }
.room li.me { font-weight: 700; color: var(--accent); }
.palette { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.palette label {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px;
  border: 1px solid #c9b79e; border-radius: 8px; cursor: pointer; font-size: .85rem;
}
.palette input { position: absolute; opacity: 0; pointer-events: none; }
.palette label:has(input:checked) { border-color: var(--accent); background: #fff3d6; }
.mini { width: 28px; height: 28px; border-radius: 50%; position: relative; display: inline-block; }
.mini.w { background: #f4f4f4; border: 2px solid #9a9a9a; }
.mini.b { background: #2b2b2b; border: 2px solid #000; }
.mini.k::after { content: "♛"; position: absolute; inset: 0; display: grid; place-items: center; color: #d4a017; font-size: 15px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(440px, calc(100vw - 32px));
  background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
dialog::backdrop { background: rgba(20, 10, 4, .6); }
dialog form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0; font-size: 1.25rem; }
dialog p { margin: 0; }
fieldset { border: 1px solid #d8c7ae; border-radius: 10px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
fieldset[disabled] { opacity: .45; }
fieldset label { display: flex; gap: 8px; align-items: center; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-size: .95rem; }
menu { display: flex; justify-content: flex-end; gap: 8px; margin: 4px 0 0; padding: 0; }
#invite-link, #msg-input { width: 100%; }
#msg-text { white-space: pre-line; }

.slots { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 55vh; overflow: auto; }
.slots button { width: 100%; justify-content: flex-start; text-align: left; }
.slots .empty { color: var(--muted); }

.records { width: 100%; border-collapse: collapse; font-size: .9rem; }
.records th, .records td { padding: 6px 4px; border-bottom: 1px solid #e3d5c0; text-align: left; }
.records td:first-child, .records th:first-child { width: 2em; text-align: center; }
.records-empty { color: var(--muted); text-align: center; }

@media (min-width: 900px) {
  .layout { flex-direction: row; align-items: flex-start; justify-content: center; }
  .board-area { max-width: min(calc(100vh - 110px), 640px); }
  .side { width: 300px; }
}
