/* 月蝕こいこい — 仮の見た目。盤面・札の裏・ボタンは後で生成画像に差し替える(制作規約§5) */
:root {
  color-scheme: dark;
  --yoi: #131320; --yoi-hi: #1B1B2E;
  --kin: #D9A94C; --kin-hi: #F0CE7E; --shoku: #C93A2E;
  --geppaku: #E8E4D8; --sub: #9D93B5; --anshi: #5C4470;
  --line: rgba(232, 228, 216, .16);
  --serif: "Shippori Mincho B1", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --num: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", sans-serif;
  --cw: clamp(36px, min(10.4vw, 8.6vh), 96px);   /* 札の幅 */
  --sw: calc(var(--cw) * .58);                     /* 取り札の幅 */
  --ease: cubic-bezier(.215, .61, .355, 1);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(ellipse 120% 70% at 50% 45%, #1d1a33 0%, var(--yoi) 70%) fixed, var(--yoi);
  color: var(--geppaku); font-family: var(--serif); font-weight: 500;
  -webkit-tap-highlight-color: transparent; overflow: hidden;
}
#app {
  height: 100%; max-width: 1180px; margin: 0 auto;
  display: grid; grid-template-rows: auto auto 1fr auto auto;
  padding: env(safe-area-inset-top, 0px) 12px env(safe-area-inset-bottom, 0px);
}

/* ---- 上の帯 ---- */
.bar { display: flex; align-items: center; gap: 12px; padding: 8px 0 6px; border-bottom: 1px solid var(--line); }
.bar-round { font-weight: 800; letter-spacing: .12em; color: var(--kin-hi); font-size: 15px; white-space: nowrap; }
.bar-round small { color: var(--sub); font-weight: 500; font-size: 12px; letter-spacing: .05em; }
.bar-scores { display: flex; gap: 14px; margin-left: auto; }
.sc { display: flex; align-items: baseline; gap: 4px; font-size: 12px; color: var(--sub); }
.sc b { font-family: var(--num); font-size: 18px; color: var(--geppaku); font-variant-numeric: tabular-nums; }
.sc-p b { color: var(--kin-hi); }
.oya { font-size: 11px; color: var(--yoi); background: var(--kin); border-radius: 3px; padding: 0 4px; font-weight: 700; }
.bar-btn { font: 700 12px var(--serif); letter-spacing: .12em; color: var(--geppaku); background: none;
  border: 1px solid var(--line); border-radius: 5px; padding: 6px 10px; cursor: pointer; min-height: 32px; }

