/* Animal Chess styles. / どうぶつチェス スタイル */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #fdf8ef;
  --card: #ffffff;
  --ink: #5b4a3f;
  --accent: #f2a65a;
  --accent-dark: #e08c3c;
  --light-sq: #fdf3dd;
  --dark-sq: #bcd9a0;
  --select: #ffe08a;
  --lastmove: rgba(255, 200, 90, 0.55);
  --check: #ff8f8f;
  --hint: #9ad0ff;
  --radius: 16px;
  /* Desktop: both banquet rooms fit vertically; the turn/status bar lives in
     the right sidebar and no longer needs height below the board. */
  --board-size: min(54vw, 660px, max(360px, calc(100vh - 352px)));
  --board-size: min(54vw, 660px, max(360px, calc(100dvh - 352px)));
  --side-w: 360px;
  --cell: calc(var(--board-size) / 8);
  /* The two illustrated views share identical banquet-room geometry. */
  --illustrated-room-height: 94px;
}

html, body {
  background: linear-gradient(160deg, #fdf8ef 0%, #f3ecdd 60%, #e8f2dc 100%);
  color: var(--ink);
  font-family: "Segoe UI", "Hiragino Maru Gothic ProN", Meiryo, sans-serif;
  min-height: 100vh;
}

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px 6px;
}
.app-header h1 { font-size: 1.5rem; letter-spacing: 1px; }
.app-header .sub { font-size: 0.85rem; color: #a08c7a; font-weight: normal; margin-left: 6px; }
.icon-btn {
  font-size: 1.3rem; background: var(--card); border: 2px solid #eadfce;
  border-radius: 50%; width: 44px; height: 44px; cursor: pointer;
  transition: transform 0.15s;
}
.icon-btn:hover { transform: scale(1.1); }
.header-btns { display: flex; gap: 8px; align-items: center; }
.language-select {
  min-height: 32px;
  border: 1px solid #eadfce;
  border-radius: 8px;
  padding: 4px 7px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
}
.icon-btn.muted { opacity: 0.4; filter: grayscale(1); }

.layout {
  display: flex; gap: 20px; padding: 6px 22px 24px;
  align-items: flex-start; justify-content: center;
}

/* ===== Board / 盤面 ===== */
.board-col { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.side-col { display: flex; flex-direction: column; gap: 16px; width: var(--side-w); flex-shrink: 0; }

.board-wrap { position: relative; width: var(--board-size); }
.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: var(--board-size);
  aspect-ratio: 1;
  border: 6px solid #8a6f56;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(120, 90, 60, 0.25);
  user-select: none;
}
.square {
  border: 0; border-radius: 0; padding: 0; font: inherit; color: inherit;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  min-width: 0; min-height: 0;
}
.square.light { background: var(--light-sq); }
.square.dark  { background: var(--dark-sq); }
.square:focus-visible { outline: 3px solid #28625a; outline-offset: -3px; }
.square.selected { background: var(--select) !important; }
.square.lastmove::before {
  content: ""; position: absolute; inset: 0; background: var(--lastmove);
  pointer-events: none;
}
.square.check { background: var(--check) !important; animation: pulse 0.8s ease-in-out infinite alternate; }
.square.hint-sq { outline: 4px solid var(--hint); outline-offset: -4px; animation: pulse 0.7s ease-in-out infinite alternate; }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.18); } }

.square .dot {
  position: absolute; width: 26%; height: 26%;
  background: rgba(90, 70, 50, 0.35); border-radius: 50%;
  pointer-events: none;
}
.square.cap-target .dot {
  width: 88%; height: 88%; background: none;
  border: 4px dashed rgba(220, 90, 60, 0.65);
}
.square .coord {
  position: absolute; font-size: 0.7rem; color: #493827; z-index: 21;
  pointer-events: none; font-weight: bold;
}
.square .coord.file { right: 3px; bottom: 2px; }
.square .coord.rank { left: 3px; top: 2px; }

