/**
 * replay_v2 NAGA 固定 skeleton — 唯一の layout owner（ゲーム画面）
 * replay-v2.css の layout は .replay-ui-v2-shell 配下で neutralize
 */

/* ═══════════════════════════════════════════════════════════════
   ① 旧 replay-v2.css / index layout 干渉の neutralize
   ═══════════════════════════════════════════════════════════════ */
#replay_panel.replay-ui-v2-active.replay-ui-v2-shell.card {
  margin-top: 0 !important;
  padding: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  max-height: calc(100vh - 36px) !important;
  min-height: 0 !important;
  overflow: hidden !important;
  background: #141a1e !important;
}

#replay_panel.replay-ui-v2-active.replay-ui-v2-shell .replay-panel-inner {
  min-height: 0 !important;
  height: calc(100vh - 40px) !important;
  max-height: calc(100vh - 40px) !important;
  padding: 0 !important;
  overflow: hidden !important;
}

#replay_v2_mount {
  height: calc(100% - 18px) !important;
  min-height: 0 !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}

/* replay-v2.css が .replay-v2-root に当てる規則の保険（shell 内の mat 等） */
#replay_panel.replay-ui-v2-active.replay-ui-v2-shell .replay-v2-shell-root .replay-stage,
#replay_panel.replay-ui-v2-active.replay-ui-v2-shell .replay-v2-shell-root .replay-stage-main,
#replay_panel.replay-ui-v2-active.replay-ui-v2-shell .replay-v2-shell-root .replay-mat-wrap,
#replay_panel.replay-ui-v2-active.replay-ui-v2-shell .replay-v2-shell-root .replay-self-hand-dock {
  margin: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding: 0 !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: visible !important;
  transform: none !important;
  flex: none !important;
}

#replay_panel.replay-ui-v2-active.replay-ui-v2-shell .replay-v2-shell-root .replay-mat-scale-shell {
  --replay-scale-gap-pull: 0vh !important;
  margin-bottom: 0 !important;
}

#replay_panel.replay-ui-v2-active.replay-ui-v2-shell .replay-v2-shell-root .replay-step-dock {
  position: static !important;
  top: auto !important;
  right: auto !important;
  width: auto !important;
  opacity: 1 !important;
  transform: none !important;
}

/* ═══════════════════════════════════════════════════════════════
   shell 変数・ルート
   ═══════════════════════════════════════════════════════════════ */
.replay-v2-shell-root {
  --rv2-shell-overlay-h: 18px;
  --rv2-shell-bottom-h: 84px;
  --rv2-shell-sidebar-w: 82px;
  --rv2-shell-table-scale: clamp(0.7, calc(0.8 - (100svh - 980px) * 0.00042), 0.82);
  --rv2-shell-tile: 26px;
  --rv2-shell-hand-max-h: 36px;
  --rv2-shell-felt: #0a3558;
  --rv2-shell-felt-edge: rgba(6, 40, 72, 0.9);
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0 !important;
  max-height: none !important;
  margin: 0;
  padding: 0;
  overflow: hidden;
  box-sizing: border-box;
  background: radial-gradient(ellipse 95% 70% at 50% 38%, #1a2830 0%, #121a1f 48%, #0e1418 100%);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@supports not (height: 1svh) {
  .replay-v2-shell-root {
    --rv2-shell-table-scale: clamp(0.7, calc(0.8 - (100vh - 980px) * 0.00042), 0.82);
  }
}

.replay-v2-shell-root[hidden] {
  display: none !important;
}

#replay_panel.replay-ui-v2-active.replay-ui-v2-shell .replay-panel-title-row {
  min-height: 18px;
  padding: 0 6px;
  margin: 0;
  border-bottom: none;
  background: rgba(10, 14, 18, 0.75);
}

#replay_panel.replay-ui-v2-active.replay-ui-v2-shell .replay-panel-title-row > div:first-child {
  display: none;
}

#replay_panel.replay-ui-v2-active.replay-ui-v2-shell .replay-ui-mode-btn {
  padding: 0 5px;
  font-size: 8px;
  border: none;
  background: transparent;
  color: rgba(176, 190, 197, 0.7);
}

#replay_panel.replay-ui-v2-active.replay-ui-v2-shell .replay-ui-mode-btn.is-active {
  color: rgba(236, 239, 241, 0.95);
  text-decoration: underline;
}

