* {
  box-sizing: border-box;
}

:root {
  --page-bg: #eeeeee;
  --text-color: #222222;
  --panel-bg: #ffffff;
  --panel-border: #d4d4d4;
  --muted-text: #666666;
  --button-bg: #333333;
  --button-hover: #111111;
  --button-text: #ffffff;
  --input-bg: #ffffff;
  --input-border: #cfcfcf;
  --status-bg: #ffffff;
  --status-text: #1f2937;
  --status-border: #cccccc;
  --board-size: min(86vw, 480px);
  --square-size: calc(var(--board-size) / 8);
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --selected-square: #2563eb;
  --legal-move: rgba(37, 99, 235, 0.42);
  --legal-capture: rgba(185, 28, 28, 0.65);
  --last-move: rgba(234, 179, 8, 0.65);
  --check-square: #ef4444;
  --board-border: rgba(15, 23, 42, 0.32);
  --board-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
  --coordinate-text: rgba(52, 41, 32, 0.96);
  --coordinate-shadow: 0 1px 1px rgba(255, 255, 255, 0.82);
  --annotation-color: rgba(249, 115, 22, 0.68);
  --analysis-arrow: #57c84d;
  --analysis-circle: #57c84d;
  --white-piece: #f3f1eb;
  --black-piece: #182235;
  --piece-outline: rgba(0, 0, 0, 0.74);
  --white-piece-stroke: rgba(0, 0, 0, 0.9);
  --black-piece-stroke: rgba(255, 255, 255, 0.12);
  --white-piece-shadow:
    0 1px 0 rgba(0, 0, 0, 0.66),
    0 1px 1px rgba(0, 0, 0, 0.36);
  --black-piece-shadow:
    0 1px 0 rgba(255, 255, 255, 0.18),
    0 1px 1px rgba(0, 0, 0, 0.22);
  --promotion-bg: rgba(255, 255, 255, 0.96);
  --promotion-border: rgba(15, 23, 42, 0.26);
  --promotion-choice-bg: #f8fafc;
  --promotion-choice-border: rgba(15, 23, 42, 0.18);
  --promotion-choice-hover: #ffffff;
  --promotion-choice-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.68),
    0 2px 8px rgba(15, 23, 42, 0.14);
}

body.dark-theme {
  --page-bg: #141414;
  --text-color: #f2f2f2;
  --panel-bg: #1f1f1f;
  --panel-border: #3a3a3a;
  --muted-text: #cfcfcf;
  --button-bg: #2a2a2a;
  --button-hover: #333333;
  --button-text: #f2f2f2;
  --input-bg: #2a2a2a;
  --input-border: #3a3a3a;
  --status-bg: #262626;
  --status-text: #f5f5f5;
  --status-border: #3a3a3a;
  --white-piece: #f3f1eb;
  --black-piece: #182235;
  --board-border: rgba(255, 255, 255, 0.14);
  --board-shadow: 0 12px 32px rgba(0, 0, 0, 0.46);
  --coordinate-text: rgba(245, 245, 245, 0.88);
  --coordinate-shadow: 0 1px 2px rgba(0, 0, 0, 0.72);
  --analysis-arrow: #57c84d;
  --analysis-circle: #57c84d;
  --piece-outline: rgba(255, 255, 255, 0.62);
  --white-piece-stroke: rgba(0, 0, 0, 0.9);
  --black-piece-stroke: rgba(255, 255, 255, 0.12);
  --white-piece-shadow:
    0 1px 0 rgba(0, 0, 0, 0.66),
    0 1px 1px rgba(0, 0, 0, 0.36);
  --black-piece-shadow:
    0 1px 0 rgba(255, 255, 255, 0.18),
    0 1px 1px rgba(0, 0, 0, 0.22);
  --promotion-bg: rgba(31, 31, 31, 0.96);
  --promotion-border: rgba(255, 255, 255, 0.18);
  --promotion-choice-bg: rgba(255, 255, 255, 0.88);
  --promotion-choice-border: rgba(255, 255, 255, 0.22);
  --promotion-choice-hover: rgba(255, 255, 255, 0.98);
  --promotion-choice-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.5),
    0 3px 10px rgba(0, 0, 0, 0.34);
  --custom-background-image: none;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-family: Arial, sans-serif;
  background: var(--page-bg);
  color: var(--text-color);
  overscroll-behavior: contain;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

main {
  position: relative;
  z-index: 2;
  width: min(98vw, 1120px);
  text-align: center;
}

#drag-layer {
  position: fixed;
  inset: 0;
  z-index: 2147483600;
  pointer-events: none;
  overflow: visible;
  contain: layout style;
}

h1 {
  margin: 0 0 8px;
}

#status {
  width: fit-content;
  min-width: 160px;
  margin: 0 auto 8px;
  padding: 6px 12px;
  border: 1px solid var(--status-border);
  border-radius: 4px;
  background: var(--status-bg);
  color: var(--status-text);
  font-weight: bold;
}

#status.white-turn {
  border-color: #94a3b8;
  background: #f8fafc;
  color: #111827;
}

#status.black-turn {
  border-color: #3f3f46;
  background: #27272a;
  color: #ffffff;
}

#status.danger {
  border-color: #b91c1c;
  background: #fee2e2;
  color: #7f1d1d;
}

#status.neutral {
  border-color: #64748b;
  background: #f1f5f9;
  color: #334155;
}

#status.warning {
  border-color: #d97706;
  background: #fef3c7;
  color: #92400e;
}

body.dark-theme #status.white-turn {
  border-color: #3a3a3a;
  background: #242424;
  color: #f2f2f2;
}

body.dark-theme #status.black-turn {
  border-color: #3a3a3a;
  background: #202020;
  color: #f2f2f2;
}

body.dark-theme #status.danger {
  border-color: #7f1d1d;
  background: #3b1111;
  color: #fecaca;
}

body.dark-theme #status.neutral {
  border-color: #3a3a3a;
  background: #242424;
  color: #e5e5e5;
}

body.dark-theme #status.warning {
  border-color: #92400e;
  background: #3a240b;
  color: #fed7aa;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(320px, 506px) 34px minmax(220px, 280px);
  gap: 10px;
  align-items: start;
  justify-content: center;
}

.author-credit {
  width: fit-content;
  max-width: calc(100vw - 24px);
  margin: 7px auto 0;
  padding: 2px 8px;
  border-radius: 999px;
  color: color-mix(in srgb, var(--muted-text) 88%, var(--text-color));
  background: color-mix(in srgb, var(--panel-bg) 72%, transparent);
  font-size: 12px;
  line-height: 1.3;
  text-align: center;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
}

body.has-custom-background .author-credit {
  background: color-mix(in srgb, var(--panel-bg) 80%, transparent);
  text-shadow: 0 1px 2px color-mix(in srgb, var(--panel-bg) 70%, transparent);
}

body.embed-mode {
  --board-size: min(54vh, 450px, calc(100vw - 28px));
  --square-size: calc(var(--board-size) / 8);
  display: block;
  min-height: 0;
  height: 100vh;
  padding: 5px 8px 7px;
  place-items: initial;
  overflow: hidden;
  overscroll-behavior: none;
}

body.embed-mode main {
  width: min(100%, calc(var(--board-size) + 26px));
  margin: 0 auto;
}

body.embed-mode #appTitle,
body.embed-mode .left-panel {
  display: none;
}

body.embed-mode #status {
  margin-bottom: 4px;
  padding: 5px 10px;
  font-size: 12.5px;
}

body.embed-mode .game-layout {
  grid-template-columns: 1fr;
  grid-template-areas:
    "settings"
    "board"
    "controls";
  gap: 5px;
  justify-content: center;
  justify-items: center;
  align-items: start;
}

body.embed-mode .board-area {
  grid-area: board;
  grid-column: 1;
  width: min(100%, calc(var(--board-size) + 22px));
  justify-self: center;
}

body.embed-mode .settings-popover-anchor {
  grid-area: settings;
  width: 34px;
  justify-self: center;
  align-self: start;
  margin-top: 0;
}

