/* Match layout: board between the opponent's rack and a shared record/rack rail. */
:root {
  --shogi-piece-ratio:22 / 23
}
.match-only {
  display:none
}
.is-playing .match-only {
  display:inline-flex
}
.is-playing .app-header {
  display:flex;
  height:52px;
  padding:0 20px;
  gap:12px
}
.is-playing .brand {
  font-size:15px
}
.is-playing .brand-mark {
  width:26px;
  height:30px;
  font-size:19px
}
.is-playing #context-label {
  display:none
}
.is-playing #game-mode {
  display:block;
  min-width:0;
  max-width:min(42vw,560px);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap
}
.is-playing .header-actions {
  align-items:center
}
.is-playing .header-actions .round-chip {
  margin:0 18px 0 0;
  gap:8px
}
.is-playing #history-toggle[aria-pressed="false"] {
  opacity:.5
}
.game-screen {
  --rack-size:clamp(150px,12vw,216px);
  --right-size:clamp(240px,22vw,360px);
  --board-size:min(calc(100svh - 76px),calc(100vw - var(--rack-size) - var(--right-size) - 76px));
  width:calc(100% - 40px);
  max-width:calc(var(--board-size) + var(--rack-size) + var(--right-size) + 36px);
  padding:12px 0;
  margin-inline:auto
}
.arena {
  display:block
}
.local-controls {
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  gap:8px 14px;
  min-height:48px;
  margin-bottom:10px
}
.local-controls-label {
  color:var(--muted);
  font-size:11px
}
.local-sides {
  display:flex;
  gap:6px
}
.local-sides button {
  display:flex;
  align-items:center;
  gap:12px;
  min-height:40px;
  padding:7px 12px;
  border:1px solid var(--line);
  border-radius:5px;
  background:#ffffff04;
  font-size:12px
}
.local-sides button[aria-pressed="true"] {
  border-color:#c1a87888;
  background:#d9bb8215;
  color:var(--gold-light)
}
.local-sides button small {
  font-size:9px;
  color:var(--muted)
}
.local-sides button:disabled {
  opacity:.6
}
#local-status {
  margin:0 0 0 auto;
  color:var(--muted);
  font-size:11px
}
@media (min-width:1101px) {
  .game-screen.is-local {
    --board-size:min(calc(100svh - 134px),calc(100vw - var(--rack-size) - var(--right-size) - 76px))
  }
}
.playfield {
  display:grid;
  grid-template-columns:var(--rack-size) minmax(0,1fr) var(--right-size);
  align-items:start;
  gap:18px
}
.board-surround {
  min-width:0
}
#board .piece {
  aspect-ratio:var(--shogi-piece-ratio);
  height:auto
}
.side-rail {
  min-width:0
}
.test-controls {
  display:flex;
  flex-direction:column;
  gap:10px;
  margin-top:14px;
  padding:12px 10px;
  border:1px solid var(--line);
  border-radius:5px;
  background:#ffffff03
}
.test-heading,.test-hand-heading {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:6px
}
.test-heading strong {
  font-size:12px;
  font-weight:500
}
.test-heading>span,#test-hand-side {
  color:var(--muted);
  font-size:10px
}
.test-presets,.test-tools,.test-fields {
  display:grid;
  gap:6px
}
.test-tools,.test-fields {
  grid-template-columns:repeat(2,minmax(0,1fr));
  margin-bottom:10px
}
.test-controls .secondary,.test-controls .primary,.test-tools button {
  min-height:34px;
  padding:7px 3px;
  font-size:11px
}
.test-tools button,.test-palette button,.test-hand-row button {
  border:1px solid var(--line);
  border-radius:4px;
  background:#ffffff04
}
.test-controls [aria-pressed="true"] {
  border-color:#c1a87888;
  background:#d9bb8215;
  box-shadow:inset 0 0 0 1px #d9bb8222
}
.test-fields label,.test-label {
  color:var(--muted);
  font-size:10px
}
.test-fields select {
  width:100%;
  min-width:0;
  height:32px;
  padding:4px 1px;
  margin-top:5px;
  font-size:11px
}
.test-palette {
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:5px;
  margin:6px 0 12px
}
.test-palette button {
  min-height:34px;
  padding:3px;
  font-family:"Shogi Brush",var(--serif);
  font-size:21px
}
.test-hands {
  display:grid;
  gap:5px;
  margin-top:7px
}
#test-hand-editor summary {
  min-height:28px;
  cursor:pointer
}
#test-hand-editor summary:after {
  content:"＋";
  color:var(--muted)
}
#test-hand-editor[open] summary:after {
  content:"−"
}
.test-hand-row {
  display:grid;
  grid-template-columns:minmax(20px,1fr) 28px 28px 28px;
  align-items:center;
  gap:3px;
  font-size:12px
}
.test-hand-row button {
  min-height:26px;
  padding:0;
  font-size:14px
}
.test-hand-row output {
  text-align:center;
  color:var(--muted);
  font-size:11px;
  font-variant-numeric:tabular-nums
}
.test-hint {
  margin:0;
  color:var(--muted);
  font-size:10px;
  line-height:1.7
}
.game-screen.is-test .opponent-rack .hand-tray {
  min-height:100px;
  gap:8px 6px;
  padding-block:10px
}
.game-screen.is-test .opponent-rack .hand-empty {
  padding-top:10px
}
.is-editing #board .cell {
  cursor:crosshair
}
.is-editing #board .cell.occupied {
  cursor:grab;
  touch-action:none
}
.test-piece-menu {
  position:absolute;
  z-index:8;
  width:min(244px,calc(100% - 12px));
  padding:10px 12px 12px;
  border:1px solid #b79b6377;
  border-radius:7px;
  background:#242a26;
  box-shadow:0 8px 28px #0007;
  color:var(--text)
}
.test-piece-heading {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom:6px
}
.test-piece-heading strong {
  font-size:13px;
  font-weight:500
}
.test-piece-heading .icon-button {
  width:28px;
  height:28px;
  font-size:18px
}
.test-piece-menu fieldset {
  margin:0;
  padding:6px 0 0;
  border:0
}
.test-piece-menu fieldset+fieldset {
  margin-top:10px
}
.test-piece-menu legend {
  padding:0;
  color:var(--muted);
  font-size:10px
}
.test-piece-options {
  display:flex;
  gap:5px
}
.test-piece-options button {
  flex:1;
  min-height:36px;
  padding:7px 3px;
  border:1px solid var(--line);
  border-radius:4px;
  background:#ffffff04;
  font-size:11px
}
.test-piece-options [aria-pressed="true"] {
  border-color:#c1a87888;
  background:#d9bb8215;
  color:var(--gold-light)
}
.test-piece-options [data-editor-state="promote"] {
  color:var(--red)
}
.test-piece-options [data-editor-state="upgrade"] {
  color:var(--blue)
}
.is-dragging-piece,.is-dragging-piece * {
  cursor:grabbing !important
}
#board .editor-drag-source .piece {
  opacity:.22
}
#board .editor-drop-target {
  background:#52654355;
  box-shadow:inset 0 0 0 2px #526543cc
}
.test-drag-preview {
  position:fixed;
  z-index:50;
  translate:-50% -50%;
  pointer-events:none;
  container-type:inline-size;
  filter:drop-shadow(0 5px 5px #0005)
}
.test-drag-preview .piece {
  width:100%;
  height:auto;
  aspect-ratio:var(--shogi-piece-ratio)
}
.test-drag-preview .piece-symbol {
  font-size:78cqw
}
.test-drag-preview .rank-badge {
  font-size:12cqw
}
.test-drag-preview.will-delete {
  filter:drop-shadow(0 0 6px #e3626288)
}
.test-drag-label {
  position:absolute;
  top:calc(100% + 7px);
  left:50%;
  translate:-50% 0;
  padding:5px 8px;
  border:1px solid var(--line);
  border-radius:4px;
  background:#242a26;
  color:var(--text);
  font-size:11px;
  white-space:nowrap
}
.will-delete .test-drag-label {
  border-color:#db797977;
  color:#ffaaaa
}
.self-rail {
  display:flex;
  flex-direction:column;
  gap:14px;
  height:calc(var(--board-size) - 3px);
  min-height:0
}
.player-rack {
  flex:0 0 auto;
  min-width:0
}
.self-rack {
  margin-top:0
}
.player-strip {
  display:grid;
  grid-template-columns:28px minmax(0,1fr);
  grid-template-rows:auto auto;
  column-gap:7px;
  row-gap:4px;
  height:auto;
  min-height:64px;
  padding:4px 0 10px;
  align-items:center
}
.player-avatar {
  grid-row:1 / 3;
  width:28px;
  height:32px;
  font-size:20px
}
.player-name {
  max-width:100%;
  font-size:12px;
  line-height:1.5
}
.player-side {
  display:block;
  margin:0;
  font-size:9px
}
.player-status {
  grid-column:2;
  margin:0;
  font-size:9px
}
.hand-tray,.hand-tray.bottom {
  display:grid;
  grid-template-columns:repeat(3,minmax(0,1fr));
  align-content:start;
  justify-items:center;
  gap:12px 7px;
  height:auto;
  min-height:270px;
  overflow:visible;
  padding:16px 10px;
  border:1px solid #b799642b;
  border-radius:5px;
  background:repeating-linear-gradient(94deg,#b88e4c06 0 2px,transparent 3px 8px),linear-gradient(135deg,#443a2b77,#292b2677);
  box-shadow:inset 0 1px 0 #e4c7960c,0 3px 9px #0001
}
.hand-tray.bottom {
  grid-template-columns:repeat(4,minmax(0,1fr));
  min-height:252px;
  padding:16px 12px
}
.hand-label {
  grid-column:1 / -1;
  justify-self:start;
  margin:0 0 2px 4px;
  font-size:10px;
  color:#9c9e8d
}
.hand-empty {
  grid-column:1 / -1;
  padding-top:70px;
  font-size:10px;
  color:#778075
}
.hand-piece {
  display:grid;
  place-items:center;
  position:relative;
  width:100%;
  min-width:0;
  max-width:76px;
  min-height:44px;
  height:auto;
  padding:4px 4px 12px;
  border:0;
  border-radius:0;
  background:none;
  isolation:isolate;
  container-type:inline-size
}
.hand-piece .piece {
  width:100%;
  height:auto;
  aspect-ratio:var(--shogi-piece-ratio);
  transition:translate .16s,filter .16s
}
.hand-piece .piece-symbol {
  font-size:76cqw
}
.hand-piece .rank-badge {
  display:none
}
.hand-piece small {
  position:absolute;
  z-index:1;
  right:0;
  bottom:0;
  display:grid;
  place-items:center;
  min-width:19px;
  height:20px;
  margin:0;
  padding:0 4px;
  border-radius:10px;
  background:#292d27;
  border:1px solid #ab92644d;
  color:#eddbb6;
  font-size:11px;
  font-variant-numeric:tabular-nums
}
.hand-piece:disabled,.history-row:disabled {
  opacity:1
}
.history-row:disabled:hover {
  background:none
}
.hand-piece:enabled:hover,.hand-piece.selected {
  background:none;
  border:0
}
.hand-piece:enabled:hover .piece {
  translate:0 -3px;
  filter:drop-shadow(0 3px 3px #0008) brightness(1.12)
}
.hand-piece.selected .piece {
  translate:0 -4px;
  filter:drop-shadow(0 0 3px #e0c68e) drop-shadow(0 0 6px #e0c68e66)
}
.game-sidebar {
  flex:1 1 0;
  display:flex;
  flex-direction:column;
  min-height:0;
  max-height:none;
  margin:0;
  padding:0;
  overflow:hidden
}
.game-sidebar>.tab-bar {
  flex:0 0 auto;
  margin-bottom:8px
}
.game-sidebar .tab-bar>button {
  padding:13px 5px
}
#history-panel {
  display:flex;
  flex-direction:column;
  flex:1;
  min-height:0;
  overflow:hidden
}
.history-heading {
  flex:0 0 auto
}
.history-list {
  flex:1;
  max-height:none;
  min-height:0;
  overflow:auto
}
.last-event {
  flex:0 0 auto;
  max-height:58px;
  overflow:auto;
  margin-top:8px;
  padding:8px 10px;
  font-size:10px
}
#replay-panel {
  min-height:0;
  overflow:auto;
  scrollbar-width:thin
}
.match-controls {
  flex:0 0 auto;
  display:flex;
  flex-direction:column;
  position:relative;
  margin-top:auto
}
.input-status {
  min-height:0;
  padding:0;
  justify-content:flex-end
}
.input-status #input-hint:before {
  display:none
}
.input-status .text-button {
  min-height:30px
}
.match-controls .sidebar-bottom {
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  padding:0;
  margin:0
}
.match-controls .sidebar-bottom .full {
  width:100%;
  min-height:36px;
  font-size:11px
}
.match-controls .piece-key {
  margin:0;
  font-size:9px;
  gap:10px
}
.match-controls .resign-button {
  margin:0;
  min-height:32px
}
.connection-notice {
  position:fixed;
  top:58px;
  left:50%;
  transform:translateX(-50%);
  width:min(600px,calc(100% - 24px));
  z-index:10;
  background:#3b3528;
  box-shadow:0 4px 20px #0005
}
.is-playing .toast {
  top:60px
}
.choice-popover {
  width:min(228px,96%);
  left:clamp(114px,var(--choice-x,50%),calc(100% - 114px))
}
@media (min-width:1101px) and (max-height:700px) {
  .hand-tray.bottom {
    min-height:200px;
    padding-block:12px
  }
  .player-strip {
    min-height:48px
  }
}
@media (max-width:1100px) {
  .game-screen.is-test .playfield {
    grid-template-areas:"board" "self" "opponent" "editor" "history" "controls"
  }
  .test-controls {
    grid-area:editor;
    margin:0 3px;
    padding:12px;
    gap:10px
  }
  .test-presets {
    grid-template-columns:repeat(2,minmax(0,1fr))
  }
  .test-palette {
    grid-template-columns:repeat(8,minmax(0,1fr))
  }
  .test-hands {
    grid-template-columns:repeat(2,minmax(0,1fr));
    column-gap:20px
  }
  .game-screen.is-test .opponent-rack .hand-tray {
    min-height:84px
  }
  .game-screen.is-test .opponent-rack .hand-empty {
    padding-top:0
  }
  .local-controls {
    margin-inline:6px;
    gap:6px 10px
  }
  .local-sides button {
    gap:8px;
    padding-inline:10px
  }
  #local-status {
    width:100%;
    margin:0;
    font-size:10px
  }
  .game-screen {
    --board-size:100%;
    width:calc(100% - 12px);
    max-width:680px;
    padding:8px 0 18px
  }
  .playfield {
    grid-template-columns:minmax(0,1fr);
    grid-template-areas:"board" "self" "opponent" "history" "controls";
    gap:10px
  }
  .opponent-rail,.self-rail {
    display:contents
  }
  .board-surround {
    grid-area:board
  }
  .opponent-rack {
    grid-area:opponent
  }
  .self-rack {
    grid-area:self
  }
  .player-rack {
    margin:0 3px
  }
  .player-strip {
    display:flex;
    gap:7px;
    min-height:30px;
    height:30px;
    padding:0 3px 4px
  }
  .player-avatar {
    width:21px;
    height:23px;
    font-size:16px
  }
  .player-name {
    max-width:68%;
    font-size:11px
  }
  .player-side {
    display:inline;
    margin-left:7px
  }
  .player-status {
    margin-left:auto
  }
  .hand-tray,.hand-tray.bottom {
    display:flex;
    align-items:center;
    gap:7px;
    height:84px;
    min-height:84px;
    padding:5px 7px;
    overflow-x:auto;
    overflow-y:hidden;
    border-radius:4px;
    scrollbar-width:thin
  }
  .hand-label {
    position:absolute;
    width:1px;
    height:1px;
    overflow:hidden;
    clip-path:inset(50%);
    margin:0
  }
  .hand-empty {
    padding:0 6px
  }
  .hand-piece {
    flex:0 0 54px;
    width:54px;
    max-width:none;
    min-width:54px;
    height:auto;
    padding:4px 4px 12px
  }
  .game-sidebar {
    grid-area:history;
    width:auto;
    height:auto;
    max-height:360px;
    margin:3px 6px 0;
    overflow:hidden
  }
  .history-list {
    max-height:200px
  }
  .match-controls {
    grid-area:controls;
    margin:0 6px
  }
}
@media (max-width:720px) {
  .is-playing .app-header {
    height:46px;
    padding:0 9px;
    gap:7px
  }
  .is-playing .brand>span:last-child,.is-playing #game-mode,
  .is-playing #rules-open,.is-playing #settings-open {
    display:none
  }
  .is-playing .app-header .icon-button {
    width:34px;
    height:38px
  }
  .is-playing .header-actions {
    gap:2px
  }
  .is-playing .header-actions .round-chip {
    margin-right:7px;
    font-size:7px;
    gap:5px
  }
  .is-playing .round-chip strong {
    font-size:17px
  }
  .game-screen {
    padding-top:5px
  }
}
