:root {
  --primary-color: #4e342e;   /* 木の駒のような焦げ茶 */
  --accent-color: #8d6e63;    /* 明るいウォールナット */
  --bg-color: #f8f5f2;        /* アイボリー */
  --card-bg: #ffffff;
  --input-bg: #fafafa;
  --border-color: #e0d8d5;
  --success-color: #1b8a5a;
  --success-bg: #e3f6ec;
  --fail-color: #c0392b;
  --fail-bg: #fdecea;
  --sand-color: #fffbf0;
  --sand-border: #ffe0b2;
}

* { box-sizing: border-box; }

body {
  font-family: 'Hiragino Kaku Gothic ProN', 'Meiryo', -apple-system, sans-serif;
  background: var(--bg-color);
  color: var(--primary-color);
  margin: 0;
  padding: 24px 16px 60px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

.app {
  max-width: 980px;
  margin: 0 auto;
}

.app-header {
  text-align: center;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

.home-link {
  display: block;
  flex-shrink: 0;
  line-height: 0;
  border-radius: 10px;
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
}
.home-link:hover {
  transform: scale(1.05);
  box-shadow: 0 3px 10px rgba(74, 144, 226, 0.25);
}
.home-link:focus-visible {
  outline: 3px solid #4a90e2;
  outline-offset: 2px;
}
.home-icon {
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
}

.brand-name {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', sans-serif;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #1f2937;
  margin: 0;
}
.tagline {
  font-size: 0.9rem;
  color: #6d4c41;
  margin: 0;
}
.tagline a {
  color: var(--accent-color);
  font-weight: 700;
  text-decoration: underline;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}

@media (max-width: 800px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- board column ---------- */
.board-column {
  text-align: center;
  min-width: 0;
}

.board-wrapper {
  position: relative;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
  touch-action: none;
}

.board {
  width: 100%;
}

.annotation-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
.annot-circle {
  fill: none;
  stroke: rgba(46, 160, 67, 0.9);
}
.annot-arrow {
  stroke: rgba(46, 160, 67, 0.9);
  stroke-linecap: round;
}
.annot-arrowhead {
  fill: rgba(46, 160, 67, 0.9);
}

.status-bar {
  margin-top: 18px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  font-weight: 600;
  font-size: 0.95rem;
  min-height: 1.2em;
}
.status-bar.hidden { display: none; }

.btn-tiny {
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 700;
  background: #ffe0b2;
  color: #e65100;
  flex: none;
}
.btn-tiny:hover { background: #ffcc80; }

/* chessboard.js square highlight hooks for tap-to-move / premove */
#board .square-55d63.selected-square::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(141, 110, 99, 0.65);
  pointer-events: none;
}
#board .square-55d63.premove-square::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(230, 81, 0, 0.55);
  pointer-events: none;
}

/* legal-move hint markers, lichess-style: a filled dot on empty squares,
   a ring around the edge on squares with a capturable piece */
#board .square-55d63 .move-hint-dot {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 30%; height: 30%;
  border-radius: 50%;
  background: rgba(78, 52, 46, 0.45);
  pointer-events: none;
}
#board .square-55d63 .move-hint-ring {
  position: absolute;
  top: 4%; left: 4%; right: 4%; bottom: 4%;
  border-radius: 50%;
  box-shadow: inset 0 0 0 5px rgba(78, 52, 46, 0.45);
  pointer-events: none;
}

.result-banner {
  margin-top: 14px;
  padding: 16px;
  border-radius: 14px;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}
.result-banner.success {
  background: var(--success-bg);
  color: var(--success-color);
  border: 2px solid var(--success-color);
}
.result-banner.fail {
  background: var(--fail-bg);
  color: var(--fail-color);
  border: 2px solid var(--fail-color);
}
.result-banner.hidden { display: none; }

/* Compact result banner overlaid on the bottom edge of the board itself —
   desktop/PC only. Mobile keeps the full-message banner below the
   buttons (see the max-width:800px override further down). */
.result-banner-board {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px;
  text-align: center;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.03em;
  z-index: 5;
}
.result-banner-board.success {
  background: var(--success-bg);
  color: var(--success-color);
  border-top: 2px solid var(--success-color);
}
.result-banner-board.fail {
  background: var(--fail-bg);
  color: var(--fail-color);
  border-top: 2px solid var(--fail-color);
}
.result-banner-board.hidden { display: none; }

@media (min-width: 801px) {
  #resultBanner { display: none !important; }
}
@media (max-width: 800px) {
  .result-banner-board { display: none !important; }
}

/* "Thinking..." overlay — shown only while White has already moved but
   the engine hasn't finished loading yet (see requestEngineMove() in
   app.js). It's really just a loading placeholder, not a genuine
   per-move "engine is thinking" indicator, so it only ever appears once
   per session, before the engine's very first move. */
