*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --border-glow: #38bdf8;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-green: #4ade80;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 500px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 12px;
}

.header {
  text-align: center;
  padding: 8px 0;
}
.title {
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 2px;
  background: linear-gradient(to right, #38bdf8, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

.scoreboard {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--bg-card);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  border: 1px solid #2e3c51;
}
.score-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px;
  border-radius: 8px;
  transition: all 0.3s ease;
  border: 1px solid transparent;
}
.score-card.active {
  background-color: rgba(56, 189, 248, 0.1);
  border-color: rgba(56, 189, 248, 0.3);
}
.score-card.is-you {
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.2);
}
.score-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.score-value {
  font-size: 1.6rem;
  font-weight: 700;
}
.turn-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
}
.turn-disc {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  transition: all 0.3s ease;
}
.disc--black {
  background: radial-gradient(circle at 30% 30%, #4b5563, #111827);
  border: 1px solid #374151;
}
.disc--white {
  background: radial-gradient(circle at 30% 30%, #ffffff, #e2e8f0);
  border: 1px solid #cbd5e1;
}
.turn-text {
  font-size: 0.75rem;
  font-weight: bold;
  color: var(--border-glow);
  white-space: nowrap;
}

.game-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}
.game-area--hidden {
  display: none !important;
}

.board-wrap {
  position: relative !important;
  width: 100% !important;
  padding-bottom: 100% !important;
  height: 0 !important;
  background-color: #0f172a;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  border: 2px solid #2e3c51;
}

#board {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  display: grid !important;
  grid-template-columns: repeat(8, 1fr) !important;
  grid-template-rows: repeat(8, 1fr) !important;
  gap: 0px !important;
  background-color: transparent !important;
  padding: 0px !important;
  box-sizing: border-box !important;
}

.cell {
  background-color: #15803d;
  border: 1px solid #0f172a !important;
  position: relative;
  cursor: pointer;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background-color 0.2s ease;
}
.cell:focus {
  outline: none;
}
.cell.show-hint::before {
  content: "";
  position: absolute;
  width: 25%;
  height: 25%;
  background-color: rgba(56, 189, 248, 0.6);
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 6px var(--border-glow);
  z-index: 2;
}
.cell.show-hint:hover {
  background-color: #166534;
}

