:root {
  --bg: #241a38;
  --bg2: #3b2a5c;
  --card: #fff;
  --ink: #241a38;
  --muted: #6d6480;
  --accent: #e0569b;
  --accent-ink: #fff;
  --light: #efe6f7;
  --dark: #9a7fc4;
  --last: rgba(255, 214, 64, 0.55);
  --sel: rgba(90, 210, 140, 0.6);
  --check: radial-gradient(circle, #ff1f1f 0%, #e81515 55%, #b30000 100%);
  --hint: rgba(60, 200, 110, 0.55);
  --hint-capture: rgba(255, 120, 40, 0.7);
  --radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; min-height: 100%; }
html { background: var(--bg); }

body {
  background: linear-gradient(180deg, var(--bg2), var(--bg)) fixed;
  color: #fff;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}

/* ---------- home / join ---------- */

.hero { text-align: center; padding: 24px 0 12px; }
.hero h1 { margin: 8px 0 4px; font-size: 34px; letter-spacing: 0.5px; }
.tagline { margin: 0; color: #d9cdef; }
.logo { width: 84px; height: 84px; margin: 0 auto; background-size: contain; background-repeat: no-repeat; filter: drop-shadow(0 6px 12px rgba(0,0,0,.35)); }

.card {
  background: var(--card);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 18px;
  margin: 16px 0;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.card h2 { margin: 0 0 10px; font-size: 18px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }
.field input {
  width: 100%;
  font-size: 18px;
  padding: 12px 14px;
  border: 2px solid #e2dcec;
  border-radius: 12px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.field input:focus { border-color: var(--dark); }

.seg { display: flex; background: #f1edf7; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button {
  flex: 1; border: 0; background: transparent; padding: 10px 0; font-size: 16px; border-radius: 9px; color: var(--ink); font-weight: 600;
}
.seg button.on { background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.12); }

.btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 16px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
}
.card .btn { background: #f1edf7; color: var(--ink); }
.btn.primary, .card .btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: rgba(255, 90, 90, 0.25); }
.btn.big { width: 100%; padding: 15px; font-size: 18px; }
.btn.link, .card .btn.link { background: none; color: var(--muted); width: 100%; margin-top: 8px; }
.btn.icon { width: 42px; height: 42px; padding: 0; font-size: 26px; line-height: 42px; }
.btn:disabled { opacity: 0.45; }
.btn:active { transform: scale(0.97); }

.error { color: #c62828; margin: 10px 0 0; font-weight: 600; }

.games { list-style: none; margin: 0; padding: 0; }
.games li { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-top: 1px solid #eee8f5; cursor: pointer; }
.games li:first-child { border-top: 0; }
.games .gicon { width: 36px; height: 36px; background-size: contain; flex: none; }
.games .ginfo { flex: 1; min-width: 0; }
.games .gtitle { font-weight: 700; }
.games .gsub { color: var(--muted); font-size: 14px; }
.games .badge { background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 4px 9px; }
.games .remove { background: none; border: 0; color: #b3a9c4; font-size: 22px; padding: 4px 8px; }

.install-tip { text-align: center; color: #d9cdef; font-size: 14px; line-height: 1.5; }

/* ---------- game ---------- */

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.topbar .title { font-weight: 700; font-size: 18px; }

.player-bar { display: flex; align-items: center; gap: 8px; padding: 8px 4px; min-height: 40px; font-weight: 600; font-size: 17px; }
.player-bar .dot { width: 10px; height: 10px; border-radius: 50%; background: #777; flex: none; }
.player-bar .dot.on { background: #4cd07d; box-shadow: 0 0 8px #4cd07d; }
.player-bar.turn .pname::after { content: "  \2022  to move"; color: #ffd84a; font-weight: 600; font-size: 14px; }
.player-bar .captured { margin-left: auto; display: flex; align-items: center; }
.player-bar .captured .pc { width: 20px; height: 20px; margin-left: -4px; background-size: contain; }
.player-bar .captured .adv { margin-left: 6px; font-size: 13px; color: #d9cdef; }

.board-wrap { position: relative; width: 100%; aspect-ratio: 1; }
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  touch-action: manipulation;
}
.sq { position: relative; background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.last::before, .sq.sel::before, .sq.check::before { content: ""; position: absolute; inset: 0; }
.sq.last::before { background: var(--last); }
.sq.sel::before { background: var(--sel); }
.sq.check::before { background: var(--check); }
.sq .pc { position: absolute; inset: 0; background-size: 100% 100%; z-index: 1; transition: transform .08s; }
.sq.sel .pc { transform: scale(1.08); }
/* Hints: color every square the selected piece can move to. */
.sq.target::after { content: ""; position: absolute; inset: 0; z-index: 0; background: var(--hint); box-shadow: inset 0 0 0 2px rgba(255,255,255,.35); }
.sq.target.capture::after { background: var(--hint-capture); }
.sq.check .pc { animation: pulse 1s ease-in-out 2; }
@keyframes pulse { 50% { transform: scale(1.12); } }
.coord { position: absolute; z-index: 3; font-size: 11px; font-weight: 700; pointer-events: none; }
.coord.file { right: 3px; bottom: 1px; }
.coord.rank { left: 3px; top: 1px; }
.sq .coord { color: var(--dark); }
.sq.dark .coord { color: var(--light); }

.promo {
  position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: rgba(20, 12, 34, 0.7); border-radius: 10px;
}
.promo button { width: 22%; aspect-ratio: 1; border: 0; border-radius: 14px; background-color: #fff; background-size: 85%; background-position: center; background-repeat: no-repeat; }

.status { text-align: center; font-size: 18px; font-weight: 700; margin: 10px 0; min-height: 24px; }
.status.win { color: #ffd84a; font-size: 22px; }
.status.check { color: #ff5a5a; font-size: 22px; }

.hint-toggle { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 6px 0 10px; font-weight: 600; color: #d9cdef; cursor: pointer; }
.hint-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.hint-toggle .switch { width: 50px; height: 30px; border-radius: 999px; background: rgba(255,255,255,.2); position: relative; transition: background .15s; }
.hint-toggle .switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; }
.hint-toggle input:checked + .switch { background: #4cd07d; }
.hint-toggle input:checked + .switch::after { transform: translateX(20px); }

.chat { background: #fff; color: var(--ink); border-radius: var(--radius); padding: 12px; margin: 14px 0; }
.chat-head { font-weight: 700; margin-bottom: 8px; display: flex; align-items: baseline; gap: 8px; }
.chat-note { font-weight: 500; font-size: 12px; color: var(--muted); }
.chat-log { max-height: 240px; min-height: 60px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px 2px; -webkit-user-select: text; user-select: text; }
.chat-empty { color: var(--muted); font-size: 14px; text-align: center; margin: auto; }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 16px; background: #f1edf7; align-self: flex-start; word-wrap: break-word; overflow-wrap: anywhere; font-size: 16px; line-height: 1.3; }
.msg.mine { align-self: flex-end; background: var(--accent); color: #fff; }
.msg .who { display: block; font-size: 11px; font-weight: 700; opacity: .7; margin-bottom: 2px; }
.chat-form { display: flex; gap: 8px; margin-top: 8px; }
.chat-form input { flex: 1; min-width: 0; font-size: 16px; padding: 10px 12px; border: 2px solid #e2dcec; border-radius: 12px; outline: none; -webkit-user-select: text; user-select: text; }
.chat-form input:focus { border-color: var(--dark); }

.offer { background: #fff; color: var(--ink); border-radius: var(--radius); padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; font-weight: 600; }
.offer-btns { display: flex; gap: 8px; }
.offer .btn { background: #f1edf7; color: var(--ink); }
.offer .btn.primary { background: var(--accent); color: #fff; }

.notify { background: rgba(255,255,255,.1); border-radius: var(--radius); padding: 14px; text-align: center; margin: 10px 0; }
.notify p { margin: 0 0 10px; line-height: 1.4; }
.notify.info .btn { display: none; }

.invite { background: rgba(255,255,255,.1); border-radius: var(--radius); padding: 14px; text-align: center; margin: 10px 0; }
.invite p { margin: 0 0 10px; }

.actions { display: flex; gap: 8px; margin: 10px 0; }
.actions .btn { flex: 1; }

.moves { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 0 0 0 28px; margin: 14px 0 0; color: #d9cdef; font-size: 15px; }
.moves li { min-width: 110px; }
.moves li::marker { color: #9d90b6; }
.moves span { display: inline-block; min-width: 50px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #fff; color: var(--ink); padding: 12px 18px; border-radius: 999px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,.35); z-index: 100; max-width: 90vw; text-align: center;
}

@media (min-height: 800px) {
  .screen { padding-top: 24px; }
}