body.embed-mode .settings-popover-panel {
  left: auto;
  right: 0;
  transform: none;
}

body.embed-mode .settings-popover-panel .board-theme-panel,
body.embed-mode .custom-background-panel {
  left: auto;
  right: 0;
  transform: none;
}

body.embed-mode .side-panel {
  grid-area: controls;
  width: min(100%, calc(var(--board-size) + 22px));
  gap: 5px;
  justify-self: center;
}

body.embed-mode .mode-panel {
  grid-template-columns: 1fr;
  align-items: end;
  gap: 5px;
  padding: 7px;
}

body.embed-mode .mode-panel label {
  gap: 3px;
  font-size: 12.5px;
}

body.embed-mode .mode-panel select {
  min-height: 32px;
  padding: 5px 7px;
  font-size: 12.5px;
}

body.embed-mode .mode-panel button {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 12.5px;
}

body.embed-mode #applySettingsButton {
  align-self: end;
}

body.embed-mode .controls {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}

body.embed-mode .controls button,
body.embed-mode .board-theme-anchor > button {
  min-height: 32px;
  padding: 5px 5px;
  font-size: 12px;
}

body.embed-mode .icon-control-button {
  min-height: 34px;
  padding: 5px 4px;
}

body.embed-mode .toolbar-icon-button,
body.embed-mode .board-theme-anchor > .toolbar-icon-button {
  min-height: 32px;
}

body.embed-mode .online-board-player {
  min-height: 23px;
  padding: 3px 8px;
  font-size: 12px;
}

body.embed-mode .online-board-player__clock {
  font-size: 14px;
}

body.embed-mode .author-credit {
  display: none;
}

.embed-full-version-link {
  display: none;
}

body.embed-mode .embed-full-version-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: center;
  min-height: 25px;
  padding: 3px 9px;
  border: 1px solid rgba(15, 23, 42, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  color: #1f2937;
  font-size: 11px;
  font-weight: 740;
  line-height: 1.1;
  text-decoration: none;
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.42);
}

body.embed-mode .embed-full-version-link.hidden {
  display: none;
}

body.embed-mode .embed-full-version-link:hover {
  border-color: rgba(15, 23, 42, 0.28);
  background: rgba(255, 255, 255, 0.94);
  color: #111827;
}

body.embed-mode .embed-full-version-link:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--selected-square) 70%, white);
  outline-offset: 2px;
}

body.dark-theme.embed-mode .embed-full-version-link {
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.12);
  color: #f8fafc;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

body.dark-theme.embed-mode .embed-full-version-link:hover {
  border-color: rgba(255, 255, 255, 0.36);
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

html.dragging-piece,
body.dragging-piece,
html.dragging-piece body,
body.embed-mode.dragging-piece {
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
}

@media (min-width: 900px) {
  body.embed-mode {
    --board-size: clamp(520px, 52vw, 620px);
  }

  body.embed-mode main {
    width: min(100%, calc(var(--board-size) + 306px));
  }

  body.embed-mode .game-layout {
    grid-template-columns: minmax(0, calc(var(--board-size) + 22px)) 34px minmax(208px, 230px);
    grid-template-areas: "board settings controls";
    gap: 8px;
    justify-items: stretch;
  }

  body.embed-mode .board-area,
  body.embed-mode .side-panel {
    width: 100%;
  }

  body.embed-mode .settings-popover-anchor {
    justify-self: end;
    margin-top: 28px;
  }

  body.embed-mode .side-panel {
    align-self: start;
    justify-self: stretch;
  }

  body.embed-mode .mode-panel {
    grid-template-columns: 1fr;
  }

  body.embed-mode .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.board-area {
  position: relative;
  justify-self: center;
}

.app-title {
  display: block;
  width: 100%;
  max-width: calc(100vw - 24px);
  margin: 0 auto 4px;
  text-align: center;
  overflow: visible;
  font-size: clamp(25px, 3.35vw, 36px);
  line-height: 1.04;
  letter-spacing: 0;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(255, 255, 255, 0.28);
}

#appTitle.app-title {
  max-width: calc(100vw - 24px);
  overflow: visible;
  white-space: nowrap;
}

body.dark-theme #appTitle.app-title {
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.48);
}

body.has-custom-background:not(.dark-theme) #appTitle.app-title {
  -webkit-text-stroke: 0.55px rgba(255, 255, 255, 0.68);
  text-shadow:
    0 2px 8px rgba(255, 255, 255, 0.56),
    0 1px 2px rgba(0, 0, 0, 0.22);
}

body.has-custom-background.dark-theme #appTitle.app-title {
  -webkit-text-stroke: 0.55px rgba(0, 0, 0, 0.58);
  text-shadow:
    0 2px 8px rgba(0, 0, 0, 0.64),
    0 1px 2px rgba(0, 0, 0, 0.5);
}

body:not(.dark-theme) .rank-coordinates,
body:not(.dark-theme) .file-coordinates {
  color: rgba(52, 41, 32, 0.96);
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.82);
}

@media (max-width: 900px) {
  #appTitle.app-title {
    font-size: clamp(24px, 4.4vw, 36px);
  }
}

@media (max-width: 600px) {
  #appTitle.app-title {
    font-size: clamp(22px, 5vw, 28px);
  }
}

@media (max-width: 430px) {
  #appTitle.app-title {
    font-size: clamp(22px, 5vw, 23px);
  }
}

@media (max-width: 390px) {
  #appTitle.app-title {
    font-size: clamp(20px, 5vw, 22px);
  }
}

.left-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
  align-self: start;
  margin-top: -64px;
}

.game-over-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.48);
  z-index: 20;
}

.game-over-overlay.hidden {
  display: none;
}

.game-over-card {
  width: min(86%, 320px);
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--text-color);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.28);
}

.game-over-title {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 6px;
}

.game-over-reason {
  color: var(--muted-text);
  font-weight: 700;
  margin-bottom: 14px;
}

.game-over-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.replay-panel {
  width: 100%;
  min-height: 120px;
  max-height: 150px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--text-color);
  font-weight: 700;
  text-align: center;
}

.history-slot-panel {
  width: 100%;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
}

.history-slot-panel.hidden {
  display: none;
}

.game-history-button {
  width: 100%;
  min-height: 96px;
  display: grid;
  gap: 7px;
  place-items: center;
  padding: 15px 13px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--text-color);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
  font-family: inherit;
  text-align: center;
}

.game-history-button:hover {
  border-color: var(--button-bg);
  background: var(--status-bg);
}

.game-history-button span:first-child {
  font-size: 20px;
  font-weight: 730;
  letter-spacing: -0.015em;
  line-height: 1.15;
}

.game-history-button span:last-child {
  color: var(--muted-text);
  font-size: 14px;
  font-weight: 520;
  line-height: 1.3;
}

.game-history-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.52);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
}

.game-history-modal.hidden {
  display: none;
}

.game-history-modal__card {
  width: min(92vw, 620px);
  max-height: min(78vh, 680px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: var(--panel-bg);
  color: var(--text-color);
  box-shadow: 0 24px 54px rgba(0, 0, 0, 0.28);
  text-align: left;
  transform: translateY(32px);
}

.game-history-modal__header {
  display: grid;
  place-items: center;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--panel-border);
}

.game-history-modal__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 4px;
  border-top: 1px solid var(--panel-border);
}

.game-history-modal__header h2 {
  margin: 0;
  font-size: 27px;
  font-weight: 780;
  letter-spacing: -0.02em;
  line-height: 1.12;
  text-align: center;
}

.online-room-modal,
.online-time-edit-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.52);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
}

.online-room-modal.hidden,
.online-time-edit-modal.hidden,
.online-only.hidden,
.controls > .hidden {
  display: none;
}

.online-room-modal__card,
.online-time-edit-modal__card {
  width: min(92vw, 440px);
  max-height: min(82vh, 620px);
  overflow-y: auto;
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: var(--panel-bg);
  color: var(--text-color);
  box-shadow: 0 24px 54px rgba(0, 0, 0, 0.28);
  text-align: left;
}

