#shogi-frame {
  container-type: size;
  container-name: shogi-frame;
}
.shogi-standalone-page { margin: 0; background: #e8e4d7; }
#shogi-frame.shogi-standalone { height: 100svh; }
#shogi-frame.shogi-standalone[data-expanded] { height: 100dvh; }

.shogi-game {
  color-scheme: light;
  font: 16px/1.5 system-ui, sans-serif;
  color: #183536;
  background: #e8e4d7;
  --paper: #fffdf6;
  --ink: #183536;
  --muted: #4e6260;
  --line: #bac6bb;
  --teal: #1d544e;
  --game-height: 100cqh;
  position: relative;
}

.shogi-game *, .shogi-game *::before, .shogi-game *::after { box-sizing: border-box; }
.shogi-game [hidden] { display: none !important; }

.shogi-game h2, .shogi-game p { margin: 0; }
.shogi-game button, .shogi-game input { font: inherit; }
.shogi-game button {
  border: 1px solid var(--line);
  border-radius: .48rem;
  background: var(--paper);
  color: var(--ink);
  min-height: 42px;
  padding: .35rem .7rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.shogi-game button:disabled { cursor: default; }
.shogi-game button:not(:disabled):active { filter: brightness(.94); }
.shogi-game :focus-visible { outline: 3px solid #116b8b; outline-offset: 2px; }
.shogi-game .primary { background: var(--teal); color: white; border-color: var(--teal); }

.shogi-game .frame {
  min-height: var(--game-height);
  max-width: 980px;
  margin-inline: auto;
  padding: clamp(8px, 2cqw, 24px);
  border-top: 5px solid var(--teal);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: clamp(.35rem, 1.6cqh, 1rem);
  background: var(--paper);
}
.shogi-game .game-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.shogi-game .header-actions { display: flex; gap: .3rem; }
.shogi-game .header-actions button { white-space: nowrap; }
#shogi-frame[data-expanded] .shogi-game .frame {
  max-width: none;
  padding-left: max(clamp(8px, 2cqw, 24px), env(safe-area-inset-left));
  padding-right: max(clamp(8px, 2cqw, 24px), env(safe-area-inset-right));
}
.shogi-game #shogi-game-title { font-family: "Yu Mincho", "Hiragino Mincho ProN", serif; font-size: clamp(1.7rem, 4cqw, 2.7rem); line-height: 1.1; }
.shogi-game #shogi-game-title small { font-family: system-ui, sans-serif; font-size: .46em; margin-inline-end: .5em; }

.shogi-game #menu {
  width: min(100%, 720px);
  justify-self: center;
  align-self: center;
  display: grid;
  align-items: center;
  gap: clamp(12px, 4cqw, 36px);
}
.shogi-game .menu-board {
  justify-self: center;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  width: min(44cqw, 170px);
  border: 5px solid #8a613b;
  border-radius: .4rem;
  color: #543321;
  background-color: #e2b97c;
  background-image: linear-gradient(#8b623766 1px, transparent 1px), linear-gradient(90deg, #8b623766 1px, transparent 1px);
  background-size: 20% 20%;
  box-shadow: 0 4px 0 #69452b, 0 8px 20px #63452730;
}
.shogi-game .menu-board .piece { width: 56%; height: 62%; font-size: clamp(1.9rem, 8cqw, 3.5rem); }
.shogi-game .menu-options { display: grid; gap: .75rem; }
.shogi-game fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.shogi-game legend { margin-bottom: .32rem; font-size: .9rem; font-weight: 750; }
.shogi-game .choices, .shogi-game .menu-actions, .shogi-game .match-actions, .shogi-game .decision { display: grid; gap: .4rem; }
.shogi-game .choices, .shogi-game .menu-actions, .shogi-game .match-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.shogi-game .choices label { position: relative; cursor: pointer; }
.shogi-game .choices input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.shogi-game .choices label > span { display: grid; place-content: center; text-align: center; height: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: .5rem; padding: 4px; font-weight: 700; }
.shogi-game .choices small { display: block; font-size: .75rem; color: var(--muted); }
.shogi-game .choices input:checked + span { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); background: #e1eee8; }
.shogi-game .choices input:focus-visible + span { outline: 3px solid #116b8b; outline-offset: 2px; }
.shogi-game #start:has(+ #resume[hidden]) { grid-column: 1 / -1; }

.shogi-game #match {
  display: grid;
  align-items: start;
  align-self: center;
  gap: .5rem;
  width: min(100%, 920px);
  justify-self: center;
}
.shogi-game .table { display: grid; justify-items: center; gap: .3rem; align-self: center; }
.shogi-game .rack { display: flex; width: min(100%, var(--board-size)); min-width: 0; min-height: 31px; align-items: center; gap: .3rem; }
.shogi-game .rack-name { font-weight: 750; flex-shrink: 0; font-size: .76rem; }
.shogi-game .hand { display: flex; flex: 1; gap: .18rem; justify-content: end; align-items: center; flex-wrap: wrap; }
.shogi-game .hand:empty::after { content: "なし"; color: var(--muted); font-size: .75rem; }
.shogi-game .hand button { min-height: 31px; min-width: 30px; padding: 1px 3px; font-size: .88rem; color: #583322; background: #f6e6c6; }
.shogi-game .hand button:disabled { opacity: .87; }
.shogi-game .hand button[aria-pressed="true"] { outline: 2px solid var(--teal); background: #d4e9df; }
.shogi-game .hand button small { padding-inline-start: .1em; }
.shogi-game .table { --board-size: min(100%, 540px, calc(var(--game-height) - 216px)); }
.shogi-game .board-stack {
  width: var(--board-size);
  min-width: min(100%, 205px);
  aspect-ratio: 1;
  position: relative;
  border: 3px solid #795638;
  border-radius: .24rem;
  background: #e4bf87;
  box-shadow: 0 3px 0 #6f4a30;
}
.shogi-game #board, .shogi-game #board-grid {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.shogi-game #board { display: block; pointer-events: none; }
.shogi-game #board-grid { display: grid; grid-template-rows: repeat(var(--size), minmax(0, 1fr)); }
.shogi-game .rank { display: flex; min-width: 0; }
.shogi-game .cell {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  border: 0;
  padding: 0;
  border-radius: 0;
  background: transparent;
}
.shogi-game .cell:focus-visible { outline-offset: -3px; z-index: 1; }
.shogi-game [data-canvas-unavailable] .cell {
  background: #e4bf87;
  border: 1px solid #87603d;
  color: #372314;
  font-size: min(3cqw, 1.2rem);
}
.shogi-game [data-canvas-unavailable] .cell[data-gote] { rotate: 180deg; }
.shogi-game [data-canvas-unavailable] .cell[data-promoted] { color: #8e312c; }
.shogi-game [data-canvas-unavailable] .cell[data-target] { box-shadow: inset 0 0 0 2px #21564e; }
.shogi-game [data-canvas-unavailable] .cell[data-last] { background: #f3d984; }
.shogi-game [data-canvas-unavailable] .cell[data-selected] { background: #b4d3ac; }
.shogi-game [data-canvas-unavailable] .cell[data-check] { background: #e49b83; }
.shogi-game .piece {
  display: grid;
  place-items: center;
  width: 83%;
  height: 88%;
  clip-path: polygon(50% 0, 89% 18%, 98% 100%, 2% 100%, 11% 18%);
  padding-top: 12%;
  background: linear-gradient(118deg, #fff0c8, #edcb92);
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
}
.shogi-game .match-side { display: grid; align-content: center; gap: .35rem; }
.shogi-game #mode-display, .shogi-game #last-move { font-size: .79rem; color: var(--muted); }
.shogi-game #last-move { min-height: 1lh; }
.shogi-game #status { font-weight: 800; }
.shogi-game .match-actions button { min-height: 38px; }
.shogi-game .match-actions button:disabled { color: #526561; background: #ebece5; }
.shogi-game #undo { white-space: nowrap; }
.shogi-game dialog { width: min(440px, calc(100% - 16px)); max-height: calc(var(--game-height) - 16px); padding: clamp(12px, 4cqw, 24px); border: 1px solid var(--line); border-radius: .75rem; color: var(--ink); background: var(--paper); }
.shogi-game dialog::backdrop { background: #183536a0; }
.shogi-game dialog h2 { font-size: 1.2rem; }
.shogi-game dialog > * + * { margin-top: .65rem; }
.shogi-game dialog ol { padding-inline-start: 1.4em; margin-bottom: 0; }
.shogi-game dialog li + li { margin-top: .35rem; }
.shogi-game dialog form:not(.decision) { text-align: end; }
.shogi-game .decision { grid-auto-flow: column; }
.shogi-game .option { display: block; min-height: 42px; }
.shogi-game .option, .shogi-game .volume { accent-color: var(--teal); }
.shogi-game .volume { display: grid; grid-template-columns: auto minmax(0, 1fr) 4ch; align-items: center; gap: .55rem; min-height: 42px; }
.shogi-game .volume output { text-align: end; }

.shogi-game #ad-area-limited { display: none; }
#shogi-frame[data-ad-area-limited] .shogi-game .frame { display: none; }
#shogi-frame[data-ad-area-limited] .shogi-game #ad-area-limited {
  display: grid;
  place-items: center;
  min-height: var(--game-height);
  padding: 4px 12px;
  text-align: center;
}

.shogi-game #ad-status {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: max-content;
  max-width: calc(100% - 24px);
  margin: 0;
  padding: .6rem .9rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  color: var(--ink);
  background: var(--paper);
  pointer-events: none;
}

@container shogi-frame (min-width: 560px) or ((orientation: landscape) and (min-width: 480px)) {
  .shogi-game #menu { grid-template-columns: minmax(130px, .85fr) minmax(0, 1.15fr); }
  .shogi-game .menu-board { width: min(100%, 235px); }
  .shogi-game #match { grid-template-columns: minmax(0, 1fr) minmax(150px, .42fr); align-items: center; gap: clamp(8px, 3cqw, 32px); }
  .shogi-game .table { --board-size: min(100%, 590px, calc(var(--game-height) - 186px)); }
  .shogi-game .match-side { gap: .55rem; }
}

@container shogi-frame ((max-height: 475px) and (min-width: 560px)) or ((max-height: 475px) and (orientation: landscape) and (min-width: 480px)) {
  .shogi-game .frame { padding-block: 5px; gap: .2rem; }
  .shogi-game .game-header button { min-height: 34px; }
  .shogi-game .table { --board-size: min(100%, 590px, calc(var(--game-height) - 138px)); }
  .shogi-game .board-stack { min-width: 0; }
  .shogi-game .rack { width: min(100%, max(var(--board-size), 310px)); }
  .shogi-game .menu-options { gap: .45rem; }
}

@container shogi-frame (min-width: 900px) and (min-height: 750px) {
  #shogi-frame[data-expanded] .shogi-game #match { width: min(100%, 1170px); }
  #shogi-frame[data-expanded] .shogi-game .table { --board-size: min(100%, 730px, calc(var(--game-height) - 186px)); }
  #shogi-frame[data-expanded] .shogi-game #menu { width: min(100%, 900px); }
  #shogi-frame[data-expanded] .shogi-game .menu-board { width: min(100%, 286px); }
}

@container shogi-frame (max-width: 479px) or ((max-width: 559px) and (orientation: portrait)) {
  .shogi-game .header-actions button { padding-inline: .45rem; }
  .shogi-game #mode-display, .shogi-game #last-move { display: inline; }
  .shogi-game .match-side { grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0 .5rem; }
  .shogi-game #status { grid-column: 1; grid-row: 1; }
  .shogi-game #mode-display { grid-column: 1; grid-row: 2; }
  .shogi-game #last-move { grid-column: 1; grid-row: 3; }
  .shogi-game .match-actions { grid-column: 2; grid-row: 1 / span 3; }
}

@container shogi-frame ((max-height: 600px) and (max-width: 479px)) or ((max-height: 600px) and (max-width: 559px) and (orientation: portrait)) {
  .shogi-game .menu-board { width: min(32cqw, 114px); }
  .shogi-game #menu { gap: .55rem; }
  .shogi-game .menu-options { gap: .57rem; }
}

@container shogi-frame (max-height: 450px) and (max-width: 479px) {
  .shogi-game .table { --board-size: min(100%, calc(var(--game-height) - 250px)); }
  .shogi-game .board-stack { min-width: min(100%, 140px); }
  .shogi-game .rack { width: min(100%, 310px); }
  .shogi-game .menu-board { width: min(25cqw, 82px); }
}