.piece {
  width: 84%;
  height: 84%;
  border-radius: 50%;
  box-shadow: 0 4px 6px rgba(0,0,0,0.4), inset 0 -2px 4px rgba(0,0,0,0.2);
  z-index: 1;
  transform: scale(1);
  transition: transform 0.2s ease;
}
.piece.black {
  background: radial-gradient(circle at 30% 30%, #4b5563, #090d16);
  border: 1px solid #111827;
}
.piece.white {
  background: radial-gradient(circle at 30% 30%, #ffffff, #d1d5db);
  border: 1px solid #e2e8f0;
}

.piece.flip {
  animation: flipAnimation 0.4s ease-out forwards;
}
@keyframes flipAnimation {
  0% { transform: scale(1) rotateY(0deg); }
  50% { transform: scale(1.1) rotateY(90deg); }
  100% { transform: scale(1) rotateY(180deg); }
}

.message {
  text-align: center;
  font-weight: bold;
  color: var(--accent-green);
  min-height: 20px;
  font-size: 0.95rem;
}

.controls {
  display: flex;
  gap: 10px;
}
.btn {
  flex: 1;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.btn:active {
  transform: translateY(1px);
}
.btn--primary {
  background: linear-gradient(135deg, #38bdf8, #2563eb);
  color: #fff;
}
.btn--primary:hover {
  background: linear-gradient(135deg, #7dd3fc, #3b82f6);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}
.btn--secondary {
  background-color: #334155;
  color: #f1f5f9;
  border: 1px solid #475569;
}
.btn--secondary:hover {
  background-color: #475569;
}
.btn--danger {
  background-color: #ef4444;
  color: #fff;
}
.btn--danger:hover {
  background-color: #dc2626;
}

.modal {
  border: none;
  border-radius: 16px;
  background-color: #1e293b;
  color: #f8fafc;
  padding: 0;
  max-width: 90%;
  width: 360px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid #334155;
}
.modal::backdrop {
  background-color: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(4px);
}
.modal-content {
  padding: 24px;
}
.modal h2 {
  font-size: 1.4rem;
  margin-bottom: 16px;
  text-align: center;
  letter-spacing: 1px;
  color: var(--border-glow);
}
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-muted);
}
.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.3;
}
.radio-group {
  display: flex;
  gap: 12px;
}
.radio-label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s;
  user-select: none;
}
.radio-label:hover {
  border-color: var(--border-glow);
}
.radio-label input[type="radio"],
.radio-label input[type="checkbox"] {
  display: none;
}
.radio-label:has(input:checked) {
  background-color: rgba(56, 189, 248, 0.1);
  border-color: var(--border-glow);
  color: var(--border-glow);
}
.level-badge {
  background-color: #3b82f6;
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: bold;
}
.modal-score {
  font-size: 2.4rem;
  font-weight: 800;
  margin: 12px 0;
  background: linear-gradient(to right, #fff, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.best-score-badge {
  display: inline-block;
  background-color: #eab308;
  color: #0f172a;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 800;
  margin-bottom: 10px;
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.gameover-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(32%, 160px);
  min-width: 120px;
  aspect-ratio: 1 / 1;
  padding: 16px;
  z-index: 12;
  cursor: pointer;
  transform: translate(-50%, -50%) scale(0.95);
  transition: transform 0.25s ease, opacity 0.25s ease;
  opacity: 0;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  display: none;
  justify-content: center;
  align-items: center;
  text-align: center;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(16px);
  background: rgba(15, 23, 42, 0.55);
}
.gameover-banner.is-visible {
  display: flex;
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}
.gameover-banner--black {
  background: rgba(15, 23, 42, 0.92);
}
.gameover-banner--white {
  background: rgba(255, 255, 255, 0.92);
}
.gameover-banner--white .gameover-headline,
.gameover-banner--white .gameover-subline {
  color: #0f172a !important;
}
.gameover-banner--draw {
  background: rgba(51, 65, 85, 0.82);
}
.gameover-banner-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.gameover-headline {
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 1px;
}
.gameover-subline {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.best-scores-preview {
  background-color: rgba(30, 41, 59, 0.4);
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 4px;
}
.best-scores-preview h3 {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-align: center;
}
.best-scores-table {
  width: 100%;
  border-collapse: collapse;
}
.best-scores-table th {
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 2px;
  border-bottom: 1px solid #334155;
}
.best-scores-table td {
  padding: 6px 2px;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  color: #fff;
}
.best-scores-table td.updated {
  color: #eab308;
  animation: pulse 1s infinite;
}

.footer {
  text-align: center;
  padding: 8px 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: auto;
}
.text-center { text-align: center; }

.char-zone {
  display: flex;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid #1e293b;
  border-radius: 12px;
  padding: 10px 14px;
  margin: 4px 0;
  gap: 12px;
  align-items: center;
  box-shadow: inset 0 1px 3px rgba(255, 255, 255, 0.02);
  min-height: 72px;
}
.char-zone--hidden {
  display: none !important;
}
.char-avatar-wrap {
  flex-shrink: 0;
}
.char-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  border: 1px solid #334155;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.char-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.char-meta {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.char-name {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--border-glow);
}
.char-title {
  font-size: 0.65rem;
  color: var(--text-muted);
  background-color: #0f172a;
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid #1e293b;
}
.char-line {
  font-size: 0.8rem;
  color: #e2e8f0;
  line-height: 1.4;
  font-weight: 500;
}

.btn-selected {
  background-color: rgba(56, 189, 248, 0.2) !important;
  border-color: var(--border-glow) !important;
  color: var(--border-glow) !important;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.3) !important;
}

/* フォーカス時のアウトラインを消す */
.back-link:focus {
  outline: none;
  box-shadow: none;
}

/* ▼▼▼ スマホのセリフ切り替え時のちらつき（ガタつき）防止対策 ▼▼▼ */
.char-line {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2; /* 最大2行まで表示（はみ出し防止） */
  overflow: hidden;
  
  /* 常に2行分の高さを固定（文字サイズ13px × 行間1.5 × 2行 ≒ 39px） */
  line-height: 1.5;
  height: calc(13px * 1.5 * 2); 
}

.char-zone {
  /* セリフが2行になったときでもアバター画像や枠がはみ出さない安全な高さに固定 */
  min-height: 82px;
  height: 82px; 
}
/* ▲▲▲ ここまで ▲▲▲ */