.online-room-modal__header,
.online-time-edit-modal__header {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 36px;
  align-items: center;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--panel-border);
}

.online-room-modal__header h2,
.online-time-edit-modal__header h2 {
  grid-column: 2;
  margin: 0;
  font-size: 25px;
  font-weight: 780;
  line-height: 1.12;
  text-align: center;
}

.online-room-modal__x {
  grid-column: 3;
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 999px;
  font-size: 24px;
  line-height: 1;
}

.online-time-edit-modal {
  z-index: 110;
}

.online-time-edit-modal__card {
  width: min(92vw, 420px);
  gap: 12px;
}

.online-time-edit-current {
  margin: 0;
  color: var(--muted-text);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
}

.online-room-info {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--status-bg);
}

.online-room-code-section {
  display: grid;
  gap: 7px;
  padding-bottom: 4px;
}

.online-room-code-label {
  color: var(--muted-text);
  font-size: 13px;
  font-weight: 760;
  line-height: 1.2;
}

.online-room-code-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--button-bg) 34%, var(--panel-border));
  border-radius: 8px;
  background: color-mix(in srgb, var(--button-bg) 10%, var(--panel-bg));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.32), 0 8px 18px rgba(15, 23, 42, 0.10);
}

.online-room-code-value {
  min-width: 0;
  color: var(--text-color);
  font-family: "Segoe UI Mono", "Roboto Mono", Consolas, monospace;
  font-size: clamp(28px, 8vw, 38px);
  font-variant-numeric: tabular-nums;
  font-weight: 820;
  letter-spacing: 0.08em;
  line-height: 1;
  text-align: center;
}

.online-room-code-copy {
  width: 44px;
  height: 44px;
  min-width: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--button-bg) 42%, var(--panel-border));
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--text-color);
  font-size: 20px;
  line-height: 1;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.10);
}

.online-room-code-copy:hover {
  background: var(--button-bg);
  color: var(--button-text);
}

.online-room-info__row {
  display: grid;
  grid-template-columns: minmax(98px, auto) minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  min-width: 0;
}

.online-room-info__row span {
  color: var(--muted-text);
  font-weight: 680;
}

.online-room-info__row strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 760;
}

.online-room-time-current {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.online-room-time-current button {
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 13px;
  line-height: 1;
}

.online-room-time-current button.hidden {
  display: none;
}

.online-room-time-current button.online-room-time-edit--active:not(:disabled) {
  border-color: color-mix(in srgb, var(--button-bg) 46%, var(--panel-border));
  background: color-mix(in srgb, var(--button-bg) 8%, var(--panel-bg));
}

.online-room-seat-swap {
  justify-self: center;
  width: 36px;
  height: 32px;
  min-width: 36px;
  min-height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-size: 19px;
  line-height: 1;
}

.online-room-seat-swap.hidden {
  display: none;
}

.online-room-main-info {
  min-width: 0;
  display: grid;
  gap: 10px;
  padding: 0;
  border: 0;
  background: transparent;
}

.online-room-time-control-panel,
.online-room-custom-panel,
.online-time-proposal-panel {
  display: grid;
  gap: 7px;
  padding: 9px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--status-bg) 88%, var(--panel-bg));
}

.online-room-time-control-panel.hidden,
.online-room-custom-panel.hidden,
.online-time-proposal-panel.hidden,
.online-time-proposal-actions.hidden,
.online-room-time-control-note.hidden {
  display: none;
}

.online-room-custom-panel {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}

.online-room-custom-panel__title {
  grid-column: 1 / -1;
  color: var(--muted-text);
  font-size: 12px;
  font-weight: 780;
  line-height: 1.2;
}

.online-room-time-control-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
}

.online-room-time-control-actions {
  display: grid;
  grid-template-columns: auto auto;
  gap: 7px;
}

.online-room-time-control-head span,
.online-time-proposal-panel strong {
  min-width: 0;
  color: var(--muted-text);
  font-size: 12px;
  font-weight: 760;
  line-height: 1.2;
}

.online-room-time-control-head button,
.online-room-time-control-actions button {
  min-height: 34px;
  padding: 7px 9px;
  border-radius: 7px;
  font-size: 13px;
  line-height: 1;
}

.online-room-time-control-head button:disabled,
.online-room-time-control-actions button:disabled,
.online-time-edit-modal__actions button:disabled,
.online-time-proposal-actions button:disabled {
  border-color: color-mix(in srgb, var(--panel-border) 78%, transparent);
  background: color-mix(in srgb, var(--status-bg) 86%, var(--panel-bg));
  color: var(--muted-text);
  opacity: 0.72;
  cursor: not-allowed;
  box-shadow: none;
}

.online-room-time-apply--changed:not(:disabled) {
  border-color: color-mix(in srgb, var(--button-bg) 62%, var(--panel-border));
  box-shadow: 0 5px 14px rgba(37, 99, 235, 0.18);
}

.online-room-time-control-note,
.online-time-proposal-panel span {
  margin: 0;
  color: var(--muted-text);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.3;
}

.online-time-proposal-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.online-time-proposal-actions button {
  min-height: 36px;
  padding: 7px 9px;
  border-radius: 7px;
}

@media (min-width: 681px) {
  .online-time-proposal-panel {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .online-time-proposal-panel strong {
    grid-column: 1 / -1;
  }

  .online-time-proposal-actions {
    grid-column: 2;
    grid-row: 2 / span 2;
    min-width: 176px;
    align-self: center;
  }
}

.online-room-modal__actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--panel-border);
}

.online-room-modal__actions button {
  min-width: 0;
  min-height: 44px;
  padding-inline: 10px;
}

.online-time-edit-modal__actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding-top: 2px;
}

.online-time-edit-modal__actions button {
  min-height: 38px;
  padding: 8px 10px;
}

@media (max-width: 380px) {
  .online-room-modal__actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .online-room-modal {
    padding: 12px;
  }

  .online-room-modal__card {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 24px);
    padding: 14px;
  }

  .online-room-code-section {
    grid-template-columns: 1fr;
  }

  .online-room-code-label {
    text-align: left;
  }

  .online-room-modal__actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .online-room-modal__actions button {
    min-height: 40px;
    padding-inline: 10px;
  }
}

@media (max-width: 380px) {
  .online-room-modal__actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.game-history-profile-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 12px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--status-bg);
}

.game-history-profile-field {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted-text);
  font-size: 12px;
  font-weight: 680;
  letter-spacing: 0.01em;
}

.game-history-profile-field select {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 8px 34px 8px 10px;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted-text) 50%),
    linear-gradient(135deg, var(--muted-text) 50%, transparent 50%),
    var(--input-bg);
  background-position:
    calc(100% - 17px) 16px,
    calc(100% - 12px) 16px,
    0 0;
  background-size:
    5px 5px,
    5px 5px,
    100% 100%;
  background-repeat: no-repeat;
  color: var(--text-color);
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.2;
  appearance: none;
  cursor: pointer;
}

.game-history-profile-field select:hover,
.game-history-profile-field select:focus {
  border-color: var(--button-bg);
  outline: none;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.16);
}

.game-history-profile-field select option {
  background: var(--input-bg);
  color: var(--text-color);
}

#addProfileButton,
#renameProfileButton,
#deleteProfileButton {
  height: 38px;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 680;
  line-height: 1;
  white-space: nowrap;
}

#deleteProfileButton {
  border-color: rgba(185, 28, 28, 0.42);
}

.game-history-list {
  min-height: 120px;
  overflow: auto;
  display: grid;
  gap: 10px;
  padding-right: 2px;
}

.game-history-empty {
  min-height: 120px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--panel-border);
  border-radius: 8px;
  color: var(--muted-text);
  font-weight: 700;
  text-align: center;
}

.game-history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 13px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--status-bg);
}

.game-history-item__date {
  font-weight: 730;
  margin-bottom: 5px;
  font-size: 15.5px;
  letter-spacing: -0.01em;
  line-height: 1.22;
}

.game-history-item__summary {
  color: var(--muted-text);
  font-size: 13.5px;
  font-weight: 560;
  line-height: 1.35;
}

