/* BreachGammon Prototype Styling */
:root {
  --bg-color: #1a1816;
  --surface-color: #26221f;
  --surface-border: #3b3530;
  --text-main: #f0eae1;
  --text-muted: #a69c91;
  --primary-color: #0077b6;
  --primary-hover: #0096c7;
  --accent-color: #e63946;
  --accent-hover: #f77f00;
  --success-color: #2a9d8f;
  --warning-color: #e76f51;
  --border-radius: 8px;
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  padding-top: var(--safe-top);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background-color: var(--surface-color);
  border-bottom: 1px solid var(--surface-border);
  gap: 16px;
  flex-wrap: wrap;
}

.title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.title-group h1 {
  font-size: 1.3rem;
  letter-spacing: 0.5px;
}

.version-tag {
  background-color: #3d352e;
  color: #ffb703;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: bold;
}

.turn-status-bar {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
}

.status-item .label {
  color: var(--text-muted);
}

.player-badge {
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: bold;
  font-size: 0.85rem;
}

.player-badge.white-turn {
  background-color: #f8f9fa;
  color: #212529;
  border: 1px solid #ced4da;
}

.player-badge.black-turn {
  background-color: #212529;
  color: #f8f9fa;
  border: 1px solid #495057;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-header-quick {
  display: inline-flex;
  align-items: center;
}

.btn-menu {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #2a2d36;
  color: #f8f9fa;
  border: 1px solid #4a4e5a;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 40px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-menu:hover {
  background: #383c48;
  border-color: #6c757d;
}

.turn-commit-row {
  display: flex;
  gap: 8px;
  width: 100%;
  margin-top: 6px;
  flex-shrink: 0;
}

.turn-commit-row .btn-undo {
  flex: 1;
  min-height: 44px;
}

.turn-commit-row .btn-finish {
  flex: 2;
  min-height: 44px;
}

.action-disabled-hint.compact-hint {
  font-size: 0.72rem;
  padding: 3px 8px;
  margin-top: 3px;
  background: rgba(234, 88, 12, 0.15);
  border-left: 2px solid var(--accent-orange);
  border-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* App Menu Drawer */
.menu-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  justify-content: flex-end;
  animation: fadeIn 0.15s ease-out;
}

.menu-drawer-content {
  width: 100%;
  max-width: 360px;
  height: 100%;
  background: var(--bg-card);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.75);
  animation: slideLeft 0.2s ease-out;
  overflow: hidden;
}

@keyframes slideLeft {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.menu-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.25);
}

.menu-drawer-header h3 {
  font-size: 1rem;
  margin: 0;
  color: var(--text-main);
}

.menu-drawer-body {
  padding: 14px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.drawer-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.drawer-section h4 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
}

.drawer-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.3;
}

.drawer-btn-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drawer-btn-group .btn {
  width: 100%;
  min-height: 44px;
  font-size: 0.85rem;
}

.build-info-card {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.build-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
}

.build-info-label {
  color: var(--text-muted);
  font-weight: 500;
}

.build-info-val {
  color: var(--accent-orange);
  font-weight: 600;
  font-family: monospace;
}

/* Main Layout */
.main-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 16px;
  padding: 16px;
  flex: 1;
  overflow: hidden;
}

/* Board Column */
.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 100%;
}

.direction-indicator {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.5px;
}

.board-container-wrapper {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: center;
  gap: 14px;
  width: 100%;
  max-width: 1140px;
  position: relative;
}

.board-wrapper {
  flex: 1;
  min-width: 0;
  max-width: 960px;
  max-height: 640px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Player Status Boxes Beside Bear-off Trays */
.trays-status-column {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 165px;
  flex-shrink: 0;
  padding: 4px 0;
}

.player-status-box {
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 6px;
  user-select: none;
  transition: all 0.2s ease;
}

.black-status-box {
  background: linear-gradient(145deg, #2b2d35 0%, #16181b 100%);
  border: 1px solid #495057;
  color: #f8f9fa;
}

.white-status-box {
  background: linear-gradient(145deg, #ffffff 0%, #e9ecef 100%);
  border: 1px solid #ced4da;
  color: #121417;
}

.status-player-header {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(128, 128, 128, 0.25);
  display: flex;
  align-items: center;
  gap: 6px;
}

.black-status-box .status-player-header {
  color: #f8f9fa;
}

.white-status-box .status-player-header {
  color: #121417;
}

.status-metric-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  gap: 6px;
}

.black-status-box .metric-name {
  color: #adb5bd;
}

.black-status-box .metric-num {
  font-weight: 700;
  color: #ffffff;
  font-size: 0.95rem;
}

.white-status-box .metric-name {
  color: #495057;
}

.white-status-box .metric-num {
  font-weight: 700;
  color: #121417;
  font-size: 0.95rem;
}

.status-column-spacer {
  flex: 1;
  min-height: 20px;
}

/* Winner Banner Overlay */
.winner-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(18, 20, 24, 0.95);
  border: 3px solid #ffb703;
  box-shadow: 0 14px 45px rgba(0, 0, 0, 0.85), 0 0 25px rgba(255, 183, 3, 0.45);
  border-radius: 14px;
  padding: 24px 42px;
  text-align: center;
  z-index: 100;
  pointer-events: auto;
  cursor: default;
  animation: bannerPop 0.35s ease-out;
}

@keyframes bannerPop {
  0% { transform: translate(-50%, -50%) scale(0.85); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.winner-title {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: #ffb703;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.winner-desc {
  font-size: 1.05rem;
  color: #f8f9fa;
  font-weight: 600;
}

#board-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.6));
}

/* Board interaction lock during GAME_OVER */
.board-wrapper.game-over #board-svg,
#board-svg.game-over {
  pointer-events: none;
  cursor: default;
}

.board-wrapper.game-over #board-svg *,
#board-svg.game-over * {
  cursor: default !important;
}

