:root {
  --game-bg: #0a0c10;
  --panel: #12151c;
  --text: #e8eaef;
  --muted: #7d8596;
  --accent: #5ee0d0;
  --font: "DM Sans", system-ui, sans-serif;
  --ad-banner-w: 768px;
  --ad-banner-h: 90px;
  /* 薄いオレンジ系 / 茶色系のマス */
  --square-light: #f0d4a8;
  --square-dark: #6b4423;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--game-bg);
  color: var(--text);
}

.page-layout {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 1.5rem;
  padding: 1rem 1rem 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

.main-column {
  flex: 1 1 320px;
  min-width: 0;
  max-width: 920px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.back {
  align-self: flex-start;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45rem;
}

.back a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}

.back a:hover {
  text-decoration: underline;
}

.btn-ad-ui-help {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-ad-ui-help:hover {
  color: var(--accent);
}

.board-wrap {
  position: relative;
  width: 100%;
  max-width: min(90vmin, 560px);
  background: var(--panel);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 8px;
}

.board-popup {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  top: auto;
  z-index: 3;
  pointer-events: none;
  background: rgba(8, 10, 14, 0.94);
  border: 1px solid rgba(94, 224, 208, 0.35);
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}

.board-popup-row {
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--muted);
}

.board-popup-scrub {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.35rem;
  text-align: center;
}

.board-popup-hint {
  margin: 0 0 0.25rem;
  font-size: 0.62rem;
  line-height: 1.35;
  color: var(--muted);
  text-align: center;
}

.board-popup-hint--before-bookmarks {
  margin-top: 0.35rem;
  margin-bottom: 0.3rem;
}

.board-popup-bookmarks {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}

.popup-bookmark-chip {
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--muted);
  font-size: 0.65rem;
}

.popup-bookmark-chip.highlight {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 10px rgba(94, 224, 208, 0.25);
}

.chess-board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 0;
  border-radius: 8px;
  overflow: hidden;
  outline: none;
}

.chess-board.chess-load-error {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
}

.chess-board:focus-visible {
  box-shadow: 0 0 0 2px var(--accent);
}

.square {
  margin: 0;
  padding: 0;
  border: none;
  font-size: clamp(1.5rem, 10vmin, 2.75rem);
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", sans-serif;
}

.square.light {
  background: var(--square-light);
}

.square.dark {
  background: var(--square-dark);
}

/* プレイヤー（白）— 明るい駒＋黒縁でマスの色に埋もれない */
.square.piece-white {
  color: #fffef6;
  text-shadow:
    0 0 5px #000,
    0 0 1px #000,
    1px 0 0 #1a1006,
    -1px 0 0 #1a1006,
    0 1px 0 #1a1006,
    0 -1px 0 #1a1006,
    1px 1px 0 #1a1006,
    -1px -1px 0 #1a1006;
}

/* NPC（黒）— 濃い駒＋淡い縁 */
.square.piece-black {
  color: #0c0806;
  text-shadow:
    0 0 4px rgba(255, 245, 220, 0.95),
    1px 0 0 rgba(255, 235, 200, 0.85),
    -1px 0 0 rgba(255, 235, 200, 0.85),
    0 1px 0 rgba(255, 235, 200, 0.85),
    0 -1px 0 rgba(255, 235, 200, 0.85);
}

.square.selected {
  box-shadow: inset 0 0 0 3px var(--accent);
}

.square.legal-target {
  box-shadow: inset 0 0 0 2px rgba(94, 224, 208, 0.65);
}

.ply-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 0.75rem;
  width: 100%;
}

.ply-line {
  margin: 0;
  width: 100%;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text);
  font-weight: 600;
  line-height: 1.45;
  min-height: 1.35em;
}

.ply-row .ply-line {
  flex: 1 1 auto;
  min-width: 0;
}

