/* Shogi. Everything is sized from one number, --sg-c (the width of a board square in px), which game.js sets from the
   room it has; --sg-h is the width of a piece in the hand trays. */
.sg { --sg-c: 38px; --sg-h: 44px; max-width: 880px; margin: 0 auto; padding: 10px 8px 16px; color: #dfe9ff; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; position: relative; box-sizing: border-box; }
.sg *, .sg *::before, .sg *::after { box-sizing: border-box; }
.sg [hidden] { display: none !important; }
.sg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---- controls ---- */
.sg-top { display: flex; flex-flow: row wrap; gap: 8px 12px; align-items: flex-end; margin-bottom: 10px; }
.sg-opts { display: contents; }
.sg .rg-modes { max-width: 600px; flex: 1 1 520px; }
.sg-picks { display: flex; gap: 8px; flex: 0 1 auto; min-width: 0; align-items: center; }
.sg-pick { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 0 1 auto; font-size: 11px; color: #8aa3c4; font-weight: 600; letter-spacing: .02em; }
.sg-pick select { background: #0b1328; color: #dfe9ff; border: 1px solid #1c2b4a; border-radius: 6px; padding: 5px 6px; font: inherit; font-size: 13px; font-weight: 600; max-width: 100%; min-width: 0; }
.sg-pick select:hover { border-color: #55d6ff; }
.sg-tools { display: flex; gap: 6px; align-items: center; flex: 1 1 380px; min-width: 0; }
.sg-gap { flex: 1 1 auto; }
.sg-btn { background: #0b1328; color: #dfe9ff; border: 1px solid #1c2b4a; border-radius: 8px; padding: 7px 12px; font: inherit; font-weight: 700; font-size: 13px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.sg-btn:hover:not(:disabled) { border-color: #55d6ff; }
.sg-btn:disabled { opacity: .4; cursor: default; }
.sg-btn.sg-primary { background: #ffd166; color: #1a1200; border-color: #ffd166; }
.sg-btn.sg-primary:hover:not(:disabled) { background: #ffdc85; border-color: #ffdc85; }
.sg-icon { width: 38px; padding: 0; height: 34px; flex: 0 0 auto; }
.sg-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
#sg-sound[aria-pressed="false"] .sg-on, #sg-sound[aria-pressed="true"] .sg-off { display: none; }
#sg-sound[aria-pressed="false"] { color: #8aa3c4; }
.sg-setbtn span { display: block; width: 22px; height: 25px; }
.sg-setbtn .sg-piece { width: 100%; height: 100%; stroke: none; fill: initial; stroke-width: initial; }
.sg-narrow { display: none; }
.sg :focus-visible { outline: 2px solid #55d6ff; outline-offset: 2px; }

/* ---- board and trays ---- */
.sg-main { display: grid; grid-template-columns: auto 240px; justify-content: center; gap: 20px; align-items: start; }
.sg-boardwrap { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.sg-frame { display: grid; grid-template-columns: calc(var(--sg-c) * .16) auto calc(var(--sg-c) * .46); grid-template-rows: calc(var(--sg-c) * .46) auto calc(var(--sg-c) * .16); background: linear-gradient(160deg, #b88748, #9a6a31); border: 2px solid #5b3a17; border-radius: 7px; box-shadow: 0 6px 18px rgba(0, 0, 0, .45); flex: 0 0 auto; }
.sg-files { grid-column: 2; grid-row: 1; display: grid; grid-template-columns: repeat(9, 1fr); align-items: center; padding: 0 1.5px; }
.sg-ranks { grid-column: 3; grid-row: 2; display: grid; grid-template-rows: repeat(9, 1fr); align-items: center; padding: 1.5px 0; }
.sg-files span, .sg-ranks span { text-align: center; font-size: calc(var(--sg-c) * .29); font-weight: 700; color: #3a2409; line-height: 1; }
.sg-board { grid-column: 2; grid-row: 2; display: grid; grid-template-columns: repeat(9, var(--sg-c)); grid-auto-rows: calc(var(--sg-c) * 1.1); gap: 1px; background: #54350f; border: 1.5px solid #3f2709; touch-action: none; outline: none; }
.sg-sq { position: relative; background: #e0b168; cursor: pointer; outline: none; }
.sg-sq.sg-star::after { content: ""; position: absolute; right: -3.5px; bottom: -3.5px; width: 6px; height: 6px; border-radius: 50%; background: #3f2709; z-index: 2; pointer-events: none; }
.sg-sq.sg-last { background: #f0d67c; }
.sg-sq.sg-sel { background: #a9dccb; }
.sg-sq.sg-check { background: radial-gradient(circle at 50% 50%, rgba(255, 60, 70, .95) 0%, rgba(255, 70, 80, .6) 45%, #e0b168 78%); }
.sg-sq.sg-hint { box-shadow: inset 0 0 0 3px #6a35ff; animation: sg-pulse 1.1s ease-in-out infinite; z-index: 1; }
.sg-sq:focus-visible { box-shadow: inset 0 0 0 3px #55d6ff, inset 0 0 0 5px #06223a; outline: none; z-index: 1; }
.sg-sq .sg-piece, .sg-hp .sg-piece { position: absolute; left: 4%; top: 2.5%; width: 92%; height: 95%; pointer-events: none; filter: drop-shadow(0 1px 1px rgba(40, 20, 0, .45)); }
.sg-sq.sg-drag .sg-piece, .sg-hp.sg-drag .sg-piece { opacity: .25; }
.sg-dot { position: absolute; left: 50%; top: 50%; width: 28%; aspect-ratio: 1; border-radius: 50%; transform: translate(-50%, -50%); background: rgba(12, 44, 60, .42); pointer-events: none; z-index: 3; }
.sg-ring { position: absolute; inset: 4%; border: 3px solid rgba(8, 70, 96, .7); border-radius: 12%; pointer-events: none; z-index: 3; }
.sg-shake { animation: sg-shake .3s linear; }
.sg-ghost { position: fixed; z-index: 90; pointer-events: none; transform: translate(-50%, -58%) scale(1.15); filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .5)); }
.sg-ghost .sg-piece { width: 100%; height: 100%; display: block; }

.sg-hand { width: calc(var(--sg-c) * 9.62 + 15px); max-width: 100%; height: calc(var(--sg-h) * 1.1 + 12px); display: flex; align-items: center; gap: 6px; padding: 0 8px; background: #0b1328; border: 1px solid #1c2b4a; border-radius: 10px; flex: 0 0 auto; touch-action: none; transition: border-color .2s; }
.sg-hand.sg-turn { border-color: #55d6ff; }
.sg-who { flex: 0 0 auto; width: 6.5em; font-size: 12px; line-height: 1.25; color: #8aa3c4; font-weight: 600; overflow: hidden; }
.sg-who b { display: block; color: #dfe9ff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sg-hand.sg-turn .sg-who b { color: #fff; }
.sg-held { display: flex; align-items: center; gap: 1px; flex: 1 1 auto; min-width: 0; height: 100%; }
.sg-held:empty::before { content: "No pieces in hand"; color: #5d7396; font-size: 12px; }
.sg-hp { position: relative; flex: 0 1 var(--sg-h); width: var(--sg-h); min-width: 0; height: calc(var(--sg-h) * 1.1); background: none; border: 0; padding: 0; border-radius: 8px; cursor: pointer; font: inherit; }
.sg-hp:disabled { cursor: default; }
.sg-hp.sg-sel { background: rgba(85, 214, 255, .22); box-shadow: inset 0 0 0 2px #55d6ff; }
.sg-hp.sg-hint { box-shadow: inset 0 0 0 3px #a98bff; animation: sg-pulse 1.1s ease-in-out infinite; }
.sg-ct { position: absolute; right: 0; bottom: 0; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: #04060f; color: #ffd166; border: 1px solid #2a3d63; font-size: 11px; font-weight: 800; line-height: 15px; text-align: center; pointer-events: none; }

.sg-promo { position: absolute; z-index: 20; display: flex; gap: 8px; padding: 8px; background: #0b1328; border: 1px solid #55d6ff; border-radius: 12px; box-shadow: 0 10px 28px rgba(0, 0, 0, .65); animation: sg-pop .14s ease-out; }
.sg-promo-b { width: 76px; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 4px 6px; background: #101c3a; color: #dfe9ff; border: 1px solid #2a3d63; border-radius: 9px; font: inherit; font-size: 12px; cursor: pointer; }
.sg-promo-b:hover { border-color: #55d6ff; }
.sg-promo-p { display: block; width: 46px; height: 51px; }
.sg-promo-p .sg-piece { width: 100%; height: 100%; display: block; }

/* ---- side panel ---- */
.sg-side { background: #0b1328; border: 1px solid #1c2b4a; border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.sg-status { font-size: 15px; font-weight: 700; color: #fff; line-height: 1.3; min-height: 1.3em; }
.sg-think { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #55d6ff; margin-right: 7px; animation: sg-blink 1s ease-in-out infinite; vertical-align: 1px; }
.sg-note { font-size: 13px; line-height: 1.3; min-height: 1.3em; color: #ffd166; font-weight: 600; }
.sg-note.sg-good { color: #7be3a4; }
.sg-declare { border-color: #ffd166; color: #ffd166; white-space: normal; }
.sg-moves { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 1px 4px; align-content: start; max-height: 320px; min-height: 44px; overflow-y: auto; font-size: 13px; font-variant-numeric: tabular-nums; scrollbar-width: thin; }
.sg-moves li { display: flex; align-items: center; gap: 4px; padding: 2px 4px; border-radius: 4px; white-space: nowrap; }
.sg-moves li.sg-cur { background: #1c2b4a; }
.sg-moves .sg-num { color: #5d7396; min-width: 1.6em; text-align: right; font-size: 11px; }
.sg-moves:empty::before { content: "Moves appear here."; color: #5d7396; grid-column: 1 / -1; padding: 2px 4px; }
.sg-mk { width: 9px; height: 10px; flex: 0 0 auto; }
.sg-record { font-size: 12px; color: #8aa3c4; line-height: 1.4; }
.sg-puz-h { font-size: 13px; color: #8aa3c4; line-height: 1.4; margin-bottom: 8px; }
.sg-plist { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; }
.sg-pbtn { min-height: 40px; background: #101c3a; color: #dfe9ff; border: 1px solid #1c2b4a; border-radius: 8px; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.sg-pbtn:hover { border-color: #55d6ff; }
.sg-pbtn.sg-done { color: #7be3a4; border-color: #2c6a4a; }
.sg-pbtn.sg-on { border-color: #55d6ff; background: #14315a; }

/* ---- dialogs ---- */
.sg-overlay { position: fixed; inset: 0; background: rgba(2, 5, 14, .78); display: flex; align-items: center; justify-content: center; padding: 14px; z-index: 50; }
.sg-dialog { background: #0b1328; border: 1px solid #244b6b; border-radius: 12px; padding: 22px; width: min(100%, 380px); text-align: center; animation: sg-pop .2s ease-out; }
.sg-dialog h3 { margin: 0 0 8px; font-size: 22px; color: #fff; }
.sg-dialog p { margin: 0 0 10px; color: #c6d4ee; font-size: 14px; line-height: 1.45; }
.sg-over-rec { color: #8aa3c4 !important; font-size: 13px !important; }
.sg-dialog-btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.sg-dialog-btns .sg-btn { padding: 10px 16px; font-size: 14px; }
.sg-helpbox { width: min(100%, 540px); max-height: 100%; overflow-y: auto; text-align: left; padding: 16px 18px 18px; }
.sg-help-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.sg-help-head h3 { margin: 0; font-size: 19px; }
.sg-tabs { display: flex; gap: 4px; background: #060b1a; border: 1px solid #1c2b4a; border-radius: 9px; padding: 3px; margin-bottom: 12px; }
.sg-tab { flex: 1 1 0; min-height: 36px; background: none; border: 0; border-radius: 7px; color: #8aa3c4; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.sg-tab[aria-selected="true"] { background: #1c2b4a; color: #fff; }
.sg-lead { font-size: 13px !important; color: #8aa3c4 !important; }
.sg-pp { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin-bottom: 12px; }
.sg-ppb { position: relative; aspect-ratio: 10 / 11; min-height: 44px; background: #101c3a; border: 1px solid #1c2b4a; border-radius: 8px; padding: 0; cursor: pointer; }
.sg-ppb .sg-piece { position: absolute; inset: 6% 9%; width: 82%; height: 88%; }
.sg-ppb[aria-pressed="true"] { border-color: #55d6ff; background: #14315a; }
.sg-demo { display: flex; gap: 14px; align-items: flex-start; }
.sg-mini { flex: 0 0 auto; display: grid; grid-template-columns: repeat(7, 30px); grid-auto-rows: 33px; gap: 1px; background: #54350f; border: 1.5px solid #3f2709; border-radius: 3px; }
.sg-mini i { position: relative; background: #e0b168; display: block; font-style: normal; }
.sg-mini i.sg-go::after { content: ""; position: absolute; left: 50%; top: 50%; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%; background: #0e4c66; }
.sg-mini i.sg-run { background: #cfe0b4; }
.sg-mini i.sg-run::after { content: ""; position: absolute; left: 50%; top: 50%; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%; background: #0e4c66; }
.sg-mini .sg-piece { position: absolute; left: 4%; top: 2.5%; width: 92%; height: 95%; }
.sg-demo-t h4 { margin: 0 0 4px; font-size: 16px; color: #fff; }
.sg-demo-t h4 small { font-weight: 600; color: #8aa3c4; font-size: 12px; margin-left: 6px; }
.sg-demo-t p { font-size: 13.5px; margin: 0; }
.sg-rules { margin: 0; padding: 0 0 0 18px; display: flex; flex-direction: column; gap: 8px; font-size: 13.5px; line-height: 1.45; color: #c6d4ee; }
.sg-rules b { color: #fff; }

/* ---- stacked layout: phones, and any tall full-screen window ---- */
.sg-stack .sg-main { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.sg-stack .sg-side { display: contents; }
.sg-stack .sg-status { order: -3; font-size: 14px; }
.sg-stack .sg-note { order: -2; margin-top: -4px; }
.sg-stack .sg-boardwrap { order: -1; }
.sg-stack .sg-moves { display: flex; gap: 2px; overflow-x: auto; overflow-y: hidden; max-height: none; min-height: 26px; flex: 0 0 auto; background: #0b1328; border: 1px solid #1c2b4a; border-radius: 8px; padding: 3px 6px; scrollbar-width: none; }
.sg-stack .sg-moves::-webkit-scrollbar { display: none; }
.sg-stack .sg-moves li { flex: 0 0 auto; }
.sg-stack .sg-puz { background: #0b1328; border: 1px solid #1c2b4a; border-radius: 10px; padding: 10px; }
.sg-stack .sg-record { text-align: center; }
.sg-stack .sg-picks, .sg-land .sg-picks, .sg-stack .sg-tools, .sg-land .sg-tools { flex-basis: 100%; }
.sg-stack .sg-picks:not(:has(.sg-pick:not([hidden]))), .sg-land .sg-picks:not(:has(.sg-pick:not([hidden]))) { display: none; }
.sg-stack .sg-pick, .sg-land .sg-pick { flex: 1 1 0; }
.sg-stack .sg-pick select, .sg-land .sg-pick select { width: 100%; }
.sg-tight .sg-wide { display: none; }
.sg-tight .sg-narrow { display: inline; }
.sg-tight .sg-btn:not(.sg-icon) { padding: 7px 8px; }
.sg-tight .sg-tools { gap: 4px; }
.sg-tight .sg-icon { width: 36px; }
.sg-tight .sg-demo { flex-direction: column; align-items: center; }
.sg-tight .sg-mini { grid-template-columns: repeat(7, 38px); grid-auto-rows: 41.8px; }
.sg-tight .sg-demo-t { align-self: stretch; }

/* ---- full screen: the board takes whatever height is left ---- */
.sg.sg-fit { max-width: none; width: 100%; height: 100%; display: flex; flex-direction: column; padding: 8px; overflow: hidden; }
.sg.sg-fit .sg-top { flex: 0 0 auto; margin-bottom: 8px; }
.sg.sg-fit .sg-main { flex: 1 1 0; min-height: 0; }
.sg.sg-fit.sg-stack { overflow-y: auto; }
.sg.sg-fit.sg-stack .sg-main { flex: 0 0 auto; }
.sg.sg-fit.sg-stack .sg-boardwrap { flex: 0 0 auto; align-items: center; }
/* wide full screen: trays stand at the sides of the board, the controls and the move list sit in a column on the right */
.sg.sg-land { display: grid; grid-template-columns: auto var(--sg-side, 320px); grid-template-rows: auto minmax(0, 1fr); gap: 8px 12px; justify-content: center; }
.sg.sg-land .sg-main { display: contents; }
.sg.sg-land .sg-boardwrap { grid-column: 1; grid-row: 1 / 3; flex-direction: row; align-items: center; justify-content: center; }
.sg.sg-land .sg-top { grid-column: 2; grid-row: 1; margin: 0; }
.sg.sg-land .sg-side { grid-column: 2; grid-row: 2; overflow-y: auto; min-height: 0; align-self: stretch; }
.sg.sg-land .sg-moves { flex: 1 1 60px; max-height: none; min-height: 60px; }
.sg.sg-land .sg-hand { flex-direction: column; width: calc(var(--sg-h) + 14px); height: calc(var(--sg-c) * 10.52 + 15px); padding: 6px 0; }
.sg.sg-land .sg-who { width: auto; max-width: 100%; text-align: center; font-size: 10px; }
.sg.sg-land .sg-who b { font-size: 11px; }
.sg.sg-land .sg-held { flex-direction: column; width: 100%; height: auto; flex: 1 1 0; min-height: 0; justify-content: flex-start; align-items: center; }
.sg.sg-land .sg-hp { flex: 0 1 calc(var(--sg-h) * 1.1); width: var(--sg-h); height: auto; min-height: 0; }
.sg.sg-land .sg-held:empty::before { content: "\2013"; }

@media (pointer: coarse) {
  .sg-btn, .sg-pick select { min-height: 40px; }
  .sg-icon { height: 40px; width: 40px; }
  .sg-tight .sg-icon { width: 38px; }
}
@keyframes sg-pulse { 50% { box-shadow: inset 0 0 0 3px rgba(106, 53, 255, .25); } }
@keyframes sg-blink { 50% { opacity: .25; } }
@keyframes sg-pop { from { transform: scale(.92); opacity: 0; } }
@keyframes sg-shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
@media (prefers-reduced-motion: reduce) {
  .sg *, .sg *::before, .sg *::after { animation: none !important; transition: none !important; }
}

/* ---- small extras ---- */
.sg-sq.sg-over { box-shadow: inset 0 0 0 3px rgba(85, 214, 255, .9); }
.sg-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.sg-modes { display: inline-flex; gap: 4px; background: #0b1328; border: 1px solid #1c2b4a; border-radius: 10px; padding: 3px; }
.sg-modebtn { font: inherit; font-size: 13px; font-weight: 700; color: #8aa3c4; background: none; border: 0; border-radius: 7px; padding: 7px 12px; min-height: 36px; cursor: pointer; }
.sg-modebtn[aria-pressed="true"] { background: #16264a; color: #fff; }
.sg-modebtn:focus-visible { outline: 2px solid #55d6ff; outline-offset: 1px; }
.sg.ol-on .sg-picks { display: none; }
.sg .rg-mode { padding: 5px 6px; gap: 6px; }
.sg .rg-mode-pre { display: none; }
.sg-touchdrag .sg-ghost { transform: translate(-50%, -58%) scale(1.5); }
.sg-touchdrag .sg-sq.sg-over { z-index: 3; }
.sg-touchdrag .sg-sq.sg-over::before { content: ""; position: absolute; left: 50%; top: 50%; width: 230%; height: 230%; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(85, 214, 255, .2); border: 2px solid rgba(85, 214, 255, .65); pointer-events: none; }
.sg-stack:not(.sg-fit) { padding-left: 0; padding-right: 0; }
.sg.sg-fit.sg-stack { padding: 8px 4px; }
@container (max-width: 500px) { .sg .rg-mode { flex-direction: column; gap: 2px; padding: 4px 2px; font-size: 12px; } .sg .rg-mode svg { width: 18px; height: 18px; } }
.sg.sg-land .sg-who b { font-size: clamp(9px, calc(var(--sg-h) * .2), 11px); letter-spacing: -.03em; text-overflow: clip; }
.sg-tight .sg-pick select { font-size: 12px; padding: 5px 1px 5px 3px; }
.sg-land.sg-tight .sg-demo { flex-direction: row; align-items: flex-start; }
.sg-land.sg-tight .sg-mini { grid-template-columns: repeat(7, 30px); grid-auto-rows: 33px; }
.sg-land.sg-tight .sg-pp { grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 3px; }
.sg-land.sg-tight .sg-ppb { min-height: 0; }
.sg-xs .sg-tools { flex-wrap: wrap; }
.sg-xs .sg-gap { flex-basis: 100%; height: 0; }
.sg-xs .sg-tools .sg-btn:not(.sg-icon) { flex: 1 1 auto; }
.sg-xs .sg-tools .sg-icon { flex: 1 1 0; }
.sg-land.sg-tight .sg-pick:has(#sg-level) { flex-grow: 1.1; }
.sg-land.sg-tight .sg-pick:has(#sg-side) { flex-grow: .75; }
.sg.sg-land.sg-xs .rg-mode { font-size: 11px; letter-spacing: -.02em; padding: 4px 0; }