.feedback-panel {
  width: 100%;
  max-width: 980px;
  padding: 10px 16px;
  background-color: var(--surface-color);
  border: 1px solid var(--surface-border);
  border-radius: var(--border-radius);
  font-size: 0.9rem;
  min-height: 42px;
  display: flex;
  align-items: center;
}

.feedback-panel .hint { color: var(--text-muted); }
.feedback-panel .error-msg { color: #ff6b6b; font-weight: 500; }
.feedback-panel .info-msg { color: #48cae4; font-weight: 500; }

/* Sidebar Column */
.sidebar-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-right: 4px;
}

.card {
  background-color: var(--surface-color);
  border: 1px solid var(--surface-border);
  border-radius: var(--border-radius);
  padding: 14px;
}

.card h3 {
  font-size: 0.95rem;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--surface-border);
  padding-bottom: 6px;
  color: #e9ecef;
}

/* Dice View */
.dice-status-summary {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.die-pill {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 4px;
  background-color: #343a40;
  border: 1px solid #495057;
}

.die-pill.reserved {
  background-color: #7209b7;
  color: #f72585;
}

.die-pill.recovering {
  background-color: #f77f00;
  color: #000;
}

.dice-row {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
}

.die-box {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
  border: 2px solid #adb5bd;
  transition: all 0.2s ease;
  user-select: none;
}

/* White Player Active Dice */
.die-box.player-white {
  background: linear-gradient(145deg, #ffffff 0%, #edf2f4 100%);
  color: #121417;
  border: 2px solid #ced4da;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}

.die-box.player-white .die-val {
  color: #121417;
}

.die-box.player-white .die-lbl {
  color: #495057;
}

/* Black Player Active Dice */
.die-box.player-black {
  background: linear-gradient(145deg, #2b2d35 0%, #131518 100%);
  color: #ffffff;
  border: 2px solid #5a6270;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.65);
}

.die-box.player-black .die-val {
  color: #ffffff;
}

.die-box.player-black .die-lbl {
  color: #adb5bd;
}

/* Auxiliary / Replacement Die */
.die-box.player-white.auxiliary {
  background: linear-gradient(145deg, #fff3cd 0%, #ffe082 100%);
  border-color: #f77f00;
  color: #3d2600;
}
.die-box.player-white.auxiliary .die-val {
  color: #3d2600;
}
.die-box.player-white.auxiliary .die-lbl {
  color: #7a4f00;
}

.die-box.player-black.auxiliary {
  background: linear-gradient(145deg, #3d2c14 0%, #20170a 100%);
  border-color: #f77f00;
  color: #ffe3a0;
}
.die-box.player-black.auxiliary .die-val {
  color: #ffe3a0;
}
.die-box.player-black.auxiliary .die-lbl {
  color: #e09f3e;
}

/* Used / Spent Die in Turn */
.die-box.used {
  opacity: 0.35 !important;
  filter: grayscale(100%) !important;
  background: #1e2126 !important;
  color: #656d76 !important;
  border: 2px dashed #444a53 !important;
  box-shadow: none !important;
  transform: scale(0.95);
}

.die-box.used .die-val {
  color: #656d76 !important;
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.die-box.used .die-lbl,
.die-box.used .die-lbl.used-lbl {
  color: #8b949e !important;
  font-weight: 700;
}

/* Auxiliary Inactive / Zero styling */
.die-box.auxiliary.used,
.die-box.auxiliary.aux-zero {
  opacity: 0.85 !important;
  filter: none !important;
  border-style: dashed !important;
  transform: scale(0.98);
}
.die-box.player-white.auxiliary.used,
.die-box.player-white.auxiliary.aux-zero {
  background: linear-gradient(145deg, #fff3cd 0%, #ffe082 100%) !important;
  border-color: #f77f00 !important;
  color: #3d2600 !important;
}
.die-box.player-white.auxiliary.used .die-val,
.die-box.player-white.auxiliary.aux-zero .die-val {
  color: #3d2600 !important;
}
.die-box.player-white.auxiliary.used .die-lbl,
.die-box.player-white.auxiliary.aux-zero .die-lbl {
  color: #7a4f00 !important;
}
.die-box.player-black.auxiliary.used,
.die-box.player-black.auxiliary.aux-zero {
  background: linear-gradient(145deg, #3d2c14 0%, #20170a 100%) !important;
  border-color: #f77f00 !important;
  color: #ffe3a0 !important;
}
.die-box.player-black.auxiliary.used .die-val,
.die-box.player-black.auxiliary.aux-zero .die-val {
  color: #ffe3a0 !important;
}
.die-box.player-black.auxiliary.used .die-lbl,
.die-box.player-black.auxiliary.aux-zero .die-lbl {
  color: #e09f3e !important;
}

.die-box.aux-zero .die-val {
  text-decoration: none !important;
}

.die-box.reserved {
  background-color: #3c096c;
  color: #e0aaff;
  border-color: #7b2cbf;
  border-style: dashed;
}

.die-box.recovering {
  background-color: #582f0e;
  color: #ddb892;
  border-color: #9c6644;
}

.die-box.waiting {
  background-color: #2b2d42;
  color: #8d99ae;
  border-color: #4a4e69;
  border-style: dotted;
}

/* Selectable / Clickable Action Die */
.die-box.selectable {
  cursor: pointer;
}
.die-box.selectable:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 6px 16px rgba(255, 183, 3, 0.4);
}
.die-box.action-selected {
  outline: 3px solid #ffb703 !important;
  outline-offset: 2px;
  box-shadow: 0 0 14px #ffb703, 0 6px 14px rgba(0, 0, 0, 0.5) !important;
  transform: scale(1.06) !important;
}

/* Action Disambiguation Choice Modal / Prompt */
.dice-choice-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
  padding: 12px;
  box-sizing: border-box;
}
.dice-choice-modal {
  background: #1e2229;
  border: 2px solid #ffb703;
  border-radius: 12px;
  padding: 16px 20px;
  max-width: 520px;
  width: 95%;
  max-height: 88vh;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.8), 0 0 20px rgba(255, 183, 3, 0.25);
  animation: bannerPop 0.2s ease-out;
}
.dice-choice-modal h3 {
  margin: 0 0 8px 0;
  color: #ffb703;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.dice-choice-modal p {
  color: #d1d5db;
  font-size: 0.88rem;
  margin-bottom: 12px;
  line-height: 1.35;
  flex-shrink: 0;
}
.dice-choice-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: calc(88dvh - 160px);
  padding-right: 4px;
}
.dice-choice-btn {
  background: #2b303c;
  border: 1px solid #495057;
  color: #f8f9fa;
  padding: 10px 14px;
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: all 0.15s ease;
  min-height: 44px;
  touch-action: manipulation;
  flex-shrink: 0;
}
.dice-choice-btn:hover {
  background: #3b4252;
  border-color: #ffb703;
  transform: translateX(3px);
}
.dice-choice-btn:focus-visible {
  outline: 2px solid #ffb703;
  outline-offset: 2px;
}
.dice-choice-btn-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #ffb703;
}
.dice-choice-btn-desc {
  font-size: 0.82rem;
  color: #ced4da;
}
.dice-choice-cancel-btn {
  background: transparent;
  border: 1px solid #6c757d;
  color: #adb5bd;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  display: block;
  margin-left: auto;
  min-height: 44px;
  min-width: 80px;
  touch-action: manipulation;
  flex-shrink: 0;
}
.dice-choice-cancel-btn:hover {
  background: #343a40;
  color: #fff;
}
.dice-choice-cancel-btn:focus-visible {
  outline: 2px solid #ffb703;
  outline-offset: 2px;
}

.wall-decision-banner {
  background-color: rgba(230, 57, 70, 0.15);
  border: 1px solid #e63946;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  line-height: 1.4;
  color: #ffccd5;
}

.die-rule-note {
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 4px;
  background-color: rgba(0, 119, 182, 0.15);
  border-left: 3px solid var(--primary-color);
  color: #90e0ef;
  margin-bottom: 8px;
}

.die-rule-note.aux-zero {
  background-color: rgba(231, 111, 81, 0.15);
  border-left-color: var(--warning-color);
  color: #f4a261;
}

.die-rule-note.doubles {
  background-color: rgba(42, 157, 143, 0.15);
  border-left-color: var(--success-color);
  color: #52b788;
}

.die-box .die-val {
  font-size: 1.5rem;
  font-weight: bold;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.die-pips {
  display: block;
  width: 28px;
  height: 28px;
}

.die-box.player-white .die-pips circle {
  fill: #121417;
}

.die-box.player-black .die-pips circle {
  fill: #ffffff;
}

.die-box.used .die-pips circle {
  fill: #656d76 !important;
}

.die-box .die-num {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
}

.die-box.auxiliary .die-num {
  font-size: 1.7rem;
  font-weight: 800;
}

.die-box .die-lbl {
  font-size: 0.65rem;
  color: #495057;
  font-weight: 600;
  text-align: center;
  max-width: 50px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.die-box.reserved .die-lbl,
.die-box.recovering .die-lbl,
.die-box.waiting .die-lbl {
  color: inherit;
}

.retained-dice-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.action-tag {
  background-color: var(--primary-color);
  color: #ffffff;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: bold;
}

.action-tag.player-white {
  background: linear-gradient(145deg, #ffffff 0%, #edf2f4 100%);
  color: #121417;
  border: 1px solid #ced4da;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.action-tag.player-black {
  background: linear-gradient(145deg, #2b2d35 0%, #131518 100%);
  color: #ffffff;
  border: 1px solid #5a6270;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* Controls */
.controls-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.button-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn {
  padding: 8px 14px;
  border-radius: 6px;
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  touch-action: manipulation;
  box-sizing: border-box;
}

.btn:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid #ffb703 !important;
  outline-offset: 2px;
}

.btn:disabled,
.btn.disabled {
  opacity: 0.45 !important;
  cursor: not-allowed !important;
  filter: grayscale(80%) !important;
  pointer-events: auto !important;
}

#btn-deploy-wall:disabled,
#btn-deploy-wall.disabled {
  background-color: #2b2d42 !important;
  border: 1px dashed #6c757d !important;
  color: #8d99ae !important;
  opacity: 0.5 !important;
  cursor: not-allowed !important;
  pointer-events: auto !important;
}

.btn-primary { background-color: var(--primary-color); color: #fff; }
.btn-primary:hover:not(:disabled) { background-color: var(--primary-hover); }

.btn-secondary { background-color: #495057; color: #fff; }
.btn-secondary:hover:not(:disabled) { background-color: #6c757d; }

.btn-success { background-color: var(--success-color); color: #fff; }
.btn-success:hover:not(:disabled) { background-color: #21867a; }

.btn-warning { background-color: var(--warning-color); color: #fff; }
.btn-accent { background-color: var(--accent-color); color: #fff; }
.btn-danger { background-color: #d90429; color: #fff; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--surface-border);
  color: var(--text-main);
}
.btn-outline:hover:not(:disabled) {
  background-color: rgba(255, 255, 255, 0.05);
}

.btn-large {
  padding: 12px;
  font-size: 1rem;
}

.btn-sm {
  padding: 4px 8px;
  font-size: 0.75rem;
}

/* Debug Panel */
.debug-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 0.8rem;
}

.debug-field label {
  color: var(--text-muted);
}

.input-with-button {
  display: flex;
  gap: 6px;
}

.input-with-button select,
.input-with-button input {
  flex: 1;
  background-color: #1a1816;
  border: 1px solid var(--surface-border);
  color: var(--text-main);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
}

.mode-toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.metrics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  margin-top: 6px;
}

.metrics-table th, .metrics-table td {
  padding: 3px 6px;
  border: 1px solid var(--surface-border);
  text-align: left;
}

.metrics-table th {
  background-color: #343a40;
}

/* Logs */
.action-list, .history-list {
  list-style: none;
  font-size: 0.8rem;
  max-height: 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.action-list li, .history-list li {
  padding: 4px 8px;
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  border-left: 3px solid var(--primary-color);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  background-color: rgba(0, 0, 0, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 12px;
  box-sizing: border-box;
}

.modal-backdrop.visible {
  display: flex;
}

.modal-card {
  background-color: var(--surface-color);
  border: 1px solid var(--surface-border);
  border-radius: var(--border-radius);
  width: 95%;
  max-width: 680px;
  max-height: 88vh;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.8);
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--surface-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.modal-header h2 {
  font-size: 1.05rem;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 1.6rem;
  cursor: pointer;
  padding: 4px 8px;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  touch-action: manipulation;
}

.btn-close:focus-visible {
  outline: 2px solid #ffb703 !important;
  outline-offset: 2px;
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 0.88rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(88dvh - 65px);
}

.modal-body ul {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Collapsible Details Cards */
.collapsible-card {
  transition: all 0.2s ease;
}

.collapsible-card > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  position: relative;
  outline: none;
  padding-right: 28px;
}

.collapsible-card > summary::-webkit-details-marker {
  display: none;
}

.collapsible-card > summary::after {
  content: '▾';
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.collapsible-card[open] > summary::after {
  transform: translateY(-50%) rotate(180deg);
}

.collapsible-card > summary:focus-visible {
  outline: 2px solid var(--primary-color) !important;
  outline-offset: 2px;
  border-radius: 4px;
}

.badge-subtle {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
}

/* Disabled Action Hint */
.action-disabled-hint {
  font-size: 0.75rem;
  color: #ffb703;
  background: rgba(255, 183, 3, 0.12);
  border: 1px solid rgba(255, 183, 3, 0.35);
  padding: 6px 10px;
  border-radius: 5px;
  margin-top: 4px;
  line-height: 1.35;
}

/* Rotate Suggestion Banner */
.rotate-suggestion-banner {
  background: linear-gradient(90deg, #2b261f 0%, #3d352e 100%);
  border-bottom: 1px solid #ffb703;
  color: #ffdda1;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 500;
  gap: 8px;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.rotate-suggestion-banner .rotate-text {
  flex: 1;
}

.btn-dismiss-rotate {
  background: transparent;
  border: none;
  color: #a69c91;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 8px;
  min-height: 36px;
  min-width: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.btn-dismiss-rotate:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

/* Legal Action Chooser */
.legal-action-chooser {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 960px;
  background: rgba(0, 119, 182, 0.12);
  border: 1px solid rgba(0, 180, 216, 0.45);
  border-radius: var(--border-radius);
  padding: 8px 12px;
  margin-top: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.legal-chooser-header {
  font-size: 0.78rem;
  font-weight: 700;
  color: #90e0ef;
  letter-spacing: 0.3px;
}

.legal-chooser-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-legal-destination {
  background: linear-gradient(135deg, #1d3557, #132238);
  border: 1px solid #457b9d;
  color: #f1faee;
  border-radius: 6px;
  padding: 8px 12px;
  min-height: 44px;
  font-size: 0.84rem;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  flex: 1 1 calc(50% - 8px);
  min-width: 130px;
  touch-action: manipulation;
}

.btn-legal-destination:hover, .btn-legal-destination:active {
  background: linear-gradient(135deg, #2a5298, #1e3c72);
  border-color: #00b4d8;
  box-shadow: 0 0 10px rgba(0, 180, 216, 0.4);
  transform: translateY(-1px);
}

.btn-legal-destination .dest-target {
  font-weight: 700;
  color: #00f0ff;
  font-size: 0.88rem;
}

.btn-legal-destination .dest-die {
  font-size: 0.74rem;
  color: #caf0f8;
  margin-top: 2px;
}

/* ========================================================
   RESPONSIVE LAYOUTS
   ======================================================== */

/* Tablet & Intermediate Widths (<= 1080px) */
@media (max-width: 1080px) {
  .board-container-wrapper {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }
  .trays-status-column {
    display: flex !important;
    flex-direction: row !important;
    width: 100% !important;
    max-width: 100% !important;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    padding: 0;
  }
  .player-status-box {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
  }
  .status-player-header {
    border-bottom: none;
    padding-bottom: 0;
    font-size: 0.76rem;
  }
  .status-metric-line {
    display: inline-flex;
    gap: 3px;
    font-size: 0.72rem;
  }
  .status-column-spacer {
    display: none;
  }
}

/* Standard Single-Column Fallback (<= 900px) */
@media (max-width: 900px) {
  .app-container {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-y: auto;
  }
  .main-layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }
  .sidebar-column {
    overflow: visible;
  }
}

/* Portrait Phones (<= 768px, portrait or narrow) */
@media (max-width: 768px) {
  .app-container {
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .app-header {
    padding: 8px 12px;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .app-header .title-group {
    justify-content: space-between;
  }
  .turn-status-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: space-between;
  }
  .header-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  .header-actions .btn {
    min-height: 44px;
    font-size: 0.82rem;
    width: 100%;
  }
  .main-layout {
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 12px;
    overflow: visible;
  }
  .board-column {
    width: 100%;
    height: auto;
    gap: 6px;
  }
  .direction-indicator {
    font-size: 0.75rem;
    text-align: center;
  }
  .board-container-wrapper {
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 8px;
  }
  .board-wrapper {
    width: 100%;
    max-width: 100%;
    height: auto;
    aspect-ratio: 960 / 640;
  }
  #board-svg {
    width: 100%;
    height: auto;
    display: block;
  }
  .trays-status-column {
    flex-direction: row;
    width: 100%;
    max-width: 100%;
    justify-content: space-between;
    gap: 8px;
    margin-top: 4px;
    padding: 0;
  }
  .player-status-box {
    flex: 1;
    padding: 8px 10px;
  }
  .status-player-header {
    font-size: 0.85rem;
  }
  .status-metric-line {
    font-size: 0.75rem;
  }
  .sidebar-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    overflow: visible;
  }
  /* On mobile portrait, put Turn Dice & Actions at top of sidebar */
  .panel-dice {
    order: -1;
  }
  .controls-toolbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .controls-toolbar .btn {
    width: 100%;
    min-height: 44px;
  }
  .controls-toolbar .button-group {
    flex-direction: column;
    gap: 8px;
    width: 100%;
  }
  .dice-row {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }
}

/* Primary Mobile Layout: Landscape Phones (short viewport height) */
@media (orientation: landscape) and (max-height: 550px) {
  .app-container {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }
  .app-header {
    padding: 2px 8px;
    gap: 6px;
    flex-wrap: nowrap;
    min-height: 34px;
    height: 34px;
    flex-direction: row;
    align-items: center;
  }
  .title-group h1 {
    font-size: 0.92rem;
  }
  .version-tag {
    display: inline-flex !important;
    font-size: 0.68rem;
    padding: 1px 4px;
  }
  .turn-status-bar {
    gap: 6px;
    flex-wrap: nowrap;
    display: flex;
  }
  .status-item {
    font-size: 0.72rem;
    gap: 2px;
  }
  .player-badge {
    padding: 1px 5px;
    font-size: 0.7rem;
  }
  .btn-header-quick {
    display: none !important;
  }
  .btn-menu {
    min-height: 28px;
    padding: 2px 8px;
    font-size: 0.75rem;
  }
  .main-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(260px, 300px);
    gap: 6px;
    padding: 2px 6px;
    height: calc(100dvh - 36px - var(--safe-top) - var(--safe-bottom));
    max-height: calc(100dvh - 36px - var(--safe-top) - var(--safe-bottom));
    overflow: hidden;
  }
  .board-column {
    height: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2px;
    min-width: 0;
    overflow: hidden;
  }
  .direction-indicator {
    display: none;
  }
  .board-container-wrapper {
    height: calc(100% - 24px - 22px);
    max-height: calc(100% - 24px - 22px);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    width: 100%;
  }
  .board-wrapper {
    height: 100%;
    max-height: 100%;
    aspect-ratio: 960 / 640;
    flex: 1;
    min-width: 0;
  }
  #board-svg {
    width: 100%;
    height: 100%;
    max-height: 100%;
    display: block;
  }
  .trays-status-column {
    display: flex !important;
    flex-direction: row !important;
    width: 100% !important;
    max-width: 100% !important;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 1px 0;
    margin: 1px 0 0;
    flex-shrink: 0;
  }
  .player-status-box {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.72rem;
    min-height: 20px;
  }
  .status-player-header {
    font-size: 0.72rem;
    font-weight: bold;
    border-bottom: none;
    padding-bottom: 0;
  }
  .status-metric-line {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 0.68rem;
  }
  .black-status-box .metric-num, .white-status-box .metric-num {
    font-size: 0.72rem;
  }
  .status-column-spacer {
    display: none;
  }
  .feedback-panel {
    height: 22px;
    min-height: 22px;
    max-height: 22px;
    line-height: 20px;
    padding: 1px 6px;
    font-size: 0.72rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
    box-sizing: border-box;
    flex-shrink: 0;
  }
  .sidebar-column {
    height: 100%;
    max-height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 2px 0 0;
    min-width: 0;
  }
  .sidebar-column .panel-dice {
    order: -1;
    padding: 3px 6px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-bottom: 0;
    flex-shrink: 0;
  }
  .panel-dice-header {
    display: none;
  }
  .dice-status-summary {
    display: none;
  }
  .dice-row {
    margin-bottom: 2px;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .die-box {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
  }
  .die-box .die-pips {
    width: 18px;
    height: 18px;
  }
  .die-box .die-lbl {
    font-size: 0.55rem;
  }
  .retained-dice-row {
    font-size: 0.68rem;
    margin-bottom: 2px;
  }
  .controls-toolbar {
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: 100%;
  }
  .controls-toolbar .btn {
    padding: 4px 8px;
    font-size: 0.76rem;
    min-height: 34px;
    width: 100%;
  }
  .controls-toolbar .button-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: 100%;
  }
  .legal-action-chooser {
    max-height: 58px;
    overflow-y: auto;
    padding: 2px 4px;
    gap: 2px;
    margin-bottom: 2px;
    flex-shrink: 1;
  }
  .btn-legal-destination {
    padding: 2px 6px;
    min-height: 30px;
    font-size: 0.70rem;
  }
  .turn-commit-row {
    display: flex;
    flex-direction: row;
    gap: 4px;
    width: 100%;
    margin-top: 2px;
    flex-shrink: 0;
  }
  .turn-commit-row .btn {
    min-height: 34px;
    padding: 4px 6px;
    font-size: 0.78rem;
  }
  .turn-commit-row .btn-undo {
    flex: 1;
  }
  .turn-commit-row .btn-finish {
    flex: 2;
  }
}

/* Match Mode & Vs Computer Panel Styling */
.panel-gamemode {
  border-left: 4px solid #4cc9f0;
}

.panel-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.badge-mode {
  background: rgba(76, 201, 240, 0.2);
  color: #4cc9f0;
  border: 1px solid #4cc9f0;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: bold;
}

.mode-button-group {
  display: flex;
  gap: 8px;
  width: 100%;
}

.btn-mode {
  flex: 1;
  background: #232733;
  color: #a0aec0;
  border: 1px solid #374151;
  padding: 8px 10px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-mode:hover {
  background: #2d3748;
  color: #ffffff;
}

.btn-mode.active {
  background: linear-gradient(135deg, #3182ce, #2b6cb0);
  color: #ffffff;
  border-color: #63b3ed;
  box-shadow: 0 0 10px rgba(66, 153, 225, 0.4);
}

.cpu-settings {
  margin-top: 12px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 6px;
  border: 1px solid #374151;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.setting-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #cbd5e1;
}

.side-selector {
  display: flex;
  gap: 6px;
}

.btn-side {
  flex: 1;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 0.78rem;
  background: #1e293b;
  color: #94a3b8;
  border: 1px solid #475569;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-side:hover {
  background: #334155;
}

.btn-side.active {
  background: #38a169;
  color: #ffffff;
  border-color: #68d391;
  font-weight: bold;
}

.difficulty-dropdown {
  background: #1e293b;
  color: #f1f5f9;
  border: 1px solid #475569;
  padding: 6px 10px;
  border-radius: 5px;
  font-size: 0.82rem;
  cursor: pointer;
}

.difficulty-dropdown:focus {
  outline: none;
  border-color: #4cc9f0;
}

.difficulty-description {
  font-size: 0.75rem;
  color: #94a3b8;
  line-height: 1.35;
  background: rgba(0, 0, 0, 0.2);
  padding: 6px 8px;
  border-radius: 4px;
  border-left: 2px solid #4cc9f0;
}

/* Pulsing Thinking Animation */
@keyframes pulse-thinking {
  0% { opacity: 0.6; transform: scale(0.98); }
  50% { opacity: 1; transform: scale(1.02); }
  100% { opacity: 0.6; transform: scale(0.98); }
}

.cpu-thinking-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(234, 88, 12, 0.25);
  color: #fb923c;
  border: 1px solid #ea580c;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: bold;
  animation: pulse-thinking 1.5s infinite ease-in-out;
}

/* App Menu & Settings Drawer */
.menu-drawer-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: none;
  justify-content: flex-end;
  align-items: stretch;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.menu-drawer-backdrop.open {
  opacity: 1;
  pointer-events: all;
  display: flex;
}

.menu-drawer-content {
  background: #14171d;
  width: 320px;
  max-width: 90vw;
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.6);
  border-left: 1px solid #2e3646;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
}

.menu-drawer-backdrop.open .menu-drawer-content {
  transform: translateX(0);
}

.menu-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: #1a1f29;
  border-bottom: 1px solid #2e3646;
}

.menu-drawer-header h3 {
  margin: 0;
  font-size: 1.05rem;
  color: #e2e8f0;
}

.btn-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 10px;
  min-height: 38px;
  min-width: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.btn-close:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.menu-drawer-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.drawer-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid #242c3b;
  padding-bottom: 14px;
}

.drawer-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.drawer-section h4 {
  margin: 0;
  font-size: 0.85rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.drawer-desc {
  margin: 0;
  font-size: 0.78rem;
  color: #64748b;
  line-height: 1.35;
}

.drawer-btn-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.build-info-card {
  background: #0f1217;
  border: 1px solid #273040;
  border-radius: 6px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.build-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
}

.build-info-label {
  color: #64748b;
}

.build-info-val {
  color: #38bdf8;
  font-family: monospace;
  font-weight: bold;
}

/* ==========================================================================
   BreachGammon Illustrated Rules (v0.2-r2) Styling
   Clean, accessible, responsive design matching authoritative rulebook
   ========================================================================== */

/* Rules Standalone Page */
.rules-page-body {
  background: #f6f3eb;
  color: #142938;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  margin: 0;
  padding: 0;
}

/* Header & Metadata */
.rules-header {
  background: #142938;
  color: #fffdf6;
  padding: 32px 24px;
}

.rules-header-inner {
  max-width: 1000px;
  margin: 0 auto;
}

.rules-version-badge {
  color: #ccd9de;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.rules-main-title {
  font-size: clamp(26px, 4.5vw, 44px);
  line-height: 1.15;
  margin: 6px 0 10px;
  color: #fffdf6;
}

.rules-subtitle {
  color: #ccd9de;
  font-size: 1.05rem;
  margin: 0 0 16px;
}

.rules-header-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.download-rules-btn,
.standalone-rules-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 650;
  font-size: 0.92rem;
  min-height: 44px;
  box-sizing: border-box;
  transition: background 0.15s ease, transform 0.1s ease;
}

.download-rules-btn {
  background: #194d70;
  color: #fffdf6;
}

.download-rules-btn:hover {
  background: #123852;
  color: #ffffff;
}

.standalone-rules-btn {
  background: #e1ece5;
  color: #142938;
}

.standalone-rules-btn:hover {
  background: #cdded4;
  color: #0c1a24;
}

/* Guide Navigation */
.rules-guide-nav {
  display: flex;
  gap: 10px;
  padding: 16px 24px;
  flex-wrap: wrap;
  background: #ece8de;
  border-bottom: 1px solid #ccd6d1;
  position: sticky;
  top: 0;
  z-index: 20;
}

.rules-modal-card .rules-guide-nav {
  position: sticky;
  top: 0;
  background: #ece8de;
}

.guide-nav-btn {
  background: #e1ece5;
  color: #194d70;
  padding: 8px 14px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.92rem;
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  border: 1px solid rgba(25, 77, 112, 0.15);
  min-height: 44px;
  justify-content: center;
  transition: all 0.15s ease;
}

.guide-nav-btn:hover {
  background: #194d70;
  color: #fffdf6;
}

.guide-nav-hint {
  font-size: 0.72rem;
  font-weight: normal;
  opacity: 0.85;
}

.guide-nav-btn:hover .guide-nav-hint {
  color: #ccd9de;
}

/* Rules Content Body */
.rules-content-body {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 24px 50px;
}

.rules-guide {
  padding-top: 24px;
}

.rules-guide-title {
  font-size: clamp(24px, 4vw, 34px);
  color: #142938;
  line-height: 1.2;
  margin: 12px 0 4px;
}

.rules-guide-sub {
  color: #526573;
  font-size: 1rem;
  margin: 0 0 16px;
  font-weight: 500;
}

.rules-section {
  padding: 26px 0;
  border-top: 1px solid #ccd6d1;
  scroll-margin-top: 80px;
}

.rules-section-title {
  font-size: clamp(20px, 3.2vw, 26px);
  color: #142938;
  line-height: 1.25;
  margin: 6px 0 4px;
}

.rules-section-sub {
  color: #526573;
  font-size: 0.94rem;
  margin: 0 0 14px;
}

.rules-h4 {
  font-size: 1.12rem;
  color: #142938;
  margin: 22px 0 8px;
  font-weight: 700;
}

.rules-p {
  max-width: 78ch;
  margin: 10px 0 16px;
  color: #142938;
  font-size: 0.95rem;
  line-height: 1.65;
}

/* Figures & Illustration Layout */
.figrow {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  margin: 20px 0;
}

.figrow.figrow-single {
  grid-template-columns: 1fr;
}

.rules-figure {
  margin: 0;
  max-width: 420px;
  width: 100%;
}

.figrow.figrow-single .rules-figure {
  margin: 0 auto;
}

.rules-figure-img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  background: #f5f2eb;
  box-shadow: 0 2px 8px rgba(20, 41, 56, 0.08);
}

.rules-figcaption {
  font-size: 0.86rem;
  padding: 8px 3px;
  color: #142938;
  line-height: 1.45;
}

.rules-figcaption b {
  color: #142938;
}

/* Callout Note */
.note {
  background: #e1ece5;
  border-left: 4px solid #177665;
  border-radius: 6px;
  padding: 13px 17px;
  margin: 20px 0;
  color: #142938;
  font-size: 0.92rem;
  line-height: 1.55;
  max-width: 78ch;
}

.rules-section-footer {
  margin-top: 14px;
  text-align: right;
}

.rules-back-link {
  color: #194d70;
  font-size: 0.86rem;
  font-weight: 650;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 4px;
  display: inline-block;
  min-height: 36px;
  line-height: 24px;
}

.rules-back-link:hover {
  text-decoration: underline;
  background: #e1ece5;
}

.rules-footer {
  color: #526573;
  text-align: center;
  padding: 24px 20px;
  font-size: 0.82rem;
  border-top: 1px solid #ccd6d1;
  max-width: 1000px;
  margin: 0 auto;
}

/* In-game Modal Specific Overrides */
.rules-modal-card {
  max-width: 960px;
  width: 96vw;
  max-height: 92vh;
  max-height: 92dvh;
  background: #f6f3eb;
  color: #142938;
  display: flex;
  flex-direction: column;
}

.rules-modal-header {
  background: #142938;
  color: #fffdf6;
  border-bottom: 1px solid #ccd6d1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  flex-shrink: 0;
}

.rules-modal-header-info {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.rules-modal-header-info h2 {
  font-size: 1.1rem;
  margin: 0;
  color: #fffdf6;
}

.rules-modal-version-tag {
  color: #ccd9de;
  font-size: 0.76rem;
  font-weight: 600;
}

.rules-modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rules-modal-header-actions .btn {
  padding: 6px 10px;
  font-size: 0.8rem;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
}

.rules-modal-body {
  padding: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #f6f3eb;
  color: #142938;
}

.rules-modal-body .rules-guide-nav {
  padding: 12px 18px;
}

.rules-modal-body .rules-content-body {
  padding: 0 18px 40px;
}

/* Mobile Responsiveness for Rules */
@media (max-width: 600px) {
  .rules-header {
    padding: 20px 16px;
  }
  .rules-guide-nav {
    padding: 10px 14px;
    gap: 6px;
  }
  .guide-nav-btn {
    flex: 1 1 100%;
    min-height: 48px;
  }
  .rules-content-body {
    padding: 0 14px 30px;
  }
  .figrow {
    grid-template-columns: 1fr;
    gap: 18px;
  }
  .rules-figure {
    max-width: 100%;
    margin: 0 auto;
  }
  .rules-section {
    padding: 20px 0;
  }
  .rules-section-footer {
    text-align: center;
  }
  .rules-modal-card {
    width: 98vw;
    max-height: 95vh;
    max-height: 95dvh;
  }
  .rules-modal-header {
    padding: 10px 12px;
  }
  .rules-modal-header-info h2 {
    font-size: 0.95rem;
  }
  .rules-modal-header-actions .btn {
    padding: 4px 8px;
    font-size: 0.74rem;
  }
}

/* Print Optimization */
@media print {
  .rules-guide-nav,
  .rules-header-actions,
  .rules-section-footer,
  .rules-modal-header {
    display: none !important;
  }
  .rules-page-body,
  .rules-modal-body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .rules-section {
    break-before: page;
  }
  .rules-figure {
    break-inside: avoid;
  }
  .figrow {
    grid-template-columns: 1fr 1fr;
  }
}

/* --- External Playtest, Feedback Dialog & Move History Modal --- */
.badge-playtest {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: #ffffff;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: inline-flex;
  align-items: center;
}

.badge-dev {
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: #ffffff;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: inline-flex;
  align-items: center;
}

.turn-status-instruction {
  display: flex;
  align-items: center;
  gap: 6px;
}

.instruction-badge {
  background: #1e293b;
  color: #38bdf8;
  border: 1px solid #0284c7;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.btn-feedback {
  background: #0369a1;
  color: #ffffff;
  border: 1px solid #38bdf8;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-feedback:hover {
  background: #0284c7;
  border-color: #7dd3fc;
}

.winner-banner-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  margin-top: 14px;
  flex-wrap: wrap;
  pointer-events: auto;
}

.winner-banner-actions .btn {
  pointer-events: auto;
  cursor: pointer;
  position: relative;
  z-index: 101;
}

/* Feedback Modal */
.feedback-modal-card {
  width: 92%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.feedback-modal-body {
  padding: 16px 20px;
}

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: #e2e8f0;
}

.form-label .required {
  color: #ef4444;
}

.form-label .optional {
  color: var(--text-muted);
  font-weight: normal;
  font-size: 0.75rem;
}

.form-input,
.form-textarea {
  width: 100%;
  background: #14171d;
  border: 1px solid var(--surface-border);
  color: #f8fafc;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  box-sizing: border-box;
}

.form-input:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.form-textarea {
  resize: vertical;
  min-height: 85px;
}

.feedback-auto-include-note {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: #94a3b8;
  background: rgba(56, 189, 248, 0.08);
  border-left: 3px solid #0284c7;
  padding: 8px 12px;
  border-radius: 4px;
  margin-bottom: 16px;
}

.feedback-status-msg {
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  margin-bottom: 14px;
  line-height: 1.4;
}

.feedback-status-msg.sending {
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid #3b82f6;
  color: #60a5fa;
}

.feedback-status-msg.success {
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid #22c55e;
  color: #4ade80;
}

.feedback-success-header {
  font-weight: 700;
  font-size: 0.92rem;
  margin-bottom: 6px;
}

.feedback-ref-badge {
  display: inline-block;
  margin: 6px 0;
  padding: 5px 10px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 6px;
  font-size: 0.82rem;
  color: #e2e8f0;
}

.feedback-ref-badge code {
  color: #38bdf8;
  font-weight: 700;
  font-family: monospace;
  font-size: 0.9rem;
}

.feedback-success-note {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-top: 4px;
}

.feedback-status-msg.error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid #ef4444;
  color: #f87171;
}

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

/* Readable Move History Modal */
.move-history-modal-card {
  width: 92%;
  max-width: 520px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.move-history-body {
  padding: 16px 20px;
  overflow-y: auto;
  max-height: 60vh;
}

.readable-history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.readable-history-item {
  background: #181b21;
  border-left: 3px solid #4a5568;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 0.85rem;
  line-height: 1.4;
}

.readable-history-item.white-turn {
  border-left-color: #f8f9fa;
}

.readable-history-item.black-turn {
  border-left-color: #3b82f6;
}

.readable-history-header {
  font-weight: 700;
  font-size: 0.8rem;
  color: #94a3b8;
  margin-bottom: 2px;
}

.readable-history-text {
  color: #e2e8f0;
}



