/* 共通: ボタン */
.btn {
  border: 1px solid rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.08);
  color: #fff;
  height: 34px;
  padding: 0 12px;
  border-radius: 11px;
  cursor: pointer;
  font-weight: 850;
  letter-spacing: 0.2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
.btn:hover { background: rgba(255,255,255,0.14); transform: translateY(-1px); }
.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
#login-link.btn {
  border-color: rgba(255,255,255,0.34);
  background: rgba(255,255,255,0.10);
}
#login-link.btn:hover { background: rgba(255,255,255,0.16); }
.btn.gold { display: none; }

@media (max-width: 620px) and (hover: none) and (pointer: coarse) {
  .btn { height: 32px; padding: 0 10px; border-radius: 10px; }
}

/* 共通: フィルタ操作 */
.filter-actions { margin: 4px 0 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.filter-actions button {
  border: 1px solid var(--app-border);
  background: var(--app-btn);
  color: var(--app-text);
  height: 32px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  letter-spacing: 0.3px;
  font-weight: 750;
  transition: background 0.15s, color 0.15s, transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.filter-actions button:hover { background: var(--app-btn-hover); }

.scenario-switch { margin: 12px 0 12px; display: flex; gap: 10px; flex-wrap: wrap; }
.scenario-switch button {
  border: 1px solid var(--app-border);
  background: var(--app-btn);
  color: var(--app-text);
  height: 32px;
  padding: 0 12px;
  line-height: 32px;
  border-radius: var(--radius-md);
  cursor: pointer;
  letter-spacing: 0.3px;
  font-weight: 750;
  transition: background 0.15s, color 0.15s, transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.scenario-switch button.active {
  background: var(--app-active);
  color: var(--app-text);
  border-color: var(--app-active-border);
}

/* ---- アクティブリフト（共通クラス） ---- */
/* .btn-lift を付けた要素、または既存の scenario-switch button が対象 */

.btn-lift {
  transition: transform var(--duration-fast), box-shadow var(--duration-fast);
}

.btn-lift.is-active,
.btn-lift.active,
.scenario-switch button.active {
  transform: var(--lift-transform);
  box-shadow: var(--lift-shadow);
}

/* 共通: select / 入力 */
.cr-input {
  width: 52px;
  min-width: 52px;
  height: 32px;
  line-height: 32px;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid var(--app-border);
  background: var(--app-input);
  color: var(--app-text);
  text-align: center;
  font-variant-numeric: tabular-nums;
  appearance: textfield;
  -moz-appearance: textfield;
}
.cr-input::-webkit-outer-spin-button,
.cr-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.filter-select {
  height: 32px;
  min-width: 180px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--app-border);
  background: var(--app-input);
  color: var(--app-text);
  font-weight: 750;
  letter-spacing: 0.2px;
  appearance: none;
}
select.filter-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%234B5565' d='M4.2 6.2a1 1 0 0 1 1.4 0L8 8.6l2.4-2.4a1 1 0 1 1 1.4 1.4l-3.1 3.1a1 1 0 0 1-1.4 0L4.2 7.6a1 1 0 0 1 0-1.4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px 16px;
}

/* 共通: パネル / テーブル / ツールチップ */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--app-panel-border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 14px 32px rgba(0,0,0,0.32);
}
.panel h2 { margin: 0 0 10px; font-size: 18px; letter-spacing: 0.3px; }
.hint { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
table { width: 100%; border-collapse: collapse; color: var(--text); font-size: 14px; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--accent-strong); font-size: 13px; font-weight: 700; position: relative; }
tbody tr:hover { background: var(--app-hover); }

/* テーブルヘッダ: 説明(?)ツールチップ */
.th-content { display: inline-flex; align-items: center; gap: 6px; }
.th-help-wrap { position: relative; display: inline-flex; align-items: center; }
.th-help {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.18);
  color: var(--app-text);
  font-weight: 900;
  font-size: 12px;
  line-height: 18px;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.th-help:focus { outline: 2px solid rgba(110,224,202,0.7); outline-offset: 2px; }
