:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #69726d;
  --panel: #ffffff;
  --line: #d9e2dc;
  --soft: #edf3ef;
  --field-dark: #277747;
  --field-light: #2f8650;
  --home: #1f63d1;
  --home-deep: #15458f;
  --away: #d7423f;
  --away-deep: #9d2927;
  --gold: #f0c94c;
  /* トグルON時のアクセント。ピッチ緑の補色寄りのバーントオレンジ。
     白文字とのコントラストは AA を満たす（約4.6:1）。 */
  --accent: #c05621;
  --danger: #b43a31;
  --shadow: 0 18px 48px rgba(30, 46, 37, 0.16);
  font-family:
    "Segoe UI",
    "Hiragino Kaku Gothic ProN",
    "Yu Gothic",
    Meiryo,
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  /* タッチ時にタップ可能要素へ出る既定のタップハイライト（青い四角）を無効化。
     継承プロパティなのでルートに置けば全要素へ波及する。フォーカス枠は
     :focus-visible の金色アウトラインで別途担保。 */
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: #f4f7f4;
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(240, 201, 76, 0.72);
  outline-offset: 2px;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px clamp(16px, 3vw, 32px);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: contain;
}

h1,
h2,
p {
  margin: 0;
}

.brand h1 {
  font-size: 1.12rem;
  line-height: 1.1;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.select-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

select,
input {
  min-height: 38px;
  padding: 8px 10px;
}

textarea {
  width: 100%;
  resize: vertical;
  padding: 10px 12px;
  line-height: 1.55;
}

.primary-button,
.secondary-button,
.danger-button,
.text-button {
  min-height: 38px;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 700;
  white-space: nowrap;
}

.primary-button {
  background: var(--ink);
  color: #fff;
}

.secondary-button {
  background: #e7eee9;
  color: var(--ink);
}

.secondary-button.is-active {
  background: var(--accent);
  color: #fff;
}

/* 縦横切り替えボタン: ピッチ型アイコンのみ。アイコンは aria-pressed に応じて
   縦（ポートレート）⇔横（ランドスケープ）へ90°回転して向きを示す。
   ラベルは持たず、aria-label / title で「縦表示／横表示」を伝える。 */
.orientation-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
}

.orientation-icon {
  width: 18px;
  height: 18px;
  flex: none;
  transition: transform 0.2s ease;
}

.orientation-icon rect,
.orientation-icon line {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linejoin: round;
}

.orientation-icon circle {
  fill: currentColor;
}

.orientation-toggle[aria-pressed="true"] .orientation-icon {
  transform: rotate(90deg);
}

.danger-button {
  width: 100%;
  margin-top: 12px;
  background: #f7e8e6;
  color: var(--danger);
}

.text-button {
  min-height: 32px;
  background: transparent;
  color: var(--muted);
  padding: 4px 8px;
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  gap: 18px;
  padding: 18px clamp(14px, 3vw, 32px) 28px;
}