.game-history-item__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  white-space: nowrap;
}

.game-history-item__actions button {
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 680;
  line-height: 1;
}

.replay-panel.hidden {
  display: none;
}

.board-frame {
  display: grid;
  grid-template-columns: 18px var(--board-size);
  grid-template-rows: var(--board-size) 18px;
  column-gap: 2px;
  row-gap: 2px;
  justify-content: center;
  align-items: center;
}

.online-board-player {
  width: var(--board-size);
  max-width: 100%;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--text-color);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.15;
  overflow: hidden;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
}

.online-board-player__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.online-board-player__meta {
  flex: 0 0 auto;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.online-player-material {
  flex: 0 1 auto;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: color-mix(in srgb, var(--text-color) 88%, transparent);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.online-player-material--behind {
  color: color-mix(in srgb, var(--muted-text) 88%, transparent);
}

.online-player-material-score {
  font-variant-numeric: tabular-nums;
}

.online-player-material-pieces {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 1px;
  overflow: hidden;
}

.online-player-material-piece {
  width: 16px;
  height: 16px;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2));
}

.online-board-player__clock {
  flex: 0 0 auto;
  font-family: "Segoe UI Mono", "Roboto Mono", Consolas, monospace;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.online-board-player--active {
  border-color: color-mix(in srgb, var(--button-bg) 58%, rgba(148, 163, 184, 0.28));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--button-bg) 30%, transparent), 0 6px 16px rgba(15, 23, 42, 0.08);
}

.online-board-player--low-time .online-board-player__clock {
  color: #b91c1c;
}

.online-board-player.hidden {
  display: none;
}

.online-board-player--top {
  margin-bottom: 6px;
}

.online-board-player--bottom {
  margin-top: 6px;
}

body.dark-theme .online-board-player {
  background: rgba(15, 23, 42, 0.72);
  border-color: rgba(148, 163, 184, 0.24);
}

body.dark-theme .online-player-material {
  color: rgba(226, 232, 240, 0.9);
}

body.dark-theme .online-player-material--behind {
  color: rgba(203, 213, 225, 0.72);
}

body.dark-theme .online-room-modal__card,
body.dark-theme .online-time-edit-modal__card {
  border-color: rgba(148, 163, 184, 0.34);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.48);
}

body.dark-theme .online-time-edit-current {
  color: rgba(226, 232, 240, 0.74);
}

body.dark-theme .online-room-info,
body.dark-theme .online-room-time-control-panel,
body.dark-theme .online-room-custom-panel,
body.dark-theme .online-time-proposal-panel {
  border-color: rgba(148, 163, 184, 0.26);
  background: rgba(15, 23, 42, 0.66);
}

body.dark-theme .online-room-main-info {
  border-color: transparent;
  background: transparent;
}

body.dark-theme .online-room-code-card {
  border-color: rgba(148, 163, 184, 0.30);
  background: rgba(30, 41, 59, 0.72);
}

body.dark-theme .online-time-field select {
  border-color: rgba(96, 165, 250, 0.46);
  background: rgba(15, 23, 42, 0.94);
  color: #f8fafc;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.14);
}

body.dark-theme .online-time-field select:focus {
  border-color: rgba(147, 197, 253, 0.86);
  outline: 2px solid rgba(59, 130, 246, 0.34);
  outline-offset: 2px;
}

body.dark-theme .online-time-slider input[type="range"] {
  accent-color: #60a5fa;
}

body.dark-theme .online-time-slider input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(71, 85, 105, 0.95);
}

body.dark-theme .online-time-slider input[type="range"]::-webkit-slider-thumb {
  width: 20px;
  height: 20px;
  margin-top: -6px;
  border: 2px solid #dbeafe;
  border-radius: 999px;
  background: #60a5fa;
  box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.18);
}

body.dark-theme .online-time-slider input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(71, 85, 105, 0.95);
}

body.dark-theme .online-time-slider input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 2px solid #dbeafe;
  border-radius: 999px;
  background: #60a5fa;
  box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.18);
}

body.dark-theme .online-room-time-control-head button:not(:disabled),
body.dark-theme .online-room-time-control-actions button:not(:disabled),
body.dark-theme .online-time-edit-modal__actions button:not(:disabled),
body.dark-theme .online-time-proposal-actions button:not(:disabled) {
  border-color: rgba(96, 165, 250, 0.52);
  background: #2563eb;
  color: #f8fafc;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.34);
}

body.dark-theme .online-room-time-current button:not(:disabled) {
  border-color: rgba(148, 163, 184, 0.34);
  background: rgba(30, 41, 59, 0.82);
  color: #e2e8f0;
  box-shadow: none;
}

body.dark-theme .online-room-time-current button.online-room-time-edit--active:not(:disabled) {
  border-color: rgba(96, 165, 250, 0.42);
  background: rgba(30, 64, 115, 0.46);
}

body.dark-theme .online-room-time-control-head button:disabled,
body.dark-theme .online-room-time-control-actions button:disabled,
body.dark-theme .online-time-edit-modal__actions button:disabled,
body.dark-theme .online-time-proposal-actions button:disabled {
  border-color: rgba(100, 116, 139, 0.44);
  background: rgba(51, 65, 85, 0.64);
  color: rgba(226, 232, 240, 0.68);
  opacity: 1;
}

.online-draw-offer-panel,
.online-rematch-offer-panel {
  width: 100%;
  max-width: 100%;
  padding: 10px;
  border: 1px solid rgba(37, 99, 235, 0.28);
  border-radius: 6px;
  background: rgba(239, 246, 255, 0.94);
  color: var(--text-color);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 700;
}

.online-draw-offer-panel.hidden,
.online-rematch-offer-panel.hidden {
  display: none;
}

.online-draw-offer-actions,
.online-rematch-offer-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: stretch;
}

.online-draw-offer-actions button,
.online-rematch-offer-actions button {
  flex: 1 1 96px;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
}

body.dark-theme .online-draw-offer-panel,
body.dark-theme .online-rematch-offer-panel {
  background: rgba(30, 41, 59, 0.94);
  border-color: rgba(96, 165, 250, 0.28);
}

#board {
  position: relative;
  z-index: 4;
  width: var(--board-size);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--board-border);
  border-radius: 6px;
  box-shadow:
    var(--board-shadow),
    0 0 0 4px rgba(255, 255, 255, 0.06),
    inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  touch-action: none;
  user-select: none;
  overscroll-behavior: contain;
}

.rank-coordinates {
  grid-column: 1;
  grid-row: 1;
  height: var(--board-size);
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  font-size: 13px;
  font-weight: bold;
  color: var(--coordinate-text);
  text-shadow: var(--coordinate-shadow);
}

.file-coordinates {
  grid-column: 2;
  grid-row: 2;
  width: var(--board-size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  font-size: 13px;
  font-weight: bold;
  color: var(--coordinate-text);
  text-shadow: var(--coordinate-shadow);
}

.rank-coordinates span,
.file-coordinates span {
  display: grid;
  place-items: center;
}

.square {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  font-size: clamp(28px, 8vw, 46px);
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  color: var(--black-piece);
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5),
    0 0 2px rgba(255, 255, 255, 0.55);
}

.square:not(:empty) {
  -webkit-text-stroke: 0.55px var(--piece-outline);
  paint-order: stroke fill;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.42));
}

.white-piece {
  color: var(--white-piece);
  -webkit-text-fill-color: var(--white-piece);
  -webkit-text-stroke: 1px var(--white-piece-stroke);
  opacity: 1;
  text-shadow: var(--white-piece-shadow);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.32));
}

.black-piece {
  color: var(--black-piece);
  -webkit-text-fill-color: var(--black-piece);
  -webkit-text-stroke: 0.24px var(--black-piece-stroke);
  opacity: 1;
  text-shadow: var(--black-piece-shadow);
  filter: none;
}

.piece-image {
  display: block;
  width: 82%;
  height: 82%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.square .piece-image {
  max-width: 86%;
  max-height: 86%;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.26));
}

