/* ハーツ固有スタイル */

.game-panel {
  margin-top: 20px;
}

.ht-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin: 0 auto 14px;
  padding: 12px 14px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface);
}

.ht-status__main,
.ht-status__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  min-width: 0;
}

.ht-status__text {
  margin: 0;
  color: var(--md-sys-color-on-surface);
  font-size: 0.95rem;
  font-weight: 600;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--md-sys-color-primary) 14%, var(--md-sys-color-surface));
  color: var(--md-sys-color-on-surface);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.status-pill.is-player {
  background: color-mix(in srgb, #22d3ee 22%, var(--md-sys-color-surface));
  color: #0e7490;
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.28);
}

.status-pill.is-cpu {
  background: color-mix(in srgb, #c084fc 20%, var(--md-sys-color-surface));
  color: #7e22ce;
}

.status-pill.is-pass {
  background: color-mix(in srgb, #f472b6 18%, var(--md-sys-color-surface));
  color: #be185d;
}

.status-pill.is-result {
  background: color-mix(in srgb, #60a5fa 18%, var(--md-sys-color-surface));
  color: #1d4ed8;
}

.status-pill.is-win {
  background: color-mix(in srgb, var(--success, #16a34a) 18%, var(--md-sys-color-surface));
  color: var(--success, #15803d);
}

.status-pill.is-lose {
  background: color-mix(in srgb, #ef4444 16%, var(--md-sys-color-surface));
  color: #b91c1c;
}

.ht-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 999px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ht-chip--broken {
  border-color: rgba(225, 29, 72, 0.45);
  background: color-mix(in srgb, #f43f5e 12%, var(--md-sys-color-surface));
  color: #be123c;
  box-shadow: 0 0 10px rgba(244, 63, 94, 0.22);
}

.ht-chip[hidden] {
  display: none;
}

.ht-feedback {
  margin: 0 auto 12px;
  padding: 8px 12px;
  border: 1px solid rgba(34, 211, 238, 0.4);
  border-radius: var(--md-sys-shape-corner-medium);
  background: color-mix(in srgb, #22d3ee 10%, var(--md-sys-color-surface));
  color: #0e7490;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}

/* ---- 結果 ---- */

.ht-result {
  margin: 0 auto 14px;
  padding: 16px;
  border: 1px solid rgba(63, 196, 255, 0.35);
  border-radius: var(--md-sys-shape-corner-medium);
  background:
    radial-gradient(ellipse 80% 120% at 10% 0%, rgba(63, 196, 255, 0.12), transparent 55%),
    #0f1a34;
  text-align: center;
}

.ht-result.is-win {
  border-color: rgba(63, 196, 255, 0.6);
  box-shadow: 0 0 20px rgba(63, 196, 255, 0.22);
}

.ht-result.is-moon {
  border-color: rgba(244, 114, 182, 0.6);
  box-shadow: 0 0 22px rgba(244, 114, 182, 0.25);
}

.ht-result__moon {
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid rgba(244, 114, 182, 0.5);
  border-radius: var(--md-sys-shape-corner-small, 8px);
  background: rgba(244, 114, 182, 0.12);
  color: #fbcfe8;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.5;
}

.ht-result__title {
  margin: 0 0 4px;
  color: #e8f4ff;
  font-family: Outfit, "Noto Sans JP", sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
}

.ht-result.is-win .ht-result__title {
  color: #7ee0ff;
  text-shadow: 0 0 14px rgba(63, 196, 255, 0.45);
}

.ht-result__detail {
  margin: 0 0 12px;
  color: rgba(220, 236, 255, 0.9);
  font-size: 0.92rem;
  line-height: 1.5;
}

.ht-result__table {
  width: 100%;
  max-width: 360px;
  margin: 0 auto 14px;
  border-collapse: collapse;
  color: #dcecff;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

.ht-result__table th,
.ht-result__table td {
  padding: 6px 10px;
  border-bottom: 1px solid rgba(120, 170, 220, 0.2);
}

.ht-result__table thead th {
  color: rgba(180, 210, 245, 0.85);
  font-size: 0.78rem;
  font-weight: 700;
}

.ht-result__table th {
  text-align: left;
}

.ht-result__table td,
.ht-result__table thead th:not(:first-child) {
  text-align: right;
}

.ht-result__table tbody th {
  font-weight: 600;
}

.ht-result__table tr.is-you {
  background: rgba(63, 196, 255, 0.1);
}

.ht-result__table tr.is-winner th {
  color: #7ee0ff;
}

.ht-result__actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.ht-result__actions [hidden] {
  display: none;
}

/* ---- 卓 ---- */

.ht-stage {
  --ht-card-w: 62px;
  --ht-trick-w: 58px;
  --ht-radius: 8px;
  --ht-neon: #3fc4ff;

  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
  grid-template-areas:
    ". top ."
    "left center right"
    "you you you";
  align-items: center;
  gap: 10px 12px;
  width: 100%;
  max-width: min(100%, 820px);
  margin: 0 auto 14px;
  padding: 16px;
  border: 1px solid rgba(96, 154, 214, 0.35);
  border-radius: var(--md-sys-shape-corner-large);
  background:
    radial-gradient(ellipse 55% 38% at 50% 46%, rgba(63, 196, 255, 0.1), transparent 70%),
    radial-gradient(ellipse 60% 40% at 85% 100%, rgba(167, 139, 250, 0.12), transparent 55%),
    radial-gradient(ellipse 60% 40% at 10% 0%, rgba(99, 102, 241, 0.12), transparent 55%),
    #0d1730;
  box-shadow: 0 14px 34px rgba(28, 52, 96, 0.24);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ht-seat {
  min-width: 0;
  padding: 8px;
  border: 1px solid rgba(96, 154, 214, 0.18);
  border-radius: var(--md-sys-shape-corner-medium);
  background: rgba(10, 20, 44, 0.55);
  text-align: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.ht-seat--top { grid-area: top; justify-self: center; min-width: 180px; }
.ht-seat--left { grid-area: left; }
.ht-seat--right { grid-area: right; }
.ht-seat--you { grid-area: you; padding: 10px 8px 12px; }

.ht-seat.is-turn {
  border-color: rgba(63, 196, 255, 0.6);
  background: rgba(63, 196, 255, 0.08);
  box-shadow: 0 0 16px rgba(63, 196, 255, 0.2);
}

.ht-seat.is-trick-winner {
  border-color: rgba(244, 114, 182, 0.6);
  box-shadow: 0 0 14px rgba(244, 114, 182, 0.22);
}

.ht-seat__header,
.ht-seat__stats {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 2px 10px;
}

.ht-seat__name {
  color: #e2efff;
  font-family: Outfit, "Noto Sans JP", sans-serif;
  font-size: 0.92rem;
  font-weight: 700;
}

.ht-seat__dir {
  color: rgba(167, 139, 250, 0.95);
  font-size: 0.7rem;
  font-weight: 700;
}

.ht-seat__stats {
  margin-top: 2px;
}

.ht-seat__count,
.ht-seat__score,
.ht-seat__round {
  color: rgba(180, 210, 245, 0.85);
  font-size: 0.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ht-seat__score b {
  color: #e8f4ff;
  font-size: 0.95rem;
}

.ht-seat__round b {
  color: #f9a8d4;
}

.ht-backs {
  display: flex;
  justify-content: center;
  min-height: 34px;
  margin-top: 6px;
}

.ht-back {
  flex: 0 0 auto;
  width: 22px;
  height: 32px;
  border: 1px solid rgba(90, 170, 255, 0.5);
  border-radius: 4px;
  background-color: #050b24;
  background-image: url('/images/card-back.webp');
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  box-shadow: 0 1px 3px rgba(4, 10, 24, 0.5);
}

.ht-back + .ht-back {
  margin-left: -15px;
}

.ht-backs--side .ht-back + .ht-back {
  margin-left: -17px;
}

/* ---- 中央トリック ---- */

.ht-center {
  grid-area: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.ht-trick {
  position: relative;
  width: calc(var(--ht-trick-w) * 3.6);
  max-width: 100%;
  height: calc(var(--ht-trick-w) * 1.4 * 2.1);
  border: 1px dashed rgba(120, 170, 220, 0.25);
  border-radius: 50%;
}

.ht-trick__slot {
  position: absolute;
  width: var(--ht-trick-w);
  height: calc(var(--ht-trick-w) * 1.4);
}

.ht-trick__slot--bottom { left: 50%; bottom: 0; transform: translateX(-50%); }
.ht-trick__slot--top { left: 50%; top: 0; transform: translateX(-50%); }
.ht-trick__slot--left { left: 4%; top: 50%; transform: translateY(-50%); }
.ht-trick__slot--right { right: 4%; top: 50%; transform: translateY(-50%); }

.ht-trick .ht-card {
  --ht-card-w: var(--ht-trick-w);
  width: 100%;
  height: 100%;
}

.ht-trick-message {
  min-height: 1.5em;
  margin: 0;
  color: rgba(200, 222, 250, 0.85);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
}

.ht-trick-message.is-winner {
  color: #fbcfe8;
  text-shadow: 0 0 10px rgba(244, 114, 182, 0.35);
}

/* ---- 交換 ---- */

.ht-pass {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 14px;
  margin: 8px auto 4px;
  padding: 8px 12px;
  border: 1px solid rgba(244, 114, 182, 0.4);
  border-radius: var(--md-sys-shape-corner-medium);
  background: rgba(244, 114, 182, 0.08);
}

.ht-pass[hidden] {
  display: none;
}

.ht-pass__text {
  margin: 0;
  color: #fbcfe8;
  font-size: 0.9rem;
  font-weight: 700;
}

.ht-pass__count {
  margin-left: 6px;
  color: #e8f4ff;
  font-variant-numeric: tabular-nums;
}

/* ---- 手札 ---- */

.ht-hand {
  --count: 13;
  --ht-overlap-min: 18px;
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: flex-end;
  width: 100%;
  max-width: min(100%, 720px);
  min-height: calc(var(--ht-card-w) * 1.4 + 14px);
  margin: 8px auto 0;
  padding-top: 14px;
}

.ht-hand .ht-card:not(:first-child) {
  margin-left: calc(
    min(
      var(--ht-card-w) + 4px,
      max(var(--ht-overlap-min), (100% - var(--ht-card-w)) / max(var(--count) - 1, 1))
    ) - var(--ht-card-w)
  );
}

/* ---- カード ---- */

.ht-card {
  position: relative;
  display: block;
  flex: 0 0 auto;
  width: var(--ht-card-w);
  height: calc(var(--ht-card-w) * 1.4);
  margin: 0;
  padding: 0;
  border: 1px solid rgba(20, 36, 68, 0.18);
  border-radius: var(--ht-radius);
  background: linear-gradient(180deg, #ffffff 0%, #f3f7fd 100%);
  box-shadow: 0 2px 6px rgba(8, 16, 36, 0.28);
  color: #1b2436;
  font-family: Outfit, "Noto Sans JP", sans-serif;
  cursor: default;
  appearance: none;
  -webkit-appearance: none;
  overflow: hidden;
  touch-action: manipulation;
}

.ht-card[data-color="red"] {
  color: #c62828;
}

.ht-card:disabled {
  opacity: 1;
}

.ht-card.is-interactive {
  cursor: pointer;
  outline: 2px solid transparent;
  outline-offset: 1px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, outline-color 0.12s ease;
}

.ht-card.is-playable {
  outline: 1.5px solid rgba(63, 196, 255, 0.5);
}

.ht-card.is-interactive:hover,
.ht-card.is-interactive:focus-visible {
  transform: translateY(-8px);
  outline-color: var(--ht-neon);
  box-shadow:
    0 0 0 2px rgba(63, 196, 255, 0.35),
    0 0 14px rgba(63, 196, 255, 0.5),
    0 4px 10px rgba(8, 16, 36, 0.35);
  z-index: 2;
}

.ht-card.is-disabled {
  filter: brightness(0.55) saturate(0.6);
  cursor: not-allowed;
}

.ht-card.is-selected {
  transform: translateY(-14px);
  border-color: #22d3ee;
  outline: 2px solid #22d3ee;
  background: linear-gradient(180deg, #ecfeff 0%, #cffafe 100%);
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.55), 0 4px 10px rgba(8, 16, 36, 0.35);
  z-index: 3;
}

.ht-card.is-selected:hover,
.ht-card.is-selected:focus-visible {
  transform: translateY(-14px);
}

.ht-card.is-received::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f472b6;
  box-shadow: 0 0 6px rgba(244, 114, 182, 0.8);
}

.ht-card.is-played {
  animation: ht-play 0.3s ease-out;
}

.ht-card.is-winner {
  outline: 2px solid #f472b6;
  outline-offset: 1px;
  box-shadow: 0 0 16px rgba(244, 114, 182, 0.55);
}

@keyframes ht-play {
  0% { transform: scale(1.1); opacity: 0.6; }
  100% { transform: scale(1); opacity: 1; }
}

.ht-card__corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.ht-card__corner--tl {
  top: 4%;
  left: 6%;
}

.ht-card__corner--br {
  right: 6%;
  bottom: 4%;
  transform: rotate(180deg);
}

.ht-card__rank {
  font-size: calc(var(--ht-card-w) * 0.28);
  font-weight: 700;
}

.ht-card__suit {
  font-size: calc(var(--ht-card-w) * 0.22);
  line-height: 1;
}

.ht-card__center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--ht-card-w) * 0.42);
  pointer-events: none;
}

.ht-guide {
  max-width: min(100%, 760px);
  margin: 0 auto 12px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.88rem;
  line-height: 1.55;
  text-align: center;
}

.ht-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.how-to-list--ordered {
  list-style: decimal;
  padding-left: 1.35em;
}

.how-to-list--ordered li {
  margin: 0.35em 0;
}

/* ---- スマートフォン ---- */

@media (max-width: 640px) {
  .ht-stage {
    --ht-trick-w: 46px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas:
      "left top right"
      "center center center"
      "you you you";
    gap: 8px 6px;
    padding: 10px 8px;
  }

  .ht-seat {
    padding: 6px 4px;
  }

  .ht-seat--top {
    justify-self: stretch;
    min-width: 0;
  }

  .ht-seat__header,
  .ht-seat__stats {
    gap: 0 6px;
  }

  .ht-seat__name {
    font-size: 0.82rem;
  }

  .ht-seat__dir {
    display: none;
  }

  .ht-seat--cpu .ht-seat__stats {
    flex-direction: column;
    align-items: center;
  }

  .ht-backs {
    display: none;
  }

  .ht-trick {
    width: calc(var(--ht-trick-w) * 4);
  }

  /* 13枚を重ねず2段に並べ、タップ領域を確保する */
  .ht-seat--you {
    padding: 8px 4px 10px;
  }

  .ht-hand {
    container-type: inline-size;
    display: grid;
    grid-template-columns: repeat(7, auto);
    justify-content: center;
    gap: 12px 3px;
    min-height: 0;
  }

  .ht-hand .ht-card {
    --ht-card-w: min(50px, calc((100cqw - 18px) / 7));
  }

  .ht-hand .ht-card:not(:first-child) {
    margin-left: 0;
  }

  .ht-card.is-interactive:hover,
  .ht-card.is-interactive:focus-visible {
    transform: translateY(-4px);
  }

  .ht-card.is-selected,
  .ht-card.is-selected:hover,
  .ht-card.is-selected:focus-visible {
    transform: translateY(-10px);
  }

  .ht-status__text {
    font-size: 0.88rem;
  }
}

@media (hover: none) {
  .ht-card.is-interactive:not(.is-selected):hover {
    transform: none;
    box-shadow: 0 2px 6px rgba(8, 16, 36, 0.28);
  }

  .ht-card.is-playable:not(.is-selected):hover {
    outline-color: rgba(63, 196, 255, 0.5);
  }
}

/* 共通の外枠・HUD・アイコン操作を再利用し、テーブルだけを固有配置にする。 */
html.gs-playing .game-panel { align-items: center; }
html.gs-playing .game-panel > .gs-bar,
html.gs-playing .game-panel > .gs-hud,
html.gs-playing .ht-stage,
html.gs-playing .ht-controls,
html.gs-playing .ht-status__text,
html.gs-playing .ht-feedback,
html.gs-playing .ht-break { width: 100%; max-width: 640px; flex: none; }
html.gs-playing .status-pill {
  min-height: 0;
  padding: 0;
  border-radius: 0;
  background: none;
  color: var(--play-text);
  box-shadow: none;
  font-size: 1.15rem;
}
html.gs-playing .ht-status__text {
  min-height: 3em;
  margin: 0;
  color: var(--play-text-muted);
  font-size: .85rem;
  line-height: 1.5;
  text-align: center;
}
html.gs-playing .ht-break {
  height: 1.5em;
  color: #fda4af;
  font-size: .8rem;
  text-align: center;
}
html.gs-playing .ht-feedback {
  height: 3em;
  margin: 0 auto 10px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--play-accent);
  font-size: .8rem;
  line-height: 1.5;
}
html.gs-playing .ht-feedback[hidden] { display: block; visibility: hidden; }
html.gs-playing .ht-stage { border-color: var(--play-border); }
html.gs-playing .ht-trick-message { height: 3em; font-size: .8rem; line-height: 1.5; }
html.gs-playing .ht-pass { min-height: 84px; }
html.gs-playing .ht-pass[hidden] { display: flex; visibility: hidden; }
html.gs-playing .ht-hand { min-height: 110px; }
html.gs-playing .ht-controls { margin: 0; gap: 12px; }
html.gs-playing .ht-result {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin: 0;
  padding: 16px;
  overflow-y: auto;
  background: rgba(11, 20, 42, .97);
}
html.gs-playing .ht-result[hidden] { display: none; }
html.gs-playing .ht-guide {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
@media (min-width: 768px) and (min-height: 700px) {
  html.gs-playing .game-panel { padding-top: max(28px, env(safe-area-inset-top)); }
  html.gs-playing .game-panel > .gs-bar { margin-bottom: 24px; }
  html.gs-playing .ht-stage { margin-bottom: 20px; }
}
@media (max-width: 640px) {
  html.gs-playing .ht-hand { min-height: 166px; align-content: start; }
  html.gs-playing .ht-pass { min-height: 104px; padding: 6px 4px; }
}
