/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:            #f2ede4;
  --surface:       #faf6ef;
  --wood-dark:     #5c3a1e;
  --wood-mid:      #8b5e34;
  --wood-light:    #c9934a;
  --accent:        #7b3a10;
  --text:          #2c1a0e;
  --text-muted:    #7a6050;
  --border:        #c8b49a;
  --shadow:        rgba(60,30,10,.18);
  --answer-bg:     #fff8f0;
  --answer-border: #d4a96a;

  /* 将棋盤 */
  --board-bg:      #ddb06b;
  --board-line:    #8b5e34;
  --board-border:  #5c3a1e;
  --piece-sente:   #1a0a00;
  --piece-gote:    #5c2a0a;

  /* 段ラベル幅（盤面左右の対称オフセット用） */
  --rank-w: 1.7em;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Meiryo", "メイリオ", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  font-size: 15px;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== Header ===== */
.site-header {
  background: var(--wood-dark);
  color: #f5e8d0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px var(--shadow);
}

.site-title {
  font-size: clamp(15px, 4vw, 22px);
  font-weight: 700;
  letter-spacing: .05em;
  color: #f5e8d0;
}

/* ===== Buttons ===== */
.btn {
  border: none;
  cursor: pointer;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  padding: 8px 14px;
  transition: filter .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover    { filter: brightness(1.12); }
.btn:active   { filter: brightness(.92); }
.btn:disabled { opacity: .5; cursor: default; }

.btn-answer {
  background: var(--wood-dark);
  color: #f5e8d0;
  flex: 1;
  min-width: 0;
  padding: 11px;
  font-size: 15px;
}

.btn-nav {
  background: var(--wood-mid);
  color: #fff;
  padding: 8px 16px;
  font-size: 14px;
}

/* ===== Tab Nav ===== */
.tab-nav {
  display: flex;
  background: var(--wood-dark);
  padding: 0 12px;
  border-bottom: 3px solid var(--wood-light);
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-nav::-webkit-scrollbar { display: none; }

.tab {
  background: transparent;
  border: none;
  color: #c8b49a;
  cursor: pointer;
  font-family: inherit;
  font-size: clamp(12px, 3vw, 14px);
  padding: 10px 16px;
  letter-spacing: .03em;
  border-bottom: 3px solid transparent;
  margin-bottom: -3px;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.tab:hover { color: #f5e8d0; }
.tab.active {
  color: #f5e8d0;
  border-bottom-color: var(--wood-light);
  font-weight: 700;
}

/* ===== Main Layout ===== */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 14px 12px 4px;
  max-width: 940px;
  margin: 0 auto;
}

@media (min-width: 720px) {
  .main-content {
    flex-direction: row;
    align-items: flex-start;
    padding: 20px 20px 0;
    gap: 24px;
    max-width: 1060px;
  }
}

@media (min-width: 1200px) {
  .main-content {
    max-width: 1280px;
    gap: 32px;
  }
}

/* ===== Board Column ===== */
.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  /* モバイル: 画面幅に合わせて伸縮、最大 460px */
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
}

@media (min-width: 720px) {
  .board-column {
    flex-shrink: 0;
    width: 440px;
    max-width: none;
    margin: 0;
  }
}

@media (min-width: 1200px) {
  .board-column {
    width: 540px;
  }
}

/* ===== 持駒 ===== */
.hand {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  flex-wrap: wrap;
}

.hand-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
  min-width: 52px;
}

.hand-pieces {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  flex: 1;
}

.hand-piece {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  background: #f5ead4;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-weight: 700;
  font-size: clamp(13px, 3.8vw, 20px);
  color: var(--text);
  line-height: 1.4;
}

.hand-piece .cnt {
  font-size: 0.65em;
  color: var(--text-muted);
  font-weight: 600;
}

.hand-piece.sente { color: var(--piece-sente); }
.hand-piece.gote  { color: var(--piece-gote); }

.no-pieces {
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Board Area (将棋盤ラベル込み) ===== */
.board-area {
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* 筋ラベル行: [offset][9 8 7 6 5 4 3 2 1] */
.board-top-row {
  display: flex;
  align-items: flex-end;
  padding-bottom: 3px;
}

.rank-offset {
  width: var(--rank-w);
  flex-shrink: 0;
}

.file-labels {
  flex: 1;
  display: flex;
}

.file-labels span {
  flex: 1;
  text-align: center;
  font-size: clamp(9px, 2.2vw, 12px);
  color: var(--text-muted);
  line-height: 1;
}

/* 盤グリッド + 段ラベル行 */
.board-mid-row {
  display: flex;
  align-items: stretch;
}

/* ===== 将棋盤 CSS描画 ===== */
.board-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  background: var(--board-bg);
  border: 3px solid var(--board-border);
  border-radius: 2px;
  box-shadow:
    0 4px 20px rgba(60,30,10,.35),
    inset 0 1px 4px rgba(255,220,140,.5);
}

.board-cell {
  border: 1px solid var(--board-line);
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  overflow: hidden;
}

/* ===== 駒テキスト ===== */
.piece {
  font-weight: 700;
  line-height: 1;
  /* セル幅の約60%: セル ≈ board幅/9, board幅 ≈ 100vw-ラベル分 */
  font-size: clamp(12px, 5.6vw, 28px);
  text-align: center;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 88%;
  height: 88%;
}

.piece.sente          { color: var(--piece-sente); }
.piece.gote           { color: var(--piece-gote);  transform: rotate(180deg); }
.piece.promoted.sente { color: var(--piece-sente); }
.piece.promoted.gote  { color: var(--piece-gote);  transform: rotate(180deg); }

/* デスクトップでは盤サイズが固定されるためフォントも固定 */
@media (min-width: 720px) {
  .piece { font-size: 28px; }
  .hand-piece { font-size: 20px; }
}

@media (min-width: 1200px) {
  .piece { font-size: 36px; }
  .hand-piece { font-size: 24px; }
}

/* ===== 段ラベル ===== */
.rank-labels {
  width: var(--rank-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding-left: 4px;
}

.rank-labels span {
  flex: 1;
  display: flex;
  align-items: center;
  font-size: clamp(9px, 2.2vw, 12px);
  color: var(--text-muted);
  line-height: 1;
}

/* ===== Info Column ===== */
.info-column {
  flex: 1;
  min-width: 0;
}

.quiz-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  box-shadow: 0 2px 10px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.quiz-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quiz-title {
  font-size: clamp(14px, 4vw, 18px);
  font-weight: 700;
  color: var(--wood-dark);
  line-height: 1.5;
  margin-bottom: 4px;
}

.quiz-meta { display: flex; gap: 8px; flex-wrap: wrap; }

.meta-tag {
  background: var(--wood-dark);
  color: #f5e8d0;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 600;
}

/* ===== Question ===== */
.question-box {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  font-size: clamp(13px, 3.5vw, 15px);
  line-height: 1.8;
  color: var(--text);
}

.question-box .q-label {
  font-weight: 700;
  font-size: 13px;
  color: var(--wood-mid);
  margin-bottom: 6px;
}

.question-box .q-highlight {
  font-weight: 700;
  font-size: clamp(14px, 4vw, 17px);
  color: var(--accent);
}

/* ===== Answer ===== */
.answer-box {
  background: var(--answer-bg);
  border: 1px solid var(--answer-border);
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.9;
}

.answer-box .a-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--answer-border);
}

.answer-box .a-row {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.answer-box .a-key {
  color: var(--text-muted);
  font-size: 12px;
  min-width: 72px;
  flex-shrink: 0;
}

.answer-box .a-val { color: var(--text); font-weight: 600; }
.answer-box .a-val.advantage-sente { color: #1a6bba; }
.answer-box .a-val.advantage-gote  { color: #ba1a1a; }
.answer-box .a-val.advantage-even  { color: #2a8a2a; }

.answer-box .pv-line {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.7;
  word-break: break-all;
}

/* ===== Nav Bar ===== */
.nav-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  z-index: 50;
  box-shadow: 0 -2px 8px var(--shadow);
}

.counter {
  font-size: 15px;
  font-weight: 700;
  color: var(--wood-dark);
  min-width: 60px;
  text-align: center;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 12px;
  font-size: 13px;
  line-height: 2.2;
}

/* ===== Header Menu Button ===== */
.btn-menu {
  background: transparent;
  color: #f5e8d0;
  border: 1px solid rgba(245,232,208,.35);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-menu:hover { background: rgba(255,255,255,.1); }

/* クイズページ: ヘッダーを [戻るボタン][タイトル中央][スペーサー] の3カラムにする */
.site-header:has(.btn-menu) .site-title { flex: 1; text-align: center; }
.header-spacer { width: 90px; flex-shrink: 0; }

/* ===== Menu Screen ===== */
#menuScreen {
  min-height: calc(100vh - 52px - 72px);
  display: flex;
  align-items: center;
}

.menu-container {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 36px 16px 28px;
}

.menu-heading {
  text-align: center;
  font-size: clamp(16px, 5vw, 22px);
  font-weight: 700;
  color: var(--wood-dark);
  margin-bottom: 28px;
  letter-spacing: .04em;
}

.menu-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 600px) {
  .menu-grid { grid-template-columns: repeat(3, 1fr); }
}

.menu-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 24px 18px;
  cursor: pointer;
  text-align: left;
  transition: border-color .2s, box-shadow .2s, transform .15s;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 2px 8px var(--shadow);
  text-decoration: none;
  color: inherit;
}
.menu-card:hover {
  border-color: var(--wood-mid);
  box-shadow: 0 6px 20px var(--shadow);
  transform: translateY(-2px);
}
.menu-card:active { transform: translateY(0); }

.menu-card-title {
  font-size: clamp(14px, 4vw, 17px);
  font-weight: 700;
  color: var(--wood-dark);
}

.menu-card-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.65;
  flex: 1;
}

.menu-card-note {
  font-size: 11px;
  color: var(--accent);
  background: #fff3eb;
  border: 1px solid var(--answer-border);
  border-radius: 6px;
  padding: 7px 10px;
  line-height: 1.6;
}

/* ===== Board Interaction Highlights ===== */
.board-cell.cell-selected {
  background: rgba(255, 210, 0, 0.60);
}
.board-cell.cell-valid {
  background: rgba(30, 190, 70, 0.32);
  cursor: pointer;
}
.board-cell.cell-valid:hover {
  background: rgba(30, 190, 70, 0.52);
}
.hand-piece.cell-selected {
  background: rgba(255, 210, 0, 0.55);
  border-color: #c8960a;
}

/* ===== Promotion Dialog ===== */
.promo-dialog {
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 400;
}
.promo-inner {
  background: var(--surface);
  border: 2px solid var(--wood-mid);
  border-radius: 14px;
  padding: 28px 36px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.promo-question {
  font-size: 18px;
  font-weight: 700;
  color: var(--wood-dark);
}
.promo-buttons { display: flex; gap: 14px; justify-content: center; }
.btn-promo-yes {
  background: var(--accent);
  color: #fff;
  padding: 10px 28px;
  font-size: 15px;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.btn-promo-no {
  background: #888;
  color: #fff;
  padding: 10px 28px;
  font-size: 15px;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.btn-promo-yes:hover { filter: brightness(1.12); }
.btn-promo-no:hover  { filter: brightness(1.12); }

/* ===== Result Overlay ===== */
.result-overlay {
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.40);
  z-index: 500;
  pointer-events: none;
}
.result-text {
  font-size: clamp(44px, 14vw, 80px);
  font-weight: 700;
  padding: 20px 52px;
  border-radius: 18px;
  letter-spacing: .06em;
}
.result-text.correct {
  background: #e8f5e9;
  color: #1b5e20;
  border: 4px solid #43a047;
}
.result-text.wrong {
  background: #fde8e8;
  color: #b71c1c;
  border: 4px solid #e53935;
}

/* ===== Quiz List Page ===== */
.quiz-list-section {
  min-height: calc(100vh - 52px - 72px);
  display: flex;
  align-items: flex-start;
  padding-top: 8px;
}

.quiz-list-container {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 28px 16px 24px;
}

.quiz-list-heading {
  font-size: clamp(15px, 4vw, 20px);
  font-weight: 700;
  color: var(--wood-dark);
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
}

.quiz-list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.quiz-list-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  transition: border-color .18s, box-shadow .18s, transform .14s;
  box-shadow: 0 1px 6px var(--shadow);
}
.quiz-list-card:hover {
  border-color: var(--wood-mid);
  box-shadow: 0 4px 14px var(--shadow);
  transform: translateY(-2px);
}
.quiz-list-card:active { transform: translateY(0); }

.qlc-num {
  font-size: clamp(16px, 4.5vw, 20px);
  font-weight: 700;
  color: var(--wood-dark);
}

.qlc-turn {
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== Quiz Detail: button row & hint ===== */
.quiz-btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-hint {
  background: var(--wood-mid);
  color: #fff;
  flex: 1;
  min-width: 0;
  padding: 11px;
  font-size: 15px;
}

.hint-box {
  background: #fffbe8;
  border: 1px solid #d4b84a;
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 14px;
}

.hint-text {
  font-weight: 600;
  color: #7a5a00;
}

.cp-note {
  color: #999;
  font-size: 11px;
  margin-left: 5px;
}

/* ===== Keisei Judgment Buttons ===== */
.keisei-judge-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-keisei {
  flex: 1;
  min-width: 0;
  padding: 12px 8px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s, background .15s, color .15s;
}

.btn-keisei-sente {
  color: #1a5ca8;
  border-color: #6fa8dc;
}
.btn-keisei-sente:hover {
  background: #e8f0fb;
  border-color: #1a5ca8;
}

.btn-keisei-even {
  color: #2a7a2a;
  border-color: #7abd7a;
}
.btn-keisei-even:hover {
  background: #e8f5e8;
  border-color: #2a7a2a;
}

.btn-keisei-gote {
  color: #a82020;
  border-color: #dc6f6f;
}
.btn-keisei-gote:hover {
  background: #fbe8e8;
  border-color: #a82020;
}

/* ===== Footer ===== */
.site-footer {
  background: var(--wood-dark);
  color: #a89070;
  text-align: center;
  padding: 18px 16px;
  font-size: 12px;
  line-height: 2;
}
