/* HexDrop (試作版) — 専用スタイル。style.css には依存しない(サイトの配色だけ合わせている) */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: #04051a;   /* 宇宙の背景(#space)が読み込まれるまでのフォールバック */
  color: #f0f0f5;
  font-family: 'Segoe UI', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  /* 注: body を flex にしない(過去に狭い画面で横あふれした) */
}

.hd-page { position: relative; z-index: 1; }
/* 宇宙の背景: 固定レイヤー。星雲と星は1度だけ描画し、ゆっくり漂わせるだけ */
#space { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
  background: linear-gradient(#03041a, #0a0833 45%, #02141b); }   /* 画像の読み込み中・失敗時のフォールバック */
#space.hasimg .layer { display: none; }                          /* 画像が出たら手続き描画の星は止める */

/* ---- 背景画像レイヤー(2枚重ねてクロスフェード) ---- */
.bgl { position: absolute; inset: 0; overflow: hidden; opacity: 0; transition: opacity 1.5s ease; }
.bgl.on { opacity: 1; }
/* パン用レイヤー: ビューポートより大きく(cover+18%)、CSS変数はJSがビューポートに合わせて設定する */
.bgpan { position: absolute; left: var(--l); top: var(--t); width: var(--iw); height: var(--ih);
  transform-origin: 50% 50%; will-change: transform; backface-visibility: hidden;
  animation: bgdrift var(--dur, 80s) ease-in-out infinite alternate; }
.bgpan > img { display: block; width: 100%; height: 100%; user-select: none; pointer-events: none; }
/* 往復(alternate)+ ease-in-out: 折り返しで速度が0になるので継ぎ目なくループする */
@keyframes bgdrift {
  from { transform: translate3d(var(--x0, 0), var(--y0, 0), 0) scale(var(--s0, 1)); }
  to   { transform: translate3d(var(--x1, 0), var(--y1, 0), 0) scale(var(--s1, 1.06)); }
}
/* オーロラのゆらぎ */
.aur { position: absolute; mix-blend-mode: screen; pointer-events: none; opacity: 0.5;
  animation: aurpulse 10s ease-in-out infinite alternate; }
@keyframes aurpulse {
  from { opacity: 0.35; transform: translate3d(-3%, 0, 0) scaleX(0.94); }
  to   { opacity: 1;    transform: translate3d(3%, -4%, 0) scaleX(1.08); }
}
/* またたく光(都市の灯り / 星のスパイク) */
.tw { position: absolute; aspect-ratio: 1; pointer-events: none; animation: twinkle 4s ease-in-out infinite alternate; }
.tw.city { background: radial-gradient(circle, rgba(255,236,190,0.95) 0%, rgba(255,170,70,0.6) 28%, rgba(255,140,40,0) 68%); mix-blend-mode: screen; }
.tw.flare { background-size: 100% 100%; background-repeat: no-repeat; }
@keyframes twinkle {
  from { opacity: 0.2; transform: scale(0.75); }
  to   { opacity: 1;   transform: scale(1.25); }
}
/* 星雲のごく薄いもや */
.haze { position: absolute; inset: -6%; pointer-events: none; opacity: 0.32; mix-blend-mode: screen;
  background: radial-gradient(ellipse at 30% 40%, rgba(70,150,200,0.35), rgba(70,150,200,0) 55%),
              radial-gradient(ellipse at 72% 62%, rgba(210,130,70,0.28), rgba(210,130,70,0) 55%);
  animation: hazedrift 70s ease-in-out infinite alternate; }
@keyframes hazedrift {
  from { transform: translate3d(-3%, -2%, 0) scale(1); }
  to   { transform: translate3d(3%, 2%, 0) scale(1.08); }
}
/* 読みやすさのための暗いグラデーション+ビネット(HUD・ボタン・盤面・遊び方パネルを見やすく) */
.bgshade { position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(3,5,22,0.12) 0%, rgba(3,5,22,0.38) 62%, rgba(2,3,14,0.74) 100%),
    linear-gradient(rgba(4,6,24,0.5), rgba(4,6,24,0.14) 28%, rgba(4,6,24,0.14) 62%, rgba(4,6,24,0.58)); }

#space .layer { position: absolute; inset: 0; animation: spaceDrift 260s ease-in-out infinite alternate; transform-origin: 50% 50%; }
#space canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; }
@keyframes spaceDrift {
  from { transform: translate3d(-6px, -4px, 0) scale(1.05); }
  to { transform: translate3d(6px, 4px, 0) scale(1.05); }
}
@media (prefers-reduced-motion: reduce) {
  #space .layer { animation: none; transform: none; }
  .bgpan { animation: none; transform: translate3d(var(--x0, 0), var(--y0, 0), 0); }
  .aur, .haze, .tw { animation: none; }
  .tw { opacity: 0.7; }
  .bgl { transition-duration: 0.01s; }
}