/* ---- 札 ---- */
.card {
  position: relative; width: var(--cw); aspect-ratio: 2 / 3; flex: none;
  padding: 0; border: 0; border-radius: calc(var(--cw) * .07); overflow: hidden;
  background: #0d0c18; cursor: default; font: inherit; color: inherit;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .55), 0 0 0 1px rgba(0, 0, 0, .6);
  transition: transform 200ms var(--ease), box-shadow 200ms var(--ease), filter 200ms var(--ease);
}
.card img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; user-select: none; }
.card.small { width: var(--sw); }
.card.back {
  background:
    radial-gradient(circle at 50% 42%, rgba(217, 169, 76, .22) 0 18%, transparent 19%),
    linear-gradient(160deg, #221c38, #120f20);
  box-shadow: 0 3px 8px rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(217, 169, 76, .35);
}
.tag {
  position: absolute; left: 50%; bottom: 3px; transform: translateX(-50%);
  display: flex; align-items: baseline; gap: 2px;
  font-size: 11px; line-height: 1; white-space: nowrap; padding: 3px 4px 2px; border-radius: 3px;
  background: rgba(10, 9, 20, .82); color: var(--geppaku); font-weight: 700; letter-spacing: 0;
}
.tag em, .tag i { font-style: normal; }
.tg-hikari { background: rgba(60, 44, 10, .92); box-shadow: inset 0 0 0 1px rgba(240, 206, 126, .6); }
.tg-hikari em, .tg-hikari i { color: var(--kin-hi); }
.tg-rain { background: rgba(26, 38, 66, .95); box-shadow: inset 0 0 0 1px rgba(160, 190, 240, .8); }
.tg-rain em, .tg-rain i { color: #CFE0FF; }
.tg-tane { background: rgba(50, 36, 70, .92); }
.tg-tane i { color: #E3D2FA; }
.tg-tan-aka { background: rgba(110, 24, 18, .92); }
.tg-tan-aka i { color: #FFD9D2; }
.tg-tan-ao { background: rgba(22, 40, 96, .92); }
.tg-tan-ao i { color: #D6E2FF; }
.tg-tan-plain { background: rgba(48, 44, 60, .92); }
/* 取り札(小)は印だけ出す。カスは出さない */
.small .tag { bottom: 2px; padding: 2px 2px 1px; }
.small .tag em { display: none; }
.small .tag:not(:has(i)) { display: none; }

/* ---- 相手 ---- */
.side { display: grid; gap: 6px; padding: 8px 0; }
.hand { display: flex; justify-content: center; gap: 4px; min-height: calc(var(--cw) * 1.5); }
.hand-c { min-height: calc(var(--sw) * 1.5); gap: 3px; }
.pile { display: flex; flex-wrap: wrap; gap: 6px 14px; min-height: calc(var(--sw) * 1.5); align-items: flex-end; }
.pgroup { display: flex; align-items: flex-end; gap: 6px; }
.pcount { display: grid; justify-items: center; font-size: 11px; color: var(--sub); line-height: 1.2; }
.pcount b { font-family: var(--num); color: var(--geppaku); font-size: 13px; }
.pcards { display: flex; }
.pcards .card + .card { margin-left: calc(var(--sw) * -.55); }
.yakuline { display: flex; flex-wrap: wrap; gap: 6px; min-height: 20px; font-size: 12px; }
.yk { color: var(--kin-hi); border: 1px solid rgba(217, 169, 76, .45); border-radius: 4px; padding: 1px 6px; }
.yk b { font-family: var(--num); margin-left: 4px; }
.koi { color: #FFD9D2; border: 1px solid rgba(201, 58, 46, .7); border-radius: 4px; padding: 1px 6px; }

/* ---- 場 ---- */
.table { display: flex; align-items: center; gap: clamp(10px, 3vw, 28px); padding: 6px 0; min-height: 0; }
.deckzone { display: grid; gap: 10px; justify-items: center; flex: none; }
.deck { position: relative; width: var(--cw); aspect-ratio: 2 / 3; }
.deck .card { position: absolute; inset: 0; width: 100%; }
.deck .card::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: 3px 3px 0 -1px #0d0b18, 5px 5px 0 -2px rgba(217, 169, 76, .25); }
.dcount { position: absolute; right: -6px; bottom: -8px; font: 800 12px var(--num); color: var(--geppaku);
  background: var(--yoi-hi); border-radius: 9px; padding: 1px 6px; box-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
.float { width: var(--cw); aspect-ratio: 2 / 3; }
.field { flex: 1; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 8px; min-width: 0; }
.pair { display: flex; }
.pair .onpair { margin-left: calc(var(--cw) * -.62); transform: translateY(-8%) rotate(4deg); }
.card.lit { box-shadow: 0 0 0 2px var(--kin-hi), 0 0 16px rgba(240, 206, 126, .55); }
.card.choice, .card.hint { cursor: pointer; box-shadow: 0 0 0 2px var(--kin-hi), 0 0 14px rgba(240, 206, 126, .45); transform: translateY(-3px); }
.card.floating { box-shadow: 0 0 0 2px var(--kin-hi), 0 8px 18px rgba(0, 0, 0, .6); }

.status { text-align: center; font-size: 13px; color: var(--sub); min-height: 20px; letter-spacing: .06em; }

/* ---- 自分の手札 ---- */
.hand-p { padding-bottom: 6px; }
.card.playable { cursor: pointer; }
.card.playable:hover { transform: translateY(-6px); }
.card.cantake::before { content: ""; position: absolute; top: 4px; right: 4px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--kin-hi); box-shadow: 0 0 6px var(--kin-hi); z-index: 1; }
.card.selected { transform: translateY(-14%); box-shadow: 0 0 0 2px var(--kin-hi), 0 10px 20px rgba(0, 0, 0, .6); }
body:not(.myturn) .hand-p .card { filter: saturate(.75) brightness(.85); }
/* 取れる札があるときの、取れない手札 */
.card.nocap { filter: grayscale(1) brightness(.45); }
.card.nocap:hover { filter: grayscale(.6) brightness(.7); }
.card.nocap.selected { filter: none; }
.card:focus-visible { outline: 2px solid var(--kin-hi); outline-offset: 2px; }

/* ---- 知らせ ---- */
.toast {
  position: fixed; left: 50%; top: 44%; transform: translate(-50%, -50%);
  padding: 12px 22px; border-radius: 10px; background: rgba(24, 22, 38, .95);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .6); font-weight: 800; letter-spacing: .2em; font-size: 17px;
  color: var(--kin-hi); z-index: 20; pointer-events: none; white-space: nowrap;
}
.toast.show { animation: toast-in 280ms var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, calc(-50% + 8px)) scale(.96); } }

/* ---- 対話(羽二重パネル) ---- */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(8, 7, 16, .55); z-index: 30; }
.overlay.sheet { z-index: 40; }
.panel {
  width: min(440px, 100%); max-height: calc(100% - 32px); overflow-y: auto; position: relative;
  padding: 24px 22px 20px; border-radius: 18px;
  background: radial-gradient(ellipse 220% 220% at 50% -30%, rgba(36, 32, 62, .96), rgba(24, 20, 50, .96) 42%, rgba(17, 15, 30, .96));
  box-shadow: 0 18px 44px rgba(0, 0, 0, .7), 0 4px 14px rgba(0, 0, 0, .5);
}
.panel::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent 14%, rgba(232, 228, 216, .14) 50%, transparent 86%); }
.panel.glow { box-shadow: 0 0 34px 2px rgba(240, 206, 126, .25), 0 18px 44px rgba(0, 0, 0, .7); }
.panel.enter { animation: panel-in 280ms var(--ease); }
@keyframes panel-in { from { opacity: 0; transform: translateY(8px) scale(.96); } }
.dlg-eyebrow { margin: 0 0 6px; font-size: 12px; letter-spacing: .2em; color: var(--sub); }
.dlg-title, .title-logo {
  margin: 0 0 12px; font-weight: 800; letter-spacing: .2em; line-height: 1.3; text-wrap: balance;
  background: linear-gradient(180deg, #FFF9E6, #F2D88E 40%, #CFA040 75%, #96692A);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: var(--kin-hi);
}
.dlg-title { font-size: 24px; }
.title-logo { font-size: clamp(32px, 9vw, 44px); letter-spacing: .24em; }
.title-lede { margin: 0; line-height: 1.9; font-size: 14px; }
.title-foot { margin: 18px 0 0; font-size: 11px; color: var(--sub); line-height: 1.7; }
.yakulist, .histlist, .monthlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.yakulist li, .histlist li { display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 7px 2px; border-bottom: 1px solid var(--line); font-size: 15px; }
.yakulist li b, .histlist li b { font-family: var(--num); color: var(--kin-hi); font-variant-numeric: tabular-nums; }
.yakulist li b small { font-family: var(--serif); font-size: 11px; color: var(--sub); margin-left: 2px; }
.yakulist li span small { display: block; font-size: 11px; color: var(--sub); line-height: 1.5; margin-top: 2px; }
.yakulist.compact li { font-size: 14px; padding: 5px 2px; }
.yakulist li.note span { font-size: 12px; color: #FFD9D2; }
.yakulist li.muted span { color: var(--sub); font-size: 13px; }
.histlist li em { font-style: normal; color: var(--sub); flex: 1; }
.monthlist { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 4px 10px; }
.monthlist li { display: flex; gap: 6px; align-items: baseline; font-size: 13px; }
.monthlist em { font-style: normal; color: var(--sub); font-size: 11px; min-width: 3em; }
.monthlist small { color: var(--kin-hi); font-size: 11px; }
.dlg-score { margin: 14px 0 0; font-size: 14px; }
.dlg-score b { font-family: var(--num); font-size: 26px; color: var(--kin-hi); margin: 0 4px; }
.dlg-score small { display: block; font-size: 11px; color: var(--sub); }
.dlg-total { margin: 8px 0 0; font-size: 13px; color: var(--sub); }
.dlg-total.big { font-size: 16px; color: var(--geppaku); margin-bottom: 12px; }
.dlg-note { font-size: 12px; color: var(--sub); margin: 8px 0 0; }
.dlg-btns { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

/* 公式UIキットの主/副ボタン(仮。後で画像ボタンに差し替え) */
.kbtn { flex: 1 1 120px; min-height: 48px; padding: 1px; border: 0; border-radius: 5px; cursor: pointer;
  background: linear-gradient(180deg, #E2C176, #95713A, #6A4E22); box-shadow: 0 4px 10px rgba(0, 0, 0, .55);
  transition: transform 90ms ease-out; font-family: var(--serif); }
.kbtn:active { transform: scale(.965); }
.kbtn > span { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; min-height: 46px;
  border-radius: 4px; padding: 4px 12px; background: linear-gradient(180deg, #232033, #161320);
  color: var(--kin-hi); font-size: 15px; font-weight: 800; letter-spacing: .24em; line-height: 1.2;
  text-shadow: 0 0 8px rgba(240, 214, 150, .35), 0 1px 2px rgba(0, 0, 0, .87); }
.kbtn small { font-size: 11px; font-weight: 700; letter-spacing: .06em; color: var(--sub); margin-top: 3px; text-shadow: none; }
.kbtn.quiet { background: linear-gradient(180deg, #565064, #2C2838); }
.kbtn.quiet > span { color: var(--geppaku); text-shadow: 0 1px 0 rgba(0, 0, 0, .87); }
.kbtn:focus-visible { outline: 2px solid var(--kin-hi); outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  .card, .kbtn { transition: none; }
  .panel.enter, .toast.show { animation: none; }
}
/* 手札8枚が1列に収まらないときは少し重ねる */
.hand-p .card + .card { margin-left: min(0px, calc((100vw - 24px - 8 * var(--cw) - 7 * 4px) / 7)); }
@media (max-width: 520px) {
  #app { padding-inline: 8px; --cw: clamp(36px, min(15vw, 8.6vh), 96px); }
  .table { flex-direction: column; align-items: stretch; }
  .deckzone { grid-auto-flow: column; justify-content: start; align-items: center; }
  .field { gap: 5px; }
  .hand { gap: 3px; }
  .bar-round small { display: none; }
}