.th-tooltip {
  display: none;
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translate(-50%, -100%);
  background: rgba(0,0,0,0.9);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.35;
  width: max-content;
  max-width: 70vw;
  white-space: normal;
  word-break: break-word;
  box-shadow: 0 2px 8px rgba(0,0,0,0.16);
  z-index: 9000;
}
/* overflow の挙動を分かりやすく表示するための参考ツールチップ */
#th-help-tooltip {
  display: none;
  position: fixed;
  background: rgba(0,0,0,0.92);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.35;
  width: max-content;
  max-width: 70vw;
  white-space: normal;
  word-break: break-word;
  box-shadow: 0 2px 8px rgba(0,0,0,0.16);
  z-index: 12000;
  pointer-events: none;
}
#th-help-tooltip::after {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
}
#th-help-tooltip.arrow-up::after {
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-bottom: 6px solid rgba(0,0,0,0.92);
}
#th-help-tooltip.arrow-down::after {
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-top: 6px solid rgba(0,0,0,0.92);
}
.th-tooltip::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid rgba(0,0,0,0.9);
}
.th-help:hover + .th-tooltip,
.th-help:focus + .th-tooltip,
.th-help.open + .th-tooltip { display: none !important; }

/* 共通: セルツールチップ */
.cell-tip-wrap { position: relative; display: inline-flex; align-items: center; justify-content: center; }
.cell-tip {
  display: none;
  position: fixed;
  background: rgba(0,0,0,0.85);
  border: 1px solid rgba(255,255,255,0.20);
  border-radius: 12px;
  padding: 10px 12px;
  z-index: 50;
  width: max-content;
  max-width: 340px;
  text-align: left;
  box-shadow: 0 16px 34px rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.keep-with-title { color: var(--app-text); font-weight: 800; margin-bottom: 6px; }
.keep-with-list { display: grid; gap: 6px; }
.keep-with-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.keep-with-card { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.keep-with-card .cost { width: 18px; height: 18px; border-radius: 6px; font-size: 11px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.keep-with-card .name { font-size: 12px; font-weight: 700; color: var(--app-card-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.keep-with-right { display: inline-flex; align-items: center; justify-content: flex-end; gap: 10px; flex: 0 0 auto; }
.keep-with-thumb { width: 88px; height: 22px; flex: 0 0 auto; overflow: hidden; }
.keep-with-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  -webkit-mask-image: linear-gradient(to right, transparent 0%, rgba(0,0,0,1) 46%, rgba(0,0,0,1) 100%);
  mask-image: linear-gradient(to right, transparent 0%, rgba(0,0,0,1) 46%, rgba(0,0,0,1) 100%);
}
.keep-with-metric { font-size: 12px; color: var(--app-card-text); white-space: nowrap; }

/* 共通: パネルメタ情報 */
.panel-meta { text-align: right; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.panel-meta.panel-meta-footer { margin-top: 8px; margin-bottom: 0; }
.sortable { cursor: pointer; }
.sortable::after { content: "\2195"; font-size: 13px; margin-left: 4px; color: var(--muted); font-weight: 700; }
.sortable.active.asc::after { content: "\25B2"; color: var(--accent-strong); }
.sortable.active.desc::after { content: "\25BC"; color: var(--accent-strong); }

/* 共通: カードセル */
.card-cell { display: flex; align-items: center; gap: 10px; min-height: 44px; line-height: 1.15; }
.card-cell .cost { width: 24px; height: 24px; border-radius: 8px; background: transparent; color: #ffffff; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 13px; box-shadow: 0 4px 10px rgba(0,0,0,0.3); flex-shrink: 0; border: 1px solid rgba(0,0,0,0.35); }
.card-cell .cost.r1 { background: #5a4a33; }
.card-cell .cost.r2 { background: #7087a7; }
.card-cell .cost.r3 { background: #b08c2d; }
.card-cell .cost.r4 { background: linear-gradient(135deg, #ffd6ff 0%, #b5d8ff 35%, #d5ffea 70%, #ffd6ff 100%); color: #1b1d2a; }
.card-cell .name { position: relative; z-index: 1; font-weight: 600; letter-spacing: 0.2px; flex: 1; min-width: 0; max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-cell .card-thumb {
  margin-left: auto;
  width: 150px;
  height: 44px;
  border-radius: 10px;
  pointer-events: none;
  background: var(--app-card-bg);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
  overflow: hidden;
  display: block;
  position: relative;
}
.card-cell .card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-cell .card-thumb.crop img {
  /* --crop-* は、判定された矩形に合わせる */
  width: calc(100% / var(--crop-w));
  height: calc(100% / var(--crop-h));
  object-fit: fill;
  transform-origin: top left;
  transform:
    translate(
      calc(var(--crop-x) * (-100% / var(--crop-w))),
      calc(var(--crop-y) * (-100% / var(--crop-h)))
    );
}

@media (max-width: 768px) {
  .card-cell { gap: 8px; min-height: 40px; }
  .card-cell .card-thumb { width: 120px; height: 38px; }
}