#replay_panel.replay-ui-v2-active.replay-ui-v2-shell .replay-close {
  padding: 0 5px;
  font-size: 8px;
  color: rgba(144, 164, 174, 0.8);
  border: none;
  background: transparent;
}

/* ═══════════════════════════════════════════════════════════════
   overlay — 文字だけ浮く HUD
   ═══════════════════════════════════════════════════════════════ */
.rv2-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--rv2-shell-overlay-h);
  z-index: 40;
  display: flex;
  align-items: center;
  padding: 0 6px 0 5px;
  box-sizing: border-box;
  pointer-events: none;
  background: transparent;
  border: none;
  box-shadow: none;
}

.rv2-overlay > * {
  pointer-events: auto;
}

.rv2-overlay-hud {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 3px;
  overflow: hidden;
}

.rv2-overlay-hud-primary {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 3px;
  overflow: hidden;
}

.rv2-overlay-hud-primary .replay-top-bar {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 3px;
  margin: 0 !important;
  padding: 0 !important;
  max-height: none !important;
  font-size: 7px;
  line-height: 1.05;
  color: rgba(236, 239, 241, 0.88);
  background: transparent;
  border: none;
}

.rv2-overlay-hud-primary .replay-compact-summary {
  flex: 1 1 auto;
  margin: 0;
  padding: 0;
  font-size: 7px;
  font-weight: 500;
  line-height: 1.05;
  color: rgba(236, 239, 241, 0.92);
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rv2-overlay-hud-primary details.replay-fold {
  flex: 0 0 auto;
  margin: 0;
  border: none;
  background: transparent;
}

.rv2-overlay-hud-primary details.replay-fold > summary {
  padding: 0 1px;
  font-size: 7px;
  line-height: 1.05;
  color: rgba(144, 164, 174, 0.55);
  background: transparent;
  list-style: none;
  cursor: pointer;
}

.rv2-overlay-hud-primary details.replay-fold > summary::-webkit-details-marker {
  display: none;
}

.rv2-overlay-details-vault {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  padding: 0;
  margin: -1px;
}

.rv2-overlay-hud-hit {
  flex: 0 0 auto;
  opacity: 0.45;
  transition: opacity 0.12s ease;
}

.rv2-overlay:hover .rv2-overlay-hud-hit {
  opacity: 0.85;
}

.rv2-overlay-hud-hit .replay-bottom-bar {
  margin: 0;
  padding: 0;
  gap: 1px;
  border: none;
  background: transparent;
  box-shadow: none;
}

.rv2-overlay-hud-hit .replay-bottom-bar button {
  padding: 0 3px;
  font-size: 7px;
  line-height: 1.05;
  border: none;
  border-radius: 1px;
  background: transparent;
  color: rgba(207, 216, 220, 0.75);
  box-shadow: none;
}

.rv2-overlay-hud-hit .replay-bottom-bar button:hover {
  color: #eceff1;
  background: rgba(255, 255, 255, 0.08);
}

.rv2-overlay-hud-hit .replay-step-readout {
  display: none;
}

.rv2-overlay-hud-primary details.replay-fold[open] .replay-fold-body {
  position: fixed;
  top: calc(var(--rv2-shell-overlay-h) + 20px);
  left: 6px;
  right: calc(var(--rv2-shell-sidebar-w) + 28px);
  z-index: 50;
  max-height: min(30vh, 220px);
  overflow: auto;
  margin: 0;
  padding: 5px 7px;
  font-size: 8px;
  line-height: 1.15;
  background: rgba(14, 20, 24, 0.94);
  color: #b0bec5;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* ═══════════════════════════════════════════════════════════════
   main / 卓 cluster（absolute 中央 + 内側は1塊）
   ═══════════════════════════════════════════════════════════════ */
.rv2-main {
  position: absolute;
  top: var(--rv2-shell-overlay-h);
  left: 0;
  right: 0;
  bottom: var(--rv2-shell-bottom-h);
  overflow: hidden;
  margin: 0;
  padding: 0;
}

.rv2-table-zone {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  margin: 0 !important;
  padding: 0;
  z-index: 10;
  width: min(860px, calc(100% - var(--rv2-shell-sidebar-w) - 40px));
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  text-align: center;
  pointer-events: none;
}

.rv2-table-zone > * {
  pointer-events: auto;
}

.rv2-center-table {
  position: relative;
  width: 100%;
  margin: 0;
  padding: 0;
}

.rv2-stage-main.replay-stage-main {
  width: 100%;
  margin: 0 !important;
  padding: 0 !important;
}

.replay-v2-shell-root .replay-mat-scale-shell {
  --replay-mat-scale: var(--rv2-shell-table-scale) !important;
  transform: scale(var(--rv2-shell-table-scale)) !important;
  transform-origin: top center !important;
  width: calc(100% / var(--rv2-shell-table-scale)) !important;
  max-width: calc(860px / var(--rv2-shell-table-scale)) !important;
  margin: 0 auto !important;
  margin-bottom: 0 !important;
}

.replay-v2-shell-root .replay-mat {
  gap: 0 !important;
  grid-template-columns: minmax(44px, 0.78fr) minmax(96px, 172px) minmax(44px, 0.78fr) !important;
}

/* ═══════════════════════════════════════════════════════════════
   player — 名前 + リーチのみ
   ═══════════════════════════════════════════════════════════════ */
.replay-v2-shell-root .replay-pos--self {
  margin: 0 !important;
  padding: 0 !important;
  height: 0 !important;
  min-height: 0 !important;
  overflow: visible;
}

.replay-v2-shell-root .replay-pos--self .replay-player {
  display: none !important;
}

.replay-v2-shell-root .replay-pos--toimen {
  margin-bottom: -6px !important;
  padding-bottom: 0 !important;
}

.replay-v2-shell-root .replay-pos--center {
  max-width: 188px !important;
}

.replay-v2-shell-root .replay-pos--shimocha,
.replay-v2-shell-root .replay-pos--kamicha {
  min-width: 0 !important;
  max-width: 108px !important;
}

.replay-v2-shell-root .replay-player-stats,
.replay-v2-shell-root .replay-player-extra,
.replay-v2-shell-root .replay-player-rank,
.replay-v2-shell-root .replay-player-meta,
.replay-v2-shell-root .replay-player-furo,
.replay-v2-shell-root .replay-seat-status,
.replay-v2-shell-root .replay-meld-group {
  display: none !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}

.replay-v2-shell-root .replay-player {
  margin: 0 !important;
  padding: 0 1px !important;
  border: none !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  min-height: 0 !important;
}

.replay-v2-shell-root .replay-player-head {
  display: block !important;
  margin: 0 0 1px !important;
  padding: 0 !important;
  gap: 0 !important;
  min-height: 0 !important;
  text-align: center;
}

.replay-v2-shell-root .replay-player-title {
  display: inline-block;
  max-width: 100%;
  font-size: 6px !important;
  font-weight: 500 !important;
  line-height: 1.05 !important;
  color: rgba(236, 239, 241, 0.75) !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.replay-v2-shell-root .replay-player--riichi .replay-player-title {
  color: rgba(239, 154, 154, 0.95) !important;
}

.replay-v2-shell-root .replay-player--riichi .replay-player-title::after {
  content: " リーチ";
  font-size: 6px;
  font-weight: 600;
}

.replay-v2-shell-root .replay-seat-stack--toimen {
  gap: 0 !important;
  padding-bottom: 0 !important;
}

.replay-v2-shell-root .replay-seat-side-layout {
  gap: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

.replay-v2-shell-root .replay-seat-info-stack {
  gap: 0 !important;
  min-height: 0 !important;
}

.replay-v2-shell-root .replay-seat-area--shimocha,
.replay-v2-shell-root .replay-seat-area--kamicha {
  padding: 0 !important;
}

/* ═══════════════════════════════════════════════════════════════
   河吸着 — 卓フェルトの一部（独立 card 感を除去）
   ═══════════════════════════════════════════════════════════════ */
.replay-v2-shell-root .replay-river-wrap,
.replay-v2-shell-root .replay-river-wrap--shimocha,
.replay-v2-shell-root .replay-river-wrap--kamicha,
.replay-v2-shell-root .replay-river-wrap--toimen,
.replay-v2-shell-root .replay-river-wrap--self {
  margin: 0 !important;
  padding: 0 !important;
}

.replay-v2-shell-root .replay-river.discard-river {
  box-sizing: border-box;
  width: 100%;
  margin: 0 !important;
  padding: 1px 3px !important;
  border-radius: 2px !important;
  background-color: var(--rv2-shell-felt) !important;
  border: 1px solid var(--rv2-shell-felt-edge) !important;
  box-shadow: none !important;
}

.replay-v2-shell-root .replay-river-flow {
  gap: 1px 2px !important;
  min-height: 0 !important;
  width: max-content;
  max-width: 100%;
}

.replay-v2-shell-root .replay-seat-area--shimocha .replay-river-flow,
.replay-v2-shell-root .replay-seat-area--kamicha .replay-river-flow {
  column-gap: 6px !important;
  row-gap: 0 !important;
}

.replay-v2-shell-root .replay-seat-area--toimen .replay-river-tile-wrapper,
.replay-v2-shell-root .replay-seat-area--shimocha .replay-river-tile-wrapper,
.replay-v2-shell-root .replay-seat-area--kamicha .replay-river-tile-wrapper {
  margin-top: 0 !important;
  margin-block: 0 !important;
}

.replay-v2-shell-root .replay-river-tile-wrapper {
  margin: 0 !important;
}

.replay-v2-shell-root .replay-table-center {
  margin: 0 !important;
  padding: 1px 3px !important;
  background: var(--rv2-shell-felt) !important;
  border: 1px solid var(--rv2-shell-felt-edge) !important;
  border-radius: 2px !important;
  box-shadow: none !important;
}

.replay-v2-shell-root .replay-table-center-kmeta {
  margin: 0 0 1px !important;
  padding: 0 !important;
  font-size: 7px !important;
  line-height: 1.05 !important;
  color: rgba(207, 216, 220, 0.85) !important;
}

/* ═══════════════════════════════════════════════════════════════
   自分手牌 — 卓底辺
   ═══════════════════════════════════════════════════════════════ */
.rv2-self-hand {
  position: relative;
  width: 100%;
  margin: -1px 0 0 !important;
  padding: 0;
  line-height: 0;
  text-align: center;
}

.rv2-self-name {
  position: absolute;
  left: max(0px, calc(50% - min(400px, 42vw) / 2));
  top: -1px;
  z-index: 2;
  font-size: 6px;
  line-height: 1;
  color: rgba(176, 190, 197, 0.5);
  pointer-events: none;
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rv2-self-name:empty,
.rv2-self-name[hidden] {
  display: none;
}

.rv2-self-hand .replay-self-hand-dock,
.rv2-self-hand-inner.replay-self-hand-dock {
  display: inline-block;
  margin: 0 auto !important;
  padding: 0 !important;
  transform: none !important;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
}

.rv2-self-hand .replay-hand-row {
  min-height: 0 !important;
  padding: 0 !important;
  margin: 0 auto !important;
  gap: 1px !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.rv2-self-hand .replay-hand-row::before {
  display: none !important;
  content: none !important;
}

.rv2-self-hand .replay-hand-row .replay-tile-svg-img {
  width: var(--rv2-shell-tile);
  max-height: var(--rv2-shell-hand-max-h);
}

.rv2-self-hand .replay-self-hand-dock {
  --replay-hand-svg-width: var(--rv2-shell-tile);
  --replay-hand-svg-max-height: var(--rv2-shell-hand-max-h);
}

/* ═══════════════════════════════════════════════════════════════
   sidebar — HUD overlay
   ═══════════════════════════════════════════════════════════════ */
.rv2-sidebar {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: var(--rv2-shell-sidebar-w);
  z-index: 20;
  margin: 0;
  padding: 2px 1px;
  box-sizing: border-box;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  opacity: 0.34;
  transition: opacity 0.12s ease;
  pointer-events: auto;
}

.rv2-sidebar:hover,
.rv2-sidebar:focus-within {
  opacity: 0.9;
}

.rv2-sidebar .replay-step-dock {
  position: static !important;
  width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  transform: none !important;
}

.rv2-sidebar .replay-bottom-bar--dock {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 0;
  padding: 0;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  transform: none !important;
}

.rv2-sidebar .replay-bottom-bar--dock button {
  width: 100%;
  margin: 0;
  padding: 1px 2px;
  font-size: 7px;
  line-height: 1.05;
  border: none !important;
  border-radius: 1px;
  background: transparent !important;
  color: rgba(176, 190, 197, 0.65);
  box-shadow: none !important;
}

.rv2-sidebar:hover .replay-bottom-bar--dock button,
.rv2-sidebar:focus-within .replay-bottom-bar--dock button {
  color: rgba(236, 239, 241, 0.9);
  background: rgba(255, 255, 255, 0.06) !important;
}

.rv2-sidebar .replay-slider-wrap {
  font-size: 7px;
  gap: 0;
  margin: 0;
  padding: 0;
  color: rgba(144, 164, 174, 0.55);
}

.rv2-sidebar .replay-slider-wrap input[type="range"] {
  height: 10px;
  margin: 0;
}

.rv2-sidebar .replay-step-readout {
  font-size: 6px;
  line-height: 1.05;
  color: rgba(144, 164, 174, 0.5);
  text-align: center;
  margin: 0;
  padding: 0;
}

/* ═══════════════════════════════════════════════════════════════
   下部 graph / stats / ptEV placeholder
   ═══════════════════════════════════════════════════════════════ */
.rv2-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--rv2-shell-bottom-h);
  z-index: 15;
  margin: 0;
  padding: 0 8px 4px;
  box-sizing: border-box;
  background: linear-gradient(0deg, rgba(8, 12, 16, 0.72) 0%, rgba(8, 12, 16, 0.2) 55%, transparent 100%);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  pointer-events: none;
}

.rv2-bottom-strip {
  display: grid;
  grid-template-columns: 1fr minmax(100px, 140px) minmax(88px, 120px);
  gap: 8px;
  align-items: stretch;
  height: 100%;
  padding-top: 4px;
  box-sizing: border-box;
}

.rv2-ph-label {
  font-size: 6px;
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(144, 164, 174, 0.45);
  margin-bottom: 3px;
}

.rv2-ph-graph {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 2px 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.12);
}

.rv2-ph-graph-bars {
  flex: 1 1 auto;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  min-height: 36px;
  padding: 0 2px 2px;
}

.rv2-ph-bar {
  flex: 1 1 0;
  min-width: 3px;
  max-width: 10px;
  background: linear-gradient(180deg, rgba(79, 195, 247, 0.55) 0%, rgba(41, 121, 168, 0.35) 100%);
  border-radius: 1px 1px 0 0;
  opacity: 0.7;
}

.rv2-ph-stats,
.rv2-ph-ptev {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 2px 6px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.1);
  font-size: 7px;
  line-height: 1.2;
  color: rgba(176, 190, 197, 0.65);
}

.rv2-ph-stat-row,
.rv2-ph-ptev-line {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-top: 2px;
}

.rv2-ph-stat-row strong,
.rv2-ph-ptev-line em {
  font-style: normal;
  font-weight: 600;
  color: rgba(207, 216, 220, 0.8);
}

.rv2-ph-ptev-line em {
  color: rgba(129, 199, 132, 0.75);
}

.replay-v2-shell-root .replay-loading {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  z-index: 12;
  padding: 6px 10px;
  font-size: 9px;
  color: #eceff1;
  background: rgba(14, 20, 24, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 3px;
}

.replay-v2-shell-root .replay-mat-wrap--loading .replay-mat-scale-shell {
  display: none;
}

#replay_v2_mount > .replay-v2-root:not(.replay-v2-shell-root) {
  display: none !important;
}

#replay_panel.replay-ui-v2-active.replay-ui-v2-shell > .replay-panel-inner > #replay_stage,
#replay_panel.replay-ui-v2-active.replay-ui-v2-shell > .replay-panel-inner > #replay_source_meta,
#replay_panel.replay-ui-v2-active.replay-ui-v2-shell > .replay-panel-inner > #replay_game_datetime,
#replay_panel.replay-ui-v2-active.replay-ui-v2-shell > .replay-panel-inner > #replay_top_bar,
#replay_panel.replay-ui-v2-active.replay-ui-v2-shell > .replay-panel-inner > #replay_hit_nav {
  display: none !important;
}

@media (max-width: 1100px) {
  .replay-v2-shell-root {
    --rv2-shell-sidebar-w: 76px;
    --rv2-shell-bottom-h: 76px;
    --rv2-shell-table-scale: clamp(0.68, calc(0.78 - (100svh - 900px) * 0.00048), 0.78);
  }

  .rv2-bottom-strip {
    grid-template-columns: 1fr 100px 80px;
    gap: 4px;
  }
}