.board-area {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.score-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

.score-strip > div {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.team-dot {
  width: 10px;
  height: 10px;
  display: inline-block;
  border-radius: 999px;
}

.home-dot {
  background: var(--home);
}

.away-dot {
  background: var(--away);
}

.draw-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-button {
  min-height: 30px;
  border-radius: 7px;
  padding: 5px 10px;
  background: #e7eee9;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
}

.tool-button[aria-pressed="true"] {
  background: var(--ink);
  color: #fff;
}

.kbd-hint {
  display: inline-block;
  margin-left: 6px;
  padding: 0 5px;
  min-width: 1.4em;
  font-size: 0.72em;
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
  vertical-align: baseline;
  border: 1px solid currentColor;
  border-radius: 4px;
  opacity: 0.55;
  pointer-events: none;
}

.color-swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 999px;
  border: 2px solid rgba(23, 33, 27, 0.18);
}

.color-swatch.yellow { background: #f5d90a; }
.color-swatch.red { background: #ef4444; }
.color-swatch.blue { background: #3b82f6; }
.color-swatch.white { background: #ffffff; }

.color-swatch[aria-pressed="true"] {
  outline: 3px solid var(--gold);
  outline-offset: 1px;
}

.field-shell {
  background: #20342a;
  border-radius: 8px;
  padding: clamp(8px, 1.4vw, 16px);
  box-shadow: var(--shadow);
}

.board-hint {
  margin: 0.5rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.field {
  position: relative;
  width: 100%;
  aspect-ratio: 105 / 68;
  overflow: hidden;
  border-radius: 6px;
  background:
    repeating-linear-gradient(
      90deg,
      var(--field-dark) 0 9.09%,
      var(--field-light) 9.09% 18.18%
    );
  border: 2px solid rgba(255, 255, 255, 0.9);
  touch-action: none;
}

.field::before {
  content: "";
  position: absolute;
  inset: 3.5%;
  border: 2px solid rgba(255, 255, 255, 0.86);
  pointer-events: none;
}

.field-marking {
  position: absolute;
  pointer-events: none;
}

.half-line {
  top: 3.5%;
  bottom: 3.5%;
  left: 50%;
  border-left: 2px solid rgba(255, 255, 255, 0.86);
}

.center-circle {
  width: 18%;
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.center-spot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

/* PA・ゴールの寸法値は app.js の戦術ガイド定数（GUIDE_LANE_YS / GUIDE_BIELSA_LINES）と
   対で揃えている。ここを変える場合は app.js 側も同期すること。 */
.penalty-box {
  top: 22%;
  width: 15.5%;
  height: 56%;
  border: 2px solid rgba(255, 255, 255, 0.86);
}

.penalty-box.left {
  left: 3.5%;
  border-left: 0;
}

.penalty-box.right {
  right: 3.5%;
  border-right: 0;
}

.six-box {
  top: 36%;
  width: 5.5%;
  height: 28%;
  border: 2px solid rgba(255, 255, 255, 0.86);
}

.six-box.left {
  left: 3.5%;
  border-left: 0;
}

.six-box.right {
  right: 3.5%;
  border-right: 0;
}

/* ゴール位置 44-56% は app.js の GUIDE_BIELSA_LINES（ポスト端点）と対。変更時は要同期。 */
.goal {
  top: 44%;
  width: 1.6%;
  height: 12%;
  border: 2px solid rgba(255, 255, 255, 0.86);
}

.goal.left {
  left: 0.8%;
  border-right: 0;
}

.goal.right {
  right: 0.8%;
  border-left: 0;
}

.field.vertical {
  aspect-ratio: 68 / 105;
  background: repeating-linear-gradient(
    0deg,
    var(--field-dark) 0 9.09%,
    var(--field-light) 9.09% 18.18%
  );
}

.field.vertical .half-line {
  top: 50%;
  bottom: auto;
  left: 3.5%;
  right: 3.5%;
  height: 0;
  border-left: 0;
  border-top: 2px solid rgba(255, 255, 255, 0.86);
}

.field.vertical .center-circle {
  width: auto;
  height: 18%;
  aspect-ratio: 1;
}

.field.vertical .penalty-box {
  top: auto;
  bottom: auto;
  left: 22%;
  right: auto;
  width: 56%;
  height: 15.5%;
  border: 2px solid rgba(255, 255, 255, 0.86);
}

.field.vertical .penalty-box.left {
  bottom: 3.5%;
  border-bottom: 0;
}

.field.vertical .penalty-box.right {
  top: 3.5%;
  border-top: 0;
}

.field.vertical .six-box {
  top: auto;
  bottom: auto;
  left: 36%;
  right: auto;
  width: 28%;
  height: 5.5%;
  border: 2px solid rgba(255, 255, 255, 0.86);
}

.field.vertical .six-box.left {
  bottom: 3.5%;
  border-bottom: 0;
}

.field.vertical .six-box.right {
  top: 3.5%;
  border-top: 0;
}

.field.vertical .goal {
  top: auto;
  bottom: auto;
  left: 44%;
  right: auto;
  width: 12%;
  height: 1.6%;
  border: 2px solid rgba(255, 255, 255, 0.86);
}

.field.vertical .goal.left {
  bottom: 0.8%;
  border-top: 0;
}

.field.vertical .goal.right {
  top: 0.8%;
  border-bottom: 0;
}

.guides-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.guides-layer .guide-lane {
  stroke: rgba(255, 255, 255, 0.55);
  stroke-width: 2px;
  stroke-dasharray: 2 6;
  stroke-linecap: round;
}

.guides-layer .guide-bielsa {
  stroke: rgba(240, 201, 76, 0.85);
  stroke-width: 2px;
  stroke-dasharray: 8 6;
}

.guides-layer .guide-third {
  stroke: none;
}

.guides-layer .guide-third.defensive {
  fill: rgba(31, 99, 209, 0.13);
}

.guides-layer .guide-third.middle {
  fill: rgba(240, 201, 76, 0.1);
}

.guides-layer .guide-third.attacking {
  fill: rgba(215, 66, 63, 0.13);
}

.guides-layer .guide-third-line {
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 1.5px;
}

.draw-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.field.draw-mode .draw-layer {
  pointer-events: auto;
  cursor: crosshair;
  touch-action: none;
}

.field.draw-mode .players-layer {
  pointer-events: none;
}

.players-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
}

/* 選手・ボールの表示サイズ3段階。#field の data-token-scale で切り替える倍率。
   子孫の .player-token / .ball-token が継承して --token / --ball に乗算する。 */
.field[data-token-scale="small"] {
  --token-scale: 0.7;
}
.field[data-token-scale="medium"] {
  --token-scale: 1;
}
.field[data-token-scale="large"] {
  --token-scale: 1.4;
}

.player-token {
  --token: calc(46px * var(--token-scale, 1));
  position: absolute;
  width: var(--token);
  min-width: var(--token);
  transform: translate(-50%, -50%);
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 0;
  background: transparent;
  color: #fff;
  border-radius: 8px;
  touch-action: none;
  user-select: none;
}

.player-token .number {
  width: var(--token);
  height: var(--token);
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 18px rgba(10, 20, 14, 0.28);
  font-weight: 900;
  /* 背番号は円（--token）に比例。円は据え置きで文字だけ大きめ（円径の0.5倍）。
     PC 約23px / モバイル 約19px。--token 基準なので後段のサイズ切替でも円と一緒に追従。 */
  font-size: calc(var(--token) * 0.5);
  line-height: 1;
}

.player-token.home .number {
  background: var(--home);
}

.player-token.away .number {
  background: var(--away);
}

.player-token .name-tag {
  max-width: 92px;
  min-height: 18px;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(20, 28, 24, 0.72);
  color: #fff;
  font-size: calc(0.7rem * var(--token-scale, 1));
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-token .dir-arc {
  position: absolute;
  top: calc(var(--token) / 2);
  left: 50%;
  width: calc(var(--token) + 10px);
  height: calc(var(--token) + 10px);
  border-radius: 50%;
  background: conic-gradient(
    from 180deg,
    var(--arc-color, rgba(23, 33, 27, 0.85)) 0 180deg,
    transparent 180deg 360deg
  );
  transform: translate(-50%, -50%) rotate(var(--dir-screen, 0deg));
  pointer-events: none;
  z-index: -1;
}

.player-token.home .dir-arc {
  --arc-color: var(--home-deep);
}

.player-token.away .dir-arc {
  --arc-color: var(--away-deep);
}

.player-token .dir-handle {
  position: absolute;
  top: calc(var(--token) / 2);
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(10, 20, 14, 0.4);
  transform: rotate(var(--dir-screen, 0deg)) translateX(calc(var(--token) / 2 + 14px));
  display: none;
  cursor: grab;
  z-index: 2;
}

.player-token .dir-handle::before {
  content: "";
  position: absolute;
  inset: -8px;
}

.player-token.selected .dir-handle {
  display: block;
}

.player-token.selected .number {
  border-color: var(--gold);
  box-shadow:
    0 0 0 4px rgba(240, 201, 76, 0.36),
    0 8px 18px rgba(10, 20, 14, 0.28);
}

.player-token.dragging {
  z-index: 5;
}

.ball-token {
  --ball: calc(26px * var(--token-scale, 1));
  position: absolute;
  width: var(--ball);
  height: var(--ball);
  transform: translate(-50%, -50%);
  padding: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #ffffff 0 36%, #eef1f4 58%, #c3ccd3 100%);
  border: 1px solid rgba(20, 28, 24, 0.35);
  box-shadow: 0 6px 14px rgba(10, 20, 14, 0.42);
  touch-action: none;
  user-select: none;
  z-index: 3;
}

.ball-token::before {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 40%;
  height: 40%;
  background: #1c2620;
  clip-path: polygon(50% 0%, 100% 38%, 81% 100%, 19% 100%, 0% 38%);
}

.ball-token.dragging {
  z-index: 6;
}

.side-panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(30, 46, 37, 0.08);
  overflow: hidden;
  align-self: start;
}

.panel-section {
  padding: 15px;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child {
  border-bottom: 0;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-title h2 {
  font-size: 0.98rem;
}

.empty-state {
  color: var(--muted);
  background: var(--soft);
  border: 1px dashed #c9d7ce;
  border-radius: 8px;
  padding: 12px;
  font-size: 0.9rem;
}

.selection-card {
  display: grid;
  gap: 10px;
}

.selection-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.pill {
  border-radius: 999px;
  padding: 4px 9px;
  color: #fff;
  font-weight: 800;
}

.pill.home {
  background: var(--home-deep);
}

.pill.away {
  background: var(--away-deep);
}

.field-grid {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 8px;
}

.field-grid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.field-grid input {
  width: 100%;
}

.add-player-form {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 12px;
}

.roster-list {
  display: grid;
  gap: 8px;
}

.roster-group {
  display: grid;
  gap: 7px;
}

.roster-group + .roster-group {
  margin-top: 12px;
}

.group-heading {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.player-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 7px;
  background: #f8faf8;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.player-row.selected {
  border-color: var(--gold);
  background: #fff9df;
}

.opponent-list {
  grid-template-columns: 1fr;
}

.opponent-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 6px;
  background: #f8faf8;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.opponent-row.selected {
  border-color: var(--gold);
  background: #fff9df;
}

.number-badge {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-weight: 900;
  overflow: hidden;
}

.number-badge.home {
  background: var(--home);
}

.number-badge.away {
  background: var(--away);
}

.player-name {
  min-width: 0;
}

.player-name strong,
.player-name span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-name strong {
  font-size: 0.92rem;
}

.player-name span {
  color: var(--muted);
  font-size: 0.76rem;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mini-button {
  min-height: 30px;
  border-radius: 7px;
  padding: 5px 8px;
  background: #e7eee9;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
}

.mini-button.primary {
  background: var(--ink);
  color: #fff;
}

.mini-button.danger {
  background: #f7e8e6;
  color: var(--danger);
}

.opponent-input {
  width: 100%;
}

.opponent-input.number {
  text-align: center;
  font-weight: 900;
  color: var(--away-deep);
}

.sent-off-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 7px;
  background: #f8faf8;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.sent-off-row .player-name {
  flex: 1;
}

.red-card {
  flex: none;
  width: 13px;
  height: 18px;
  border-radius: 2px;
  background: #e11d1d;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.12),
    0 1px 2px rgba(10, 20, 14, 0.25);
}

.sent-off-badge {
  font-weight: 700;
  color: var(--away-deep);
}

.sent-off-badge[hidden] {
  display: none;
}

@media (max-width: 1020px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    align-self: stretch;
  }
}

@media (max-width: 680px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
    justify-content: stretch;
  }

  .toolbar > * {
    flex: 1 1 auto;
  }

  .select-control {
    min-width: 150px;
  }

  .select-control select {
    width: 100%;
  }

  .field-shell {
    margin-inline: -6px;
    border-radius: 0;
  }

  .player-token {
    --token: calc(38px * var(--token-scale, 1));
  }

  .ball-token {
    --ball: calc(22px * var(--token-scale, 1));
  }

  .player-token .name-tag {
    max-width: 70px;
    font-size: calc(0.64rem * var(--token-scale, 1));
  }

  .add-player-form {
    grid-template-columns: 64px 1fr;
  }

  .add-player-form button {
    grid-column: 1 / -1;
  }
}

/* 縦表示のデスクトップ時のみフィールド幅を抑えて中央寄せ。
   :has() 非対応の旧ブラウザではこの規則が無視され、縦フィールドは
   シェル幅いっぱい・縦長で表示される（描画・操作は影響なし）。 */
@media (min-width: 681px) {
  .field-shell:has(.field.vertical) {
    width: 100%;
    max-width: min(460px, calc((100vh - 220px) * 0.6476));
    margin-inline: auto;
  }
}

/* ===== ヘッダー/側面パネルのしまい込み =====
   衝突回避のため末尾追記（append-only）でCSSの後勝ちを利用して上書きする。 */

/* --- ① ヘッダーの折りたたみ --- */
.header-lead {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.header-toggle {
  flex: none;
  min-width: 38px;
  min-height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e7eee9;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
}

/* 言語切替: タイトル横に置くコンパクトなゴーストピル。
   操作用の .secondary-button より一段控えめ・小さめの utility として扱う。 */
.lang-toggle {
  flex: none;
  min-height: 26px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.lang-toggle:hover {
  color: var(--ink);
  border-color: var(--ink);
  background: #eef3f0;
}

.app-header.is-collapsed {
  padding-top: 10px;
  padding-bottom: 10px;
}

.app-header.is-collapsed .toolbar {
  display: none;
}

.app-header.is-collapsed .brand p {
  display: none;
}

/* --- ② パネルをレイアウトから外し盤面を全幅に --- */
.layout {
  grid-template-columns: minmax(0, 1fr);
}

/* 盤面カラムは全幅を基本とし、横表示の最大幅は app.js の fitBoardSize() が
   実測の残り高さから計算して max-width(インラインstyle)で与える。
   width:100% を明示するのは、margin auto によって grid の stretch が外れ
   内容幅（描画ツールバーの幅）に縮んでしまうのを防ぐため。 */
.board-area {
  width: 100%;
  margin-inline: auto;
}

/* --- ② 側面パネル: 右スライドのかぶせ型ドロワー --- */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 40;
  width: min(380px, 88vw);
  height: 100vh;
  border-radius: 0;
  border-left: 1px solid var(--line);
  box-shadow: -14px 0 36px rgba(30, 46, 37, 0.22);
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  pointer-events: none;
}

.side-panel.is-open {
  transform: translateX(0);
  pointer-events: auto;
}

.panel-scrim {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(20, 28, 24, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.panel-scrim.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.panel-toggle {
  position: fixed;
  top: 50%;
  right: 0;
  z-index: 35;
  transform: translateY(-50%);
  writing-mode: vertical-rl;
  min-width: 40px;
  min-height: 96px;
  padding: 14px 9px;
  border-radius: 12px 0 0 12px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  letter-spacing: 2px;
  box-shadow: var(--shadow);
}

@media (prefers-reduced-motion: reduce) {
  .side-panel,
  .panel-scrim,
  .orientation-icon {
    transition: none;
  }
}
