:root {
  --color-red: #FF5D5D;
  --color-red-light: #FF9A8A;
  --color-red-dark: #C83A4A;
  --color-blue: #4D8DFF;
  --color-blue-light: #8FBCFF;
  --color-blue-dark: #2C5BC7;
  --color-green: #3DCB7A;
  --color-green-light: #85E8A8;
  --color-green-dark: #1F9354;
  --color-yellow: #FFC53D;
  --color-yellow-light: #FFE28A;
  --color-yellow-dark: #D9921A;
  --color-garbage: #5A5160;
  --color-garbage-light: #7A7080;
  --color-garbage-dark: #2E2833;
  --color-board: #2B2140;
  --color-bg-top: #A8E2FF;
  --color-bg-bottom: #FFF3D1;
  --color-text: #3A2E5C;
  --color-accent: #FF7AB6;
  --color-accent-press: #FF5AA0;
  --color-deadline: #FF4D6D;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  font-family: 'M PLUS Rounded 1c', -apple-system, system-ui, sans-serif;
  background-color: var(--color-board);
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
}

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.clickable,
button,
a,
input,
select {
  pointer-events: auto;
}

/* 共通ボタンスタイル */
.mc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-weight: 800;
  font-size: 16px;
  color: #FFFFFF;
  background: var(--color-accent);
  border: 3px solid #FFFFFF;
  border-radius: 9999px;
  padding: 8px 18px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(43, 33, 64, 0.25), inset 0 2px 0 rgba(255, 255, 255, 0.4);
  transition: transform 0.08s ease, background 0.08s ease;
  outline: none;
  text-decoration: none;
  pointer-events: auto;
}

.mc-btn:active {
  transform: translateY(2px) scale(0.97);
  background: var(--color-accent-press);
  box-shadow: 0 2px 5px rgba(43, 33, 64, 0.25);
}

.mc-btn-sub {
  background: #FFFFFF;
  color: var(--color-text);
  border: 2px solid #E2D9F3;
}

.mc-btn-sub:active {
  background: #F0EBFA;
}

/* 重ね表示（一時停止・リザルトなど） */
.mc-modal {
  position: absolute;
  inset: 0;
  background: rgba(43, 33, 64, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  pointer-events: auto;
}

.mc-card {
  background: #FFFFFF;
  border-radius: 24px;
  padding: 24px 22px;
  width: 100%;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: var(--color-text);
}

.mc-card-title {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 4px;
}

.mc-card-note {
  font-size: 14px;
  color: #8A7DA4;
  margin-bottom: 4px;
}

.mc-btn-block {
  width: 100%;
  height: 48px;
  font-size: 18px;
}

/* DOM の画面（選択・リザルト・ホーム） */
.mc-screen {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
  color: var(--color-text);
  pointer-events: none;
}

.mc-screen > * {
  pointer-events: auto;
}

/* 画面に収まれば上下中央、収まらなければスクロール（低い画面・横持ちで下のボタンに届くように） */
.mc-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  pointer-events: auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
}

.mc-scroll::before,
.mc-scroll::after {
  content: '';
  flex: 1 0 0;
}

/* 下寄せ版（上に立ち絵を見せる画面） */
.mc-scroll-bottom::after {
  flex: 0 0 8px;
}

.mc-heading {
  font-size: 22px;
  font-weight: 800;
  text-shadow: 0 2px 0 #FFFFFF;
}

.mc-label {
  font-size: 14px;
  font-weight: 800;
  color: #6D5B8D;
  align-self: flex-start;
}

.mc-row {
  display: flex;
  gap: 8px;
  width: 100%;
  justify-content: center;
}

.mc-char-card {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.85);
  border: 3px solid #FFFFFF;
  border-radius: 16px;
  padding: 6px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  font-size: 14px;
  color: var(--color-text);
  box-shadow: 0 3px 8px rgba(43, 33, 64, 0.15);
}

/* 立ち絵 canvas は portraitCanvas がインラインで px 指定するので、狭い画面では !important で縮める */
.mc-char-card canvas {
  max-width: 100%;
  height: auto !important;
}

/* 横持ちなど高さが低い画面では立ち絵を小さくする */
@media (max-height: 520px) {
  .mc-char-card canvas {
    height: 56px !important;
    width: auto !important;
  }
}

.mc-char-card small {
  overflow-wrap: anywhere;
  font-size: 10px;
  font-weight: 700;
  color: #8A7DA4;
}

@media (max-width: 359px) {
  .mc-char-card small {
    font-size: 9px;
  }
}

.mc-char-card.is-selected {
  border-color: var(--color-accent);
  background: #FFF0F7;
  transform: translateY(-2px);
}

.mc-chip {
  flex: 1;
  height: 44px;
  border-radius: 9999px;
  border: 3px solid #FFFFFF;
  background: rgba(255, 255, 255, 0.85);
  font-family: inherit;
  font-weight: 800;
  font-size: 16px;
  color: var(--color-text);
  cursor: pointer;
}

.mc-chip.is-selected {
  background: var(--color-accent);
  color: #FFFFFF;
}

.mc-stats {
  background: #F6F3FC;
  border-radius: 16px;
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  font-size: 14px;
  text-align: left;
}

.mc-stats strong {
  text-align: right;
  font-size: 16px;
}

/* 縦画面専用（Web 品質基準 1-7）: スマホを横にしたときだけ案内を出す。PC の横長画面は縦レイアウトを中央に表示する */
#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(43, 33, 64, 0.85);
  align-items: center;
  justify-content: center;
  padding: 20px;
  pointer-events: auto;
}

@media (orientation: landscape) and (max-height: 500px) {
  body[data-orientation="portrait"] #rotate {
    display: flex;
  }
}

/* リプレイ一覧（spec §7.5） */
.mc-replay-list {
  list-style: none;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mc-replay {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.9);
  border: 3px solid #FFFFFF;
  border-radius: 16px;
  padding: 8px;
  box-shadow: 0 3px 8px rgba(43, 33, 64, 0.15);
}

.mc-replay-badge {
  flex: 0 0 auto;
  min-width: 52px;
  padding: 4px 6px;
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  color: #FFFFFF;
  background: #8A7DA4;
}

.mc-replay-badge.is-win {
  background: var(--color-accent);
}

.mc-replay-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 15px;
}

.mc-replay-info small {
  font-size: 12px;
  font-weight: 700;
  color: #6D5B8D;
  overflow-wrap: anywhere;
}

.mc-replay-info .mc-replay-old {
  color: var(--color-deadline);
}

.mc-replay-play,
.mc-fav {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 18px;
}

.mc-fav[aria-pressed="true"] {
  color: #E8A400;
}

.mc-replay-play:disabled {
  opacity: 0.4;
  cursor: default;
}

.mc-replay-empty,
.mc-replay-note {
  font-size: 14px;
  font-weight: 700;
  color: #6D5B8D;
  text-align: center;
  text-shadow: 0 1px 0 #FFFFFF;
}

.mc-replay-note:empty {
  display: none;
}

.mc-streak {
  color: var(--color-accent);
  font-weight: 800;
  font-size: 18px;
}
