:root {
  --gold: #e6c77a;
  --ink: #f4ead2;
  --panel: rgba(10, 12, 18, 0.82);
  --serif: 'Noto Serif JP', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  /* 画面の幅・高さの 1%。縦長のスマホで画面ごと回すとき（T063、末尾の @media）は入れ替わる。vw・vh は直に使わずこれを使う */
  --vw: 1vw;
  --vh: 1vh;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #05070c; color: var(--ink);
  font-family: system-ui, -apple-system, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
[hidden] { display: none !important; }
/* 表示領域いっぱい。高さは dvh（iOS でツールバーの出入りに合わせて変わる高さ）。描画の解像度は TableScene が
   この大きさを ResizeObserver で見て合わせる（100vh はツールバーを隠したときの高さなので手牌が切れる。
   innerHeight を resize イベントで読む方式は、iOS の Chrome で古い高さのまま残り画面の下に余白が出た） */
#stage { position: fixed; top: 0; left: 0; display: block; width: 100%; height: 100%; height: 100dvh; }

.btn {
  font: 700 18px var(--serif); color: var(--ink); background: linear-gradient(#2c3240, #161a22);
  border: 1px solid #5d5440; border-radius: 10px; padding: 10px 26px; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: linear-gradient(#b8862e, #7a5416); border-color: #f0d38a; font-size: 22px; padding: 12px 40px; }

.info {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 12px; padding: 6px 12px; border-radius: 8px;
  background: var(--panel); border: 1px solid #3c3628; font: 700 13px var(--serif);
}
.info-text { display: flex; flex-direction: column; gap: 2px; line-height: 1.3; }
.info-text b { font-size: 17px; color: #fff; }
.info-text .gap { color: #ffcf6a; }
.dora { display: flex; align-items: center; gap: 6px; }
.dora .tile { height: 44px; }

/* 位置はツモ牌の真上（--act-right / --act-bottom は HandView が手牌の配置から計算する） */
.actions {
  position: fixed; right: var(--act-right, 16px); bottom: var(--act-bottom, calc(27 * var(--vh)));
  display: flex; gap: 12px;
}

.btn.choice { display: flex; align-items: center; gap: 8px; padding: 8px 14px; }
.btn .mini { display: flex; gap: 1px; }
.btn .mini .tile { height: 34px; }

.callout {
  position: fixed; pointer-events: none; z-index: 5; font: 900 44px var(--serif); color: #fff;
  text-shadow: 0 0 18px rgba(255, 170, 60, 0.95), 0 0 3px #000; animation: callout 1.2s ease-out forwards;
}
.callout.seat0 { left: 50%; bottom: calc(30 * var(--vh)); translate: -50% 0; }
.callout.seat1 { right: calc(9 * var(--vw)); top: calc(42 * var(--vh)); }
.callout.seat2 { left: 50%; top: calc(12 * var(--vh)); translate: -50% 0; }
.callout.seat3 { left: calc(9 * var(--vw)); top: calc(42 * var(--vh)); }
@keyframes callout {
  0% { opacity: 0; scale: 1.5; }
  15% { opacity: 1; scale: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

.tile { height: 64px; border-radius: 5px; box-shadow: 0 2px 0 #0d6150, 0 3px 6px rgba(0, 0, 0, 0.5); background: #f6f1e4; }

.announce {
  position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none;
  font: 900 min(18 * var(--vw), 160px) var(--serif); color: #fff; opacity: 0;
  text-shadow: 0 0 30px rgba(255, 120, 40, 0.9), 0 0 4px #000;
}
.announce.show { animation: announce 1.4s ease-out forwards; }
@keyframes announce {
  0% { opacity: 0; transform: scale(1.6); }
  20% { opacity: 1; transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: scale(0.96); }
}

.overlay { position: fixed; inset: 0; display: grid; place-items: center; }

/* 役満和了の演出: 周辺減光と役満名（不透明度・倍率・--shine は js/fx.js が時間に合わせて書く） */
.fx-vignette {
  position: fixed; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse 70% 60% at 50% 58%, transparent 25%, rgba(0, 0, 0, 0.88) 85%);
}
.fx-name {
  position: fixed; left: 0; right: 0; top: calc(13 * var(--vh)); pointer-events: none; opacity: 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px; --shine: 0;
}
.fx-name span {
  font: 900 min(12 * var(--vw), 23 * var(--vh), 128px) / 1.1 var(--serif); letter-spacing: 0.06em;
  background:
    linear-gradient(105deg, transparent calc(var(--shine) * 160% - 45%), rgba(255, 255, 255, 0.95) calc(var(--shine) * 160% - 30%), transparent calc(var(--shine) * 160% - 15%)),
    linear-gradient(#fff6d8, #e0b45a 55%, #9c6a1c);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 22px rgba(255, 180, 60, 0.75)) drop-shadow(0 3px 2px rgba(0, 0, 0, 0.7));
}
.fx-name.multi span { font-size: min(8 * var(--vw), 14 * var(--vh), 92px); }
/* 自動和了の稲妻（js/fx.js の strike が描く 2D canvas）。#stage と同じ位置・大きさにする */
.fx-bolt { position: fixed; top: 0; left: 0; width: 100%; height: 100%; height: 100dvh; pointer-events: none; }

.title { background: radial-gradient(ellipse at center, rgba(8, 16, 34, 0.45), rgba(3, 4, 8, 0.86)); text-align: center; } /* 後ろにオープニングの卓が見える濃さ */
/* 1 行目が 1 画面目（題字・難度・リンク）、2 行目が「このゲームについて」（T078）。タイトル画面だけ縦にスクロールして読む。
   body の touch-action: none の下でも指でスクロールできるよう、ここで指の移動を許す。touch-action の向きは実際の画面の向きで決まり、
   縦長のスマホで画面ごと回したとき（T063）は回した中の上下が実際の画面の左右になるので、pan-x も許す */
.title { overflow-y: auto; overscroll-behavior: contain; grid-template-rows: 100% auto; touch-action: pan-x pan-y; }
.title .about {
  max-width: 40em; margin: 0 16px 32px; padding: 14px 22px 16px; border-radius: 10px; background: rgba(3, 4, 8, 0.85);
  text-align: left; font-size: 15px; line-height: 1.8; color: #d8ccb0;
}
.title .about h2 { margin: 0 0 6px; text-align: center; font: 700 17px var(--serif); color: var(--gold); letter-spacing: 0.15em; }
.title .about p { margin: 0; }
/* 下に続きがある目印（T079）。1 画面目の下端（クレジットの上）。押すと説明文へ送る。押せる範囲は上下の余白で 44px 以上 */
.title .about-cue { position: absolute; left: 0; right: 0; bottom: 30px; margin: 0; pointer-events: none; }
.title .about-cue a { display: inline-block; padding: 13px 10px; font: 700 14px var(--serif); color: var(--gold); text-decoration: none; pointer-events: auto; }
.title .about-cue .short { display: none; }
.title h1 {
  margin: 6px 0 14px; font: 900 min(16 * var(--vw), 120px) / 1 var(--serif); letter-spacing: 0.08em;
  background: linear-gradient(#fff6d8, #e0b45a 55%, #9c6a1c); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 18px rgba(230, 170, 60, 0.45));
}
.title .kicker { margin: 0; font: 700 18px var(--serif); color: var(--gold); letter-spacing: 0.3em; }
.title .lead { margin: 0 0 28px; line-height: 1.8; color: #d8ccb0; }
.levels { display: flex; gap: 14px; justify-content: center; }
.btn.level { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 150px; padding: 10px 18px; }
.btn.level b { font-size: 22px; }
.btn.level > span { font: 500 12px system-ui, sans-serif; color: #d8ccb0; } /* 直下だけ（記録の中の件数の span には当てない。T065） */
.btn.level.last { background: linear-gradient(#b8862e, #7a5416); border-color: #f0d38a; } /* 前回選んだ難度 */
.btn.level.last span { color: #fff3d6; }
.btn.level .rank { margin-top: 4px; font: 700 13px var(--serif); color: #fff; }
.btn.level .rec { margin-top: 2px; font-size: 11px; color: var(--gold); }
.btn.level.last .rec { color: #fff3d6; }
.info-text .lv { color: var(--gold); }
.result .level-tag { margin: 0 0 4px; font: 700 13px var(--serif); color: var(--gold); letter-spacing: 0.2em; }
.result .rank { margin-left: 1.2em; color: #fff; letter-spacing: 0.05em; }
.result .rank em { font-style: normal; }
.result .rank .up { color: #7fe08a; }
.result .rank .down { color: #ff8a7a; }
.result .stats { margin-left: 1.2em; letter-spacing: 0.05em; color: #d8ccb0; }
.result .stats b { margin-right: 1em; color: #ffcf6a; }
.result .buttons { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: center; justify-content: center; }
.title .credit { position: absolute; bottom: 10px; width: 100%; margin: 0; font-size: 12px; color: #8f8670; }
.title .credit a { color: inherit; }
.title .guide-link { margin: 18px 0 0; font: 700 15px var(--serif); }
.title .tally { margin: 14px 0 0; font: 700 14px var(--serif); color: #d8ccb0; letter-spacing: 0.05em; }
.title .tally b { margin: 0 0.15em; font-size: 20px; color: #ffcf6a; }
.title .guide-link a, .result .guide-link a { color: var(--gold); }
.guide-link a + a { margin-left: 1.4em; } /* 役満の一覧と展示室のリンクを 1 行に並べる */
.result .guide-link { margin: 12px 0 0; font: 700 14px var(--serif); }
/* サイトのトップへ戻るリンク（T073）: 上下の余白で押せる範囲を高さ 44px 以上にする（インラインの余白なので行の高さは変わらない） */
.title .portal-link { margin: 16px 0 0; font: 700 15px var(--serif); }
.title .portal-link a { padding: 14px 0; color: var(--gold); }
.result .guide-link .portal { padding: 10px 0 15px; } /* 結果では上のボタンの行との間が 11px しかないので、余白を下に多く取る */
/* ログイン（T010）: タイトル右上のボタンと、ログインの画面 */
.title .account { position: absolute; top: 12px; right: 16px; text-align: right; }
/* 添え書きには下線を付けない（下線は「ユーザ登録」の部分だけ） */
.title .account .link:has(.note) { text-decoration: none; }
.title .account .label { text-decoration: underline; }
.title .account .note { display: block; margin-top: 2px; font: 500 12px system-ui, sans-serif; color: #d8ccb0; }
/* ニックネーム（T068）は利用者が決めた字なので、自前配信の書体（D014）でなく端末の書体で描く */
.title .account .link.name { font-family: system-ui, -apple-system, 'Hiragino Sans', 'Noto Sans JP', sans-serif; }
.btn.link, button.link { padding: 0; border: 0; background: none; box-shadow: none; color: var(--gold); font: 700 15px var(--serif); text-decoration: underline; cursor: pointer; }
.login-screen .box { max-width: 520px; }
.login-lead { margin: 0 0 14px; color: #d8ccb0; line-height: 1.7; }
.login-input { display: block; box-sizing: border-box; width: min(100%, 360px); margin: 0 auto; padding: 10px 12px; border-radius: 8px;
  border: 1px solid #6b5c38; background: #0b0f18; color: #fff; font: 500 18px system-ui, sans-serif; }
.login-input.code { width: 200px; text-align: center; letter-spacing: 0.3em; font-size: 24px; }
.login-error { min-height: 1.5em; margin: 8px 0; color: #ff8a7a; font-size: 14px; }
.login-screen .privacy { margin: 12px 0 0; font-size: 13px; }
.login-screen .privacy a { color: #a99c7c; }
.ad-screen .ad-text, .replay-screen .ad-text { margin: 0 0 18px; font: 700 20px var(--serif); color: #fff; letter-spacing: 0.05em; }

.result { background: rgba(0, 0, 0, 0.55); }
.result .box {
  min-width: min(92 * var(--vw), 640px); padding: 22px 28px 26px; border-radius: 14px; text-align: center;
  background: var(--panel); border: 1px solid #6b5c38; box-shadow: 0 10px 50px rgba(0, 0, 0, 0.7);
}
.result .verdict { margin: 0; font: 900 22px var(--serif); letter-spacing: 0.2em; }
.result .verdict.win { color: #ffcf6a; }
.result .verdict.lose { color: #9fb3d6; }
.result .yakuman { margin: 6px 0; font: 900 52px var(--serif); color: #fff; text-shadow: 0 0 22px rgba(255, 190, 80, 0.6); }
.result .meta { margin: 4px 0 14px; color: #d8ccb0; }
.result .hand { display: flex; justify-content: center; gap: 2px; margin-bottom: 20px; flex-wrap: nowrap; }
.result .hand .tile { height: min(64px, 5.8 * var(--vw)); }
.result .hand.melded .tile { height: min(54px, 4.3 * var(--vw)); }
.result .hand .sep { width: 10px; }
.result .win-tile { outline: 2px solid #ff8a4a; }
.result .called { filter: brightness(0.86); }
.tile.back { display: inline-block; aspect-ratio: 512 / 712; background: linear-gradient(#138069, #0a5243); }
.standings { margin: 0 auto 16px; border-collapse: collapse; font: 600 15px system-ui, sans-serif; }
.standings td { padding: 3px 12px; text-align: right; color: #d8ccb0; }
.standings td:nth-child(2) { text-align: left; }
.standings tr.me td { color: #fff; font-weight: 800; }
.standings .plus { color: #7fe08a; }
.standings .minus { color: #ff8a7a; }

.rotate { display: none; }
/* 縦長のスマホ（T063）: 画面ごと時計回りに 90° 回して横画面として描く。アプリ（SNS など）の内蔵ブラウザは縦固定のことが多く、
   端末を横にしても画面が回らないため。端末の向きで画面が回るブラウザでは、横にすればこの条件が外れて元に戻る。
   body に transform をかけると、中の position: fixed の要素は body を基準に並ぶので、オーバーレイや後から足す要素もまとめて回る。
   回した中では幅と高さが入れ替わるので --vw・--vh も入れ替える（幅は dvh: ツールバーの出入りに合わせる。#stage と同じ理由） */
@media (orientation: portrait) and (max-width: 700px) {
  :root { --vw: 1vh; --vh: 1vw; }
  @supports (height: 1dvh) { :root { --vw: 1dvh; } }
  body {
    position: fixed; top: 0; left: 0; width: 100vh; width: 100dvh; height: 100vw;
    transform-origin: 0 0; transform: translateX(100vw) rotate(90deg);
  }
  #stage, .fx-bolt { height: 100%; }
}
/* 結果のシェア（T060）。もう一局・タイトルへと同じ列に、各 SNS と画像保存の丸いアイコンを並べる（スマホ横の高さに収めるため） */
.result .share-row { display: flex; gap: 8px; align-items: center; margin-left: 6px; }
.result .share-row span { font: 700 13px var(--serif); color: #d8ccb0; letter-spacing: 0.1em; }
.sns {
  display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border-radius: 50%; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.25); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.sns img { width: 20px; height: 20px; }
.sns:hover { filter: brightness(1.15); }
.sns.x, .sns.threads { background: #000; }
.sns.facebook { background: #0866ff; }
.sns.instagram { background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fd5949 45%, #d6249f 60%, #285aeb 90%); }
.sns.save { background: linear-gradient(#b8862e, #7a5416); border-color: #f0d38a; }
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 30; transform: translateX(-50%); max-width: calc(90 * var(--vw)); padding: 10px 18px; border-radius: 10px;
  font: 500 14px / 1.6 system-ui, sans-serif; color: #f4ead2; background: rgba(10, 12, 18, 0.94); border: 1px solid #6b5c38;
}

/* 段位が変わったときの告知（T054）。文字が拡大して現れ、光が横切り、消える。押すと消える */
.rank-notice {
  position: fixed; inset: 0; z-index: 15; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: radial-gradient(ellipse at center, rgba(8, 6, 2, 0.9), rgba(0, 0, 0, 0.6) 75%);
  animation: rank-notice 2.4s ease-out forwards;
}
.rank-notice p { margin: 0; }
.rank-notice .kind {
  font: 900 min(16 * var(--vw), 34 * var(--vh), 150px) / 1.05 var(--serif); letter-spacing: 0.2em; padding-left: 0.2em;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.95) 50%, transparent 60%) no-repeat,
    linear-gradient(#fff6d8, #e0b45a 55%, #9c6a1c);
  background-size: 300% 100%, 100% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 24px rgba(255, 180, 60, 0.8)) drop-shadow(0 3px 2px rgba(0, 0, 0, 0.7));
  animation: rank-notice-pop 0.6s cubic-bezier(0.2, 1.6, 0.4, 1) both, rank-notice-shine 1.1s 0.5s ease-in-out both;
}
.rank-notice .label { font: 900 min(6 * var(--vw), 11 * var(--vh), 52px) var(--serif); color: #fff; text-shadow: 0 0 18px rgba(255, 190, 80, 0.7); animation: rank-notice-pop 0.6s 0.25s both; }
.rank-notice.down { animation-duration: 2.8s; background: radial-gradient(ellipse at center, rgba(3, 6, 14, 0.9), rgba(0, 0, 0, 0.6) 75%); }
.rank-notice.down .kind {
  background: linear-gradient(#e4ecf8, #9fb3d6 55%, #5d7092); -webkit-background-clip: text; background-clip: text;
  filter: drop-shadow(0 0 18px rgba(120, 150, 210, 0.6)); animation: rank-notice-sink 1s ease-out both;
}
.rank-notice.down .label { color: #c7d3ea; text-shadow: none; animation: rank-notice-sink 1s 0.2s ease-out both; }
@keyframes rank-notice { 0% { opacity: 0; } 8% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }
@keyframes rank-notice-pop { 0% { transform: scale(2.2); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes rank-notice-shine { 0% { background-position: 120% 0, 0 0; } 100% { background-position: -20% 0, 0 0; } }
@keyframes rank-notice-sink { 0% { transform: translateY(-24px); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } }

/* 高さの低い画面（スマホ横）。画面ごと回しているとき（T063）は、実際の画面の幅が回した中の高さになる */
@media (max-height: 520px), (orientation: portrait) and (max-width: 520px) {
  .result .box { padding: 12px 18px 16px; }
  .sns { width: 34px; height: 34px; }
  .sns img { width: 17px; height: 17px; }
  .result .yakuman { font-size: 34px; margin: 2px 0; }
  .result .meta { margin: 2px 0 8px; }
  .result .hand { margin-bottom: 8px; }
  .standings { font-size: 12px; margin-bottom: 8px; }
  .standings td { padding: 1px 10px; }
  .info .tile { height: 34px; }
  .btn .mini .tile { height: 26px; }
  .callout { font-size: 32px; }
  .info-text b { font-size: 14px; }
  /* タイトル（T065）: 中央は題字・難度ボタン・残り回数だけにし、リンクは左上、総数とクレジットは下端の左右へ寄せる。
     右上はログイン（T010）のために空けておく。難度の説明文と記録の件数は隠す */
  .title .kicker { font-size: 14px; }
  .title h1 { margin: 2px 0 8px; font-size: 56px; }
  .title .lead { margin-bottom: 12px; font-size: 14px; line-height: 1.6; }
  .btn.level { min-width: 120px; padding: 6px 12px; gap: 2px; }
  .btn.level b { font-size: 18px; }
  .btn.level > span:first-of-type, .btn.level .count, .title .guide-link .long, .title .portal-link .long { display: none; }
  .btn.level .rank { margin-top: 0; }
  .title #title-plays { margin-top: 10px; }
  .title .guide-link { position: absolute; top: 10px; left: 14px; margin: 0; font-size: 13px; }
  .title .portal-link { position: absolute; top: 44px; left: 14px; margin: 0; font-size: 13px; } /* 左上のリンクの下。押せる範囲が上の行に重ならない高さ */
  .title #title-tally { position: absolute; bottom: 10px; left: 14px; margin: 0; font-size: 12px; }
  .title #title-tally b { font-size: 15px; }
  .title .credit { right: 14px; width: auto; text-align: right; }
  /* 下端の中央は総数とクレジットの間が狭いので、右下のクレジットの上（T079）。難度ボタンと残り回数の右の幅に収まるよう短い文にする */
  .title .about-cue { left: auto; right: 4px; text-align: right; }
  .title .about-cue a { font-size: 13px; }
  .title .about-cue .long { display: none; }
  .title .about-cue .short { display: inline; }
  .title .account { top: 10px; right: 14px; }
  .title .account .link { font-size: 13px; }
  .title .account .note { display: inline; margin: 0 0 0 0.4em; font-size: 11px; } /* 高さを取らないよう 1 行に並べる */
  .login-screen .box { padding: 10px 18px 12px; }
  .login-screen .ad-text { margin-bottom: 6px; font-size: 17px; }
  .login-lead { margin-bottom: 8px; font-size: 13px; line-height: 1.5; }
  .login-input { padding: 6px 10px; font-size: 16px; }
  .login-input.code { font-size: 20px; }
  .login-error { margin: 4px 0; font-size: 12px; }
  .login-screen .privacy { margin-top: 6px; }
  .result .guide-link { margin-top: 6px; }
}
/* さらに低い画面（高さ 400px 以下。iPhone SE の横、横でツールバーが出たとき）: 結果の枠を画面の高さに収める。
   順位表を 2 列に並べ、ボタンの行が折り返さないよう詰める（押せる高さは 44px 以上のまま） */
@media (max-height: 400px), (orientation: portrait) and (max-width: 400px) {
  #result .box { padding: 8px 16px 15px; }
  #result .yakuman { font-size: 30px; }
  #result .guide-link { margin-top: 9px; } /* サイトのトップへのリンクの押せる範囲（上 10px・下 15px）がボタンの行と枠に重ならない間隔 */
  #result .standings { display: grid; grid-template-columns: repeat(2, auto); justify-content: center; column-gap: 20px; }
  #result .standings tbody { display: contents; }
  #result .standings tr { display: grid; grid-template-columns: 3em 3em 5.2em 5.6em; } /* 2 行の列をそろえる（順位・席・点・増減） */
  #result .standings td { padding: 1px 5px; }
  #result .buttons { gap: 8px; }
  #result .btn { padding: 10px 14px; font-size: 16px; }
  #result .btn.primary { padding: 10px 20px; font-size: 18px; }
}
