/* simple styling */
:root {
  --accent: #2b6cb0;
  --muted: #64748b;
}
body{
  font-family: system-ui, -apple-system, "Noto Sans JP", "Hiragino Kaku Gothic ProN", Roboto, sans-serif;
  background: #f3f6fb;
  margin: 0; padding: 16px;
  display:flex; justify-content:center;
}
.container {
  width: 980px;
  background: #fff;
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.06);
}
header{ display:flex; align-items:center; gap:12px; }
header h1{ margin:0; font-size:18px; }
.controls{ margin-left:auto; display:flex; gap:8px; align-items:center; }
.controls input{ padding:6px 8px; border-radius:6px; border:1px solid #ddd; }
.controls button{ padding:6px 10px; border-radius:6px; border:none; background:var(--accent); color:white; cursor:pointer; }
.controls .secondary{ background:#6b7280; }

main{ display:flex; gap:16px; margin-top:12px; }
.board {
  display:grid;
  grid-template-columns: repeat(3,120px);
  grid-template-rows: repeat(3,120px);
  gap: 10px;
  padding: 8px;
  background: linear-gradient(#fff,#fbfdff);
  border-radius:10px;
}

/* 3D化に伴う変更 */
.board-wrap { 
  flex: 1; 
  display:flex; 
  justify-content:center; 
  align-items:center; 
  min-height: 500px; /* Canvasのための高さを確保 */
  background: #f3f6fb; /* 3Dシーンの背景色と合わせる */
  border-radius: 8px;
  overflow: hidden; /* Canvasがはみ出ないように */
}

.cell{
  background:#ffffff;
  border-radius:8px;
  border: 1px solid #e6eef7;
  box-shadow: 0 4px 10px rgba(0,0,0,0.03);
  display:flex; align-items:center; justify-content:center;
  position:relative;
  cursor: pointer;
}
.cell .stack {
  position: relative;
  width: 100%;
  height: 100%;
}
.cell .stack .piece {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.piece{ border-radius:50%; display:flex; align-items:center; justify-content:center; color:#fff; font-weight:700; box-shadow: 0 2px 6px rgba(0,0,0,0.12); }
.size-small{ width:42px; height:42px; font-size:12px; }
.size-medium{ width:62px; height:62px; font-size:14px; }
.size-large{ width:86px; height:86px; font-size:15px; }
.color-A{ background:#1f78b4; } /* A */
.color-B{ background:#ef6c00; } /* B */

.panel{ width:330px; display:flex; flex-direction:column; gap:12px; }
.status{ background:#fff; padding:10px; border-radius:8px; box-shadow: 0 4px 12px rgba(0,0,0,0.03); }
.hand{ background:#fff; padding:10px; border-radius:8px; }
.hand-row{ display:flex; gap:8px; flex-wrap:wrap; align-items:center; }
.hand-piece{ cursor:pointer; display:flex; align-items:center; justify-content:center; }
.selected{ 
  outline:3px solid rgba(59,130,246,0.3); 
  transform: translateY(-3px); 
  box-shadow: 0 6px 12px rgba(0,0,0,0.1);
}
.log{ background:#fbfdff; padding:8px; border-radius:8px; height:80px; overflow:auto; font-size:13px; color:var(--muted); }

/* ホーム画面 */
#homeScreen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
  min-height: 85vh; /* 少し高さを出してゆったりさせる */
  width: 100%;
  
  /* 保存した画像をここに指定 */
  background-image: url('home-bg.png'); 
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  
  border-radius: 12px; /* containerの角丸に合わせる */
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 100px rgba(0,0,0,0.2); /* 画像の縁を少し暗くして落ち着かせる */
}

#homeScreen h1 {
  font-size: 3.5rem;
  margin: 0;
  color: #fff;
  text-transform: uppercase;
  font-family: 'Arial Black', sans-serif;
  letter-spacing: 2px;
  /* 視認性を確保するための二重の影 */
  text-shadow: 
    3px 3px 0px #ef6c00, 
    0px 0px 20px rgba(0,0,0,0.4);
  z-index: 1;
}

.home-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 260px;
}

.home-panel input {
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.5);
  background: rgba(255, 255, 255, 0.9);
  font-size: 1rem;
  outline: none;
  transition: all 0.3s;
}

.home-panel input:focus {
  border-color: #ef6c00;
  box-shadow: 0 0 0 3px rgba(239, 108, 0, 0.2);
}

/* 入室ボタンをより目立たせる */
.home-panel button {
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #ef6c00, #ff9d00);
  color: white;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(239, 108, 0, 0.3);
  transition: transform 0.2s, box-shadow 0.2s;
}

.home-panel button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(239, 108, 0, 0.4);
}

.home-panel button.secondary {
  background: rgba(100, 116, 139, 0.8);
  font-size: 0.9rem;
  margin-top: 5px;
}

/* チャット画面 */
.chat-box {
  background: #fff;
  border-radius: 8px;
  padding: 8px;
  height: 220px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 12px rgba(0,0,0,0.03);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  font-size: 13px;
  color: #333;
  padding-right: 4px;
}

.chat-input-row {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.chat-input-row input {
  flex: 1;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid #ddd;
}

.chat-input-row button {
  padding: 6px 10px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

/* 設定モーダル */
.modal-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}
.modal-overlay.hidden {
  display: none;
}

.modal-window {
  background: #fff;
  width: 400px;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}
.modal-header h2 { margin: 0; font-size: 1.2rem; color: #334155; }
.close-btn {
  background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #64748b;
}

.modal-tabs {
  display: flex;
  border-bottom: 1px solid #e2e8f0;
}
.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: #fff;
  cursor: pointer;
  color: #64748b;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}
.tab-btn:hover { background: #f1f5f9; }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: bold;
}

.modal-content {
  padding: 16px;
  min-height: 200px;
}
.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fadeIn 0.2s; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.toggle-btn {
  padding: 4px 12px; border-radius: 20px; border: 1px solid #ccc; background: #eee; cursor: pointer;
}
.toggle-btn.on {
  background: var(--accent); color: white; border-color: var(--accent);
}

.action-btn {
  display: block; width: 100%; padding: 10px; margin-bottom: 8px;
  border: 1px solid #cbd5e1; border-radius: 6px; background: white; cursor: pointer;
}
.action-btn:hover { background: #f1f5f9; }
.action-btn.danger { color: #ef4444; border-color: #fca5a5; }
.action-btn.danger:hover { background: #fef2f2; }

/* ▼▼▼ リザルト画面用スタイル ▼▼▼ */
.result-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.7); /* 少し暗くする */
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000; /* 設定モーダルより上に */
  opacity: 1;
  transition: opacity 0.3s ease;
}

.result-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.result-content {
  background: white;
  padding: 40px;
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  min-width: 400px; /* 少し幅を広げる */
}

.result-content h1 {
  font-size: 4rem;
  margin: 0 0 10px 0;
  font-weight: 900;
  /* 文字にグラデーション */
  background: linear-gradient(45deg, #ffd700, #ff8c00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.result-content.lose h1 {
  background: linear-gradient(45deg, #64748b, #334155);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.result-content p {
  font-size: 1.2rem;
  color: #64748b;
  margin-bottom: 30px;
}

/* 3つのボタン用のレイアウト調整 */
.result-actions {
  display: flex;
  flex-direction: column; /* 縦並びにするか、横並びにするかは好みだが、3つあるので整理 */
  gap: 10px;
  justify-content: center;
  align-items: center;
}
/* 横並びにする場合（画面が広いとき） */
@media (min-width: 480px) {
    .result-actions {
        flex-direction: row;
    }
}

.result-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 100px;
}

.btn-rematch {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 10px rgba(43, 108, 176, 0.3);
}
.btn-rematch:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(43, 108, 176, 0.4);
}

.btn-spectate {
  background: #10b981; /* Green */
  color: white;
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
}
.btn-spectate:hover {
    transform: translateY(-2px);
    background: #059669;
}

.btn-leave {
  background: #ef4444; /* Red */
  color: white;
  box-shadow: 0 4px 10px rgba(239, 68, 68, 0.3);
}
.btn-leave:hover {
    transform: translateY(-2px);
    background: #dc2626;
}

.result-wait-msg {
    margin-top: 15px;
    font-size: 0.9rem;
    color: #64748b;
    font-weight: bold;
    animation: blink 2s infinite;
}

@keyframes blink {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

.cutin-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(255, 255, 255, 0.1);
  z-index: 2000;
  pointer-events: none;
}
/* style.css 修正版 */

.cutin-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(255, 255, 255, 0.1);
  z-index: 2000;
  pointer-events: none;
}

.cutin-content {
  background: #fff;
  padding: 20px 80px;
  border-radius: 50px; /* 丸みを帯びさせる */
  border: 8px solid; /* 色はJSの文字色に合わせるために currentColor を使う手もあり */
  box-shadow: 
    0 20px 0 rgba(0,0,0,0.1), /* 厚み */
    0 30px 20px rgba(0,0,0,0.2); /* 影 */
  transform: scale(0);
  animation: stampIn 0.9s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

.cutin-content h2 {
  margin: 0;
  font-size: 3.5rem;
  font-weight: 900;
  /* 文字の縁取り（ストローク）をつけるとポップになります */
  -webkit-text-stroke: 2px #fff; 
  paint-order: stroke fill;
}

@keyframes stampIn {
  0% { transform: scale(3); opacity: 0; }
  60% { transform: scale(0.8); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* 既存の .hidden クラスを使用するため、ここは変更なしでOK */
.hidden {
   display: none !important;
}
@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ===== ▼ リアルタイム応援コメント（流れる演出） ▼ ===== */
.flying-comment {
  position: fixed;
  top: 20%;
  left: 100%;
  font-size: 40px;
  font-weight: bold;
  text-shadow: 2px 2px 6px rgba(0,0,0,0.7);
  white-space: nowrap;
  z-index: 9999;
  animation: commentFly linear 6s forwards;
  pointer-events: none;
  opacity: 0.9;
}

@keyframes commentFly {
  0%   { transform: translateX(0); opacity: 1; }
  50%  { opacity: 1; }
  100% { transform: translateX(-120vw); opacity: 0; }
}

/* ===== スマホ対応：完全版 ===== */
@media (max-width: 768px) {
  #homeScreen h1 {
    font-size: 2.2rem;
  }
  .home-panel {
    width: 85%;
    padding: 20px;
  }
}

@media (max-width: 768px) {

  /* 全体レイアウト */
  main {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  /* ヘッダーをコンパクトに */
  header {
    padding: 6px 8px;
  }

  header h1 {
    font-size: 18px;
    margin: 4px 0;
  }

  /* 盤面サイズ（画面基準） */
  .board-wrap {
    width: 100%;
    max-width: 100vw;
    height: min(70vw, 320px);
  }

  /* 右パネルをフル幅に */
  aside.panel {
    width: 100%;
    max-height: none;
  }

  /* ステータスを2列表示 */
  .status {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 8px;
    font-size: 13px;
  }

  /* 手駒 */
  .hand-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .hand-row {
    transform: scale(0.85);
    transform-origin: left top;
  }

  /* ログを小さく */
  .log {
    max-height: 80px;
    overflow-y: auto;
    font-size: 12px;
  }

  /* チャット */
  .chat-messages {
    max-height: 140px;
  }

  .chat-input-row input {
    font-size: 16px; /* iOS拡大防止 */
  }

  /* ボタン */
  button {
    padding: 10px 14px;
    font-size: 15px;
  }

  /* 流れるコメント */
  .flying-comment {
    font-size: 18px;
    animation-duration: 4s;
  }
}

/* タッチ端末で hover 無効化 */
@media (hover: none) {
  button:hover {
    background: inherit;
  }
}
@media (max-width: 768px) {

  main {
    gap: 6px;
    padding: 4px;
  }

  header {
    padding: 4px 6px;
  }

  header h1 {
    font-size: 16px;
    margin: 2px 0;
  }

  .board-wrap {
    width: 100%;
    height: min(60vh, 300px);
    max-height: 60vh;
  }

  
  .log {
    display: none;
  }

  .chat-messages {
    max-height: 90px;
    font-size: 12px;
  }
}
@media (max-width: 768px) {
  .hint {
    display: none;
  }
}
/* ===== スマホ：縦並びOK、中央寄せ＆崩れ防止 ===== */
@media (max-width: 768px) {

  /* mainは縦並びのままでOK */
  main{
    display: flex;
    flex-direction: column;
    align-items: center;   /* ★これで中央寄せになる */
    gap: 8px;
  }

  /* 右パネル(aside)を中央に置く */
  aside.panel{
    width: 100%;
    max-width: 520px;      /* ★デカすぎ防止（好みで調整OK） */
    margin: 0 auto;
  }

  /* パネル内の各ブロックも幅100% */
  aside.panel .status,
  aside.panel .hand,
  aside.panel .chat-box{
    width: 100%;
  }

  /* ボタンを揃える（左寄り対策） */
  

  /* 手駒が左に寄る原因になりやすいので中央基準にする */
  .hand-row{
    transform-origin: center top;
  }
}
@media (max-width: 768px) {

  /* パネル自体がはみ出さないようにする */
  aside.panel{
    box-sizing: border-box;
    overflow-x: hidden;
  }

  /* ステータスを1列にしてはみ出し防止 */
  .status{
    display: grid;
    gap: 6px;
    width: 100%;
    box-sizing: border-box;
  }

}
@media (max-width: 768px) {

  .chat-input-row{
    display: flex;
    gap: 6px;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
  }

  .chat-box{
    width: 100%;
    box-sizing: border-box;
  }

  .chat-input-row input{
    flex: 1;
    min-width: 0;          /* ★これ超重要（押し出し防止） */
    box-sizing: border-box;
  }

  #chatSendBtn{
    width: auto;
    flex: 0 0 auto;        /* ★縮まない＆押し出されない */
    padding: 10px 12px;    /* 少しだけ細くする */
    white-space: nowrap;
  }
}

