* { box-sizing: border-box; }

.site-header {
  width: 100%;
  height: 40px;
  background: #1a1a1a;
  border-bottom: 1px solid #333333;
  display: flex;
  align-items: center;
  padding: 0 16px;
}

.site-header .logo {
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 1px;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  font-family: "Yu Gothic", "Hiragino Sans", sans-serif;
  background: linear-gradient(180deg, #3b3c3f 0%, #2d2e31 100%);
  color: #f3f3f3;
}

.app {
  width: 100%;
  height: calc(100vh - 40px);
  height: calc(100dvh - 40px);
  padding: 0 10px 8px 10px;
  background: linear-gradient(180deg, #414245 0%, #2e2f32 100%);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: hidden;
}

.layout {
  width: min(100%, 1000px);
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 10px;
  align-items: start;
  justify-content: center;
  margin: 0 auto;
}

/* ===== LEFT: BOARD SIDE ===== */
.left-col {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.right-col {
  width: 400px;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

.board-side {
  width: 100%;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.board-panel {
  width: 100%;
  background: #333436;
  border: 1px solid #202124;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 0;
  position: relative;
}

.board-wrap {
  max-width: 600px;
  margin: 0;
  padding: 10px;
  background: linear-gradient(180deg, #9f5c23 0%, #7b4316 100%);
  border: 2px solid #784218;
  border-radius: 3px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 6px 18px rgba(0,0,0,0.25);
}

.board {
  width: 100%;
  height: 100%;
  background: #149437;
  border: 2px solid #7a531c;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
}

.cell {
  position: relative;
  border-right: 1px solid #6c5222;
  border-bottom: 1px solid #6c5222;
  cursor: pointer;
  transition: all 0.2s;
  touch-action: manipulation;
}
.cell:nth-child(8n) { border-right: none; }
.cell:nth-last-child(-n + 8) { border-bottom: none; }
.cell:hover { background: rgba(255,255,255,0.08); }
.cell.valid-move { background: #4ade80; cursor: pointer; }
.cell.valid-move::after {
  content: '';
  width: 25%;
  height: 25%;
  border-radius: 50%;
  background: rgba(255,255,255,0.5);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.piece {
  position: absolute;
  inset: 7%;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.22);
  transition: transform 0.3s;
}
.piece.black {
  background:
    radial-gradient(circle at 35% 32%, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0.08) 18%, transparent 28%),
    radial-gradient(circle at 50% 46%, #3e434a 0%, #22262b 42%, #0b0d10 82%, #000000 100%);
  border-color: #0f1114;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.10),
    inset 0 -1px 0 rgba(255,255,255,0.04),
    inset 0 -3px 5px rgba(0,0,0,0.24),
    0 1px 2px rgba(0,0,0,0.12);
}
.piece.white {
  background:
    radial-gradient(circle at 35% 32%, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0.55) 18%, transparent 30%),
    radial-gradient(circle at 50% 46%, #ffffff 0%, #f3f3f3 46%, #dddddd 82%, #c9c9c9 100%);
  border-color: #b7b7b7;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.92),
    inset 0 -1px 0 rgba(255,255,255,0.40),
    inset 0 -3px 5px rgba(0,0,0,0.08),
    0 1px 2px rgba(0,0,0,0.08);
}
.piece:hover { transform: scale(1.1); }

#gameMessage {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  background: linear-gradient(145deg, #ffd700, #daa520);
  padding: 20px 35px;
  border-radius: 10px;
  border: 3px solid #b8860b;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  font-size: 18px;
  font-weight: bold;
  color: #ffffff;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  display: none;
  transition: opacity 0.3s;
}

/* ===== BOTTOM ACTIONS ===== */
.bottom-actions {
  width: min(100%, 600px);
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  padding: 0;
  margin: 0;
}

.mini-btn {
  height: 34px;
  border-radius: 6px;
  border: 1px solid #4a4b4f;
  background: linear-gradient(180deg, #67686d 0%, #3d3e42 100%);
  color: #f5f5f5;
  font-size: 12px;
  font-weight: 700;
  font-family: "Yu Gothic", "Hiragino Sans", sans-serif;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.3s;
}
.mini-btn:hover {
  background: linear-gradient(180deg, #7a7b80 0%, #4d4e52 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.25), 0 2px 6px rgba(0,0,0,0.3);
}
.mini-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.mini-btn:disabled:hover {
  background: linear-gradient(180deg, #67686d 0%, #3d3e42 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18);
}

/* ===== RIGHT PANEL ===== */
.right-panel {
  width: 400px;
  min-width: 400px;
  max-width: 400px;
  height: auto;
  display: grid;
  grid-template-rows: auto auto auto auto 1fr;
  gap: 8px;
  margin-top: 0;
  padding: 8px 10px 10px;
  background: linear-gradient(180deg, #d9b892 0%, #c89f73 35%, #b68456 100%);
  border: 1px solid #b07a49;
  border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 8px 20px rgba(0,0,0,0.22);
  align-content: start;
}

/* ===== AVATARS ===== */
.avatars {
  width: 380px;
  justify-self: center;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 1px solid #21435c;
  background: linear-gradient(180deg, #2a566f 0%, #22455c 100%);
  border-radius: 4px 4px 14px 14px;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 8px 20px rgba(0,0,0,0.28);
}

.avatar-box {
  display: grid;
  grid-template-rows: 150px auto;
  border-right: 1px solid rgba(255,255,255,0.08);
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.02));
  transition: all 0.3s;
}
.avatar-box:last-child { border-right: none; }

.avatar-box.active {
  box-shadow: inset 0 0 0 3px #daa520, 0 0 15px rgba(218,165,32,0.5);
}

.avatar-visual {
  padding: 8px;
  background: linear-gradient(180deg, #e9efe6 0%, #bfd6dd 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-box.white .avatar-visual {
  background: linear-gradient(180deg, #f4efe8 0%, #ece7df 100%);
}

.avatar-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 1px solid rgba(0,0,0,0.18);
  border-radius: 2px;
  background: #ffffff;
}

/* ===== SCORE SIDE (name + score inside avatar-box) ===== */
.score-side {
  padding: 3px 10px 14px 10px;
  text-align: center;
}

.score-side.black-side {
  background: #2d2d2d;
  color: #ffffff;
  border-radius: 0 0 0 14px;
}

.score-side.white-side {
  background: #ffffff;
  color: #3b2c1f;
  border-radius: 0 0 14px 0;
}

.score-cap {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 12px;
  padding-bottom: 3px;
  padding-top: 3px;
  border-bottom: 3px solid rgba(255,255,255,0.45);
}

.score-side.white-side .score-cap {
  border-bottom: 3px solid #bfae9c;
}

.score-val {
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
  padding-top: 2px;
}

/* ===== COMPACT PANEL ===== */
.compact-panel {
  width: 380px;
  justify-self: center;
  padding: 8px;
  background: linear-gradient(180deg, #f5e6d3 0%, #e8d4ba 100%);
  border: 1px solid #8b4513;
  border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.45);
}

.levels {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

button {
  cursor: pointer;
  transition: all 0.3s;
  touch-action: manipulation;
  font-family: "Yu Gothic", "Hiragino Sans", sans-serif;
}

button.level-button {
  height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1.15;
  text-align: center;
  padding: 4px 6px;
  background: linear-gradient(145deg, #e2e8f0, #cbd5e1);
  color: #1e293b;
  border-radius: 8px;
  border: 2px solid #8b4513;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.45);
  font-weight: bold;
}
button.level-button:hover {
  background: linear-gradient(145deg, #cbd5e1, #94a3b8);
  color: #0f172a;
}
button.level-button.selected {
  background: linear-gradient(145deg, #ef4444, #dc2626);
  color: #ffffff;
  border-color: #8b4513;
  box-shadow: 0 0 10px rgba(239,68,68,0.5), 0 4px 6px rgba(0,0,0,0.25);
}

.starts,
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

.bw-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.18);
  flex: 0 0 auto;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18);
  display: inline-block;
}
.bw-dot.black {
  background: radial-gradient(circle at 36% 34%, #5b6168 0%, #2d3137 28%, #101216 66%, #050607 100%);
  border-color: rgba(255,255,255,0.14);
}
.bw-dot.white {
  background: radial-gradient(circle at 36% 34%, #ffffff 0%, #f3f3f3 34%, #dfdfdf 74%, #cbcbcb 100%);
  border-color: rgba(0,0,0,0.16);
}

button.start-btn,
button.control-btn {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  font-size: 13px;
  color: #2c1810;
  background: linear-gradient(145deg, #f5e6d3, #d4b896);
  border: 2px solid #8b4513;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.45);
  text-align: center;
  padding: 0 10px;
}
button.start-btn:hover,
button.control-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.4);
  background: linear-gradient(145deg, #daa520, #b8860b);
  color: #ffffff;
}
button.start-btn:disabled,
button.control-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
button.start-btn:disabled:hover,
button.control-btn:disabled:hover {
  transform: none;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3);
  background: linear-gradient(145deg, #f5e6d3, #d4b896);
  color: #2c1810;
}

.hint-row {
  margin-top: 8px;
  display: flex;
  justify-content: center;
}

button.hint-btn {
  width: 190px;
  height: 52px;
  font-size: 13px;
  font-weight: 700;
  color: #2c1810;
  border: 2px solid #4caf50;
  background: linear-gradient(145deg, #90ee90, #66bb6a);
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.35);
}
button.hint-btn:hover {
  background: linear-gradient(145deg, #66bb6a, #4caf50);
}
button.hint-btn.active {
  background: linear-gradient(145deg, #ffd700, #daa520);
  border-color: #b8860b;
}

/* ===== HARD MODE ===== */
.hard-wrap {
  width: 380px;
  justify-self: center;
  padding: 10px 12px;
  border: 2px solid #ef2c24;
  border-radius: 6px;
  background: #eed6c6;
  color: #ba2e21;
  text-align: center;
  line-height: 1.7;
  font-size: 12px;
}

.hard-wrap strong {
  display: block;
  font-size: 14px;
  margin-bottom: 4px;
}

button.hard-btn {
  margin-top: 8px;
  width: 196px;
  height: 48px;
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  border: 2px solid #8b4513;
  background: linear-gradient(145deg, #dc2626, #b91c1c);
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.25);
}
button.hard-btn:hover {
  background: linear-gradient(145deg, #b91c1c, #991b1b);
}

/* ===== DETAIL CARD ===== */
.detail-card {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid #a36c31;
  border-radius: 4px;
  overflow: hidden;
  background: #f3ede3;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.55), 0 2px 6px rgba(0,0,0,0.16);
}

.detail-head {
  padding: 8px 12px;
  background: linear-gradient(180deg, #f5ecdd 0%, #eadfce 100%);
  border-bottom: 1px solid #ccb395;
  color: #3e240e;
  font-weight: 700;
  font-size: 13px;
}

.detail-body {
  padding: 10px 12px;
  overflow: auto;
  color: #5b2f10;
  font-size: 12px;
  line-height: 1.7;
}
.detail-body div + div { margin-top: 6px; }

/* ===== MOBILE (縦向きスマホ・小画面) ===== */
@media (max-width: 900px) and (min-height: 500px) {
  html, body {
    overflow: auto;
  }

  .app {
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
    padding: 10px 10px 8px 10px;
    justify-content: center;
    overflow: visible;
  }

  .layout {
    width: min(100%, 600px);
    grid-template-columns: 1fr;
    gap: 10px;
    justify-items: center;
  }

  .board-side {
    width: min(100%, 600px);
    min-width: 0;
    grid-template-rows: auto auto;
    justify-items: center;
  }

  .board-panel {
    width: 100%;
    padding: 10px 0 0 0;
    justify-content: center;
  }

  .board-wrap {
    width: min(100%, 600px);
    aspect-ratio: 1 / 1;
    height: auto;
    min-width: 0;
    max-width: 600px;
  }

  .bottom-actions {
    width: min(100%, 600px);
    padding: 0;
    grid-template-columns: repeat(3, 1fr);
  }

  .right-panel {
    width: min(100%, 500px);
    min-width: 350px;
    max-width: 500px;
    min-height: auto;
    height: auto;
    margin-top: 0;
    padding: 8px 10px 10px;
  }

  .avatars,
  .compact-panel,
  .hard-wrap {
    width: min(100%, 480px);
  }
}

/* ===== 横向きスマホ (幅広・高さ狭い) ===== */
@media (max-width: 900px) and (max-height: 499px) {
  .app {
    height: calc(100vh - 40px);
    height: calc(100dvh - 40px);
    padding: 0 6px 4px 6px;
    overflow: hidden;
  }

  .layout {
    width: 100%;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 6px;
    align-items: start;
  }

  .left-col {
    height: calc(100vh - 40px);
    height: calc(100dvh - 40px);
  }

  .board-side {
    gap: 4px;
  }

  .board-panel {
    padding: 0;
  }

  .board-wrap {
    max-width: 100%;
    padding: 6px;
  }

  .bottom-actions {
    width: 100%;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
  }

  .mini-btn {
    height: 28px;
    font-size: 10px;
  }

  .right-col {
    width: 280px;
    height: calc(100vh - 40px);
    height: calc(100dvh - 40px);
    overflow-y: auto;
    overflow-x: hidden;
  }

  .right-panel {
    width: 280px;
    min-width: 280px;
    max-width: 280px;
    padding: 4px 6px 6px;
    gap: 6px;
  }

  .avatars {
    width: 268px;
  }

  .avatar-box {
    grid-template-rows: 80px auto;
  }

  .avatar-visual {
    padding: 4px;
  }

  .score-cap {
    font-size: 12px;
    margin-bottom: 4px;
    padding-bottom: 2px;
    padding-top: 2px;
  }

  .score-val {
    font-size: 22px;
  }

  .score-side {
    padding: 2px 6px 8px 6px;
  }

  .compact-panel {
    width: 268px;
    padding: 6px;
  }

  .levels {
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
  }

  button.level-button {
    height: 40px;
    font-size: 9px;
    padding: 2px 3px;
  }

  .starts,
  .controls {
    gap: 6px;
    margin-top: 6px;
  }

  button.start-btn,
  button.control-btn {
    height: 38px;
    font-size: 11px;
  }

  .hint-row {
    margin-top: 6px;
  }

  button.hint-btn {
    width: 150px;
    height: 38px;
    font-size: 11px;
  }

  .hard-wrap {
    width: 268px;
    padding: 6px 8px;
    font-size: 11px;
  }

  .hard-wrap strong {
    font-size: 12px;
  }

  button.hard-btn {
    height: 36px;
    font-size: 11px;
  }

  .detail-card {
    display: none;
  }
}