.drag-ghost .piece-image {
  width: 100%;
  height: 100%;
}

@supports (-webkit-touch-callout: none) {
  .square.white-piece,
  .square.black-piece,
  .drag-ghost.white-piece,
  .drag-ghost.black-piece {
    font-family: "Apple Symbols", "Times New Roman", Times, Georgia, serif;
    font-style: normal;
    font-variant-emoji: text;
    line-height: 1;
  }

  .square.white-piece,
  .drag-ghost.white-piece {
    color: var(--white-piece);
    -webkit-text-fill-color: var(--white-piece);
    -webkit-text-stroke-color: var(--white-piece-stroke);
  }

  .square.black-piece,
  .drag-ghost.black-piece {
    color: var(--black-piece);
    -webkit-text-fill-color: var(--black-piece);
    -webkit-text-stroke-color: var(--black-piece-stroke);
  }
}

.light {
  background: var(--board-light);
}

.dark {
  background: var(--board-dark);
}

.selected {
  outline: 3px solid rgba(255, 255, 255, 0.72);
  outline-offset: -5px;
  box-shadow:
    inset 0 0 0 5px var(--selected-square),
    inset 0 0 0 8px rgba(15, 23, 42, 0.36),
    0 0 0 1px rgba(255, 255, 255, 0.18);
}

.legal-move::after {
  content: "";
  width: 30%;
  height: 30%;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.82);
  background: var(--legal-move);
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.42),
    inset 0 0 0 2px rgba(15, 23, 42, 0.18);
}

.legal-capture {
  box-shadow:
    inset 0 0 0 5px var(--legal-capture),
    inset 0 0 0 8px rgba(255, 255, 255, 0.28);
}

.last-move {
  box-shadow:
    inset 0 0 0 5px var(--last-move),
    inset 0 0 0 8px rgba(15, 23, 42, 0.22);
}

.legal-capture.last-move {
  box-shadow:
    inset 0 0 0 5px var(--legal-capture),
    inset 0 0 0 9px var(--last-move),
    inset 0 0 0 12px rgba(255, 255, 255, 0.26);
}

.selected.last-move,
.selected.legal-capture,
.selected.premove {
  box-shadow:
    inset 0 0 0 5px var(--selected-square),
    inset 0 0 0 8px rgba(15, 23, 42, 0.36),
    inset 0 0 0 11px rgba(255, 255, 255, 0.32);
}

.premove {
  box-shadow: inset 0 0 0 5px rgba(147, 51, 234, 0.75);
}

.checked-king {
  background: var(--check-square) !important;
}

.turtle2-king-warning-flash {
  animation: none;
}

.turtle2-king-warning-square {
  animation: turtle2KingWarningFlash 650ms ease-out;
}

.turtle2-king-warning-square::before {
  content: "";
  position: absolute;
  top: 8%;
  left: 50%;
  z-index: 2;
  width: 5px;
  height: 28%;
  border-radius: 999px;
  background: rgba(180, 83, 9, 0.72);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.16));
  transform: translateX(-50%);
  pointer-events: none;
  display: none;
}

.turtle2-king-warning-square::after {
  content: "";
  position: absolute;
  top: 29%;
  left: 50%;
  z-index: 2;
  width: 20px;
  height: 20px;
  border-right: 5px solid rgba(180, 83, 9, 0.72);
  border-bottom: 5px solid rgba(180, 83, 9, 0.72);
  border-radius: 2px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.16));
  transform: translateX(-50%) rotate(45deg);
  pointer-events: none;
  display: none;
}

.turtle2-king-captured-square::after {
  content: "X";
  position: absolute;
  inset: 12%;
  z-index: 2;
  display: grid;
  place-items: center;
  border: 2px solid rgba(127, 29, 29, 0.58);
  border-radius: 50%;
  color: rgba(127, 29, 29, 0.78);
  font-size: clamp(24px, 6vw, 38px);
  font-weight: bold;
  line-height: 1;
  pointer-events: none;
  display: none;
}

@keyframes turtle2KingWarningFlash {
  0% {
    filter: brightness(1);
    box-shadow: 0 0 0 rgba(127, 29, 29, 0);
  }

  22% {
    filter: brightness(0.78) saturate(1.35);
    box-shadow: 0 0 0 6px rgba(127, 29, 29, 0.42);
  }

  48% {
    filter: brightness(1.16) saturate(0.82);
    box-shadow: 0 0 0 10px rgba(217, 119, 6, 0.24);
  }

  100% {
    filter: brightness(1);
    box-shadow: 0 0 0 rgba(127, 29, 29, 0);
  }
}

.drag-origin {
  cursor: grabbing;
}

.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  width: calc(var(--square-size) * 0.82);
  height: calc(var(--square-size) * 0.82);
  pointer-events: none;
  -webkit-text-stroke: 0.4px var(--piece-outline);
  paint-order: stroke fill;
  line-height: 1;
  user-select: none;
  -webkit-user-drag: none;
  will-change: left, top;
  transform: translate(-50%, -50%);
}

.annotation-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  pointer-events: none;
  filter: drop-shadow(0 0 4px rgba(0, 229, 255, 0.5));
}

.side-panel {
  display: grid;
  gap: 12px;
}

.mode-panel {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  text-align: left;
}

.mode-panel label {
  display: grid;
  gap: 4px;
  font-size: 14px;
  font-weight: bold;
}

.mode-panel select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--text-color);
}

.online-entry-panel {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.52);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
}

.online-entry-panel.hidden,
.online-join-panel.hidden {
  display: none;
}

.online-entry-card {
  width: min(92vw, 420px);
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: var(--panel-bg);
  color: var(--text-color);
  box-shadow: 0 24px 54px rgba(0, 0, 0, 0.28);
  text-align: left;
}

.online-entry-header {
  display: grid;
  place-items: center;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--panel-border);
}

.online-entry-title {
  margin: 0;
  font-size: 25px;
  font-weight: 780;
  line-height: 1.12;
  text-align: center;
}

.online-entry-actions,
.online-join-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.online-entry-actions button,
.online-join-actions button {
  min-width: 0;
  min-height: 42px;
  padding-inline: 10px;
}

.online-time-control-panel {
  display: grid;
  gap: 9px;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--panel-border) 78%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-bg) 86%, var(--button-bg));
}

.online-time-control-panel.hidden {
  display: none;
}

.online-time-field,
.online-time-slider {
  display: grid;
  gap: 5px;
  color: var(--muted-text);
  font-size: 13px;
  font-weight: 720;
}

.online-time-field select {
  width: 100%;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid color-mix(in srgb, var(--button-bg) 34%, var(--input-border));
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text-color);
  font: inherit;
}

.online-custom-time-panel {
  display: grid;
  gap: 7px;
}

.online-custom-time-panel.hidden,
.online-time-slider.hidden {
  display: none;
}

.online-time-slider input[type="range"] {
  width: 100%;
  min-height: 30px;
  accent-color: var(--button-bg);
}

.online-modal-status {
  padding: 10px 12px;
  border: 1px solid rgba(245, 158, 11, 0.38);
  border-radius: 8px;
  background: rgba(255, 251, 235, 0.96);
  color: #92400e;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  text-align: left;
}

.online-modal-status.hidden {
  display: none;
}

.online-modal-status--error {
  border-color: rgba(220, 38, 38, 0.34);
  background: rgba(254, 242, 242, 0.96);
  color: #991b1b;
}

.online-modal-status--info {
  border-color: rgba(37, 99, 235, 0.26);
  background: rgba(239, 246, 255, 0.96);
  color: #1d4ed8;
}

body.dark-theme .online-modal-status {
  background: rgba(69, 42, 10, 0.78);
  color: #fef3c7;
}

body.dark-theme .online-modal-status--error {
  background: rgba(69, 10, 10, 0.78);
  color: #fecaca;
}

body.dark-theme .online-modal-status--info {
  background: rgba(15, 35, 72, 0.78);
  color: #bfdbfe;
}

.online-join-panel {
  display: grid;
  gap: 9px;
  padding-top: 2px;
}

