/* ===== jsPsych: 基础与变量 ===== */
:root {
  --img-size: 22vh;
  /* 放大左侧图片尺寸 */
  --gap: 1.5vh;
  /* 调整图片间距 */
  --top-space: 0.5vh;
  /* 最小化顶部空间 */
}

#jspsych-image-button-response-stimulus {
  display: none !important;
}

body {
  font-family: "Helvetica Neue", Arial, sans-serif;
  background: #f4f5f7;
  color: #080808;
  margin: 0;
}

.jspsych-display-element {
  padding: 5px 0 !important;
}

.jspsych-content,
.jspsych-content-wrapper,
.jspsych-display-element {
  padding: 0 !important;
}

/* ===== 全局按钮（jsPsych 默认按钮） ===== */
.jspsych-btn {
  background: #007bff;
  color: #fff;
  border: 0;
  font-size: 16px;
  padding: 10px 25px;
  margin: 0;
  border-radius: 5px;
  transition: background-color .2s ease;
}

.jspsych-btn:hover {
  background: #0056b3;
  cursor: pointer;
}

.jspsych-btn[disabled] {
  opacity: .5;
  cursor: not-allowed;
}

/* ===== 选择阶段布局（左右分栏）===== */

.legacy .trial-stage {
  margin-top: var(--top-space) !important;
  display: flex !important;
  width: 100% !important;
  height: 98vh !important;
  margin-left: auto !important;
  margin-right: auto !important;
  padding: 0 20px !important;
  box-sizing: border-box !important;
  position: relative !important;
}

/* 左侧：图片网格区域 */
.legacy .image-grid-wrapper {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-width: 0;
  padding-right: 20px !important;
  box-sizing: border-box !important;
}

.legacy .jspsych-image-button-response-btngroup,
.legacy .jspsych-btn-group-grid {
  display: grid !important;
  grid-template-columns: repeat(4, var(--img-size)) !important;
  grid-template-rows: repeat(4, var(--img-size)) !important;
  column-gap: var(--gap) !important;
  row-gap: var(--gap) !important;
  justify-content: flex-start !important;
  justify-items: center !important;
  margin: 0 !important;
  width: auto !important;
  height: auto !important;
}

/* 右侧：选择区域 */
.legacy .selection-panel {
  flex: 0 0 400px !important;
  height: 100% !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 2vh !important;
  align-items: center !important;
  padding-top: 0 !important;
  box-sizing: border-box !important;
}

.legacy .grid-button,
.legacy .jspsych-image-button-response-button {
  display: block;
  border: 0;
  background: none;
  padding: 0 !important;
  width: var(--img-size) !important;
  height: var(--img-size) !important;
  margin: 0 !important;
  cursor: pointer;
  transition: transform 0.2s;
}

.legacy .grid-button img,
.legacy .jspsych-image-button-response-button img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  display: block;
  border-radius: 8px;
  border: 2px solid #ddd;
  transition: border-color .2s, transform .2s;
}

.legacy .grid-button img:hover,
.legacy .jspsych-image-button-response-button img:hover {
  border-color: #007bff;
  transform: scale(1.03);
}

.js-choice.selected img {
  position: relative;
  z-index: 1;
}

.legacy .js-choice.selected::after {
  content: "";
  position: absolute;
  top: -6px;
  left: -6px;
  right: -6px;
  bottom: -6px;
  border: 6px solid #007bff;
  border-radius: 10px;
  box-shadow: 0 0 8px rgba(0, 123, 255, 0.4);
  pointer-events: none;
  /* 不影响点击 */
  z-index: 2;
}

.legacy .grid-button,
.legacy .jspsych-image-button-response-button {
  position: relative;
  overflow: visible !important;
}

/* 右侧选择面板样式 */
.selected-images-area {
  background: #f8f9fa;
  padding: 25px;
  border-radius: 15px;
  border: 2px solid #dee2e6;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  position: relative;
}

/* 标题和游戏规则按钮的容器 */
.title-with-rules {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.selected-images-title {
  font-size: 22px;
  font-weight: 700;
  color: #333;
  margin: 0;
  flex: 1;
}

.selected-images-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
  margin-bottom: 25px;
  justify-items: center;
}

.selected-image-slot {
  width: var(--img-size) !important;
  height: var(--img-size) !important;
  border: 3px dashed #ccc;
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  transition: all 0.3s ease;
}

.selected-image-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 7px;
}

.selected-image-slot.empty {
  color: #aaa;
  font-size: 36px;
  font-weight: 600;
}

.control-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.control-buttons .jspsych-btn {
  font-size: 18px;
  padding: 15px 30px;
  border-radius: 10px;
  font-weight: 600;
}

.feedback-area {
  background: #e8f5e9;
  padding: 25px;
  border-radius: 12px;
  margin-top: 20px;
  text-align: center;
  display: none;
  border: 2px solid #4CAF50;
}