.hd-page {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 10px 40px;
}

.hd-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 8px; }
.hd-title {
  margin: 0;
  font-size: 1.15rem;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}
.hd-title { text-shadow: 0 0 14px rgba(120,140,255,0.55), 0 1px 2px rgba(0,0,0,0.8); }
.hd-title small { font-size: 0.68rem; color: #b3b9dc; font-weight: normal; }
.hd-head-buttons { display: flex; gap: 6px; flex: none; }

.hd-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "hud" "board" "ctl" "opts";
  gap: 8px;
  justify-items: center;
}
@media (min-width: 720px) {
  .hd-stage {
    grid-template-columns: max-content 250px;
    grid-template-areas: "board hud" "ctl hud" "opts hud";
    justify-content: center;
    align-items: start;
    column-gap: 18px;
  }
}

/* ---- HUD ---- */
.hd-hud {
  grid-area: hud;
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 6px;
  background: linear-gradient(rgba(24,28,84,0.6), rgba(8,10,40,0.68));
  border: 1px solid rgba(150,170,255,0.3);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1), inset 0 0 18px rgba(0,0,20,0.5), 0 0 16px rgba(90,100,255,0.16);
  border-radius: 14px;
  padding: 8px;
}
@media (min-width: 720px) {
  .hd-hud { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px; gap: 8px; }
}
.hd-stat { min-width: 0; }
.hd-stat .k { font-size: 0.62rem; color: #b3b9dc; line-height: 1.2; text-shadow: 0 1px 2px rgba(0,0,0,0.7); }
.hd-stat .v { text-shadow: 0 1px 3px rgba(0,0,0,0.8); font-size: 0.98rem; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; }
.hd-stat.wide { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.hd-stat.wide .k { font-size: 0.66rem; }
.hd-stat .v.gold { color: #ffd166; }
.hd-stat .v.green { color: #7CFC9C; }
.hd-stat .v small { font-size: 0.65rem; font-weight: normal; color: #9aa0c3; }
.hd-next { grid-row: span 2; grid-column: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; }
@media (min-width: 720px) {
  .hd-next { grid-row: auto; grid-column: 1 / -1; flex-direction: row; gap: 10px; justify-content: flex-start; }
}
.hd-next .k { font-size: 0.62rem; color: #9aa0c3; }
/* 飛来演出のオーバーレイ: ビューポート全体(固定・クリック不可)。固定配置なのでスクロール幅は増えない */
#fxCanvas { position: fixed; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; contain: strict; }
#nextCanvas { display: block; }
.hd-pulse { animation: hdNextPulse 0.32s ease-out; }
@keyframes hdNextPulse { 0% { transform: scale(1.16); filter: brightness(1.5); } 100% { transform: scale(1); filter: none; } }
.hd-flash { animation: hdScore 0.5s ease-out; }
@keyframes hdScore { 0% { color: #fff; transform: scale(1.15); } 100% { transform: scale(1); } }

.hd-opts { grid-area: opts; font-size: 0.74rem; color: #d8dcff; text-shadow: 0 1px 3px rgba(0,0,0,0.9); display: flex; gap: 6px 14px; flex-wrap: wrap; align-items: center; justify-content: center; }
.hd-opts label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.hd-opts a { color: #8fb3ff; }
.hd-seed { font-variant-numeric: tabular-nums; }

/* ---- Board ---- */
.hd-board {
  grid-area: board;
  position: relative;
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  line-height: 0;
}
#board {
  display: block;
  border-radius: 14px;
  touch-action: manipulation;
}

.hd-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 8, 28, 0.62);
  border-radius: 14px;
  line-height: 1.5;
  text-align: center;
  padding: 14px;
}
.hd-overlay.hidden { display: none; }
.hd-overlay h2 { margin: 0 0 6px; font-size: 1.3rem; }
.hd-overlay p { margin: 0 0 12px; font-size: 0.8rem; color: #e2e5fa; text-wrap: balance; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }

.hd-banner {
  position: absolute;
  left: 0; right: 0; top: 28%;
  text-align: center;
  pointer-events: none;
  line-height: 1.2;
  opacity: 0;
}
.hd-banner .main { display: block; font-size: 1.9rem; font-weight: 800; color: #fff; text-shadow: 0 0 14px rgba(255,209,102,0.9), 0 2px 0 rgba(0,0,0,0.6); }
.hd-banner .sub { display: block; font-size: 1.05rem; font-weight: 700; color: #ffd166; text-shadow: 0 2px 0 rgba(0,0,0,0.6); }
.hd-banner.show { animation: hdBanner 1.1s ease-out forwards; }
.hd-banner.chain .sub { color: #fff; text-shadow: 0 0 14px rgba(255,209,102,0.95), 0 2px 0 rgba(0,0,0,0.6); }
.hd-banner.big .main { text-shadow: 0 0 26px rgba(255,209,102,1), 0 0 8px rgba(255,255,255,0.7), 0 2px 0 rgba(0,0,0,0.6); }
.hd-banner.big.show { animation-duration: 1.25s; }
.hd-banner.ring .main { color: #ff9ad5; }
.hd-banner.pyramid .main { color: #ffd166; }
.hd-banner.line .main { color: #7CFC9C; }
@keyframes hdBanner {
  0% { opacity: 0; transform: scale(0.6); }
  15% { opacity: 1; transform: scale(1.12); }
  30% { transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-16px); }
}

/* ---- Buttons ---- */
.hd-btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.18);
  background: linear-gradient(rgba(64,74,170,0.92), rgba(38,44,120,0.94));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 2px 8px rgba(0,0,30,0.5);
  color: #f0f0f5;
  font: inherit;
  font-weight: 700;
  border-radius: 12px;
  padding: 9px 16px;
  cursor: pointer;
  line-height: 1.2;
}
.hd-btn.small { padding: 6px 10px; font-size: 0.78rem; border-radius: 10px; }
.hd-btn:hover { filter: brightness(1.15); }
.hd-btn.primary { background: linear-gradient(#5b7bff, #4159d6); }
.hd-btn.ghost { background: rgba(30,36,100,0.55); border-color: rgba(150,170,255,0.32); }

.hd-controls {
  grid-area: ctl;
  display: flex;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 420px;
}
.hd-controls .grp { display: flex; gap: 6px; flex: 1 1 0; min-width: 0; }
.hd-pad {
  flex: 1 1 0;
  min-width: 0;
  height: 54px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  gap: 1px;
  border-radius: 14px;
  /* 長押し・選択・ダブルタップ拡大・タップハイライトを無効化 */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.hd-pad .dbl { font-size: 0.8rem; line-height: 0.62; display: block; }
.hd-pad small { font-size: 0.55rem; font-weight: 600; color: #cfd4ff; line-height: 1; }
.hd-pad.on { background: linear-gradient(#5b7bff, #4159d6); transform: translateY(1px); }
.hd-pad.hard { background: linear-gradient(#b0466a, #8a2f50); }
.hd-pad.hard.on { filter: brightness(1.3); }

/* ---- How-to ---- */
.hd-howto {
  margin-top: 18px;
  background: linear-gradient(rgba(20,24,76,0.72), rgba(8,10,40,0.78));
  border: 1px solid rgba(150,170,255,0.26);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 0 16px rgba(90,100,255,0.12);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.88rem;
  line-height: 1.75;
  color: #d5d8ee;
}
.hd-howto h2 { margin: 0 0 6px; font-size: 1.05rem; color: #8fb3ff; }
.hd-howto h3 { margin: 12px 0 2px; font-size: 0.92rem; color: #ffd166; }
.hd-howto ul { margin: 4px 0; padding-left: 1.3em; }
.hd-howto li { margin: 2px 0; }
.hd-howto kbd {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  font-size: 0.8em;
}
.hd-samples { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0; }
.hd-sample { text-align: center; font-size: 0.72rem; color: #cfd4ff; line-height: 1.3; }
.hd-sample canvas { display: block; margin: 0 auto 2px; background: rgba(0,0,0,0.25); border-radius: 10px; }
.hd-note { font-size: 0.78rem; color: #aeb5d8; }

/* ---- 公開ページ用の追加(ポータルへの戻りリンク・説明表・フッター) ---- */
.hd-crumb { margin: 0 0 4px; font-size: 0.78rem; }
.hd-crumb a { color: #b3b9dc; text-decoration: none; }
.hd-crumb a:hover { color: #fff; text-decoration: underline; }
.hd-howto { min-width: 0; }
.hd-howto h2:not(:first-child) { margin-top: 20px; }
.hd-howto p { margin: 6px 0; }
.hd-howto a { color: #7CFC9C; }
.hd-howto code { background: rgba(255,255,255,0.1); padding: 0 5px; border-radius: 4px; }
.hd-table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 8px 0 12px;
  font-size: 0.8rem;
  line-height: 1.6;
}
.hd-table th, .hd-table td {
  padding: 5px 9px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  text-align: left;
  vertical-align: top;
}
.hd-table th { color: #8fb3ff; font-weight: 600; background: rgba(255,255,255,0.05); white-space: nowrap; }
.hd-table td { color: #d5d8ee; }
.hd-foot-links { margin-top: 18px; text-align: center; font-size: 0.75rem; }
.hd-foot-links a { color: #9aa4d6; }