.online-join-field {
  display: grid;
  gap: 6px;
  color: var(--muted-text);
  font-size: 13px;
  font-weight: 680;
}

.online-join-code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.online-join-field input {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--button-bg) 34%, var(--input-border));
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text-color);
  font-family: "Segoe UI Mono", "Roboto Mono", Consolas, monospace;
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  font-weight: 780;
  letter-spacing: 0.12em;
  line-height: 1;
  text-align: center;
}

.online-join-code-row button {
  min-width: 72px;
  min-height: 46px;
  padding-inline: 12px;
}

.online-keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.online-keypad button {
  min-width: 0;
  min-height: 46px;
  padding: 9px 8px;
  font-size: 18px;
  font-weight: 720;
}

#onlineClearCodeButton {
  font-size: 13px;
}

body.dark-theme .mode-panel select option {
  background: #2a2a2a;
  color: #f2f2f2;
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.controls--online {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

#undoButton {
  order: 1;
  grid-column: span 1;
}

#redoButton {
  order: 2;
  grid-column: span 1;
}

#flipButton {
  order: 3;
  grid-column: span 1;
}

#soundButton {
  order: 4;
  grid-column: span 1;
}

#languageButton {
  order: 5;
  grid-column: span 1;
}

#themeButton {
  order: 6;
  grid-column: span 1;
}

.board-theme-anchor {
  order: 7;
  grid-column: span 1;
}

.custom-background-anchor {
  order: 8;
  position: relative;
  grid-column: span 1;
}

#legalMovesButton {
  order: 9;
  grid-column: span 1;
}

#clearSavedMainGameButton {
  order: 10;
  grid-column: span 1;
}

#resetButton {
  order: 11;
  grid-column: 1 / -1;
}

.settings-popover-anchor {
  position: relative;
  top: 0;
  left: auto;
  right: auto;
  z-index: 35;
  align-self: start;
  justify-self: center;
  width: 34px;
}

.settings-popover-button {
  width: 32px;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.28);
  background: rgba(255, 255, 255, 0.96);
  color: #1f2937;
  box-shadow:
    0 8px 20px rgba(15, 23, 42, 0.16),
    inset 0 0 0 1px rgba(255, 255, 255, 0.72);
  font-size: 18px;
  line-height: 1;
}

.settings-popover-button:hover {
  border-color: rgba(15, 23, 42, 0.38);
  background: #ffffff;
  color: #111827;
}

.settings-popover-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--selected-square) 70%, white);
  outline-offset: 3px;
}

body.dark-theme .settings-popover-button {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(25, 25, 25, 0.96);
  color: #f8fafc;
  box-shadow:
    0 8px 20px rgba(0, 0, 0, 0.32),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

body.dark-theme .settings-popover-button:hover {
  border-color: rgba(255, 255, 255, 0.32);
  background: rgba(42, 42, 42, 0.98);
  color: #ffffff;
}

.settings-popover-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 32px;
  gap: 6px;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.2);
}

.settings-popover-panel.hidden {
  display: none;
}

.settings-popover-panel .toolbar-icon-button,
.settings-popover-panel .board-theme-anchor > .toolbar-icon-button,
.settings-popover-panel .custom-background-anchor > .toolbar-icon-button,
.settings-popover-panel .icon-control-button {
  width: 100%;
  min-width: 32px;
  min-height: 32px;
  padding: 4px;
  display: grid;
  place-items: center;
  grid-template-rows: 1fr;
}

.settings-popover-panel #soundButton {
  order: 1;
}

.settings-popover-panel #languageButton {
  order: 2;
}

.settings-popover-panel #flipButton {
  order: 3;
}

.settings-popover-panel #themeButton {
  order: 4;
}

.settings-popover-panel .board-theme-anchor {
  order: 5;
  grid-column: auto;
}

.settings-popover-panel .custom-background-anchor {
  order: 6;
  grid-column: auto;
}

.settings-popover-panel #legalMovesButton {
  order: 7;
}

.settings-popover-panel #clearSavedMainGameButton {
  order: 8;
}

.settings-popover-panel .board-theme-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  width: min(220px, calc(100vw - 24px));
}

.custom-background-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  z-index: 45;
  width: min(220px, calc(100vw - 28px));
  padding: 10px;
  display: grid;
  gap: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.22);
  transform: translateX(-50%);
}

.custom-background-panel.hidden {
  display: none;
}

.custom-background-title {
  margin-bottom: 0;
  color: var(--text-color);
  font-family: inherit;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 0;
  line-height: 1.25;
  text-align: left;
  text-rendering: optimizeLegibility;
}

.custom-background-panel button {
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 13px;
}

.custom-background-panel input[type="file"] {
  display: none;
}

.custom-background-note {
  color: var(--muted-text);
  font-size: 11px;
  line-height: 1.35;
  text-align: left;
}

.controls--online #undoButton {
  order: 1;
  grid-column: span 2;
}

.controls--online #onlineResignButton {
  order: 2;
  grid-column: span 2;
}

.controls--online #onlineTableInfoButton {
  order: 4;
  grid-column: span 3;
}

.controls--online #onlineTableInfoButton.online-table-info-alert {
  border-color: #f59e0b;
  background: color-mix(in srgb, #f59e0b 14%, var(--button-bg));
  box-shadow: 0 0 0 2px color-mix(in srgb, #f59e0b 24%, transparent);
}

.controls--online #onlineDrawButton {
  order: 3;
  grid-column: span 2;
}

.controls--online #onlineDrawOfferPanel {
  order: 6;
  grid-column: 1 / -1;
}

.controls--online #onlineRematchOfferPanel {
  order: 6;
  grid-column: 1 / -1;
}

.controls--online #flipButton {
  order: 6;
  grid-column: span 1;
}

.controls--online #notationButton {
  display: none;
}

.controls--online #languageButton {
  order: 5;
}

.controls--online #themeButton {
  order: 6;
}

.controls--online #onlineLeaveButton {
  order: 5;
  grid-column: span 3;
}

.controls--online #undoButton,
.controls--online #onlineResignButton,
.controls--online #onlineDrawButton {
  min-height: 42px;
  padding: 8px 6px;
  font-size: 0;
}

.controls--online #undoButton .icon-control-button__icon {
  font-size: 20px;
}

.controls--online #undoButton .icon-control-button__label,
.controls--online #undoButton .icon-control-button__state {
  display: none;
}

.controls--online #onlineResignButton::before,
.controls--online #onlineDrawButton::before {
  display: inline-grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
}

.controls--online #onlineResignButton::before {
  content: "\2691";
}

.controls--online #onlineDrawButton::before {
  content: "\00bd";
  font-weight: 800;
}

.controls button,
.board-theme-anchor > button {
  min-width: 0;
  padding-inline: 12px;
  font-size: 14px;
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
}

.icon-control-button {
  min-height: 48px;
  padding: 7px 6px;
  display: grid;
  grid-template-rows: auto auto;
  align-content: center;
  justify-items: center;
  gap: 2px;
  white-space: normal;
}

.toolbar-icon-button,
.board-theme-anchor > .toolbar-icon-button {
  position: relative;
  min-height: 40px;
  padding: 6px 4px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 1px;
  border: 1px solid color-mix(in srgb, var(--button-bg) 70%, var(--panel-border));
  border-radius: 8px;
  background: color-mix(in srgb, var(--button-bg) 82%, var(--panel-bg));
  white-space: normal;
}

.toolbar-icon-button__icon {
  font-size: 15px;
  line-height: 1;
}

.toolbar-icon-button__state {
  overflow: hidden;
  max-width: 100%;
  color: color-mix(in srgb, var(--button-text) 78%, transparent);
  font-size: 9px;
  line-height: 1;
  text-overflow: ellipsis;
}

.settings-popover-panel .toolbar-icon-button__state {
  display: none;
}

.settings-popover-panel .icon-control-button__label,
.settings-popover-panel .icon-control-button__state {
  display: none;
}

.settings-popover-panel #languageButton .toolbar-icon-button__icon {
  display: none;
}

