/* ========================================================
   nanikiru-agari.css — 何切るのあがり演出（ドラフト機能）
   種類: tier-normal（紺・青白い光）/ tier-high（紫・花びら）/ tier-mangan（赤い墨しぶき）/ tier-yakuman（赤黒い渦・光る枠）
   流れ: ①あがり牌が浮かんで光る(0.3s〜) → ②筆文字の役名(1.0s〜) → ③パネル(1.9s〜) → ④結果
   nanikiru-agari.js とセット。外すときはこのファイルごと消してよい。
   ======================================================== */

/* 筆文字フォント（Yuji Boku, SIL Open Font License 1.1。ライセンス文は fonts/yuji-boku-OFL.txt）。
   役名に使う文字だけを切り出している（scripts/fetch-brush-font.js）。
   外す場合はこの @font-face を消せば、端末の太い明朝体で表示される。 */
@font-face {
  font-family: "NK Brush";
  src: url("fonts/yuji-boku-yaku.woff2") format("woff2");
  font-display: swap;
}

.nkx-overlay {
  --accent: #7dd3fc;
  --accent-2: #1d4ed8;
  --glow: rgba(125, 211, 252, 0.75);
  --ink: #eef4ff;
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow: hidden;
  color: #f8fafc;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", serif;
  animation: nkx-fade 0.25s ease-out both;
  cursor: pointer;
}
.tier-high { --accent: #d8b4fe; --accent-2: #7e22ce; --glow: rgba(192, 132, 252, 0.8); --ink: #f5ecff; }
.tier-mangan { --accent: #fca5a5; --accent-2: #b91c1c; --glow: rgba(239, 68, 68, 0.85); --ink: #fff1f1; }
.tier-yakuman { --accent: #fecaca; --accent-2: #dc2626; --glow: rgba(248, 50, 50, 0.95); --ink: #fff5f5; }

/* ---------- 背景 ---------- */
.nkx-bg { position: absolute; inset: 0; }
.tier-normal .nkx-bg { background: radial-gradient(ellipse at 40% 35%, #16233f 0%, #070b16 55%, #020308 100%); }
.tier-high .nkx-bg { background: radial-gradient(ellipse at 40% 35%, #2a1145 0%, #0d0618 55%, #040209 100%); }
.tier-mangan .nkx-bg { background: radial-gradient(ellipse at 40% 35%, #3a0a0a 0%, #120303 55%, #050101 100%); }
.tier-yakuman .nkx-bg { background: radial-gradient(ellipse at 45% 40%, #5a0b0b 0%, #1a0303 50%, #050000 100%); }

/* 流れる光の筋（通常・高役） */
.nkx-streaks i {
  position: absolute;
  left: -30%;
  width: 70%;
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), #fff, transparent);
  filter: blur(1px) drop-shadow(0 0 8px var(--glow));
  transform: rotate(-18deg);
  opacity: 0;
  animation: nkx-streak 1.1s ease-out both;
}
.nkx-streaks i:nth-child(1) { top: 26%; animation-delay: 1.0s; }
.nkx-streaks i:nth-child(2) { top: 36%; width: 50%; animation-delay: 1.15s; }
.nkx-streaks i:nth-child(3) { top: 18%; width: 40%; animation-delay: 1.3s; }

/* 花びら（高役） */
.nkx-petals i {
  position: absolute;
  border-radius: 80% 0 80% 0;
  background: linear-gradient(135deg, #e9d5ff, #a855f7 60%, #6b21a8);
  box-shadow: 0 0 10px rgba(192, 132, 252, 0.6);
  opacity: 0;
  animation-name: nkx-petal;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}

/* 墨しぶき（満貫以上・役満） */
.nkx-splatter {
  position: absolute;
  left: 0;
  top: 0;
  width: 70%;
  height: 62%;
  fill: #b91c1c;
  filter: drop-shadow(0 0 10px rgba(220, 38, 38, 0.6));
  opacity: 0;
  transform-origin: 50% 50%;
  animation: nkx-splat 0.45s cubic-bezier(.2, 1.4, .4, 1) 1.0s both;
}
.tier-yakuman .nkx-splatter { fill: #dc2626; }
/* 斜めに走る大きな墨の一筆 */
.nkx-slash {
  position: absolute;
  left: -10%;
  top: 22%;
  width: 90%;
  height: 22%;
  background: linear-gradient(90deg, transparent, rgba(185, 28, 28, 0.9) 20%, rgba(127, 29, 29, 0.85) 70%, transparent);
  transform: rotate(-12deg) scaleX(0);
  transform-origin: left center;
  filter: blur(2px);
  border-radius: 50%;
  animation: nkx-slash 0.35s ease-out 0.95s both;
}
/* 赤黒い渦（役満） */
.nkx-swirl {
  position: absolute;
  left: 38%;
  top: 40%;
  width: 150vmax;
  height: 150vmax;
  margin: -75vmax 0 0 -75vmax;
  background: repeating-conic-gradient(from 0deg, rgba(220, 38, 38, 0.18) 0deg 10deg, rgba(0, 0, 0, 0) 10deg 30deg);
  border-radius: 50%;
  -webkit-mask-image: radial-gradient(circle, transparent 8%, #000 30%, transparent 70%);
  mask-image: radial-gradient(circle, transparent 8%, #000 30%, transparent 70%);
  animation: nkx-spin 14s linear infinite, nkx-fade 1s ease-out 0.9s both;
}

/* ---------- レイアウト ---------- */
.nkx-stage {
  position: relative;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 28%);
  align-items: center;
  gap: 3vmin;
  padding: max(14px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}
.tier-yakuman .nkx-stage { animation: nkx-shake 0.5s linear 1.0s both; }
.nkx-left { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 1.5vmin; }

/* ---------- ②筆文字の役名 ---------- */
.nkx-head { text-align: center; }
.nkx-brush {
  font-family: "NK Brush", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  font-weight: 900;
  font-size: clamp(56px, 17vmin, 150px);
  line-height: 1.05;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: var(--ink);
  /* 墨のかすれ: 明るい色の上にノイズを乗せ、周りを光らせる */
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.2' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 -1.4 1.1'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    linear-gradient(180deg, #ffffff, var(--ink) 55%, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.9)) drop-shadow(0 0 18px var(--glow)) drop-shadow(0 6px 0 rgba(0, 0, 0, 0.6));
  clip-path: inset(0 100% 0 0);
  animation: nkx-write 0.75s cubic-bezier(.6, 0, .2, 1) 1.0s both;
}
.nkx-brush.len-4 { font-size: clamp(48px, 14vmin, 128px); }
.nkx-brush.len-5 { font-size: clamp(42px, 11.5vmin, 108px); }
.nkx-brush.len-6, .nkx-brush.len-7 { font-size: clamp(36px, 9.5vmin, 92px); }

.nkx-kana {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 0.4vmin;
  font-size: clamp(13px, 3.4vmin, 24px);
  font-weight: 700;
  letter-spacing: 0.25em;
  color: var(--accent);
  opacity: 0;
  animation: nkx-fade 0.5s ease-out 1.55s both;
}
.nkx-kana::before,
.nkx-kana::after { content: ""; width: 3em; height: 1px; background: linear-gradient(90deg, transparent, var(--accent), transparent); }

/* ---------- ①手牌（奥に傾けて、床に映り込ませる） ---------- */
.nkx-table { width: 100%; perspective: 900px; }
.nkx-hand {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  transform: rotateX(24deg);
  transform-origin: 50% 100%;
  -webkit-box-reflect: below 2px linear-gradient(transparent 55%, rgba(255, 255, 255, 0.22));
  opacity: 0;
  animation: nkx-rise 0.5s ease-out 0.1s both;
}
.nkx-tile-wrap { flex: 1 1 0; min-width: 0; max-width: 52px; }
/* 鳴いた面子: 牌の大きさは手牌と同じにし、少し離して並べる */
.nkx-meld { display: contents; }
.nkx-meld > .nkx-tile-wrap:first-child { margin-left: 10px; }
.nkx-tile-wrap.is-win { margin-left: 12px; animation: nkx-lift 0.6s cubic-bezier(.2, 1.3, .4, 1) 0.35s both; }
.nkx-tile { display: block; width: 100%; height: auto; filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.6)); }
.nkx-hand .nkx-tile-wrap:not(.is-win) .nkx-tile { animation: nkx-dim-in 0.6s ease-out 1.6s both; }
.nkx-tile-wrap.is-win .nkx-tile {
  border-radius: 6px;
  animation: nkx-winglow 1.8s ease-in-out 0.5s infinite;
}
/* 役満は手牌の周りに光る枠 */
.tier-yakuman .nkx-hand {
  padding: 8px 10px;
  border: 2px solid rgba(248, 113, 113, 0.9);
  border-radius: 8px;
  box-shadow: 0 0 24px rgba(239, 68, 68, 0.7), inset 0 0 18px rgba(239, 68, 68, 0.35);
}

/* ---------- ③情報パネル ---------- */
.nkx-panel {
  align-self: center;
  padding: 16px 18px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(10, 14, 26, 0.88), rgba(4, 6, 12, 0.92));
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 20px 40px rgba(0, 0, 0, 0.5);
  opacity: 0;
  animation: nkx-panel 0.5s cubic-bezier(.2, 1, .3, 1) 1.9s both;
  cursor: default;
}
.nkx-panel-title { font-size: clamp(18px, 4vmin, 26px); font-weight: 900; padding-bottom: 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.25); }
.nkx-panel-yaku { list-style: none; margin: 8px 0; padding: 0; display: flex; flex-direction: column; gap: 3px; max-height: 30vh; overflow-y: auto; }
.nkx-panel-yaku li { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: #d4d4d8; }
.nkx-panel-yaku b { color: var(--accent); font-weight: 800; white-space: nowrap; }
.nkx-panel-row { display: flex; align-items: baseline; gap: 4px; font-size: clamp(20px, 4.6vmin, 30px); font-weight: 800; margin: 4px 0; }
.nkx-panel-row small { font-size: 0.55em; margin-right: 10px; color: #a1a1aa; }
.nkx-panel-points {
  font-size: clamp(30px, 8vmin, 54px);
  font-weight: 900;
  font-style: italic;
  line-height: 1.1;
  color: var(--ink);
  text-shadow: 0 0 16px var(--glow);
  white-space: nowrap;
}
.nkx-panel-points small { font-size: 0.45em; margin-left: 2px; }
.nkx-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; opacity: 0; animation: nkx-fade 0.4s ease-out 2.9s both; }
.nkx-btn {
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  border-radius: 6px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 700;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  cursor: pointer;
}
.nkx-btn.on { background: var(--accent-2); border-color: var(--accent-2); }
.nkx-btn-ghost { background: transparent; border-color: rgba(255, 255, 255, 0.15); }
.nkx-note { margin: 8px 0 0; font-size: 10px; color: rgba(255, 255, 255, 0.4); font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Meiryo", sans-serif; }

/* タップで飛ばしたとき: すべて最後の状態へ */
.nkx-overlay.is-skip *,
.nkx-overlay.is-skip *::before,
.nkx-overlay.is-skip *::after {
  animation-delay: 0s !important;
  animation-duration: 0.01s !important;
}
.nkx-overlay.is-skip .nkx-swirl { animation: none !important; opacity: 1; }
.nkx-overlay.is-skip .nkx-tile-wrap.is-win .nkx-tile,
.nkx-overlay.is-skip .nkx-petals i { animation-duration: 1.8s !important; }

/* ---------- アニメーション ---------- */
@keyframes nkx-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes nkx-rise { from { opacity: 0; transform: rotateX(24deg) translateY(30px); } to { opacity: 1; transform: rotateX(24deg); } }
@keyframes nkx-lift { 0% { transform: translateY(0); } 60% { transform: translateY(-22px); } 100% { transform: translateY(-10px); } }
@keyframes nkx-winglow {
  0%, 100% { box-shadow: 0 0 0 2px var(--accent), 0 0 12px var(--glow); }
  50% { box-shadow: 0 0 0 2px #fff, 0 0 30px var(--glow); }
}
@keyframes nkx-dim-in { from { filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.6)) brightness(0.45); } to { filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.6)); } }
@keyframes nkx-write {
  0% { clip-path: inset(0 100% 0 0); transform: scale(1.12); }
  70% { transform: scale(1); }
  100% { clip-path: inset(0 0 0 0); transform: scale(1); }
}
@keyframes nkx-streak { 0% { opacity: 0; transform: rotate(-18deg) translateX(0); } 20% { opacity: 1; } 100% { opacity: 0; transform: rotate(-18deg) translateX(160%); } }
@keyframes nkx-petal {
  0% { opacity: 0; transform: translate(0, 0) rotate(0deg); }
  15% { opacity: 0.9; }
  85% { opacity: 0.8; }
  100% { opacity: 0; transform: translate(-18vw, 55vh) rotate(260deg); }
}
@keyframes nkx-splat { 0% { opacity: 0; transform: scale(0.3); } 100% { opacity: 0.9; transform: scale(1); } }
@keyframes nkx-slash { to { transform: rotate(-12deg) scaleX(1); } }
@keyframes nkx-spin { to { transform: rotate(360deg); } }
@keyframes nkx-shake {
  0%, 100% { transform: none; }
  15% { transform: translate(-8px, 4px); }
  30% { transform: translate(7px, -5px); }
  50% { transform: translate(-5px, -2px); }
  70% { transform: translate(3px, 3px); }
}
@keyframes nkx-panel { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }

/* ---------- 背の低い横画面（スマホ横持ち） ---------- */
@media (orientation: landscape) and (max-height: 430px) {
  .nkx-stage { grid-template-columns: minmax(0, 1fr) minmax(180px, 30%); gap: 14px; padding: 10px 16px; }
  .nkx-brush { font-size: 66px; }
  .nkx-brush.len-4 { font-size: 56px; }
  .nkx-brush.len-5 { font-size: 46px; }
  .nkx-brush.len-6, .nkx-brush.len-7 { font-size: 40px; }
  .nkx-kana { font-size: 13px; }
  .nkx-tile-wrap { max-width: 34px; }
  .nkx-panel { padding: 10px 12px; }
  .nkx-panel-title { font-size: 17px; padding-bottom: 5px; }
  .nkx-panel-yaku { margin: 5px 0; max-height: 26vh; }
  .nkx-panel-yaku li { font-size: 11.5px; }
  .nkx-panel-row { font-size: 19px; }
  .nkx-panel-points { font-size: 30px; }
  .nkx-actions { margin-top: 8px; }
  .nkx-btn { padding: 5px 8px; font-size: 11px; }
}

/* ---------- 縦画面: 縦に積む ---------- */
@media (orientation: portrait) {
  .nkx-stage { grid-template-columns: minmax(0, 1fr); align-content: center; gap: 18px; }
  .nkx-brush { font-size: clamp(48px, 16vw, 96px); }
}

/* ---------- 動きを減らす設定 ---------- */
@media (prefers-reduced-motion: reduce) {
  .nkx-overlay *, .nkx-overlay, .nkx-overlay *::before, .nkx-overlay *::after { animation: none !important; }
  .nkx-hand, .nkx-kana, .nkx-panel, .nkx-actions, .nkx-splatter { opacity: 1; }
  .nkx-brush { clip-path: none; }
  .nkx-streaks, .nkx-petals, .nkx-slash { display: none; }
}