/* Pieces / ピース */
.piece { line-height: 1; z-index: 2; transition: transform 0.1s; }
.square:hover .piece { transform: scale(1.08); }
.piece.emoji {
  font-size: calc(var(--cell) * 0.66);
  width: 84%; height: 84%;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.piece.emoji.w { background: rgba(255, 253, 245, 0.92); box-shadow: 0 0 0 3px #f6c95c, 0 2px 4px rgba(0,0,0,0.18); }
.piece.emoji.b { background: rgba(101, 78, 63, 0.85); box-shadow: 0 0 0 3px #4e3a2d, 0 2px 4px rgba(0,0,0,0.25); }
.piece.glyph { font-size: calc(var(--board-size) / 8 * 0.8); }
.piece.glyph.w { color: #fffdf6; text-shadow: 0 0 2px #3a2c20, 0 0 3px #3a2c20, 0 2px 3px rgba(0,0,0,0.4); }
.piece.glyph.b { color: #3d2f24; text-shadow: 0 1px 2px rgba(255,255,255,0.35); }

/* ===== Banquet venues / おもてなし会場 ===== */
.venue {
  background: linear-gradient(135deg, #fff6e5, #ffeccc);
  border: 2px solid #f2d9a8;
  border-radius: var(--radius);
  padding: 5px 14px;
  width: var(--board-size);
  min-height: 46px;
}
.venue-title { font-size: 0.625rem; font-weight: bold; color: #a97f3c; margin-bottom: 2px; line-height: 1.25; }
.venue-guests { display: flex; flex-wrap: wrap; gap: 6px; min-height: 30px; align-items: center; }
.guest {
  display: inline-flex; align-items: center;
  font-size: 1.25rem;
  background: #fffdf7; border: 1.5px solid #f0dcb2; border-radius: 12px;
  padding: 2px 7px;
  animation: guest-in 0.5s ease;
}
.guest .food { font-size: 0.95rem; margin-left: 2px; animation: nibble 1.6s ease-in-out infinite; }
.guest.plain { font-size: 1.4rem; padding: 0 4px; border: none; background: none; }
@keyframes guest-in { from { transform: scale(0) rotate(-20deg); } to { transform: scale(1); } }
@keyframes nibble { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-3px) rotate(-12deg); } }

/* ===== Carriage animation / 馬車アニメーション ===== */
.overlay { position: absolute; inset: 0; pointer-events: none; z-index: 10; overflow: visible; }
.carriage {
  position: absolute;
  display: flex; align-items: flex-end;
  transition: transform 1.8s cubic-bezier(0.45, 0.05, 0.55, 0.95);
  filter: drop-shadow(0 3px 3px rgba(0,0,0,0.25));
}
.carriage .pony { font-size: 2rem; animation: trot 0.35s ease-in-out infinite alternate; }
.carriage .cart {
  position: relative;
  background: linear-gradient(#d98d4f, #b96f35);
  border: 2px solid #7c4a20;
  border-radius: 6px 10px 4px 4px;
  padding: 2px 8px 4px;
  margin-left: -4px;
  font-size: 1.5rem;
}
.carriage .cart .rider { display: inline-block; animation: bounce-ride 0.35s ease-in-out infinite alternate; }
.carriage .wheel {
  position: absolute; bottom: -12px;
  width: 16px; height: 16px;
  border: 3px solid #5d3a1a; border-radius: 50%;
  background: radial-gradient(#e8c07a 30%, #8a5a28 32%);
  animation: roll 0.6s linear infinite;
}
.carriage .wheel.w1 { left: 4px; } .carriage .wheel.w2 { right: 4px; }
@keyframes trot { from { transform: translateY(0); } to { transform: translateY(-4px); } }
@keyframes bounce-ride { from { transform: translateY(0) rotate(-4deg); } to { transform: translateY(-3px) rotate(4deg); } }
@keyframes roll { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* ===== Status bar / ステータスバー ===== */
.status-bar {
  background: var(--card); border: 2px solid #eadfce; border-radius: var(--radius);
  padding: 10px 16px; font-size: 1.05rem; font-weight: bold;
  width: var(--board-size); text-align: center; min-height: 46px;
}
.status-bar .thinking { color: #b0854f; }

/* On desktop the SAME live status element sits above the sidebar controls.
   Small screens retain the original under-board position. */
@media (min-width: 1100px) {
  .side-col > .status-bar {
    width: 100%;
    min-height: 46px;
    padding: 9px 12px;
    font-size: 1rem;
  }
}

/* ===== Panels / パネル ===== */
.panel {
  background: var(--card);
  border: 2px solid #eadfce;
  border-radius: var(--radius);
  padding: 14px;
  width: 100%;
  box-shadow: 0 6px 18px rgba(120, 90, 60, 0.12);
}
/* Give the upper-right card more room for the game record. / 右上カードは対局の棋譜を広く見せる */
.card-kifu { flex: 1 1 auto; }
.movelist-wrap.tall .movelist { max-height: min(38vh, 360px); }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab {
  flex: 1; padding: 8px 4px; font-size: 0.92rem; font-weight: bold;
  background: #f6efe2; color: #8a7460; border: none; border-radius: 10px;
  cursor: pointer; transition: background 0.15s;
  font-family: inherit;
}
.tab.active { background: var(--accent); color: #fff; }
.tab-page { display: none; }
.tab-page.active { display: block; }

.settings { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.settings label { display: flex; flex-direction: column; font-size: 0.82rem; font-weight: bold; gap: 3px; }
.settings select {
  font-size: 0.95rem; padding: 7px 8px; border: 2px solid #eadfce; border-radius: 10px;
  background: #fffdf8; color: var(--ink); font-family: inherit;
}

.btn-row { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
.btn-row.center { justify-content: center; align-items: center; }
.btn {
  padding: 8px 12px; font-size: 0.9rem; font-weight: bold;
  background: #f6efe2; color: var(--ink);
  border: 2px solid #eadfce; border-radius: 12px; cursor: pointer;
  transition: transform 0.12s, background 0.15s;
  font-family: inherit;
}
.btn:hover { transform: translateY(-2px); background: #fdf3dd; }
.btn.primary { background: var(--accent); border-color: var(--accent-dark); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.small { padding: 6px 10px; }
.btn.full { width: 100%; }
.file-btn { display: inline-flex; align-items: center; }

.movelist-wrap { border-top: 2px dashed #eadfce; padding-top: 8px; }
.movelist-title { font-size: 0.8rem; font-weight: bold; color: #a08c7a; margin-bottom: 4px; }
.movelist {
  list-style: none; max-height: 180px; overflow-y: auto;
  font-size: 0.9rem; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px;
}
.movelist li { padding: 2px 6px; border-radius: 6px; background: #faf6ec; }
.movelist li .no { color: #b3a08c; font-size: 0.75rem; margin-right: 4px; }
.movelist li.current { background: var(--select); }

/* Puzzles / パズル */
.puzzle-info { background: #f3f9ff; border: 2px solid #cfe4f7; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 10px; }
.puzzle-title { font-weight: bold; font-size: 1rem; }
.puzzle-goal { font-size: 0.88rem; color: #4d7ba6; margin-top: 3px; }
.puzzle-completion { display: flex; flex-direction: column; align-items: flex-start; gap: 9px; margin-top: 12px; padding-top: 10px; border-top: 1px solid #cfe4f7; font-size: 0.9rem; color: #285a7a; font-weight: bold; }
.puzzle-completion.hidden, .puzzle-completion .hidden { display: none; }
.puzzle-completion .btn { max-width: 100%; white-space: normal; text-align: center; }
/* Return context appears only for puzzles opened from a lesson. */
.related-lesson-return {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-bottom: 10px; padding: 8px 10px;
  border: 1.5px solid #d9ceb9; border-radius: 9px; background: #f9f5ec;
}
.related-lesson-return .btn { font-size: .81rem; padding: 6px 10px; }
.related-lesson-title { font-size: .78rem; color: #79674e; overflow-wrap: anywhere; }
.puzzle-list { display: flex; flex-direction: column; gap: 5px; max-height: 300px; overflow-y: auto; }
.puzzle-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border: 2px solid #eadfce; border-radius: 10px;
  background: #fffdf8; cursor: pointer; font-size: 0.88rem; font-weight: bold;
  color: var(--ink); font-family: inherit; text-align: left;
}
.puzzle-item:hover { background: #fdf3dd; }
.puzzle-item.active { border-color: var(--accent); background: #fff3e0; }
.puzzle-item .badge {
  font-size: 0.7rem; padding: 2px 7px; border-radius: 999px; color: #fff;
  background: #7fb069; flex-shrink: 0;
}
.puzzle-item .badge.m2 { background: #e08c3c; }
.puzzle-item .badge.m3 { background: #d1615d; }
.puzzle-item .puz-name { display: flex; flex-direction: column; gap: 1px; }
.puz-theme {
  font-size: 0.66rem; font-weight: bold; color: #9a7ac8;
  background: #f0eafb; border-radius: 6px; padding: 1px 6px; align-self: flex-start;
}
.puzzle-item .done { margin-left: auto; }
.puz-idea { font-size: 0.82rem; color: #4d7ba6; font-weight: normal; }

/* Move list / 棋譜 */
.hint-text { font-size: 0.8rem; color: #a08c7a; margin-bottom: 6px; }
#pgn-input {
  width: 100%; border: 2px solid #eadfce; border-radius: 10px; padding: 8px;
  font-size: 0.85rem; font-family: Consolas, monospace; resize: vertical;
  background: #fffdf8; color: var(--ink); margin-bottom: 8px;
}
.replay-controls { margin-bottom: 10px; }
.replay-counter { font-weight: bold; font-size: 0.9rem; padding: 0 6px; }
.hidden { display: none !important; }

/* Toasts / トースト */
.toast-area {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 100; pointer-events: none;
}
.toast {
  background: rgba(80, 60, 45, 0.92); color: #fff7ea;
  padding: 10px 20px; border-radius: 18px; font-size: 0.95rem; font-weight: bold;
  animation: toast-in 0.3s ease;
  max-width: 90vw; text-align: center; white-space: pre-line; line-height: 1.5;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
.toast.out { opacity: 0; transition: opacity 0.4s; }

/* Modals / モーダル */
.modal {
  position: fixed; inset: 0; background: rgba(70, 50, 35, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-box {
  background: var(--card); border-radius: 20px; padding: 26px 30px;
  text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,0.3);
  font-size: 1.05rem; font-weight: bold;
  max-width: 90vw;
  animation: modal-in 0.25s ease;
}
@keyframes modal-in { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.promo-choices { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.promo-choices button {
  display: flex; align-items: center; justify-content: center; min-width: 0;
  font-size: 2.2rem; width: 64px; height: 64px;
  border: 2px solid #eadfce; border-radius: 14px; background: #fffdf8; cursor: pointer;
  transition: transform 0.12s;
}
.promo-choices button:hover { transform: scale(1.12); background: #fdf3dd; }
.gameover-emoji { font-size: 2.6rem; margin-bottom: 8px; letter-spacing: 6px; }

/* Confetti / 紙吹雪 */
.confetti {
  position: fixed; top: -40px; z-index: 200; pointer-events: none;
  font-size: 1.6rem;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(720deg); }
}

/* Board shake (incorrect answer). / 盤の揺れ(不正解) */
.board.shake { animation: shake 0.4s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  50% { transform: translateX(8px); }
  75% { transform: translateX(-5px); }
}

/* ===== Piece-type badges / コマ種類バッジ ===== */
.type-badge {
  position: absolute; top: 1px; right: 1px;
  width: 18px; height: 18px; line-height: 18px;
  font-size: 14px; text-align: center;
  border-radius: 50%;
  pointer-events: none; z-index: 20;
}
.type-badge.w { background: rgba(255, 253, 245, 0.95); color: #3d2f24; box-shadow: 0 0 0 1px #c8b28a; }
.type-badge.b { background: rgba(70, 56, 46, 0.95); color: #fff6e0; box-shadow: 0 0 0 1px #2c211a; }

/* Square cells and contained miniatures, including selection. / 選択中も正方形のマス内に収める。 */
.mode-3d .board { border: 8px solid #7c6248; }
.board .square { overflow: hidden; }
.p3d {
  position: absolute; inset: 2%;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  z-index: 5;
}
.p3d canvas {
  display: block;
  width: 100%; height: 100%; object-fit: contain;
  image-rendering: auto;
  transition: transform 0.15s ease-out;
}
.p3d canvas[data-render="pixel"] { width: auto; height: 84%; image-rendering: pixelated; }
/* HD source pixels stay lossless in canvas; downscale smoothly for 8x8 boards. */
.p3d canvas[data-hd="1"], .bq-guest canvas.spr[data-hd="1"],
.promo-choices canvas[data-hd="1"] { image-rendering: auto; }

.mode-3d .square.selected .p3d canvas { transform: translateY(-2%); }
@keyframes bob3d {
  0%, 48% { transform: translateY(0); }
  52%, 100% { transform: translateY(-4%); }
}

/* Illustrated board/banquet layout is independent of the art style.
   Keep the Miniature geometry as the reference for both illustrated modes. */
.venue.v3d, .venue.vmini { padding: 6px 8px 8px; }
.venue.v3d .venue-title, .venue.vmini .venue-title {
  position: static; display: block; margin: 0 4px 3px; padding: 0;
  background: transparent; border: 0; font-size: 9px;
  line-height: 1.2; letter-spacing: 0;
}
.venue.v3d .venue-guests, .venue.vmini .venue-guests {
  height: var(--illustrated-room-height);
  min-height: var(--illustrated-room-height);
}

/* ===== 3D banquet venues / 3D宴会会場 ===== */
.venue.v3d { background: linear-gradient(#f8e2b8, #eac98e); border-color: #d8b070; }
.venue.v3d .venue-guests {
  display: block; position: relative; overflow: hidden;
  border-radius: 10px;
  background:
    linear-gradient(rgba(120, 80, 40, 0.42) 0 26px, transparent 26px),
    repeating-linear-gradient(0deg, #e2b876 0 12px, #d8ac66 12px 24px);
}
/* Matched day banquet rooms: 640x94 native-resolution frames, stacked in a
   single atlas. Mobile widths crop at the sides without squashing furniture.
   :not(.vmini) is essential: miniature rooms also carry the v3d class. */
.venue.v3d:not(.vmini) .venue-guests {
  background-image: url('../assets/scenery/banquet-day-atlas.webp');
  background-size: 640px 188px;
  background-repeat: no-repeat;
  background-position: center top;
  border-radius: 8px;
}
.venue.v3d:not(.vmini)[data-team="b"] .venue-guests {
  background-position: center bottom;
}
/* The feast is already part of the pixel background. Leave miniature props
   visible, and avoid placing redundant food over the pixel-art table. */
.venue.v3d:not(.vmini) .bq-table,
.venue.v3d:not(.vmini) .bq-deco { display: none; }
.venue.v3d:not(.vmini) .venue-guests::before,
.venue.v3d:not(.vmini) .venue-guests::after { content: none; }
/* HD food is downscaled smoothly and displayed in front of the guests. */
.venue.v3d:not(.vmini) .bq-guest canvas.item.feast-art {
  image-rendering: auto;
  right: -13px;
  bottom: 9px;
}

/* Classic art uses a distinct 640x188 sheet: two 640x94 scenes.
   Walls, furniture, cake and wood are identical; only hanging textiles and
   the table runner have red/blue palettes. Native-size center cropping
   preserves crisp proportions on mobile without vertical stretching. */
.venue.v3d.vclassic:not(.vmini) .venue-guests {
  background: #ead6b6 url('../assets/scenery/banquet-classic-day.png')
    center top / 640px 188px no-repeat;
  border-radius: 8px;
}
.venue.v3d.vclassic:not(.vmini)[data-team="b"] .venue-guests {
  background-position: center bottom;
}
/* Food and table are part of this scene. Keep the captured animals and their
   animated handheld food as separate layers, but don't double the furniture. */
.venue.v3d.vclassic:not(.vmini) .bq-table,
.venue.v3d.vclassic:not(.vmini) .bq-deco { display: none; }
.venue.v3d.vclassic:not(.vmini) .venue-guests::before,
.venue.v3d.vclassic:not(.vmini) .venue-guests::after { content: none; }

.bq-table {
  position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%);
  width: 110px; image-rendering: pixelated; z-index: 1;
}
.bq-deco { position: absolute; bottom: 30px; image-rendering: pixelated; z-index: 2; }
.bq-guest { position: absolute; bottom: 4px; z-index: 4; transition-property: left; transition-timing-function: linear; }
.bq-guest canvas.spr {
  display: block; width: 40px; height: auto; image-rendering: pixelated;
  animation: bob3d 0.8s linear infinite;
}
.bq-guest canvas.spr[data-render="miniature"] { image-rendering: auto; }
.bq-guest.flip canvas.spr { transform: scaleX(-1); }
.bq-guest canvas.item {
  position: absolute; right: -16px; bottom: 12px;
  image-rendering: pixelated; display: none;
  animation: munch 0.8s ease-in-out infinite;
}
.bq-guest.eating canvas.item, .bq-guest.drinking canvas.item { display: block; }
.bq-guest.sleeping canvas.spr { transform: rotate(90deg) translateY(-8px); animation: none; }
.bq-zzz { display: none; position: absolute; top: -14px; right: -4px; font-size: 13px; }
.bq-guest.sleeping .bq-zzz { display: block; animation: zzzfloat 1.8s ease-in-out infinite; }
@keyframes zzzfloat {
  0% { opacity: 0; transform: translateY(3px); }
  40% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-8px); }
}
@keyframes munch {
  0%, 100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(-4px) rotate(-14deg); }
}

/* ===== 3D carriage / 3D馬車 ===== */
.carriage3d {
  position: absolute;
  transition: transform 2.2s cubic-bezier(0.45, 0.05, 0.55, 0.95);
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.25));
  z-index: 30;
}
.carriage3d canvas { display: block; width: 128px; image-rendering: auto; }
.carriage3d canvas[data-render="pixel"] { image-rendering: pixelated; }
/* Do not flash placeholder pixel animals while the approved HD atlas decodes.
   The board itself remains laid out and interactive during initialization. */
.pixel-art-loading .mode-3d:not(.mode-classic) .p3d canvas,
.pixel-art-loading .venue.v3d:not(.vclassic):not(.vmini) .bq-guest canvas.spr { visibility: hidden; }

/* Miniature maple/walnut board and timber dining rooms. / ミニチュア専用の木製盤と食堂。 */
.mode-miniature {
  --light-sq: #e8d5ae;
  --dark-sq: #a18360;
  --lastmove: rgba(245, 198, 93, .48);
  --select: #efc979;
}
.mode-miniature .board {
  border: 8px solid #735438;
  border-radius: 12px;
  box-shadow: 0 0 0 1px #b99a63, 0 3px 0 2px #473727, 0 10px 24px #49372730;
}
.mode-miniature .square {
  /* The texture is quiet and does not cover move/focus indicators. / 木目は操作表示を覆わない。 */
  background-image: repeating-linear-gradient(4deg, #fff3cf0d 0 1px, transparent 1px 5px),
    linear-gradient(110deg, #fff5d11a, transparent 48%, #59422a0d);
  box-shadow: inset 0 0 0 .5px #62492e26;
}
.mode-miniature .square.dark .coord { color: #fff4dc; text-shadow: 0 1px 1px #4c352a; }
.mode-miniature .square.light .coord { color: #60472e; }
.mode-miniature .square .dot { background: #392d2873; }
.mode-miniature .square.cap-target .dot { background: none; border-color: #a93f36; }
.mode-miniature .square.selected { box-shadow: inset 0 0 0 3px #825a30; }
.mode-miniature .square:focus-visible { outline-color: #1d5458; }
.venue.vmini {
  position: relative;
  background: linear-gradient(#f4e7ca, #dac3a0);
  border: 2px solid #b4976a;
  box-shadow: inset 0 1px 0 #fff5de, 0 2px 3px #61452c1a;
}
.venue.vmini .venue-title { color: #624a32; }
.venue.vmini .venue-guests {
  background: #bd9c70 url('../assets/scenery/banquet-room.svg') center top / cover no-repeat;
  border: 1px solid #7b5d3e; border-radius: 9px;
  box-shadow: inset 0 2px 6px #49362430;
}
.venue.vmini .venue-guests::before, .venue.vmini .venue-guests::after { content: none; }
.vmini .bq-table { width: 180px; bottom: 3px; image-rendering: auto; }
.vmini .bq-deco { bottom: 35px; image-rendering: auto; }
.vmini .bq-guest { bottom: 3px; }
.vmini .bq-guest canvas.spr { width: 52px; image-rendering: auto; animation: none; }
.vmini .bq-guest canvas.item { right: -8px; bottom: 8px; image-rendering: auto; }
.vmini .bq-guest.sleeping canvas.spr { transform: rotate(68deg) translateY(-5px); }
.vmini .bq-zzz { top: -6px; right: 0; }

/* 3D promotion selection / 3Dプロモーション選択 */
.promo-choices canvas { width: 44px; height: auto; image-rendering: pixelated; }
.promo-choices canvas[data-render="miniature"] { width: 100%; height: 100%; object-fit: contain; image-rendering: auto; }

.check-line {
  flex-direction: row !important; align-items: center; gap: 6px !important;
  font-size: 0.85rem !important;
}
.check-line input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ===== Learn and replay panel (below the board) / 学習・棋譜再生パネル(盤の下) ===== */
.study-panel {
  overflow-anchor: none; /* changing lesson notes must not shift the page */
  width: 100%; box-sizing: border-box;
  background: #fbf6ec; border: 2px solid #e6d8bf; border-radius: var(--radius);
  padding: 10px 14px;
}
/* Scroll long annotations inside the panel so they do not push out the board or other cards. / 解説文が長いときは枠内スクロールにして、盤や他のカードを押し出さない */
.study-note { max-height: 40vh; overflow-y: auto; }
.study-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.study-title { font-weight: bold; font-size: 1rem; color: #7a5a2e; }
.icon-btn.small { width: 30px; height: 30px; font-size: 0.9rem; border-width: 1.5px; }
.study-meta { font-size: 0.78rem; color: #a08c7a; margin: 2px 0 6px; }
.study-note {
  font-size: 0.92rem; line-height: 1.6; color: var(--ink);
  background: #fffdf8; border: 1.5px solid #eadfce; border-radius: 10px;
  padding: 8px 12px; min-height: 3.4em; margin-bottom: 8px;
}
/* Lesson move comparison shares the existing replay chessboard.
   Modest inset layout, never overlays the banquet room or chessboard. */
.study-comparison {
  margin: 0 0 9px; padding: 9px 10px;
  border: 1.5px solid #d6c9af; border-radius: 10px;
  background: #f9f5ec;
}
.study-compare-head { font-size: .82rem; font-weight: 700; color: #655039; margin-bottom: 6px; }
.study-compare-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.study-compare-actions .btn { font-size: .79rem; padding: 6px 9px; }
.study-compare-actions .btn[aria-pressed="true"] { border-color: #8d7145; background: #eee3d0; font-weight: 700; }
.study-compare-line { font-size: .76rem; font-weight: 700; margin-top: 7px; color: #685641; }
.study-compare-reason { font-size: .81rem; line-height: 1.55; margin: 5px 0; color: #524638; }
.study-compare-disclaimer { color: #877964; font-size: .71rem; line-height: 1.45; margin: 6px 0 0; }
.study-takeaway {
  margin-top: 6px; padding-top: 6px; border-top: 1px dashed #e0d0b0;
  color: #b0763a; font-weight: bold;
}
.study-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.study-nav .replay-counter { min-width: 54px; }
.study-nav .btn.primary { margin-left: auto; }
.movelist.study-moves { max-height: 128px; margin: 0; }
/* Learning course: compact progression, clear statuses and hands-on tasks. */
.learn-chapter-desc {
  font-size: .81rem; line-height: 1.5; color: #7c695b;
  margin: 9px 0 6px;
}
.learn-progress {
  font-size: .76rem; font-weight: 600; color: #806d54;
  margin-bottom: 10px;
}
.study-item .learn-state { display: block; margin-top: 3px; font-size: .72rem; color: #6b8070; }
.study-practice {
  border: 1.5px solid #dfcdae; border-radius: 10px;
  background: #fffdf8; padding: 9px 10px; margin-bottom: 9px;
}
.practice-prompt { color: #584b3c; font-size: .84rem; line-height: 1.55; font-weight: 600; }
.practice-feedback {
  min-height: 1.25em; font-size: .82rem; line-height: 1.55;
  color: #685a43; margin: 6px 0 7px;
}
.practice-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.practice-actions .btn { padding: 6px 8px; font-size: .78rem; }
.practice-feedback.is-correct { color: #286449; }
.practice-feedback.is-incorrect { color: #955039; }


/* Small reasoning check inside the existing lesson panel. */
.study-reasoning {
  margin: 0 0 10px; padding: 10px;
  background: #f9f5ec; border: 1.5px solid #d8cbb2; border-radius: 10px;
}
.study-reasoning-heading { font-size: .89rem; font-weight: 700; color: #665039; }
.study-reasoning-progress { margin: 4px 0 7px; font-size: .75rem; color: #826e56; }
.study-reasoning-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 7px; }
.study-reasoning-tabs .btn { font-size: .8rem; padding: 6px 9px; }
.study-reasoning-tabs .btn[aria-pressed="true"] { border-color: #8d7145; background: #eee3d0; font-weight: 700; }
.study-reasoning-question { font-size: .83rem; font-weight: 650; line-height: 1.5; margin: 7px 0; color: #524639; }
.study-reasoning-options { display: grid; gap: 6px; }
.study-reasoning-options .btn {
  display: block; width: 100%; text-align: left; white-space: normal;
  font-size: .8rem; line-height: 1.45; padding: 7px 9px;
}
.study-reasoning-options .btn[aria-pressed="true"] { border-color: #8d7145; background: #eee3d0; }
.study-reasoning-options .btn.is-correct { border-color: #60866d; }
.study-reasoning-options .btn.is-incorrect { border-color: #b98575; }
.study-reasoning-feedback { min-height: 1.2em; color: #655443; font-size: .79rem; line-height: 1.55; margin: 7px 0 4px; }
.study-reasoning-caution { color: #877964; font-size: .72rem; line-height: 1.45; margin: 5px 0 0; }

.reasoning-position {
  margin: 8px 0 11px; display: flex; flex-direction: column; align-items: flex-start;
}
.reasoning-position-label {
  font-size: .76rem; font-weight: 600; color: #665039; margin: 0 0 6px;
}
.reasoning-position-board {
  width: min(100%, 240px); aspect-ratio: 1;
  display: grid; grid-template-columns: repeat(8, minmax(0, 1fr));
  border: 2px solid #9d8565; border-radius: 5px; overflow: hidden;
  user-select: none;
}
.reasoning-position-square {
  display: flex; align-items: center; justify-content: center; min-width: 0;
  aspect-ratio: 1; font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", sans-serif;
  font-size: clamp(15px, 3vw, 25px); line-height: 1; position: relative;
}
.reasoning-position-square.light { background: #f1e7d4; }
.reasoning-position-square.dark { background: #bb9f7d; }
.reasoning-position-square.white-piece { color: #fffdfa; text-shadow: 0 1px 2px #3b3027, 0 -1px #3b3027; }
.reasoning-position-square.black-piece { color: #342d29; }
.reasoning-position-square.reasoning-position-move { box-shadow: inset 0 0 0 3px #648c70; }
.reasoning-position-controls { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.reasoning-position-controls .btn { font-size: .75rem; padding: 5px 8px; }
.reasoning-position-controls .btn[aria-pressed="true"] { background: #eee3d0; border-color: #8d7145; }
.reasoning-position-controls .btn:disabled { opacity: .53; cursor: default; }
@media (max-width: 420px) {
  .reasoning-position-board { width: min(100%, 210px); }
  .reasoning-position-square { font-size: 20px; }
}


/* ===== Learn and famous-game lists / まなぶ・名局リスト ===== */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  padding: 6px 12px; font-size: 0.85rem; font-weight: bold; font-family: inherit;
  background: #f0e7d6; color: #8a7460; border: 2px solid #e6d8bf; border-radius: 999px;
  cursor: pointer;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent-dark); }
/* Use a different color for difficulty chips (mate length) so they are distinct from theme chips. / 難易度チップ(詰み手数)はテーマのチップと見分けがつくよう色を変える */
.chip.lv { background: #eaf1e2; color: #6d8a58; border-color: #cfe0be; }
.chip.lv.active { background: #7fb069; color: #fff; border-color: #6d9b58; }
.study-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.study-list.tall { max-height: 420px; }
.study-item {
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  padding: 8px 12px; border: 2px solid #eadfce; border-radius: 10px;
  background: #fffdf8; cursor: pointer; font-family: inherit; color: var(--ink);
}
.study-item:hover { background: #fdf3dd; }
.study-item-title { font-weight: bold; font-size: 0.92rem; }
.study-item-sub { font-size: 0.76rem; color: #a08c7a; }

@media (max-width: 1099px) {
  :root { --board-size: min(94vw, 660px, 58vh); }
  .layout { flex-direction: column; align-items: center; }
  .side-col { width: var(--board-size); }
  /* Let tall banquet/board groups scroll so they cannot cover the settings. / 背の高い盤と会場が設定を覆わないよう全体をスクロールする。 */
  .board-col { position: static; background: var(--bg); padding-bottom: 4px; }
}

@media (max-width: 600px) {
  .app-header { flex-wrap: wrap; gap: 8px; padding: 12px 12px 8px; }
  .app-header h1 { flex-basis: 100%; font-size: 1.2rem; letter-spacing: 0; }
  .app-header .sub { display: inline-block; font-size: 0.7rem; }
  .header-btns { width: 100%; justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Royal character art: contain within existing board square; never scale outside.
   The chick occupies ~80% of its common transparent frame to read as a pawn. */
.mode-3d .p3d canvas[data-royal="1"] {
  width: auto; height: 84%; max-height: 84%; max-width: 84%;
  object-fit: contain; image-rendering: auto;
}
.venue.v3d .bq-guest canvas.spr[data-royal="1"] {
  image-rendering: auto;
}
