/* ========================================
   pd-text-chat 共通スタイル
   （得点表まわりは引き継ぎ元「ゲーム.css」の構造を踏襲）
   ======================================== */

* { box-sizing: border-box; }

:root {
  --ink: #111;
  --muted: #666;
  --line: #d9d9d9;
  --panel: #f4f4f4;
  --accent: #0d6efd;
  --danger: #c62828;
  --ok: #2e7d32;
  --warn: #b26a00;
}

html, body { margin: 0; padding: 0; }

body {
  font-family: Arial, "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  color: var(--ink);
  background: #fff;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

.container { width: min(960px, 100%); margin: 0 auto; padding: 16px; }
.narrow { width: min(560px, 100%); }

h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 18px; margin: 18px 0 8px; border-bottom: 2px solid #999; padding-bottom: 4px; }
h3 { font-size: 15px; margin: 14px 0 6px; }
p { margin: 8px 0; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.hidden, .unvisible { display: none !important; pointer-events: none; }
.disable { pointer-events: none; }
.pre { white-space: pre-line; }

.card {
  border: 2px solid #444; border-radius: 10px; background: #fff; padding: 16px 18px; margin: 12px 0;
}
.panel {
  border: 4px solid #696969; border-radius: 10px; background: rgba(8, 8, 8, 0.06); padding: 12px 16px; margin: 12px 0;
}

/* ボタン */
.btn {
  display: inline-block; padding: 10px 22px; font-size: 16px; border-radius: 30px; cursor: pointer;
  border: 3px solid #111; background: #111; color: #fff; font-family: inherit;
}
.btn.secondary { background: #fff; color: #111; }
.btn.small { padding: 6px 14px; font-size: 13px; }
.btn.danger { border-color: var(--danger); background: var(--danger); }
.btn.link { border: none; background: transparent; color: var(--accent); padding: 4px 6px; text-decoration: underline; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* フォーム */
label.field { display: block; margin: 10px 0 4px; font-weight: bold; font-size: 14px; }
input[type="text"], input[type="password"], input[type="number"], textarea, select {
  width: 100%; padding: 9px 10px; font-size: 16px; border: 2px solid #999; border-radius: 6px; font-family: inherit;
}
input[type="number"] { width: 90px; }
textarea { min-height: 80px; resize: vertical; }
.error { color: var(--danger); font-weight: bold; margin: 8px 0; }
.ok { color: var(--ok); font-weight: bold; }

/* トップバー */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 12px; background: #1f2733; color: #fff; font-size: 14px;
}
.topbar .brand { font-weight: bold; }
.topbar .spacer { flex: 1; }
.topbar .btn { padding: 4px 12px; font-size: 13px; border-color: #fff; background: transparent; color: #fff; }

/* 在室ドット */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #bbb; margin-right: 4px; vertical-align: middle; }
.dot.on { background: #2ecc71; }
.dot.away { background: #f1c40f; }

/* ========================================
   ゲーム画面
   ======================================== */
.pd-game { width: min(960px, 100%); margin: 0 auto; }
.pd-container { border: 2px solid black; padding: 14px 16px 22px; background: #fff; }

.game-header {
  display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; padding: 8px 12px; margin-bottom: 12px;
  border: 3px solid #696969; border-radius: 10px; background: rgba(8, 8, 8, 0.06); font-size: 15px;
}
.game-header .big { font-size: 18px; font-weight: bold; }

.game-body { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.matrix-col { flex: 0 0 470px; max-width: 100%; }
.chat-col { flex: 1 1 320px; min-width: 280px; display: flex; flex-direction: column; border: 4px solid #696969; border-radius: 10px; background: #fff; overflow: hidden; }

.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #1f2733; color: #fff; font-size: 14px; }
.chat-head .timer { margin-left: auto; font-size: 22px; font-weight: bold; font-variant-numeric: tabular-nums; }
.chat-head .timer.urgent { color: #ff7675; }
.chat-area { height: 330px; overflow-y: auto; padding: 10px 12px; background: #fafafa; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 85%; padding: 8px 12px; border-radius: 14px; font-size: 15px; white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.bubble .who { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.bubble.me { align-self: flex-end; background: #d7ecff; border-bottom-right-radius: 4px; }
.bubble.them { align-self: flex-start; background: #ececec; border-bottom-left-radius: 4px; }
.bubble.ai { align-self: flex-start; background: #fff3d6; border: 1px solid #f0c36d; border-bottom-left-radius: 4px; }
.bubble.system { align-self: center; background: transparent; color: var(--muted); font-size: 12.5px; text-align: center; }
.chat-input { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); background: #fff; }
.chat-input textarea { flex: 1; min-height: 44px; max-height: 120px; font-size: 15px; }
.chat-input .btn { padding: 6px 16px; font-size: 15px; align-self: stretch; }
.chat-actions { display: flex; align-items: center; gap: 10px; padding: 8px; border-top: 1px solid var(--line); background: #fff; flex-wrap: wrap; font-size: 13px; }

.round-history { margin-top: 8px; font-size: 13px; }
.round-history table { border-collapse: collapse; width: 100%; }
.round-history th, .round-history td { border: 1px solid var(--line); padding: 3px 6px; text-align: center; }

/* ---- 得点表（引き継ぎ元の構造） ---- */
.matrix_panel { display: flex; justify-content: center; }
.matrix_set { position: relative; width: 450px; height: 330px; }
.round_texts { position: absolute; top: 5px; left: 2%; }
.round_th { position: relative; top: 35px; left: 60px; font-size: 20px; }
#round_N { position: relative; top: -8px; left: 15px; font-size: 50px; font-family: fantasy; }
.text_opp_name { position: absolute; top: 180px; left: 2px; font-size: 25px; white-space: nowrap; }
.text_you_name { position: absolute; top: 5px; left: 130px; width: 300px; font-size: 25px; text-align: center; white-space: nowrap; }
.text_choice_you { position: absolute; left: 130px; top: 55px; width: 300px; font-size: 22px; color: #696969; white-space: nowrap; }
.text_choice_you > div:first-child { position: absolute; left: 10px; width: 135px; text-align: center; white-space: nowrap; }
.text_blue_choice_you { position: absolute; left: 150px; top: 0; width: 135px; text-align: center; white-space: nowrap; }
.text_choice_opp { position: absolute; left: 55px; top: 110px; width: 70px; font-size: 22px; color: #696969; text-align: center; white-space: nowrap; }
.text_choice_opp > div:first-child { height: 85px; display: flex; align-items: center; justify-content: center; white-space: nowrap; }
.text_blue_choice_opp { position: absolute; left: 0; top: 95px; width: 70px; height: 85px; display: flex; align-items: center; justify-content: center; white-space: nowrap; }
.matrix_area { position: absolute; top: 100px; left: 130px; width: 300px; height: 200px; }
.matrix_cell {
  position: absolute; width: 135px; height: 85px; background-color: gray; border-radius: 12px; color: white;
  font-family: "Arial Black", fantasy, Gadget, sans-serif; transition: background-color 0.3s, opacity 0.3s;
}
#cell_CC { left: 10px; top: 10px; }
#cell_DC { left: 150px; top: 10px; }
#cell_CD { left: 10px; top: 105px; }
#cell_DD { left: 150px; top: 105px; }
.cell_text_you, .cell_text_opp { position: absolute; left: 8px; font-size: 17px; }
.cell_text_you { top: 10px; }
.cell_text_opp { bottom: 10px; }
.score_text_you, .score_text_opp { position: absolute; right: 20px; font-size: 30px; }
.score_text_you { top: 8px; }
.score_text_opp { bottom: 8px; }
.matrix_cell.highlight { background-color: #0d6efd; box-shadow: 0 0 0 4px #fff, 0 0 0 8px #0d6efd; }
.matrix_cell.dim { opacity: 0.35; }
.rectangle_side { position: absolute; top: 50px; width: 140px; height: 245px; border: 5px solid rgb(69, 69, 69); pointer-events: none; }
#rectangle_you_cooperate { left: 137px; }
#rectangle_you_defect { left: 276px; }

/* ---- 状態表示・操作（引き継ぎ元の構造） ---- */
#block_chat, #block_prediction, #choice_button_container, #block_next {
  width: 100%; display: flex; justify-content: center; margin-top: 14px;
}
.TextBox {
  width: min(760px, 100%); min-height: 80px; background-color: rgba(8, 8, 8, 0.126); border: 4px solid #696969; border-radius: 10px;
  padding: 14px 18px; font-size: 17px; line-height: 1.55; white-space: pre-line;
}
.TextBox.result-cc { background-color: rgba(46, 125, 50, 0.16); }
.TextBox.result-warn { background-color: rgba(198, 40, 40, 0.12); }

#prediction_slider_container { width: min(680px, 100%); border: 4px solid #696969; border-radius: 10px; padding: 12px 18px; background: rgba(8, 8, 8, 0.06); }
.prediction_question { margin: 0 0 12px; text-align: center; font-size: 16px; font-weight: bold; }
.slider_container { position: relative; width: 100%; padding: 32px 15px 10px; }
#choiceSlider {
  --slider-progress: 0%; width: 100%; height: 8px; appearance: none; -webkit-appearance: none; border-radius: 4px; outline: none; cursor: pointer;
  background: linear-gradient(to right, #0d6efd 0%, #0d6efd var(--slider-progress), #cfcfcf var(--slider-progress), #cfcfcf 100%);
}
#choiceSlider.unanswered { background: #cfcfcf; }
#choiceSlider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 22px; height: 22px; border-radius: 50%; background: #555; border: none; cursor: pointer; }
#choiceSlider.unanswered::-webkit-slider-thumb { opacity: 0; }
#choiceSlider::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #555; border: none; cursor: pointer; }
#choiceSlider.unanswered::-moz-range-thumb { opacity: 0; }
#choiceSlider::-moz-range-progress { background: transparent; }
#choiceSlider::-moz-range-track { background: transparent; height: 8px; }
.slider_scale_marks { position: absolute; top: 3px; left: 15px; right: 15px; display: flex; justify-content: space-between; font-size: 13px; font-weight: bold; }
.slider_value { margin-top: 8px; text-align: center; font-size: 18px; font-weight: bold; }

#choice_button_container { gap: 20px; min-height: 62px; flex-wrap: wrap; }
#cooperate_button, #defect_button {
  padding: 12px 48px; font-size: 24px; border: 3px solid black; border-radius: 35px; background: black; color: white; cursor: pointer; font-family: inherit;
}
#cooperate_button:disabled, #defect_button:disabled { opacity: 0.4; cursor: not-allowed; }
#next_button { padding: 10px 30px; font-size: 22px; border: 4px solid black; border-radius: 35px; background: white; color: black; cursor: pointer; font-family: inherit; }
#next_button:disabled { opacity: 0.45; cursor: not-allowed; }

/* 待機室 */
.progress { display: flex; gap: 18px; flex-wrap: wrap; font-size: 15px; }
.progress b { font-size: 20px; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid #bbb; border-top-color: #111; border-radius: 50%; animation: spin 0.9s linear infinite; vertical-align: middle; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 管理画面 */
.admin table { border-collapse: collapse; width: 100%; font-size: 13px; }
.admin th, .admin td { border: 1px solid var(--line); padding: 4px 6px; text-align: left; vertical-align: top; }
.admin th { background: #eee; }
.admin .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px 16px; }
.admin .payoff-grid { display: grid; grid-template-columns: auto 1fr 1fr; gap: 6px 10px; align-items: center; max-width: 480px; }
.admin .payoff-grid input { width: 64px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: #eee; }
.tag.chat { background: #d7ecff; }
.tag.decision { background: #fff3d6; }
.tag.result { background: #e3f6e3; }
.tag.finished { background: #ddd; }
.tag.aborted { background: #ffd6d6; }

/* スマートフォン */
@media (max-width: 760px) {
  .matrix-col { flex-basis: 100%; }
  .matrix_set { transform: scale(0.8); transform-origin: top left; height: 270px; width: 360px; margin-left: 4px; }
  .chat-area { height: 260px; }
  #cooperate_button, #defect_button { padding: 10px 28px; font-size: 20px; }
}