.btn-resume-from-here {
  flex: 0 0 auto;
  cursor: pointer;
  padding: 0.25rem 0.65rem;
  border-radius: 8px;
  border: 1px solid rgba(94, 224, 208, 0.5);
  background: rgba(94, 224, 208, 0.14);
  color: var(--accent);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.btn-resume-from-here:hover {
  background: rgba(94, 224, 208, 0.24);
}

.btn-resume-from-here[hidden] {
  display: none !important;
}

.ad-banner {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.ad-hint {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
  line-height: 1.45;
  padding: 0 0.5rem;
  width: 100%;
}

.ad-shell {
  width: var(--ad-banner-w);
  max-width: 100%;
  height: var(--ad-banner-h);
  min-height: var(--ad-banner-h);
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid rgba(94, 224, 208, 0.35);
  background: #0a0c10;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.ad-iframe {
  display: block;
  width: 100%;
  height: var(--ad-banner-h);
  border: 0;
}

.ad-parent-ack {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
  line-height: 1.35;
  min-height: 1.2em;
}

.ad-parent-ack[hidden] {
  display: none !important;
}

.sidebar {
  flex: 0 1 260px;
  min-width: 220px;
  max-width: 320px;
  background: var(--panel);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 1rem 1.1rem;
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--muted);
}

.sidebar-howto-details {
  margin: 0 0 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.sidebar-howto-summary {
  cursor: pointer;
  list-style: none;
  padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  user-select: none;
}

.sidebar-howto-summary::-webkit-details-marker {
  display: none;
}

.sidebar-howto-summary::before {
  content: "";
  flex-shrink: 0;
  width: 0.4em;
  height: 0.4em;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(-45deg);
  margin-top: -0.2em;
  transition: transform 0.15s ease;
}

.sidebar-howto-details[open] .sidebar-howto-summary::before {
  transform: rotate(45deg);
  margin-top: 0.1em;
}

.sidebar-howto-summary:hover {
  color: var(--accent);
}

.sidebar-howto-summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sidebar-howto-list {
  margin: 0 0 0.65rem !important;
  padding: 0 0.85rem 0 1.35rem !important;
}

.sidebar h2 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.sidebar h2:not(:first-child) {
  margin-top: 1.25rem;
}

.sidebar p,
.sidebar ul {
  margin: 0 0 0.5rem;
}

.sidebar ul {
  padding-left: 1.2rem;
}

.sidebar li {
  margin-bottom: 0.35rem;
}

.sidebar kbd {
  display: inline-block;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.85em;
  font-family: inherit;
  color: var(--text);
}

.sidebar code {
  font-size: 0.8em;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.sidebar a {
  color: var(--accent);
}

.btn-new-game {
  cursor: pointer;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  border: 1px solid rgba(94, 224, 208, 0.45);
  background: rgba(94, 224, 208, 0.12);
  color: var(--accent);
  font: inherit;
  font-weight: 600;
}

.btn-new-game:hover {
  background: rgba(94, 224, 208, 0.2);
}

.sidebar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.sidebar-past-wrap {
  margin: 0 0 0.5rem;
}

.btn-past-games {
  width: 100%;
  box-sizing: border-box;
}

.chess-toast {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  min-height: 1.2em;
}

.chess-toast[hidden] {
  display: none !important;
}

.chess-toast--err {
  color: #ff8a8a;
}

.sidebar-save-help {
  list-style: disc;
  padding-left: 1.2rem;
  margin: 0 0 0.5rem;
}

.saved-games-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.saved-games-overlay[hidden] {
  display: none !important;
}

.saved-games-dialog {
  width: min(520px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid rgba(94, 224, 208, 0.35);
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
  color: var(--text);
}

.saved-games-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.saved-games-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.saved-games-close {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.saved-games-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.saved-games-search-row {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.saved-games-search-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.saved-games-search-input {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
}

.saved-games-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.5rem 0.75rem 0.75rem;
  min-height: 120px;
}

.saved-games-empty {
  margin: 0;
  padding: 1rem 1rem 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.saved-games-empty[hidden] {
  display: none !important;
}

.saved-game-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem 0.65rem;
  padding: 0.55rem 0.45rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.saved-game-meta {
  flex: 1 1 180px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.saved-game-date {
  font-size: 0.75rem;
  color: var(--muted);
}

.saved-game-name-input {
  width: 100%;
  padding: 0.35rem 0.45rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
}

.saved-game-load {
  flex: 0 0 auto;
  align-self: flex-end;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
}

body.saved-games-modal-open,
body.ad-ui-help-modal-open {
  overflow: hidden;
}

.ad-ui-help-dialog {
  max-height: none;
}

.ad-ui-help-body {
  margin: 0;
  padding: 1rem 1.1rem 1.15rem;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--muted);
}

.sidebar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.npc-level-label {
  font-weight: 600;
  color: var(--text);
}

.npc-level-select {
  flex: 1 1 140px;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
}

.npc-level-select:disabled {
  opacity: 0.55;
}

.bookmark-list {
  list-style: none;
  padding-left: 0;
  font-size: 0.8rem;
}

.bookmark-list li {
  padding: 0.2rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

@media (max-width: 900px) {
  .page-layout {
    flex-direction: column;
    align-items: stretch;
  }

  .sidebar {
    max-width: none;
  }
}