.settings-popover-panel #languageButton .toolbar-icon-button__state {
  display: block;
  color: var(--button-text);
  font-size: 12px;
  font-weight: 800;
}

.settings-popover-panel .toolbar-icon-button--active::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--panel-bg) 80%, transparent);
}

.toolbar-icon-button--danger {
  border-color: rgba(185, 28, 28, 0.5);
  background: color-mix(in srgb, #b91c1c 18%, var(--button-bg));
}

.icon-control-button__icon {
  font-size: 20px;
  line-height: 1;
}

.icon-control-button__label {
  max-width: 100%;
  overflow: hidden;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
  text-overflow: ellipsis;
}

.icon-control-button__state {
  max-width: 100%;
  overflow: hidden;
  color: color-mix(in srgb, var(--button-text) 76%, transparent);
  font-size: 10px;
  line-height: 1;
  text-overflow: ellipsis;
}

#clearSavedMainGameButton {
  border-color: rgba(185, 28, 28, 0.42);
}

.board-theme-anchor {
  position: relative;
}

.board-theme-anchor > button {
  width: 100%;
}

.board-theme-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 30;
  width: min(320px, calc(100vw - 32px));
  padding: 10px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: var(--panel-bg);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  text-align: left;
}

.board-theme-panel.hidden {
  display: none;
}

.board-theme-title {
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: bold;
}

.board-theme-field {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

.board-theme-field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-color);
}

.history-panel {
  position: relative;
  height: calc(var(--square-size) * 5);
  max-height: calc(var(--square-size) * 5);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  padding: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  text-align: left;
}

.review-tool-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
  width: fit-content;
  max-width: 100%;
  min-height: 32px;
  margin: 0;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--button-bg);
  color: var(--button-text);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  font-size: 15px;
  font-weight: 670;
  letter-spacing: -0.01em;
  line-height: 1.1;
  text-decoration: none;
  white-space: nowrap;
}

.review-tool-link:hover,
.review-tool-link:focus-visible {
  background: var(--button-hover);
  outline: none;
}

body.dark-theme .review-tool-link {
  border: 1px solid #3a3a3a;
}

.history-panel h2 {
  margin: 0 0 10px;
  padding-right: 38px;
  font-size: 18px;
}

.copy-history-btn,
#copyHistoryButton {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  min-width: 30px;
  padding: 0;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
}

.material-advantage {
  display: grid;
  gap: 2px;
  margin: 0 0 10px;
  padding: 7px 9px;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: var(--status-bg);
}

.material-advantage.hidden {
  display: none;
}

.material-advantage__label {
  color: var(--muted-text);
  font-size: 12px;
  font-weight: bold;
}

.material-advantage__value {
  display: grid;
  gap: 1px;
  color: var(--text-color);
  font-size: 14px;
  font-weight: bold;
  line-height: 1.25;
}

.material-advantage__line {
  white-space: nowrap;
}

.material-detail-row {
  display: grid;
  grid-template-columns: 72px 48px minmax(0, 1fr);
  align-items: center;
  gap: 4px;
  min-width: 0;
  white-space: nowrap;
}

.material-detail-row__score {
  font-variant-numeric: tabular-nums;
}

.material-detail-row__pieces {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.material-detail-piece {
  width: 16px;
  height: 16px;
  display: block;
  flex: 0 0 auto;
  object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.18));
}

.embed-material-strip {
  display: none;
}

body.embed-mode .embed-material-strip {
  width: var(--board-size);
  min-height: 24px;
  margin: 4px auto 0;
  padding: 3px 8px;
  border: 1px solid color-mix(in srgb, var(--panel-border) 72%, transparent);
  border-radius: 6px;
  background: color-mix(in srgb, var(--panel-bg) 82%, transparent);
  color: var(--text-color);
  font-size: 12px;
  font-weight: 720;
  line-height: 1.15;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

body.embed-mode .embed-material-strip.hidden {
  display: none;
}

.embed-material-strip__label {
  color: var(--muted-text);
  white-space: nowrap;
}

.embed-material-strip__value,
.embed-material-strip__pieces {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
}

.embed-material-strip__piece {
  width: 15px;
  height: 15px;
  display: block;
  flex: 0 0 auto;
  object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.16));
}

.move-history-scroll {
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.history-row {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

body.dark-theme .history-row {
  border-bottom-color: #333333;
}

.move-number {
  color: var(--muted-text);
}

.move-history-item {
  display: inline-block;
  min-width: 0;
  padding: 2px 4px;
  border-radius: 4px;
  cursor: pointer;
}

.move-history-item:hover {
  background: rgba(37, 99, 235, 0.12);
}

.move-history-item.active {
  background: var(--selected-square);
  color: #ffffff;
}

.promotion-modal {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.promotion-modal.hidden {
  display: none;
}

.promotion-picker {
  position: absolute;
  display: grid;
  grid-template-columns: repeat(4, minmax(44px, 56px));
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--promotion-border);
  border-radius: 10px;
  background: var(--promotion-bg);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.26);
  pointer-events: auto;
}

.promotion-picker button {
  width: clamp(44px, calc(var(--square-size) * 0.9), 56px);
  height: clamp(44px, calc(var(--square-size) * 0.9), 56px);
  padding: 0;
  border: 1px solid var(--promotion-choice-border);
  background: var(--promotion-choice-bg);
  color: #111827;
  font-size: 32px;
  display: grid;
  place-items: center;
  box-shadow: var(--promotion-choice-shadow);
}

.promotion-picker button .piece-image {
  width: 78%;
  height: 78%;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.28));
}

.promotion-picker button:hover {
  background: var(--promotion-choice-hover);
  transform: translateY(-1px);
}

.promotion-picker button:focus-visible {
  outline: 3px solid var(--selected-square);
  outline-offset: 2px;
}

button {
  padding: 10px 18px;
  border: 0;
  border-radius: 4px;
  background: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
}

button:hover {
  background: var(--button-hover);
}

#undoButton.undo-used-warning {
  box-shadow:
    inset 0 0 0 2px rgba(245, 158, 11, 0.95),
    0 0 0 1px rgba(245, 158, 11, 0.24),
    0 0 12px rgba(245, 158, 11, 0.18);
}

#applySettingsButton.apply-pending {
  box-shadow:
    inset 0 0 0 2px rgba(249, 115, 22, 0.95),
    0 0 0 1px rgba(249, 115, 22, 0.24),
    0 0 12px rgba(249, 115, 22, 0.18);
}

.apply-pending-star {
  color: #ef4444;
  font-weight: 800;
  margin-left: 4px;
}

button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

body.dark-theme button {
  border: 1px solid #3a3a3a;
}

body.dark-theme #undoButton.undo-used-warning {
  box-shadow:
    inset 0 0 0 2px rgba(251, 191, 36, 0.95),
    0 0 0 1px rgba(251, 191, 36, 0.24),
    0 0 12px rgba(251, 191, 36, 0.2);
}

body.dark-theme #applySettingsButton.apply-pending {
  box-shadow:
    inset 0 0 0 2px rgba(251, 146, 60, 0.95),
    0 0 0 1px rgba(251, 146, 60, 0.24),
    0 0 12px rgba(251, 146, 60, 0.2);
}

body.dark-theme button:disabled {
  background: #242424;
  color: #9ca3af;
  border-color: #333333;
  opacity: 1;
}