.feedback-area.show {
  display: block;
}

.feedback-area p {
  font-size: 20px !important;
  margin: 10px 0 !important;
}

.feedback-area .jspsych-btn {
  font-size: 16px;
  padding: 12px 25px;
}

/* 响应式优化 */
@media (max-height: 600px) {
  .legacy .selection-panel {
    gap: 1.5vh !important;
    padding-top: 10px !important;
  }

  :root {
    --img-size: 18vh;
  }

  .control-buttons .jspsych-btn {
    font-size: 16px;
    padding: 12px 20px;
  }
}

@media (max-width: 1200px) {
  .legacy .image-grid-wrapper {
    padding-right: 15px !important;
  }

  .legacy .selection-panel {
    flex: 0 0 350px !important;
  }
}

@media (max-width: 768px) {
  .legacy .trial-stage {
    flex-direction: column !important;
    align-items: center !important;
  }

  .legacy .image-grid-wrapper {
    padding-right: 0 !important;
  }

  .legacy .selection-panel {
    position: static !important;
    width: 100% !important;
    max-width: 450px !important;
    height: auto !important;
    padding-top: 20px !important;
  }
}

/* 新增：试验信息显示 */
.legacy .trial-info {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
  color: #333;
  text-align: center;
  background: #e3f2fd;
  padding: 12px;
  border-radius: 10px;
  border: 2px solid #2196F3;
}

/* 游戏规则按钮样式调整 */
.rules-button-container {
  position: relative;
  display: inline-block;
  margin-left: 10px;
}

.game-rules-btn {
  background: #007bff;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 123, 255, 0.3);
  transition: all 0.3s ease;
}

.game-rules-btn:hover {
  background: #0056b3;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 123, 255, 0.4);
}

.rules-tooltip {
  position: absolute;
  top: 100%;
  right: 0;
  background: white;
  border: 2px solid #007bff;
  border-radius: 12px;
  padding: 15px;
  width: 280px;
  max-width: 80vw;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 1001;
  display: none;
  font-size: 15px;
  line-height: 1.6;
  margin-top: 5px;
  transform: translateX(-60px);
}

.rules-tooltip.show {
  display: block;
}

.rules-tooltip h3 {
  margin: 0 0 10px 0;
  color: #007bff;
  font-size: 18px;
  text-align: center;
}

.rules-tooltip ul {
  margin: 0;
  padding-left: 15px;
}

.rules-tooltip li {
  margin: 5px 0;
  color: #333;
}

/* 规则提示文字容器 */
.rules-hint-container {
  position: absolute;
  top: -20px;
  right: -30px;
  text-align: center;
  z-index: 1000;
}

.rules-hint {
  background: #28a745;
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
  animation: pulse 2s infinite;
  display: inline-block;
  white-space: nowrap;
}

.rules-arrow {
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid #28a745;
  margin: 1px auto 0;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.02);
  }

  100% {
    transform: scale(1);
  }
}

/* ===== 其他页面（可留可删） ===== */
h1,
h2 {
  color: #0056b3;
  font-weight: 700;
  margin: 20px 0;
}

form {
  text-align: left;
  max-width: 600px;
  margin: 0 auto;
}

form p {
  font-size: 16px;
  margin: 15px 0;
}

form input[type="text"],
form textarea {
  width: 100%;
  padding: 8px;
  margin-top: 5px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

/* === 让所有 HtmlButtonResponse 介绍页居中显示（文本 + 按钮）=== */
.jspsych-content:has(#jspsych-html-button-response-stimulus) {
  min-height: 100vh;
  display: flex !important;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2vh;
}

/* 去除介绍页 stimulus 自身可能的外边距，避免偏移 */
#jspsych-html-button-response-stimulus {
  margin: 0 !important;
  padding: 0 !important;
}

/* 介绍页按钮组：强制水平置中 */
#jspsych-html-button-response-btngroup {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  margin: 0 !important;
}

/* ======================================================
   新增：新模式（练习/正式通用）
   全屏网格 4x4、4:3 完整显示、自动最大化、右侧栏
   ====================================================== */

.exp-page {
  width: 100vw;
  height: 100vh;
  box-sizing: border-box;
  padding: clamp(12px, 2.5vw, 28px);
  display: grid;
  grid-template-columns: 1fr 260px;
  /* 左：网格 右：侧栏 */
  grid-template-rows: 1fr;
  gap: clamp(16px, 2vw, 28px);

  --gap: clamp(8px, 1.5vw, 14px);
  --cols: 4;
  --rows: 4;
  --ratio-w: 4;
  --ratio-h: 3;
  --sideW: 260px;
  /* 右侧栏宽 */
}

