/* ============================================================
   Character select screen styles
   ============================================================ */

#screen-character {
  --character-selected-border: #7396c4;
  --character-selected-bg: #16263f;
  background: #030312;
  /* html の拡大後も、画面の下端が実際の表示領域内に収まる高さにする。 */
  height: calc(100vh / var(--ui-scale));
  height: calc(100dvh / var(--ui-scale));
  overflow: hidden;
}

#screen-character.active {
  display: block;
}

.character-select-container {
  position: relative;
  z-index: 11;
  width: 90%;
  max-width: 920px;
  height: 100%;
  min-height: 0;
  margin: 0 auto;
  padding: 12px 18px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.character-title {
  flex-shrink: 0;
  font-family: 'DotGothic16', monospace;
  font-size: 1.1rem;
  color: var(--ui-text-main);
  letter-spacing: 4px;
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
  width: 100%;
}

.character-title::before,
.character-title::after {
  content: '';
  flex: 1;
  height: 2px;
  background: linear-gradient(to right, transparent, #888888);
}

.character-title::after {
  background: linear-gradient(to left, transparent, #888888);
}

.character-subtitle {
  flex-shrink: 0;
  font-family: 'DotGothic16', monospace;
  font-size: 0.78rem;
  color: var(--ui-text-subtle);
  letter-spacing: 2px;
  margin-top: 4px;
  margin-bottom: 0;
}

.character-grid {
  /* 一覧だけを縮めてスクロールさせ、見出しと操作ボタンの高さを確保する。 */
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: max-content;
  align-content: start;
  gap: 14px;
  width: 100%;
  /* スクロール領域の端でもカードの枠とホバー時の拡大を切らない。 */
  padding: 10px;
  overflow-y: auto;
  overflow-x: hidden;
}

.character-card {
  --role-bg: #909aae;
  --role-border: #cad2df;
  --role-text: #111523;
  --role-shadow: rgba(144, 154, 174, 0.18);
  position: relative;
  z-index: 1;
  background:
    linear-gradient(
      to bottom,
      rgba(14, 17, 38, 0.94),
      rgba(4, 5, 18, 0.94)
    );
  box-shadow:
    0 0 0 2px #000000,
    0 0 0 4px #555555;
  min-height: 0;
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transform-origin: center;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.character-card-balance {
  --role-bg: #909aae;
  --role-border: #cad2df;
  --role-text: #111523;
  --role-shadow: rgba(144, 154, 174, 0.18);
}

.character-card-endurance {
  --role-bg: #2f80ed;
  --role-border: #8bc0ff;
  --role-text: #ffffff;
  --role-shadow: rgba(47, 128, 237, 0.4);
}

.character-card-speed {
  --role-bg: #ff4b4b;
  --role-border: #ffaaa3;
  --role-text: #ffffff;
  --role-shadow: rgba(255, 75, 75, 0.42);
}

.character-card-healing {
  --role-bg: #39c86a;
  --role-border: #98f0b7;
  --role-text: #06180c;
  --role-shadow: rgba(57, 200, 106, 0.4);
}

.character-card-magic {
  --role-bg: #9b5cff;
  --role-border: #d0b4ff;
  --role-text: #ffffff;
  --role-shadow: rgba(155, 92, 255, 0.42);
}

.character-card-accuracy {
  --role-bg: #31d6e8;
  --role-border: #a6f6ff;
  --role-text: #03181b;
  --role-shadow: rgba(49, 214, 232, 0.4);
}

.character-card:hover:not(.is-selected) {
  z-index: 2;
  transform: translateY(-2px) scale(1.03);
}

.character-card.is-selected {
  z-index: 3;
  background: var(--character-selected-bg);
  box-shadow:
    0 0 0 2px #000000,
    0 0 0 4px var(--character-selected-border);
}

.character-card.is-selected:hover {
  z-index: 4;
  box-shadow:
    0 0 0 2px #000000,
    0 0 0 4px var(--character-selected-border);
  transform: translateY(-2px) scale(1.03);
}

.character-card:focus-visible {
  z-index: 5;
  outline: none;
}

/* 画像・型・能力欄を避け、操作中のカードの左上へカーソルを置く。 */
.character-card > .menu-cursor {
  top: 15px;
  transform: none;
}

/* 選択中のカードは枠・背景と文字を併用して示す */
.character-card-selection {
  position: absolute;
  top: 8px;
  right: 8px;
  color: var(--ui-text-main);
  font-family: 'DotGothic16', monospace;
  font-size: 0.6rem;
  line-height: 1.2;
}

.character-card:not(.is-selected) .character-card-selection {
  display: none;
}

.character-card .pixel-sprite {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 60px;
  height: 60px;
}

.character-card-name {
  font-family: 'DotGothic16', monospace;
  font-size: 0.95rem;
  color: var(--ui-text-main);
  letter-spacing: 1px;
  line-height: 1.1;
}

.character-card-role {
  min-width: 92px;
  padding: 4px 12px;
  font-family: 'DotGothic16', monospace;
  font-size: 0.86rem;
  color: var(--role-text);
  background: var(--role-bg);
  border: 2px solid var(--role-border);
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 1px;
  line-height: 1;
  text-align: center;
  box-shadow:
    0 0 0 2px #000000,
    0 0 10px 1px var(--role-shadow);
}

.character-card-stats {
  width: min(134px, 100%);
  margin: 0;
  display: grid;
  gap: 1px;
}

.character-card-stat {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  gap: 6px;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.43rem;
  line-height: 1.35;
}

.character-card-stat dt,
.character-card-stat dd {
  margin: 0;
}

.character-card-stat dt {
  color: var(--ui-text-subtle);
}

.character-card-stat dd {
  color: var(--ui-text-main);
  letter-spacing: 1px;
  white-space: nowrap;
}

.character-card-desc {
  font-family: 'DotGothic16', monospace;
  font-size: 0.64rem;
  color: var(--ui-text-subtle);
  text-align: center;
  letter-spacing: 0.5px;
  line-height: 1.35;
  min-height: 2.7em;
}

.character-actions {
  flex-shrink: 0;
  z-index: 12;
  display: flex;
  justify-content: center;
  gap: 16px;
  width: 100%;
  margin-top: 2px;
  padding: 8px 0 6px;
  background: linear-gradient(
    to bottom,
    rgba(3, 3, 18, 0),
    #030312 12px,
    #030312 100%
  );
}

/* 決定・キャンセルも、同じ寸法のカーソルで現在の操作位置だけを示す。 */
.character-actions .pixel-cursor {
  display: inline-block;
  width: 1em;
  min-width: 1em;
  font: 0.85rem/1 "DotGothic16", monospace;
  letter-spacing: 0;
  visibility: hidden;
  animation: none;
}

.character-actions button:not(:disabled):focus .pixel-cursor {
  visibility: visible;
  animation: var(--menu-cursor-animation);
}

/* ドット絵スタイルのボタン(タイトル画面のメニュー枠と同系) */
.pixel-button {
  font-family: 'DotGothic16', monospace;
  font-size: 1rem;
  color: var(--ui-text-subtle);
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 8px 18px;
  letter-spacing: 2px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: none;
  transition: color 0.1s ease, text-shadow 0.15s ease, transform 0.1s ease;
  image-rendering: pixelated;
}

.pixel-button:hover:not(:disabled) {
  color: var(--ui-text-main);
}

.pixel-button:active:not(:disabled) {
  transform: translate(2px, 2px);
}

.pixel-button:focus-visible {
  outline: none;
  color: var(--ui-text-main);
}

.pixel-button:disabled {
  color: #666666;
  cursor: not-allowed;
  box-shadow: none;
  text-shadow: none;
}

.pixel-button:disabled .pixel-cursor {
  color: #666666;
  animation: none;
}

.pixel-button-primary {
  color: var(--ui-accent);
}

.pixel-button-primary:hover:not(:disabled),
.pixel-button-primary:focus-visible:not(:disabled) {
  color: var(--ui-accent);
}

.pixel-button-primary:disabled {
  color: #666666;
}

@media (max-width: 700px) {
  .character-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .character-title {
    font-size: 0.95rem;
  }
}

@media (max-width: 480px) {
  .character-select-container {
    padding: 12px 14px 10px;
  }

  .character-grid {
    grid-template-columns: 1fr;
  }

  .character-actions {
    flex-direction: column;
    align-items: center;
  }
}