@media (min-width: 900px) {
  main {
    width: min(98vw, 1140px);
  }

  #appTitle.app-title {
    font-size: clamp(25px, 3vw, 35px);
  }

  .game-layout {
    grid-template-columns: minmax(210px, 260px) minmax(320px, 506px) 34px minmax(220px, 236px);
    gap: 9px;
  }

  .side-panel {
    gap: 10px;
  }

  .mode-panel {
    gap: 7px;
    padding: 10px;
  }

  .mode-panel label {
    gap: 4px;
    font-size: 13px;
  }

  .mode-panel select {
    min-height: 36px;
    padding: 7px 8px;
    font-size: 13px;
  }

  .mode-panel button {
    min-height: 38px;
    padding: 8px 10px;
    font-size: 13px;
  }

  .controls {
    gap: 7px;
  }

  .controls button,
  .board-theme-anchor > button {
    min-height: 38px;
    padding: 8px 8px;
    font-size: 13px;
  }

  .icon-control-button {
    min-height: 42px;
    padding: 6px 5px;
  }

  .toolbar-icon-button,
  .board-theme-anchor > .toolbar-icon-button {
    min-height: 38px;
  }

  .controls--online #undoButton,
  .controls--online #onlineResignButton,
  .controls--online #onlineDrawButton {
    min-height: 38px;
    padding: 7px 5px;
  }

  .controls--online #undoButton .icon-control-button__icon,
  .controls--online #onlineResignButton::before,
  .controls--online #onlineDrawButton::before {
    font-size: 18px;
  }
}

@media (min-width: 1120px) {
  :root {
    --board-size: 520px;
    --square-size: calc(var(--board-size) / 8);
  }

  .game-layout {
    grid-template-columns: minmax(210px, 252px) minmax(542px, 542px) 34px minmax(220px, 236px);
  }

  .square,
  .piece-ghost {
    font-size: calc(var(--square-size) * 0.72);
  }
}

@media (max-width: 760px) {
  :root {
    --board-size: min(calc(100vw - 36px), 520px);
    --square-size: calc(var(--board-size) / 8);
  }

  body {
    display: block;
    min-height: 100vh;
    padding: 10px 0 18px;
  }

  main {
    width: 100%;
    padding: 0 10px;
  }

  h1 {
    margin: 0 0 8px;
    font-size: clamp(26px, 8vw, 34px);
    line-height: 1.08;
  }

  #status {
    max-width: calc(100vw - 24px);
    margin-bottom: 10px;
    padding: 7px 12px;
    font-size: 14px;
  }

  .game-layout {
    grid-template-columns: 1fr;
    gap: 12px;
    justify-items: center;
  }

  .board-area {
    order: 1;
    width: 100%;
    display: grid;
    justify-items: center;
    overflow: visible;
  }

  .settings-popover-anchor {
    order: 2;
    top: auto;
    left: auto;
    right: auto;
    justify-self: end;
    width: 34px;
    margin-top: -4px;
    margin-right: max(6px, calc((100% - var(--board-size)) / 2));
  }

  .settings-popover-panel {
    left: auto;
    right: 0;
    transform: none;
    grid-template-columns: 32px;
    width: max-content;
  }

  .settings-popover-panel .board-theme-panel {
    left: auto;
    right: 0;
    transform: none;
  }

  .side-panel {
    order: 3;
    width: min(100%, 560px);
    gap: 10px;
  }

  .left-panel {
    order: 4;
    width: min(100%, 560px);
    margin-top: 0;
    gap: 10px;
  }

  .board-frame {
    width: min(100%, calc(var(--board-size) + 22px));
    grid-template-columns: 16px var(--board-size);
    grid-template-rows: var(--board-size) 16px;
    column-gap: 2px;
    row-gap: 2px;
  }

  #board {
    border-radius: 8px;
  }

  .square {
    font-size: calc(var(--square-size) * 0.72);
    touch-action: none;
  }

  .piece-ghost {
    font-size: calc(var(--square-size) * 0.72);
  }

  .file-coordinates,
  .rank-coordinates {
    font-size: 11px;
  }

  .game-over-overlay {
    position: fixed;
    inset: 0;
  }

  .game-over-card {
    width: min(92vw, 340px);
  }

  .mode-panel {
    grid-template-columns: 1fr;
    gap: 9px;
    padding: 10px;
    border-radius: 8px;
  }

  .mode-panel label {
    gap: 5px;
    font-size: 13px;
  }

  .mode-panel select,
  .board-theme-field select {
    min-height: 42px;
    font-size: 15px;
  }

  .mode-panel button,
  .controls button,
  .board-theme-anchor > button,
  .review-tool-link,
  .game-history-button,
  .replay-panel button {
    min-height: 42px;
  }

  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .controls--online {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .controls button,
  .board-theme-anchor > button {
    padding: 9px 8px;
    font-size: 13px;
    line-height: 1.15;
    white-space: normal;
  }

  .board-theme-panel {
    width: 100%;
    margin-top: 8px;
    border-radius: 8px;
  }

  .review-tool-link {
    width: 100%;
    align-self: stretch;
    font-size: 15px;
    padding: 10px 12px;
  }

  .history-panel {
    height: auto;
    max-height: none;
    min-height: 220px;
    grid-template-rows: auto auto minmax(120px, 1fr);
    border-radius: 8px;
  }

  .history-panel h2 {
    font-size: 17px;
  }

  .material-advantage {
    padding: 7px 8px;
  }

  .material-detail-row {
    grid-template-columns: 62px 42px minmax(0, 1fr);
    font-size: 13px;
  }

  .move-history-scroll {
    max-height: 190px;
  }

  .history-row {
    grid-template-columns: 30px minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px;
  }

  .move-history-item {
    min-height: 28px;
    padding: 4px 5px;
    line-height: 1.2;
  }

  .history-slot-panel,
  .replay-panel {
    width: 100%;
  }

  .game-history-button {
    min-height: 82px;
    padding: 12px;
  }

  .game-history-button span:first-child {
    font-size: 19px;
  }

  .game-history-modal {
    padding: 12px;
    align-items: center;
  }

  .game-history-modal__card {
    width: 100%;
    max-height: min(88vh, 720px);
    padding: 14px;
    gap: 10px;
  }

  .game-history-item {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
  }

  .game-history-profile-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 9px;
  }

  .game-history-profile-field {
    grid-column: 1 / -1;
  }

  #addProfileButton,
  #renameProfileButton,
  #deleteProfileButton {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    font-size: 12.5px;
  }

  .game-history-item__actions {
    justify-content: stretch;
    flex-wrap: wrap;
    gap: 7px;
  }

  .game-history-item__actions button {
    flex: 1;
    min-width: 86px;
    min-height: 38px;
  }

  .game-history-modal__actions {
    gap: 8px;
  }

  .game-history-modal__actions button {
    min-height: 40px;
    padding: 9px 12px;
  }
}

@media (max-width: 480px) {
  :root {
    --board-size: min(calc(100vw - 28px), 500px);
  }

  body {
    padding-top: 8px;
  }

  main {
    padding: 0 7px;
  }

  #status {
    min-width: 0;
    width: fit-content;
    max-width: calc(100vw - 18px);
    font-size: 13px;
  }

  .game-layout {
    gap: 10px;
  }

  .board-frame {
    width: min(100%, calc(var(--board-size) + 20px));
    grid-template-columns: 15px var(--board-size);
    grid-template-rows: var(--board-size) 15px;
  }

  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .controls--online {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .controls button,
  .board-theme-anchor > button {
    font-size: 12.5px;
    padding-inline: 6px;
  }

  .history-panel {
    padding: 10px;
    min-height: 210px;
  }

  .move-history-scroll {
    max-height: 170px;
  }

  .game-history-modal {
    padding: 8px;
  }

  .game-history-modal__card {
    max-height: 90vh;
    padding: 12px;
  }

  .game-history-modal__header h2 {
    font-size: 24px;
  }

  .game-history-profile-row {
    grid-template-columns: 1fr;
  }

  .game-history-item__actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .game-history-item__actions button {
    min-width: 0;
    padding-inline: 8px;
  }
}

@media (max-width: 380px) {
  :root {
    --board-size: min(calc(100vw - 24px), 480px);
  }

  h1 {
    font-size: 25px;
  }

  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .controls--online {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .mode-panel select,
  .controls button,
  .board-theme-anchor > button {
    min-height: 40px;
  }

  .material-detail-row {
    grid-template-columns: 56px 38px minmax(0, 1fr);
    font-size: 12px;
  }

  .game-history-item__actions {
    grid-template-columns: 1fr;
  }

  .game-history-modal__actions {
    flex-wrap: wrap;
  }

  .game-history-modal__actions button {
    flex: 1 1 130px;
  }
}