.exp-grid {
  width: 100%;
  height: 100%;
  display: grid;
  place-content: center;
  gap: var(--gap);

  --pad: clamp(12px, 2.5vw, 28px);
  --colGap: clamp(16px, 2vw, 28px);

  /* 扣掉右侧栏宽度与两列间距 */
  --availW: calc(100vw - 2 * var(--pad) - var(--sideW) - var(--colGap));
  --availH: calc(100vh - 2 * var(--pad));

  --wLimit: calc((var(--availW) - (var(--cols) - 1) * var(--gap)) / var(--cols));
  --hLimitAsW: calc(((var(--availH) - (var(--rows) - 1) * var(--gap)) / var(--rows)) * (var(--ratio-w) / var(--ratio-h)));
  --cellW: min(var(--wLimit), var(--hLimitAsW));

  grid-template-columns: repeat(var(--cols), var(--cellW));
  grid-template-rows: repeat(var(--rows), calc(var(--cellW) / (var(--ratio-w) / var(--ratio-h))));
}

.exp-grid .grid-button {
  width: var(--cellW);
  height: calc(var(--cellW) / (var(--ratio-w) / var(--ratio-h)));
  border: 0;
  padding: 0;
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  /* 更像截图：白底卡片 */
  cursor: pointer;
  position: relative;
}

.exp-grid .grid-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  background: #fff;
  /* contain 露底时为白 */
  border: 0;
  border-radius: 0;
}

/* 把原来的底部栏挪到右侧栏：仍用 exp-bottom/ bottom-bar 结构，不改 HTML */
.exp-bottom {
  grid-column: 2;
  grid-row: 1;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-bottom: 0;
}

.exp-bottom .bottom-bar {
  width: 220px;
  height: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  align-items: center;
  padding: 0;
  border-radius: 0;
  background: transparent;
  backdrop-filter: none;
  color: #111;
  box-sizing: border-box;
}

.exp-bottom .trial-info {
  font-size: 34px;
  font-weight: 900;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: #111;
  white-space: nowrap;
}

.exp-bottom .bottom-actions {
  display: flex;
  flex-direction: column;
  gap: 22px;
  align-items: center;
}

/* 右侧大按钮 */
.exp-bottom .jspsych-btn {
  width: 160px;
  height: 64px;
  border-radius: 12px;
  font-size: 28px;
  font-weight: 800;
}

/* 右侧提示框（像截图的灰色小框） */
.exp-bottom .hint-text {
  width: 160px;
  padding: 10px 12px;
  border-radius: 6px;
  background: #e6e6e6;
  color: #2b5aa5;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  line-height: 1.2;
  opacity: 1;
}

/* ======================================================
   新增（可选）：反馈 2x2 放大（4:3 完整显示 + 自动最大化）
   ====================================================== */

.fb-page {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: clamp(10px, 1.8vw, 18px);

  --gap: clamp(10px, 2vw, 18px);
  --cols: 2;
  --rows: 2;
  --bottom-h: 64px;
  --ratio-w: 4;
  --ratio-h: 3;
}

.fb-grid {
  width: 100%;
  height: 100%;
  display: grid;
  place-content: center;
  gap: var(--gap);

  --availW: 100%;
  --availH: calc(100% - var(--bottom-h) - clamp(10px, 1.8vw, 18px));

  --wLimit: calc((var(--availW) - (var(--cols) - 1) * var(--gap)) / var(--cols));
  --hLimitAsW: calc(((var(--availH) - (var(--rows) - 1) * var(--gap)) / var(--rows)) * (var(--ratio-w) / var(--ratio-h)));
  --cellW: min(var(--wLimit), var(--hLimitAsW));

  grid-template-columns: repeat(var(--cols), var(--cellW));
  grid-template-rows: repeat(var(--rows), calc(var(--cellW) / (var(--ratio-w) / var(--ratio-h))));
}

.fb-cell {
  width: var(--cellW);
  height: calc(var(--cellW) / (var(--ratio-w) / var(--ratio-h)));
  border-radius: 18px;
  overflow: hidden;
  background: #111;
}

.fb-cell img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  background: #111;
}

/* ===== 新模式：练习 + 正式 选中态（未选中无边框；选中粗深蓝边框）===== */
/* ===== 选中态：深蓝外边框（通用，适配 practice_block 的 .js-choice）===== */
.js-choice {
  position: relative;
  overflow: visible !important;
}

.js-choice.selected img {
  position: relative;
  z-index: 1;
}

/* 外边框（真正外扩，不挤压图片） */
.js-choice.selected::after {
  content: "";
  position: absolute;
  top: -6px;
  left: -6px;
  right: -6px;
  bottom: -6px;
  border: 6px solid #0d47a1;
  border-radius: 14px;
  box-shadow: 0 0 8px rgba(13, 71, 161, 0.35);
  pointer-events: none;
  z-index: 2;
}

/* 如果你还有新模式 inset 规则，必须关掉它 */
.exp-grid .js-choice.selected {
  box-shadow: none !important;
  outline: none !important;
}