/* ミニゲーム共通の見た目。videoshop（紺のパネル・黄色の縁・立体感のあるボタン）に寄せた、写実寄りのトーン。
   色は変数にしてあるので、ゲームごとに :root の --accent だけ差し替えれば雰囲気を変えられる。
   ドット絵はやめた（流行らないため）。盤面は高解像度のキャンバスで描く。 */
:root {
  color-scheme: dark;
  --bg: #0f1c32; --panel: #192b48; --panel-deep: #12223b;
  --ink: #e8e6dc; --mist: #8fa6bf; --line: rgba(233, 199, 74, .55);
  --accent: #e9c74a; --amber: var(--accent); --cyan: #7fd6f0; --danger: #e0634f;
  --font: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Noto Sans JP', 'Yu Gothic', system-ui, sans-serif;
  --display: 'Oswald', 'Bebas Neue', 'Arial Narrow', 'Helvetica Neue', var(--font);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font);
  overflow: hidden; overscroll-behavior: none; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }

#app { position: fixed; inset: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100dvh; }
/* コンパクト表示：Xアプリ内ブラウザ等。下端のバー（約1割）に隠れないよう全体を上 94% に収める。実機の画面では、以前の 2/3 だと小さすぎて下が余った */
.compact #app { height: 94dvh; bottom: auto; }
/* Xのアプリ内ブラウザは、ページが状態バーの下から始まるのに safe-area-inset-top を返すため、上に大きな空きができる。コンパクト表示では上の余白を詰める */
.compact #hud { padding-top: 8px; min-height: 40px; }
#hud {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) max(14px, env(safe-area-inset-right, 0px)) 8px max(14px, env(safe-area-inset-left, 0px));
  position: relative; min-height: 48px; background: linear-gradient(#162744, #0f1c32); border-bottom: 1px solid rgba(233, 199, 74, .25); font-variant-numeric: tabular-nums;
}
#hud .l { font-size: 14px; color: var(--mist); }
#hud .c { font-family: var(--display); font-size: 40px; font-weight: 700; line-height: 1; text-align: center; color: var(--accent); min-width: 3ch; text-shadow: 0 2px 6px rgba(0,0,0,.5); }
#hud .r { font-size: 14px; color: var(--mist); text-align: right; padding-right: 40px; }
#stage { position: relative; min-height: 0; display: grid; place-items: center; overflow: hidden; background: #070d18; }
#view { max-width: 100%; max-height: 100%; display: block; touch-action: none; }