.engine-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 15, 12, 0.55);
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.03em;
  z-index: 6;
  pointer-events: none;
}
.engine-loading-overlay.hidden { display: none; }
.engine-loading-overlay .dot {
  opacity: 0;
  animation: engineLoadingDot 1.4s infinite;
}
.engine-loading-overlay .dot:nth-child(2) { animation-delay: 0.2s; }
.engine-loading-overlay .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes engineLoadingDot {
  0%, 20% { opacity: 0; }
  50% { opacity: 1; }
  100% { opacity: 0; }
}

.board-controls {
  margin-top: 20px;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.board-controls .btn {
  flex: 1 1 150px;
}

/* ---------- buttons ---------- */
.btn {
  padding: 14px 22px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  border-radius: 12px;
  transition: 0.25s;
  letter-spacing: 0.03em;
  min-height: 44px;
  touch-action: manipulation;
}
.btn-primary {
  background: linear-gradient(135deg, #8d6e63 0%, #4e342e 100%);
  color: #fff;
  box-shadow: 0 6px 15px rgba(78, 52, 46, 0.25);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(78,52,46,0.35); }
.btn-secondary {
  background: transparent;
  color: var(--primary-color);
  border: 1px solid var(--primary-color);
}
.btn-secondary:hover { background: var(--input-bg); }
.btn-small {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  flex: 1;
  background: #efebe9;
  color: var(--primary-color);
}
.btn-small:hover { background: #e0d8d5; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ---------- side panel ---------- */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel-card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 10px 10px 30px #d9d6d3, -10px -10px 30px #ffffff;
}

.panel-card h2 {
  font-size: 1rem;
  margin: 0 0 10px;
  color: var(--primary-color);
}

.panel-desc {
  font-size: 0.78rem;
  color: #6d4c41;
  margin: 0 0 14px;
  line-height: 1.5;
}

.option-group {
  padding: 16px;
  background: var(--sand-color);
  border: 1px dashed var(--sand-border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.option-group label {
  cursor: pointer;
  font-size: 12.5px;
  color: #5d4037;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--primary-color);
  cursor: pointer;
  flex: none;
}

#fenDisplay {
  width: 100%;
  padding: 12px;
  font-size: 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  outline: none;
  text-align: center;
  background: var(--input-bg);
  font-family: 'Courier New', monospace;
  color: var(--primary-color);
  margin-bottom: 12px;
}

.btn-row { display: flex; gap: 8px; }
.btn-row + .btn-row { margin-top: 10px; }
.copy-msg {
  color: var(--accent-color);
  font-size: 11px;
  height: 16px;
  margin-top: 6px;
  font-weight: 700;
  opacity: 0;
  transition: 0.3s;
}
.copy-msg.show { opacity: 1; }

.pgn-box {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
}
.pgn-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary-color);
}
.pgn-content {
  margin: 0;
  max-height: 140px;
  overflow-y: auto;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #6d4c41;
  white-space: pre-wrap;
  word-break: break-word;
}

.rules-list {
  margin: 0;
  padding-left: 18px;
  font-size: 0.82rem;
  line-height: 1.7;
  color: #6d4c41;
}

.engine-status {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-color);
}

.app-footer {
  text-align: center;
  margin-top: 30px;
  font-size: 0.72rem;
  color: #8d6e63;
}
.app-footer code {
  background: #fff;
  padding: 2px 6px;
  border-radius: 6px;
}

/* ---------- mobile responsive pass ---------- */
@media (max-width: 600px) {
  body {
    padding: 12px 8px 40px;
    font-size: 19px;
  }

  .brand-name {
    font-size: 1.5rem;
  }
  .app-header {
    margin-bottom: 16px;
  }
  .tagline {
    font-size: 1.15rem;
  }

  .layout {
    gap: 14px;
  }

  .board-wrapper {
    max-width: 100%;
  }

  .status-bar {
    font-size: 1.2rem;
    padding: 14px 16px;
  }
  .result-banner {
    font-size: 1.4rem;
    padding: 20px;
  }

  .board-controls {
    gap: 8px;
  }
  .board-controls .btn {
    flex: 1 1 46%;
    padding: 15px 10px;
    font-size: 17px;
  }

  .side-panel {
    gap: 12px;
  }

  .panel-card {
    padding: 14px;
    border-radius: 16px;
  }
  .panel-card h2 {
    font-size: 1.4rem;
  }

  .option-group {
    padding: 12px;
  }
  .option-group label {
    font-size: 17px;
  }

  /* iOS Safari auto-zooms on focusing any input with font-size under
     16px — keep this one at 16px on phones to avoid that. */
  #fenDisplay {
    font-size: 17px;
    padding: 12px;
  }

  .btn-small {
    padding: 15px 10px;
    font-size: 17px;
  }
  .btn-tiny {
    padding: 11px 15px;
    font-size: 15px;
  }

  .copy-msg {
    font-size: 15px;
  }

  .pgn-box-header {
    font-size: 16px;
  }
  .pgn-content {
    max-height: 140px;
    font-size: 15px;
  }

  .rules-list {
    font-size: 1.05rem;
  }

  .engine-status {
    font-size: 1.1rem;
  }
}
