:root {
  color-scheme: dark;
  font: 16px/1.45 Inter, "Segoe UI", system-ui, sans-serif;
  --text: #f1efff; --muted: #aaa5d8; --line: #322c74; --accent: #47e5ff;
  --blue: #3d7bff; --violet: #9b4dff; --glass: #17143a; --deep: #07061a;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; color: var(--text); background:
  radial-gradient(900px 520px at 85% -8%, #2d1c74 0%, transparent 62%),
  radial-gradient(760px 480px at -12% 108%, #12357a 0%, transparent 58%), var(--deep); }
body::before { content:""; position:fixed; inset:0; pointer-events:none; opacity:.5;
  background-image:radial-gradient(1.2px 1.2px at 12% 18%,#fff 50%,transparent 51%),
  radial-gradient(1px 1px at 31% 62%,#cfd6ff 50%,transparent 51%),
  radial-gradient(1.4px 1.4px at 58% 9%,#fff 50%,transparent 51%),
  radial-gradient(1px 1px at 74% 41%,#e6dcff 50%,transparent 51%),
  radial-gradient(1.2px 1.2px at 89% 77%,#fff 50%,transparent 51%);
  background-size:310px 258px; }
main,.masthead { position:relative; }
button, input { font: inherit; }
button { cursor: pointer; color: inherit; }
button:disabled { cursor: default; opacity: .58; }
button:focus-visible, input:focus-visible { outline: 3px solid #f9daa4; outline-offset: 3px; }
.masthead { display: flex; align-items: center; gap: 22px; border-bottom: 1px solid var(--line);
  padding: 8px max(5vw, calc((100vw - 1050px) / 2)); background: #080617c9; min-height: 64px; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 23px; font-weight: 500; letter-spacing: -.07em; }
.brand img { object-fit: contain; margin-left: -8px; filter:drop-shadow(0 0 10px #9b4dff60); }
.brand strong { font-weight: 740; }
.edition { color: var(--accent); border-left: 1px solid #454352; padding-left: 20px; font-size: 13px; letter-spacing: .035em; }
#back-game { color: var(--muted); font-size: 13px; margin-left:auto; text-underline-offset:.2em; }
main { max-width: 1120px; margin: 0 auto; padding: 26px clamp(16px, 4.6vw, 44px) 34px; }
.title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; }
h1,h2,h3,p { margin: 0; }
h1 { font-size:clamp(30px,4.3vw,47px); font-weight:780; line-height:1.13; letter-spacing:-.046em;
  background:linear-gradient(90deg,#7fb0ff,#c79bff); background-clip:text; -webkit-background-clip:text; color:transparent; }
#lead { margin-top: 5px; color: var(--muted); font-size: 15px; }
.network { display: inline-flex; align-items: center; gap: 8px; color: #a4eeff; background: #0c1c32; border: 1px solid #255079; padding: 5px 12px; border-radius: 100px; font-size: 13px; white-space: nowrap; }
.network i { background:var(--accent); box-shadow:0 0 8px #47e5ffaa; width: 6px; height: 6px; border-radius: 50%; }
.network.down { color: #f0d39a; background: #393026; border-color: #65513b; }
.network.down i { background: #efc982; }
.layout { display: grid; grid-template-columns: minmax(320px, 1.63fr) minmax(245px, .83fr); gap: clamp(20px, 3.5vw, 43px); align-items: start; }
.play-area { width: 100%; max-width: min(100%, 640px); }
.seatline { min-height: 29px; padding: 0 2px 5px; display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.seatline > :first-child { color: var(--text); font-weight: 650; }
.seatline.local { padding: 7px 2px 0; }
.piece-styles { border:0; padding:0; margin:12px 0 0; min-width:0; }
.piece-styles legend { float:left; padding:0 14px 0 2px; line-height:44px; font-size:13px; color:var(--muted); }
.style-options { display:inline-flex; background:#14112f; border:1px solid var(--line); border-radius:10px; padding:2px; }
.style-options label { position:relative; margin:0; }
.style-options input { position:absolute; opacity:0; width:1px; height:1px; padding:0; }
.style-options span { display:grid; place-items:center; min-height:40px; min-width:78px; padding:4px 12px; border-radius:7px; color:var(--muted); cursor:pointer; }
.style-options input:checked + span { color:#f7f4ff; background:#42377f; box-shadow:inset 0 0 0 1px #7565b7; }
.style-options input:focus-visible + span { outline:2px solid #f9daa4; outline-offset:-2px; }
.board { isolation: isolate; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); aspect-ratio: 1; overflow: hidden; border-radius: 10px; outline: 2px solid #2a2466; box-shadow: 0 12px 30px #0008; }
.square { position: relative; display: grid; place-items: center; border: 0; padding: 0; margin: 0; min-width: 0; min-height: 0; user-select: none; -webkit-tap-highlight-color: transparent; }
.light { background: #cfc8f2; color: #514a76; }
.dark { background: #6a5acd; color: #e6e0f4; }
.square .pc { width: 97%; height: 97%; object-fit: contain; position: absolute; z-index: 2; pointer-events: none; }
.coord { position: absolute; font-size: clamp(8px,1.1vw,11px); line-height: 1; font-weight: 650; z-index: 3; pointer-events: none; opacity: .86; }
.rank { top: 3px; left: 3px; } .file { bottom: 3px; right: 3px; }
.last { background-image: linear-gradient(#e7b97a47,#e7b97a47); }
.selected { background-image: radial-gradient(ellipse at 50% 82%, #98f8ffc2, transparent 55%),linear-gradient(#442e8a6e,#442e8a6e); box-shadow:inset 0 0 0 2px #adf4ff,inset 0 0 12px #a87bfaad; }
.selected .pc { filter: drop-shadow(0 0 2px #dcffff) drop-shadow(0 0 4px #72bbffcc); animation: glint .45s ease-out; }
.dest::after { content: ""; position: absolute; width: 27%; aspect-ratio: 1; border-radius: 50%; background: #3f355a66; z-index: 3; }
.capture::after { width: 82%; background: transparent; border: 3px solid #e5c883; }
.checked { box-shadow: inset 0 0 0 4px #af3053; }
.square:focus-visible { outline-offset: -3px; z-index: 4; }
@keyframes glint { from { filter: brightness(1.38) drop-shadow(0 0 8px #ffeeda); } }
.panel { border: 1px solid var(--line); background: linear-gradient(145deg,#221d55,#17143a 66%); box-shadow: 0 12px 32px #07071170; border-radius: 15px; padding: clamp(18px, 2.6vw, 28px); margin-top: 29px; }
h2 { font-size: 21px; letter-spacing: -.035em; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
.primary,.secondary { width: 100%; min-height: 46px; border-radius: 14px; padding: 8px 13px; font-weight: 700; font-size: 15px; }
.primary { background:linear-gradient(90deg,var(--blue),var(--violet)); color:white; border:0; box-shadow:0 8px 22px #5046e659; margin-top: 17px; }
.secondary { border: 1px solid #514698; background:var(--glass); margin-top: 9px; }
.secondary:hover,.primary:hover { filter: brightness(1.08); }
form,.moves { padding-top: 18px; margin-top: 22px; border-top: 1px solid #444157; }
label { display: block; font-weight: 550; font-size: 13px; margin-bottom: 6px; color: #e0dce9; }
input { display: block; width: 100%; min-width: 0; background: #151527; border: 1px solid #504d68; border-radius: 7px; color: var(--text); font-family: ui-monospace, Consolas, monospace; padding: 9px; font-size: 14px; }
#share { margin-top: 18px; }
.match-title { display: flex; gap: 11px; align-items: center; }
.accent-line { width: 3px; min-height: 23px; border-radius: 2px; background: var(--accent); }
#role,#no-moves { color: var(--muted); font-size: 14px; margin-top: 6px; }
#history { list-style:none; padding: 0; margin: 8px 0 0; max-height: 37vh; overflow: auto; }
#history li { display: grid; grid-template-columns: 1.8em 1fr 1fr; border-bottom: 1px solid #39374c; padding: 5px 0; font-size: 15px; font-variant-numeric: tabular-nums; }
#history li span:first-child { color:#a6a0b7; font-size:13px; align-self:center; }
#notice { color: #f3d69b; font-size: 14px; margin-top: 15px; }
.link { background: transparent; border: 0; text-decoration: underline; text-underline-offset: .2em; color: var(--muted); padding: 8px 0; }
dialog { max-width: min(92vw, 410px); border: 1px solid var(--line); color: var(--text); background: var(--glass); border-radius: 12px; padding: 20px; }
dialog::backdrop { background: #121223aa; }
#choices {display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px;margin-top:12px}
#choices button {min-width:0;display:grid;justify-items:center;align-content:start;color:white;border:1px solid var(--line);border-radius:8px;background:#49415e;padding:4px;overflow-wrap:anywhere}
#choices .pc { display:block; width:min(16vw,62px); height:auto; aspect-ratio:1; }
@media (max-width: 710px){
  .masthead { min-height: 52px; padding: 5px 17px; } main { padding: 15px 14px 24px; }
  .layout { grid-template-columns:1fr; gap:14px; } .panel { margin:0; }
  .title-row { margin-bottom:10px; } .network { font-size:11px; padding:4px 8px; }
  .play-area { margin:auto; } #lead { font-size:13px; }
}
@media (prefers-reduced-motion: reduce) { .selected .pc { animation:none; } }

.confirm-moves {display:flex;align-items:center;gap:.5rem;margin-top:.7rem;}.confirm-moves input {width:auto;}

.board, #history, #invite, #share-code, #creator-code {direction:ltr;unicode-bidi:isolate;}
#history li span, .coord {unicode-bidi:isolate;}

.title-row, .masthead, .style-options { flex-wrap:wrap; }
.title-row > *, .play-area, .panel, .match-title h2, .network span, .seatline > * { min-width:0; }
.network, .style-options span, .masthead > :not(.brand), button, h1, h2, label, .panel p, .seatline {
  overflow-wrap:anywhere;
}
.network { max-width:100%; white-space:normal; }
.network i { flex:0 0 6px; }
.style-options {max-width:100%;}
.style-options label {min-width:0;max-width:100%;}
.style-options span {min-width:min(78px,100%);}
#back-game { margin-left:0; margin-inline-start:auto; }
dialog {max-height:85dvh;overflow:auto;}
#action-dialog button {max-width:100%;}
@media(max-width:710px) {
  .layout {grid-template-columns:minmax(0,1fr);}
  .masthead {column-gap:.8rem;row-gap:.2rem;}
  .piece-styles legend {float:none;line-height:1.5;}
}
.square:focus-visible {outline:3px solid white;outline-offset:-4px;box-shadow:inset 0 0 0 6px #281645;z-index:3}
.board-announcement {position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
:root[data-motion="reduced"] *, :root[data-motion="reduced"] *::before, :root[data-motion="reduced"] *::after {animation:none!important;transition:none!important;scroll-behavior:auto!important}
:root[data-motion="full"] .selected .pc {animation:glint .45s ease-out}
.display-option {display:flex;align-items:center;justify-content:space-between;gap:8px;padding:6px 0}
.display-option select {max-width:65%;color:inherit;background:#241b40;border:1px solid #85799e;border-radius:6px;padding:.4em;font:inherit}
:where([data-theme="madera"]) .square.light {background-color:#f0d9b5}
:where([data-theme="madera"]) .square.dark {background-color:#b58863}
:where([data-theme="hielo"]) .square.light {background-color:#dfe9f5}
:where([data-theme="hielo"]) .square.dark {background-color:#6f93b8}
.ep-capture {outline: 3px dashed #8d52c7; outline-offset: -5px;}