/* タイトル／リザルトのカード。盤面を完全には隠さない（リザルトは盤面の上にカードで出す） */
.screen { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 16px; background: rgba(4, 8, 16, .55); }
.screen.result { place-items: end center; background: rgba(4, 8, 16, .2); } /* 結果は下寄せにして、盤面の笑いどころ（最後の絵）を隠さない */
.card {
  width: min(360px, 100%); max-height: 100%; overflow-y: auto; touch-action: pan-y;
  background: linear-gradient(#1d3252, var(--panel)); border: 2px solid var(--accent); border-radius: 10px;
  padding: 20px 16px; display: grid; gap: 12px; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.12);
}
.card h1 { margin: 0; font-family: var(--display); font-size: clamp(30px, 11vw, 42px); font-weight: 700; letter-spacing: .14em; white-space: nowrap; color: #fff; text-shadow: 0 0 18px rgba(233,199,74,.45), 0 2px 0 rgba(0,0,0,.5); }
.card .tag, .card .how { word-break: auto-phrase; text-wrap: balance; overflow-wrap: anywhere; } /* 文節の途中で改行しない（未対応の端末でも行の長さをそろえる） */
.card .tag { margin: 0; color: var(--mist); font-size: 15px; line-height: 1.6; }
.card .how { margin: 0; font-size: 15px; line-height: 1.7; }
.card .score { font-family: var(--display); font-size: 84px; font-weight: 700; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; text-shadow: 0 3px 0 rgba(0,0,0,.45); }
.card .unit { font-family: var(--font); font-size: 20px; font-weight: 400; margin-left: 6px; color: var(--ink); }
.card .line { font-size: 18px; font-weight: 700; color: var(--cyan); margin: 0; text-wrap: balance; }
.card .cardimg { width: 100%; height: auto; border-radius: 6px; border: 1px solid rgba(255,255,255,.18); }
.card .sub { font-size: 14px; color: var(--mist); margin: 0; text-wrap: balance; }
.btn {
  min-height: 50px; padding: 10px 14px; font-size: 18px; font-weight: 700; color: var(--ink);
  background: linear-gradient(#2a4166, #213556); border: 1px solid rgba(255,255,255,.18); border-bottom-width: 3px; border-radius: 8px;
}
.btn:active { transform: translateY(1px); border-bottom-width: 2px; }
.btn.primary { background: linear-gradient(#f4dd7a, #e0b93a); color: #2b2208; border-color: #f7e9a8; border-bottom-color: #a98a1f; text-shadow: 0 1px 0 rgba(255,255,255,.4); }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; }
.row .btn { flex: 1; }
.rank { text-align: left; font-size: 15px; display: grid; gap: 3px; font-variant-numeric: tabular-nums; }
.rank div { display: flex; justify-content: space-between; gap: 8px; }
.rank .me { color: var(--accent); font-weight: 700; }
.namebox { display: flex; gap: 8px; }
.namebox input {
  flex: 1; min-width: 0; font: inherit; font-size: 18px; color: var(--ink); background: var(--panel-deep);
  border: 1px solid rgba(255,255,255,.2); border-radius: 8px; padding: 8px 10px; touch-action: manipulation; user-select: text; -webkit-user-select: text;
}
.toast { font-size: 14px; color: var(--mist); min-height: 1.4em; margin: 0; }
.mute { position: absolute; right: max(4px, env(safe-area-inset-right, 0px)); bottom: 2px; z-index: 6; min-width: 44px; min-height: 44px; background: none; border: 0; font-size: 20px; color: var(--mist); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* 結果は画像のみ（runGame の resultMode:'card'）。文字は読み上げ・検査用に DOM へ残し、画面からは隠す。画像を主役に大きく出す */
.card.card-only { width: min(560px, 100%); padding: 12px; gap: 8px; }
.card.card-only > .tag, .card.card-only > .score, .card.card-only > .line, .card.card-only > .sub:not(.best) { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.card.card-only .cardimg { border: 0; }

/* 多言語（runGame に i18n を渡したゲームだけ）。html の lang に合わせて字体の違う言語は font を切り替える */
:root:lang(zh-Hans) { --font: 'PingFang SC', 'Hiragino Sans GB', 'Noto Sans CJK SC', 'Noto Sans SC', 'Microsoft YaHei', system-ui, sans-serif; }
:root:lang(zh-Hant) { --font: 'PingFang TC', 'Noto Sans CJK TC', 'Noto Sans TC', 'Microsoft JhengHei', system-ui, sans-serif; }
:root:lang(ko) { --font: 'Apple SD Gothic Neo', 'Noto Sans CJK KR', 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif; }
:root:lang(en), :root:lang(es), :root:lang(pt), :root:lang(fr), :root:lang(de) { --font: system-ui, -apple-system, 'Segoe UI', 'Noto Sans', 'Helvetica Neue', Arial, sans-serif; }
/* 題名：英語など語の長い言語は折り返しを許し、字間を詰める（日本語・中国語・韓国語は従来どおり1行・広い字間） */
.card h1.i18n { white-space: normal; text-wrap: balance; overflow-wrap: anywhere; line-height: 1.12; }
:root:lang(en) .card h1.i18n, :root:lang(es) .card h1.i18n, :root:lang(pt) .card h1.i18n, :root:lang(fr) .card h1.i18n, :root:lang(de) .card h1.i18n { letter-spacing: .03em; font-size: clamp(24px, 8vw, 34px); }
:root:lang(ko) .card h1.i18n { letter-spacing: .06em; font-size: clamp(26px, 9vw, 38px); }
:root:lang(zh-Hans) .card h1.i18n, :root:lang(zh-Hant) .card h1.i18n { letter-spacing: .1em; }
/* 言語切替：タイトル画面の右上の地球ボタンと、2列のメニュー。操作領域（#app）の内側に絶対配置するので、上 2/3 の表示でも収まる */
.screen.hasLang { padding-top: 54px; }
.langbtn { position: absolute; top: 6px; right: max(6px, env(safe-area-inset-right, 0px)); z-index: 8; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 22px; background: rgba(18, 34, 59, .78); border: 1px solid rgba(255,255,255,.22); color: var(--ink); }
.langbtn:active { transform: translateY(1px); }
.langmenu { position: absolute; top: 54px; right: 8px; z-index: 9; width: min(300px, calc(100% - 16px)); max-height: calc(100% - 62px); overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 8px; background: var(--panel-deep); border: 2px solid var(--accent); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.6); touch-action: pan-y; }
.langitem { min-height: 42px; padding: 6px 8px; font-size: 15px; font-weight: 700; background: linear-gradient(#2a4166, #213556); border: 1px solid rgba(255,255,255,.18); border-radius: 8px; color: var(--ink); }
.langitem.on { border-color: var(--accent); color: var(--accent); }
/* 多言語で文が長くなっても、遊ぶボタンがカードの下に隠れないよう、ボタンはカードの下端に貼り付ける。背の低い画面（Xアプリ内など）では余白と字を少し詰める */
.screen.hasLang .card > .btn.primary { position: sticky; bottom: -20px; z-index: 1; box-shadow: 0 -8px 10px -4px rgba(25, 43, 72, .95); }
@media (max-height: 640px) {
  .screen.hasLang { padding-top: 50px; }
  .screen.hasLang .card { padding: 12px 14px; gap: 8px; }
  .screen.hasLang .card .tag, .screen.hasLang .card .how { font-size: 14px; line-height: 1.45; }
}
