/* ===================================================================
   脱衣フリーセル — 見た目一式

   盤面はキャラクターの絵の上に重ねる。カードは横長の白い札で、
   重ねずに縦に並べる(全部の札が常に読める)。
   =================================================================== */

:root {
  --bg:        #14161c;
  --bg-2:      #1c1f28;
  --panel:     #232734;
  --line:      #343a4b;
  --text:      #e8e9ee;
  --text-dim:  #9aa0b4;
  --accent:    #e0688a;
  --accent-2:  #6ab0e0;
  --card-face: #ffffff;
  --card-slot: #d4d4d4;
  --card-red:  #d81f26;
  --card-blk:  #14161c;

  --card-scale: 1;
  --cw:  calc(min(6.7vw, 12vh) * var(--card-scale));   /* カードの幅 */
  --chh: calc(var(--cw) * 0.45);                        /* 重なっている札の高さ */
  --chf: calc(var(--cw) * 0.92);                        /* 一番手前の札の高さ(ほぼ正方形) */
  --gap: calc(var(--cw) * 0.13);
  --pad: calc(var(--cw) * 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: #0c0d11;
  color: var(--text);
  font-family: "Noto Sans JP", "Yu Gothic UI", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
}
img { -webkit-user-drag: none; }

/* --------------------------------------------------------------- 背景の絵 */

.stage-bg { position: fixed; inset: 0; z-index: 0; background: #0c0d11; overflow: hidden; }

/* 背景。画面いっぱいに敷く */
.bg-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: center 25%;
  opacity: 0; transition: opacity .6s ease;
}
.bg-img.on { opacity: 1; }

/* 立ち絵。背景を別に持つキャラだけ使う。位置と大きさは JS が付ける */
.char-layer { position: absolute; inset: 0; }
.char-img {
  position: absolute; bottom: 0;
  height: 100%; width: auto; max-width: 100%;
  object-fit: contain; object-position: bottom;
  opacity: 0; transition: opacity .5s ease;
  filter: drop-shadow(0 0 24px rgba(0,0,0,.45));
}
.char-img.on { opacity: 1; }

.stage-bg.hidden-visual .bg-img,
.stage-bg.hidden-visual .char-img { opacity: 0; }

/* --------------------------------------------------------------- 画面 */

.screen { display: none; position: relative; z-index: 1; flex-direction: column; height: 100vh; }
.screen.active { display: flex; }

/* --------------------------------------------------------------- 部品 */

.btn {
  appearance: none; border: 1px solid var(--line);
  background: rgba(35,39,52,.92); color: var(--text);
  padding: .55em 1.1em; border-radius: 8px;
  font: inherit; font-size: .92rem; cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s;
}
.btn:hover { background: #2c3140; border-color: #4a5268; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn-primary:hover { filter: brightness(1.1); background: var(--accent); }
.btn-danger { background: #6b2230; border-color: #8b3040; }
.btn-back { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-back:hover { background: var(--panel); color: var(--text); }

/* 盤面の上に浮かぶ操作ボタン */
.plate {
  appearance: none; background: rgba(255,255,255,.96); color: #14161c;
  border: 1px solid rgba(0,0,0,.14); border-radius: 9px;
  font: inherit; font-size: calc(var(--chh) * 0.44); font-weight: 700;
  min-width: calc(var(--cw) * 0.9); height: calc(var(--chh) * 1.3);
  padding: 0 .85em; cursor: pointer; line-height: 1;
  box-shadow: 0 3px 10px rgba(0,0,0,.4);
  transition: transform .08s, background .15s, box-shadow .15s;
}
.plate:hover { background: #fff; box-shadow: 0 5px 14px rgba(0,0,0,.5); transform: translateY(-1px); }
.plate:active { transform: translateY(0); }
.plate-sm { min-width: 0; width: calc(var(--chh) * 1.3); padding: 0; font-size: calc(var(--chh) * 0.6); }
/* 絵を見るボタンは、いちばんよく使うのでアクセント色に */
.plate-peek { background: var(--accent); color: #fff; border-color: var(--accent); }
.plate-peek:hover { background: var(--accent); filter: brightness(1.08); }
.plate-retry { }

/* 右上のボタン群。まとまりとして浮かせる */
.controls {
  position: fixed; z-index: 30; top: var(--pad); right: var(--pad);
  display: flex; gap: 7px; align-items: center;
}

.bar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  background: rgba(20,22,28,.82); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line); flex: none;
}
.bar-title { margin: 0; font-size: 1.05rem; font-weight: 600; }
.bar-right { margin-left: auto; display: flex; gap: 8px; align-items: center;
             color: var(--text-dim); font-size: .88rem; }
.bar-count { margin-right: 6px; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- 盤面 */

.board {
  position: relative; flex: 1; min-height: 0;
  padding: var(--pad);
  display: flex; flex-direction: column;
}

/* 右上のボタン群と重ならないよう、行の右側にその分の余白を確保する */
.row-top {
  display: flex; align-items: flex-start; gap: var(--gap); flex: none;
  padding-right: calc(var(--cw) * 4);
}
.cells { display: flex; gap: var(--gap); }

.slot {
  width: var(--cw); height: var(--chh);
  background: var(--card-slot); border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  color: #8a8a8a; font-size: calc(var(--chh) * 0.42); font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  transition: background .15s, box-shadow .15s;
}
.slot.droppable { background: #eaeaea; box-shadow: 0 0 0 2px rgba(255,255,255,.6), 0 2px 8px rgba(0,0,0,.3); }
.slot.over      { background: #ffe9a8; box-shadow: 0 0 0 3px #ffcf4d, 0 2px 8px rgba(0,0,0,.3); }
.slot.hint-to   { animation: pulse 1.4s ease; }

@keyframes pulse {
  0%,100% { box-shadow: 0 2px 8px rgba(0,0,0,.3); }
  30%     { box-shadow: 0 0 0 6px rgba(255,207,77,.65), 0 2px 8px rgba(0,0,0,.3); }
}

.tableau {
  flex: 1; min-height: 0; margin-top: var(--gap);
  display: grid; grid-template-columns: repeat(8, var(--cw));
  gap: var(--gap); justify-content: start;
}
/* 列の枠は当たり判定だけ。見た目は下の .col-base が持つ。 */
.slot-col, .slot-col.droppable, .slot-col.over {
  height: 100%; background: none; box-shadow: none; align-items: flex-start;
}
.col-base {
  width: var(--cw); height: var(--chh); border-radius: 5px;
  background: rgba(255,255,255,.10);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.slot-col.droppable .col-base { background: rgba(255,255,255,.28); }
.slot-col.over .col-base { background: rgba(255,207,77,.55); }

/* 手札の状況(#番号 / 進行率 / 一度に動かせる枚数) */
.hud {
  margin-left: calc(var(--gap) * 1.6); align-self: center; flex: none;
  font-weight: 800; letter-spacing: .01em;
  text-shadow: 0 2px 6px rgba(0,0,0,.7), 0 0 2px rgba(0,0,0,.9);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.hud-line { font-size: calc(var(--chh) * 0.46); line-height: 1.35; }
.hud-sub { font-weight: 600; opacity: .92; }

/* --------------------------------------------------------------- カード */

.card-layer { position: absolute; inset: 0; pointer-events: none; }

.card {
  position: absolute; left: 0; top: 0;
  width: var(--cw); height: var(--chh);
  background: var(--card-face); border-radius: 5px;
  box-shadow: 0 2px 7px rgba(0,0,0,.4);
  pointer-events: auto; cursor: default;
  overflow: hidden;
  font-weight: 700; line-height: 1;
  transition: transform .16s cubic-bezier(.2,.8,.3,1), height .16s ease;
  will-change: transform;
}
.card.hidden { display: none; }

/* スート+ランクの帯。高さは常に --chh なので、重なっても位置がそろう */
.c-head {
  height: var(--chh); display: flex; align-items: center;
  /* % はカードではなく包含ブロック基準で解決されてしまうので --cw から計算する */
  padding-left: calc(var(--cw) * 0.10); gap: calc(var(--cw) * 0.17);
  font-size: calc(var(--chh) * 0.5);
}
.c-suit { font-size: 1.06em; }

/* 大きなスートの面。一番手前の札だけに出る */
.c-body { display: none; }

/* 列の一番手前 = 動かせる札。正方形に近い大きさで「カードらしく」描く */
.card.front { height: var(--chf); }
.card.front .c-body {
  display: flex; align-items: center; justify-content: center;
  height: calc(var(--chf) - var(--chh));
  font-size: calc((var(--chf) - var(--chh)) * 0.66);
  opacity: .22;
}
.card.movable { cursor: pointer; }
.card.dragging { transition: none; box-shadow: 0 12px 26px rgba(0,0,0,.6); }
/* 選択中の札は、白い内枠＋アクセントの太い外枠＋淡いハイライトでしっかり目立たせる。
   重なって頭だけ見えている札でも分かるように、カード全体を少し明るくする。 */
.card.selected {
  outline: 3px solid #fff;
  outline-offset: -3px;
  box-shadow:
    inset 0 0 0 999px rgba(255,255,255,.16),
    0 0 0 5px var(--accent-2),
    0 0 16px 3px var(--accent-2),
    0 3px 10px rgba(0,0,0,.55);
}
.card.hint-from { box-shadow: 0 0 0 3px #ffcf4d, 0 2px 7px rgba(0,0,0,.4); }
.card.red   { color: var(--card-red); }
.card.black { color: var(--card-blk); }

/* --chf を JS から測るためだけの目印(見えない) */
.chf-probe { position: absolute; left: 0; top: 0; width: 0; height: var(--chf);
             visibility: hidden; pointer-events: none; }

/* --------------------------------------------------------------- メニュー */

.menu {
  position: fixed; z-index: 40; top: calc(var(--pad) + var(--chh) * 1.6); right: var(--pad);
  background: rgba(20,22,28,.96); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px; display: flex; flex-direction: column; gap: 6px; min-width: 200px;
  box-shadow: 0 16px 40px rgba(0,0,0,.55);
}
.menu[hidden] { display: none; }
.menu .btn { text-align: left; }

/* --------------------------------------------------------------- キャラ選択 */

#screen-select { background: rgba(12,13,17,.72); backdrop-filter: blur(2px); }
.game-title { margin: 0; font-size: 1.25rem; font-weight: 800; letter-spacing: .04em; }
.game-sub { color: var(--text-dim); font-size: .84rem; }

.select-body { flex: 1; display: flex; min-height: 0; }

.char-grid {
  list-style: none; margin: 0; padding: 18px;
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  align-content: start; flex: 1; overflow-y: auto;
}
.char-card {
  position: relative; border-radius: 12px; overflow: hidden;
  background: var(--panel); border: 2px solid transparent;
  cursor: pointer; transition: transform .15s, border-color .15s;
  aspect-ratio: 4 / 3;   /* CG が横長なのでタイルも横長にする */
}
.char-card:hover { transform: translateY(-3px); }
.char-card.active { border-color: var(--accent); }
.char-card.locked { cursor: default; filter: grayscale(1) brightness(.4); }
.char-card.locked:hover { transform: none; }
.char-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.char-card.locked .char-thumb { filter: blur(10px); }
.char-cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,.88) 45%);
  display: flex; flex-direction: column; gap: 2px;
}
.char-cap b { font-size: .98rem; }
.char-cap span { font-size: .78rem; color: #c3c8d8; font-variant-numeric: tabular-nums; }
.char-badge {
  position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.72);
  border: 1px solid var(--line); padding: 2px 8px; border-radius: 999px; font-size: .72rem;
}
.char-badge.complete { background: var(--accent); border-color: var(--accent); color: #fff; }

.char-detail {
  width: min(36%, 440px); flex: none;
  border-left: 1px solid var(--line); background: rgba(28,31,40,.9);
  display: flex; flex-direction: column; min-height: 0;
}
.detail-visual { flex: 1; min-height: 0; background: rgba(0,0,0,.35); }
/* 背景を別に持つキャラは、一覧でも背景の上に立ち絵を重ねる */
.detail-visual.composed { background-size: cover; background-position: center 25%; }
.detail-visual.composed img { object-fit: contain; object-position: bottom right; }
.detail-visual img { width: 100%; height: 100%; object-fit: contain; display: block; }
.detail-text { padding: 16px 20px 20px; }
.detail-text h3 { margin: 0 0 .4em; font-size: 1.3rem; }
.detail-text h3 small { display: block; font-size: .72rem; color: var(--text-dim);
                        font-weight: 400; letter-spacing: .1em; }
.detail-profile { margin: 0 0 1em; color: var(--text-dim); font-size: .88rem; line-height: 1.7;
                  white-space: pre-wrap; }
.detail-stats { margin: 0 0 1.2em; display: grid; grid-template-columns: auto 1fr;
                gap: 4px 14px; font-size: .85rem; }
.detail-stats dt { color: var(--text-dim); }
.detail-stats dd { margin: 0; font-variant-numeric: tabular-nums; }
.detail-actions { display: flex; gap: 10px; }
.detail-actions .btn { flex: 1; }

.title-foot {
  margin: 0; padding: 14px 24px; flex: none;
  display: flex; align-items: center; gap: 20px;
  color: #6a7086; font-size: .8rem;
}
/* クリエイターのロゴ。透過 PNG なので暗い背景にそのまま載る */
.brand {
  height: clamp(48px, 7vh, 72px); width: auto; display: block;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,.5));
}
.brand[src=""], .brand:not([src]) { display: none; }

/* --------------------------------------------------------------- 絵を見る */

/* 盤面をどけて絵だけにする。「絵を見る」ボタンだけ残す */
.peeking .board,
.peeking #btn-undo,
.peeking #btn-retry,
.peeking #btn-menu { opacity: 0; pointer-events: none; }
.board { transition: opacity .25s ease; }
.plate { transition: opacity .25s ease, background .15s, transform .08s, box-shadow .15s; }

.peek-cap {
  position: fixed; left: var(--pad); bottom: var(--pad); z-index: 30;
  padding: .5em 1em; border-radius: 999px;
  background: rgba(12,13,17,.72); color: var(--text);
  font-size: .86rem; opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
}
.peeking .peek-cap { opacity: 1; }

/* --------------------------------------------------------------- ギャラリー */

#screen-gallery { background: rgba(12,13,17,.9); }
.gallery-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.gallery-tabs { display: flex; gap: 8px; padding: 12px 16px; overflow-x: auto; flex: none;
                border-bottom: 1px solid var(--line); }
.gtab {
  appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: .45em .9em; border-radius: 999px; font: inherit; font-size: .86rem;
  cursor: pointer; white-space: nowrap;
}
.gtab i { font-style: normal; margin-left: .5em; color: var(--text-dim); font-size: .78rem;
          font-variant-numeric: tabular-nums; }
.gtab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.gtab.active i { color: rgba(255,255,255,.8); }

.gallery-grid {
  list-style: none; margin: 0; padding: 18px; flex: 1; overflow-y: auto;
  display: grid; gap: 14px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.gcell { position: relative; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden;
         background: var(--panel); cursor: pointer; transition: transform .15s; }
.gcell:hover { transform: translateY(-3px); }
.gcell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gcell.composed { background-size: cover; background-position: center 25%; }
.gcell.composed img { object-fit: contain; object-position: bottom right; }
.gcell.locked { cursor: default; background: #1a1d26; }
.gcell.locked:hover { transform: none; }
.gcell-lock { position: absolute; inset: 0; display: flex; align-items: center;
              justify-content: center; font-size: 2.4rem; color: #3a4055; }
.gcell-cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 10px;
             font-size: .78rem; background: linear-gradient(transparent, rgba(0,0,0,.85) 55%); }

/* --------------------------------------------------------------- ビューア */

.viewer { position: fixed; inset: 0; z-index: 900; background: rgba(6,7,10,.95);
          display: flex; align-items: center; justify-content: center; }
.viewer[hidden] { display: none; }
.viewer img { max-width: 94vw; max-height: 88vh; object-fit: contain; z-index: 1; }
.viewer.composed { background-size: cover; background-position: center; }
.viewer.composed::before { content: ''; position: absolute; inset: 0;
                           background: rgba(6,7,10,.55); }
.viewer-close { position: absolute; top: 14px; right: 18px; z-index: 2; background: none;
                border: none; color: #cfd3e0; font-size: 2rem; cursor: pointer; line-height: 1; }
.viewer-nav { position: absolute; top: 50%; transform: translateY(-50%);
              background: rgba(0,0,0,.4); border: 1px solid var(--line); color: var(--text);
              width: 46px; height: 76px; border-radius: 8px; font-size: 2rem; cursor: pointer; }
.viewer-prev { left: 16px; } .viewer-next { right: 16px; }
.viewer-caption { position: absolute; bottom: 18px; left: 0; right: 0; text-align: center;
                  color: var(--text-dim); font-size: .88rem; }

/* --------------------------------------------------------------- 重ね窓 */

.overlay { position: fixed; inset: 0; z-index: 800; background: rgba(6,7,10,.72);
           backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; }
.overlay[hidden] { display: none; }

.clear-card, .config-card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px 32px; min-width: 340px; max-width: 90vw; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.clear-card h2 {
  margin: 0 0 .3em; font-size: 2.4rem; letter-spacing: .12em;
  background: linear-gradient(180deg, #fff, var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.clear-card p { margin: .2em 0; color: var(--text-dim); font-size: .9rem; }
.clear-unlock { color: var(--accent) !important; font-weight: 600; min-height: 1.2em; }
.clear-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 1.6em; }

.config-card { text-align: left; }
.config-card h2 { margin: 0 0 1em; font-size: 1.3rem; }
.cfg-row { display: grid; grid-template-columns: 1fr auto auto; gap: 12px;
           align-items: center; padding: .55em 0; font-size: .92rem; }
.cfg-row output { color: var(--text-dim); font-size: .84rem; min-width: 3.4em; text-align: right; }
.config-card hr { border: none; border-top: 1px solid var(--line); margin: 1.2em 0; }
.cfg-deal > span { display: block; font-size: .92rem; margin-bottom: .5em; }
.cfg-deal-row { display: flex; gap: 8px; align-items: center; }
.cfg-deal-row input {
  flex: 1; min-width: 0; background: #14161c; color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; padding: .5em .7em;
  font: inherit; font-variant-numeric: tabular-nums;
}
.cfg-deal-row .btn { flex: none; white-space: nowrap; }
.cfg-note { display: block; margin-top: .5em; color: var(--text-dim); font-size: .76rem; }
.cfg-danger { text-align: center; }
.cfg-actions { margin-top: 1.4em; text-align: right; }

/* --------------------------------------------------------------- トースト */

.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%) translateY(10px);
  background: rgba(20,22,28,.96); border: 1px solid var(--line); color: var(--text);
  padding: .7em 1.4em; border-radius: 999px; font-size: .88rem; z-index: 950;
  opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none;
  max-width: 80vw; text-align: center;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --------------------------------------------------------------- 狭い画面 */

@media (max-width: 900px) {
  :root { --cw: calc(min(11vw, 11vh) * var(--card-scale)); }
  .tableau { grid-template-columns: repeat(8, var(--cw)); }
  .hud { margin-left: 8px; }
  .select-body { flex-direction: column; }
  .char-detail { width: auto; border-left: none; border-top: 1px solid var(--line);
                 max-height: 48vh; overflow-y: auto; }
}
