/* ==========================================================================
   ガラケータイピング（garake-typing）
   画面全体が 1 台の電話機。ガラケーモードはピンクの折りたたみ携帯、
   ポケベルモードは緑の公衆電話＋ポケベルの液晶
   ========================================================================== */
:root {
  --navy: #140f33;
  --ink: #1a1c3a;
  --snow: #ffffff;
  --snow-dim: #cfc9ee;
  --gold: #ffd84a;
  --red: #ff4d6d;
  --blue: #7fb4ff;
  --cyan: #9be8ff;
  --green: #86f0b0;
  --pink: #ff8fc4;
  --panel: rgba(32, 24, 78, 0.94);
  --line: rgba(200, 190, 255, 0.34);
  --sgh-top: 0px;

  /* 電話機の色（モードで切りかえる） */
  --body-a: #ff9ccb;
  --body-b: #f0509a;
  --body-edge: #b82a6c;
  --key-a: #fff6fb;
  --key-b: #f5cfe2;
  --key-edge: #c77aa3;
  --key-ink: #4a1a38;
  --lcd-bg: #d8f6ff;
  --lcd-bg2: #b5e6f7;
  --lcd-ink: #10233a;
  --lcd-dim: #6f8ea6;
  --lcd-done: #0a8a5a;
  --lcd-accent: #e0348a;
}
#app.mode-pokebell {
  --body-a: #8fd9a8;
  --body-b: #3f9e6b;
  --body-edge: #23683f;
  --key-a: #f4f6f8;
  --key-b: #b9c1c9;
  --key-edge: #6d7780;
  --key-ink: #1c2530;
  --lcd-bg: #c4d67a;
  --lcd-bg2: #a9bf5c;
  --lcd-ink: #1c2a10;
  --lcd-dim: #6c7f3c;
  --lcd-done: #1c2a10;
  --lcd-accent: #1c2a10;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--navy);
  color: var(--snow);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
body {
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 143, 196, 0.22), transparent 42%),
    radial-gradient(circle at 86% 80%, rgba(127, 180, 255, 0.2), transparent 46%),
    var(--navy);
}

.hidden { display: none !important; }
button { font-family: inherit; }

/* ---------- 全体 ---------- */
#app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 8px calc(8px + env(safe-area-inset-right, 0px)) 8px calc(8px + env(safe-area-inset-left, 0px));
  overflow: hidden;
}

#phone {
  position: relative;
  width: 100%;
  max-width: 440px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 26px;
  background: linear-gradient(160deg, var(--body-a), var(--body-b));
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.55), inset 0 -4px 0 var(--body-edge), 0 10px 30px rgba(0, 0, 0, 0.45);
}
#phone-antenna { display: none; }

/* ---------- 液晶 ---------- */
#lcd {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  border: 4px solid #241c3c;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.07) 0 1px, transparent 1px 3px),
    linear-gradient(180deg, var(--lcd-bg), var(--lcd-bg2));
  color: var(--lcd-ink);
  overflow: hidden;
  container-type: inline-size;
  box-shadow: inset 0 0 18px rgba(255, 255, 255, 0.35);
}
#lcd.shake { animation: shake 0.22s linear; }
@keyframes shake {
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
#lcd.hurry #clock { color: #d81b3f; animation: blink 0.5s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }

#status {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
  background: rgba(16, 35, 58, 0.12);
  border-bottom: 1px solid rgba(16, 35, 58, 0.18);
}
#mode-label { font-size: 11px; opacity: 0.8; }
#clock { margin-left: auto; font-variant-numeric: tabular-nums; white-space: nowrap; }
#clock b { font-size: 17px; font-weight: 900; }

/* アンテナ＝コンボの段。0 本は「圏外」 */
#antenna { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; min-width: 34px; }
#antenna i { display: block; width: 4px; border-radius: 1px; background: var(--lcd-ink); opacity: 0.18; }
#antenna i:nth-child(1) { height: 6px; }
#antenna i:nth-child(2) { height: 10px; }
#antenna i:nth-child(3) { height: 14px; }
#antenna em { font-style: normal; font-size: 12px; font-weight: 900; margin-left: 2px; line-height: 14px; color: #d81b3f; }
#antenna.lv1 i:nth-child(-n+1), #antenna.lv2 i:nth-child(-n+2), #antenna.lv3 i { opacity: 1; }
#antenna.lv1 em, #antenna.lv2 em, #antenna.lv3 em { display: none; }
#app.mode-pokebell #antenna em { color: var(--lcd-ink); }

/* 電池＝残り時間 */
#battery {
  position: relative;
  width: 30px;
  height: 14px;
  border: 2px solid var(--lcd-ink);
  border-radius: 3px;
  padding: 1px;
  flex: none;
}
#battery::after { content: ""; position: absolute; right: -5px; top: 2px; width: 3px; height: 6px; background: var(--lcd-ink); border-radius: 0 2px 2px 0; }
#battery-fill { display: block; width: 100%; height: 100%; background: #12a36a; transform-origin: left center; }
#battery.low #battery-fill { background: #d81b3f; }
#app.mode-pokebell #battery-fill { background: var(--lcd-ink); }

#hud {
  flex: none;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 10px 2px;
  font-size: 11px;
  font-weight: 800;
  color: var(--lcd-dim);
  white-space: nowrap;
}
#hud b { font-size: 18px; font-weight: 900; color: var(--lcd-ink); font-variant-numeric: tabular-nums; }
#hud-mult b { color: var(--lcd-accent); }

#word-area {
  --n: 8;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 2px 8px 6px;
  text-align: center;
  overflow: hidden;
}
#app.veil #word-area > *, #app.veil #bell-table .lit { visibility: hidden; }
#word-text {
  font-size: min(3.4dvh, 30px, calc(96cqw / var(--n)));
  font-weight: 900;
  white-space: nowrap;
  min-height: 1.2em;
}
#app.mode-pokebell #word-text { display: none; }
#word-kana {
  display: flex;
  justify-content: center;
  font-size: min(5.2dvh, 44px, calc(94cqw / var(--n)));
  font-weight: 800;
  line-height: 1.25;
  flex-wrap: wrap;
  color: var(--lcd-dim);
}
#word-kana .w { display: inline-flex; white-space: nowrap; }
#word-kana [data-sp] { opacity: 0.4; }
#word-kana .w > span { display: inline-block; min-width: 0.62em; text-align: center; }
#word-kana .done { color: var(--lcd-done); }
#word-kana .cur { color: var(--lcd-ink); border-bottom: 3px solid var(--lcd-accent); margin-bottom: -3px; }
#app.mode-pokebell #word-kana .done { opacity: 0.4; }

#word-input {
  width: 96%;
  min-height: 1.6em;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(16, 35, 58, 0.25);
  font-size: min(4.2dvh, 36px, calc(88cqw / var(--n)));
  font-weight: 800;
  line-height: 1.5;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow: hidden;
}
#app.mode-pokebell #word-input { background: rgba(28, 42, 16, 0.1); border-color: rgba(28, 42, 16, 0.4); letter-spacing: 0.04em; }
#word-input .pend {
  display: inline-block;
  min-width: 1em;
  padding: 0 2px;
  text-align: center;
  background: var(--lcd-ink);
  color: var(--lcd-bg);
  border-radius: 3px;
}
#word-input .pend.hit { background: var(--lcd-done); }
#word-input .pend.empty { background: transparent; border-bottom: 3px solid var(--lcd-ink); border-radius: 0; animation: blink 0.9s steps(2) infinite; min-width: 0.7em; }
#app.mode-pokebell #word-input .pend.hit { background: var(--lcd-ink); }

#guide { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px; min-height: 24px; font-size: 13px; font-weight: 900; }
#app.guide-off #guide { visibility: hidden; }
#guide .chip {
  padding: 1px 8px;
  border-radius: 999px;
  border: 2px solid var(--lcd-dim);
  color: var(--lcd-dim);
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}
#guide .chip.first { border-color: var(--lcd-accent); background: var(--lcd-accent); color: #fff; }
#app.mode-pokebell #guide .chip.first { color: var(--lcd-bg); }

/* ポケベルの早見表 */
#bell-table {
  flex: none;
  display: grid;
  grid-template-columns: 1.4em repeat(5, 1fr);
  gap: 1px;
  margin: 0 6px 6px;
  font-size: clamp(10px, 1.9dvh, 14px);
  font-weight: 800;
  text-align: center;
  line-height: 1.45;
}
#bell-table .th { color: var(--lcd-dim); font-size: 0.85em; }
#bell-table .td { background: rgba(28, 42, 16, 0.1); border-radius: 2px; }
#bell-table .td.dim { opacity: 0.35; }
#bell-table .lit { background: var(--lcd-ink); color: var(--lcd-bg); border-radius: 3px; }
#bell-table .note { grid-column: 1 / -1; font-size: 0.8em; color: var(--lcd-dim); padding-top: 2px; }
#bell-table .note b { padding: 0 4px; color: var(--lcd-ink); }
#bell-table .note b.lit { color: var(--lcd-bg); }

#banner {
  position: absolute;
  left: 50%;
  top: 62px;
  z-index: 2;
  transform: translateX(-50%);
  padding: 3px 14px;
  border-radius: 999px;
  background: var(--lcd-ink);
  color: var(--lcd-bg);
  font-size: 14px;
  font-weight: 900;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}
#banner.show { animation: banner 0.6s ease-out forwards; }
#banner.tier.show { animation-duration: 0.8s; background: #e0348a; color: #fff; }
#app.mode-pokebell #banner.tier.show { background: var(--lcd-ink); color: var(--lcd-bg); }
#banner.end { top: 42%; font-size: 26px; padding: 8px 22px; }
#banner.end.show { animation: banner-end 1.2s ease-out forwards; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(0.9); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
  75% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -8px) scale(1); }
}
@keyframes banner-end {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  100% { opacity: 1; transform: translate(-50%, 0) scale(1); }
}
#count {
  position: absolute;
  inset: 44px 0 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 96px;
  font-weight: 900;
  color: var(--lcd-ink);
  pointer-events: none;
}
#count.pop { animation: count-pop 0.7s ease-out; }
@keyframes count-pop {
  0% { transform: scale(1.6); opacity: 0; }
  25% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.2; }
}

/* ---------- キー ---------- */
#pad {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
#softrow { display: grid; grid-template-columns: 1fr 52px 1.5fr; gap: 7px; }
.soft, .key {
  position: relative;
  margin: 0;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--key-a), var(--key-b));
  color: var(--key-ink);
  box-shadow: 0 4px 0 var(--key-edge), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  cursor: pointer;
  touch-action: none;
  font-weight: 900;
}
.soft { height: clamp(30px, 5.4dvh, 46px); font-size: 14px; white-space: nowrap; padding: 0 4px; }
#key-next { background: linear-gradient(180deg, #fff3a8, #ffd23f); box-shadow: 0 4px 0 #b98a00, inset 0 1px 0 rgba(255, 255, 255, 0.9); color: #3a2a00; }
#app.mode-pokebell #key-next { display: none; }
#app.mode-pokebell #softrow { grid-template-columns: 1fr 1fr; }
#keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.key {
  height: clamp(34px, 7.8dvh, 66px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 4px;
}
.key b { font-size: clamp(22px, 3.9dvh, 30px); font-weight: 900; line-height: 1; }
.key small { font-size: clamp(12px, 2dvh, 16px); font-weight: 800; opacity: 0.75; white-space: nowrap; }
.key-sym small { font-size: clamp(10px, 1.6dvh, 13px); }
.key[data-k="0"] small { font-size: clamp(10px, 1.6dvh, 13px); }
.key-punct small { letter-spacing: 0.05em; }
#app.mode-pokebell .key { border-radius: 8px; }
#app.mode-pokebell .key small { display: none; }
#app.mode-pokebell .key-sym, .key-off { opacity: 0.4; }
.soft.down, .key.down { transform: translateY(3px); box-shadow: 0 1px 0 var(--key-edge), inset 0 1px 0 rgba(255, 255, 255, 0.9); filter: brightness(0.92); }
.soft.lit, .key.lit {
  background: linear-gradient(180deg, #fffbe0, #ffe14d);
  box-shadow: 0 4px 0 #b98a00, 0 0 0 3px #fff, 0 0 16px 4px rgba(255, 225, 77, 0.9);
  color: #3a2a00;
  z-index: 1;
}
.soft.lit.down, .key.lit.down { box-shadow: 0 1px 0 #b98a00, 0 0 0 3px #fff, 0 0 16px 4px rgba(255, 225, 77, 0.9); }

/* ---------- 背の低い縦画面: すき間をつめて液晶を広く ---------- */
@media (orientation: portrait) and (max-height: 700px) {
  #app { padding-top: 5px; padding-bottom: 5px; }
  #phone { padding: 8px; gap: 6px; border-radius: 22px; }
  #pad, #softrow, #keys { gap: 5px; }
  .key { height: clamp(34px, 7.1dvh, 66px); }
  #status { padding: 2px 8px; }
  #mode-label { display: none; }
  #hud { padding: 2px 10px 0; }
  #hud b { font-size: 16px; }
  #word-area { gap: 2px; padding-bottom: 3px; }
  #guide { min-height: 22px; font-size: 12px; }
  /* ポケベルは早見表が場所をとるので、数字のチップは出さない（表とキーが光る） */
  #app.mode-pokebell.guide-on #guide { display: none; }
  #bell-table { margin-bottom: 3px; line-height: 1.15; }
  #bell-table .note { display: none; }
  #word-input { line-height: 1.35; }
}
@media (orientation: portrait) and (max-height: 520px) {
  #hud { display: none; }
  #bell-table { font-size: 9px; line-height: 1.25; }
}

/* ---------- 横長・背の低い画面: 液晶を左、キーを右に ---------- */
@media (orientation: landscape) and (max-height: 560px) {
  #phone { flex-direction: row; max-width: 980px; padding: 8px; border-radius: 20px; }
  #lcd { flex: 1 1 0; }
  #pad { flex: 0 0 46%; }
  #keys { flex: 1 1 0; min-height: 0; grid-auto-rows: 1fr; }
  .key { height: auto; min-height: 0; }
  .soft { height: clamp(28px, 11dvh, 40px); }
  #count { font-size: 64px; }
}

/* ---------- オーバーレイ（body 直下。広告の上に収める） ---------- */
.overlay {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(13, 9, 38, 0.72);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#title-overlay { background: rgba(13, 9, 38, 0.82); }
#pause-overlay { background: rgba(13, 9, 38, 0.94); }
.overlay-box {
  position: relative;
  width: min(400px, 100%);
  margin: auto;
  padding: 20px 18px 16px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 16px 44px rgba(4, 3, 16, 0.6);
  text-align: center;
}
#title-box { border-top: 6px solid var(--pink); }
.overlay-title { margin: 0 0 10px; font-size: 22px; font-weight: 900; }
.overlay-text { margin: 0 0 14px; font-size: 14px; color: var(--snow-dim); }

#title-head { margin-bottom: 12px; }
#logo-kicker {
  display: inline-block;
  margin: 0 0 6px;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(255, 216, 74, 0.18);
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
}
#logo {
  margin: 0;
  font-size: clamp(30px, 10.5vw, 44px);
  font-weight: 900;
  font-style: italic;
  line-height: 1.12;
  letter-spacing: 0.02em;
  color: #fff;
  text-shadow: 0 4px 0 #e0348a, 0 0 22px rgba(255, 110, 190, 0.6);
}
#logo span { display: block; font-size: 0.72em; color: var(--cyan); text-shadow: 0 3px 0 #2a55c8; }
#logo-en { margin: 8px 0 0; font-size: 11px; font-weight: 900; letter-spacing: 0.3em; color: var(--gold); padding-left: 0.3em; }

#mode-select { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px 9px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  color: var(--snow-dim);
  cursor: pointer;
}
.mode-btn .mode-ico { font-size: 26px; line-height: 1.1; }
.mode-btn b { font-size: 14px; font-weight: 900; color: #fff; white-space: nowrap; }
.mode-btn small { font-size: 10.5px; font-weight: 700; line-height: 1.35; }
.mode-btn.on { border-color: var(--pink); background: rgba(255, 143, 196, 0.2); box-shadow: 0 0 0 2px rgba(255, 143, 196, 0.35); }
.mode-btn[data-mode="pokebell"].on { border-color: var(--green); background: rgba(134, 240, 176, 0.16); box-shadow: 0 0 0 2px rgba(134, 240, 176, 0.3); }

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0 0 10px;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  color: var(--snow);
  font-size: 13px;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}
.toggle-knob { position: relative; flex: none; width: 38px; height: 22px; border-radius: 999px; background: #5a5388; transition: background 0.15s; }
.toggle-knob::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.toggle.on .toggle-knob { background: #12a36a; }
.toggle.on .toggle-knob::after { transform: translateX(16px); }
.toggle:not(.on) #guide-label { color: var(--gold); }

#title-best { margin: 0 0 10px; font-size: 14px; font-weight: 800; color: var(--snow-dim); }
#title-best b { font-size: 20px; color: var(--gold); font-variant-numeric: tabular-nums; }

.btn {
  display: block;
  width: 100%;
  margin: 0 0 8px;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  font-family: inherit;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.08s;
}
.btn:active { transform: translateY(2px); }
.btn-primary {
  background: linear-gradient(180deg, #ffe98c, var(--gold));
  color: var(--ink);
  border-color: #fff3bf;
  box-shadow: 0 4px 0 #b88a00;
}
.btn-primary:active { box-shadow: 0 2px 0 #b88a00; }
.btn-sub { background: rgba(255, 255, 255, 0.1); color: var(--snow); font-size: 14px; padding: 11px 10px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }
.icon-btn { display: none; }

.howto-lead { margin: 0 0 6px; font-size: 13.5px; color: var(--snow-dim); }
.howto-lead b { color: #fff; }
.howto-h { margin: 10px 0 2px; font-size: 14px; font-weight: 900; text-align: left; color: #fff; }
.howto {
  margin: 4px 0 8px;
  padding: 0 0 0 1.4em;
  text-align: left;
  font-size: 13px;
  line-height: 1.6;
  color: var(--snow-dim);
}
.howto li { margin-bottom: 5px; }
.howto b { color: #fff; }
.howto .c-gold { color: var(--gold); }
.howto .c-pink { color: var(--pink); }
#howto-box { width: min(480px, 100%); }
#howto-box .btn { margin-top: 8px; }

#footer { margin-top: 6px; font-size: 11px; line-height: 1.6; color: rgba(207, 201, 238, 0.85); }
#footer a { color: inherit; }

/* ---------- 結果 ---------- */
#result-mode { font-size: 12px; font-weight: 800; color: var(--snow-dim); margin-bottom: 4px; }
#result-rank-name { font-size: 17px; font-weight: 900; color: var(--cyan); letter-spacing: 0.06em; }
#result-score { font-size: 60px; font-weight: 900; line-height: 1.1; color: var(--gold); font-variant-numeric: tabular-nums; }
#result-score small { font-size: 22px; margin-left: 4px; }
#result-new { margin: 2px 0 8px; font-size: 15px; font-weight: 900; color: var(--green); animation: pop-in 0.5s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes pop-in { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#result-list { list-style: none; margin: 10px 0 14px; padding: 0; display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
#result-list li { grid-column: span 2; padding: 8px 4px; border-radius: 10px; background: rgba(255, 255, 255, 0.08); display: flex; flex-direction: column; gap: 2px; }
#result-list li:nth-child(n+4) { grid-column: span 3; }
#result-list span { font-size: 11px; color: var(--snow-dim); font-weight: 700; }
#result-list b { font-size: 18px; font-weight: 900; font-variant-numeric: tabular-nums; }

@media (max-height: 640px) {
  .overlay-box { padding: 14px 14px 12px; }
  #title-head { margin-bottom: 8px; }
  #logo { font-size: 30px; }
  #logo-en { display: none; }
  .mode-btn { padding: 7px 4px 6px; }
  .mode-btn .mode-ico { font-size: 20px; }
  #result-score { font-size: 46px; }
  .btn { padding: 10px 12px; }
}
@media (max-height: 460px) {
  #logo-kicker { display: none; }
  #logo { font-size: 24px; }
  #logo span { display: inline; font-size: 1em; }
  .mode-btn small { display: none; }
  .btn { padding: 8px 12px; margin-bottom: 6px; }
  .howto { font-size: 12px; line-height: 1.45; }
}
@media (prefers-reduced-motion: reduce) {
  #lcd.shake, #banner.show, #count.pop, #result-new { animation-duration: 0.01s; }
}

/* ---------- 全国ランキング（SGRanking 共通モジュール） ---------- */
.sgr-hidden { display: none !important; }

.sgr-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(6, 9, 20, 0.78);
}
.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #1b2444;
  color: var(--snow);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px 16px;
  box-shadow: 0 16px 44px rgba(6, 12, 36, 0.6);
}
.sgr-title { margin: 0; font-size: 20px; font-weight: 900; text-align: center; }
.sgr-tabs { display: flex; gap: 6px; justify-content: center; }
.sgr-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.08);
  color: var(--snow);
  cursor: pointer;
}
.sgr-tab-active { background: var(--gold); color: var(--ink); }
.sgr-register-msg { margin: 0 0 6px; font-size: 14px; font-weight: 800; color: var(--gold); text-align: center; }
.sgr-form { display: flex; gap: 8px; }
.sgr-name {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 16px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  -webkit-user-select: text;
  user-select: text;
}
.sgr-name:focus { outline: 3px solid var(--cyan); outline-offset: 0; }
.sgr-submit {
  border: 1px solid #fff3bf;
  border-radius: 10px;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  background: var(--gold);
  color: var(--ink);
  cursor: pointer;
}
.sgr-submit:disabled { opacity: 0.5; cursor: default; }
.sgr-error { margin: 4px 0 0; font-size: 12px; font-weight: 700; color: #ff9aa2; }
.sgr-status { margin: 0; font-size: 13px; color: var(--snow-dim); text-align: center; }
.sgr-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  border-top: 1px solid var(--line);
}
.sgr-row { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; font-size: 14px; }
.sgr-row:nth-child(even) { background: rgba(255, 255, 255, 0.06); }
.sgr-row.sgr-row-me { background: var(--gold); color: var(--ink); font-weight: 800; }
.sgr-rank { width: 2em; text-align: right; font-weight: 900; flex-shrink: 0; }
.sgr-row-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sgr-row-score { font-weight: 900; color: var(--gold); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.sgr-row.sgr-row-me .sgr-row-score { color: var(--ink); }
.sgr-close {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.1);
  color: var(--snow);
  cursor: pointer;
}
.sgr-cta { margin: 0 0 12px; text-align: center; }
.sgr-cta-msg { margin: 0 0 6px; font-size: 14px; font-weight: 900; color: var(--green); }
.sgr-cta-btn {
  border: 1px solid #fff3bf;
  border-radius: 12px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 900;
  background: var(--gold);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 #b88a00;
}
.sgr-cta-link {
  border: none;
  background: none;
  color: var(--cyan);
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  text-decoration: underline;
  cursor: pointer;
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / js/ad-banner.js が挿入する）
   --ad-h    : 広告そのものの高さ。広告なしのときは 0px
   --ad-space: レイアウトが空けるべき高さ（広告 + セーフエリア）
   ========================================================================== */
:root {
  --ad-h: 0px;
  --ad-space: 0px;
}
html.has-ad-banner {
  --ad-space: calc(var(--ad-h, 0px) + env(safe-area-inset-bottom, 0px));
}

.ad-banner {
  /* height は広告そのものの高さ。セーフエリアぶんの padding は外側に足す */
  box-sizing: content-box;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  /* ランキング・リザルト等の全画面オーバーレイ（2147483000）よりは下に置く */
  z-index: 2147482000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: var(--ad-h, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow: hidden;
  background: rgba(14, 16, 20, 0.86);
  /* border ではなく inset shadow にして、枠線ぶん高さがずれないようにする */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.ad-banner__frame {
  display: block;
  width: 100%;
  height: var(--ad-h, 0px);
  border: 0;
  color-scheme: light;
}

@media print {
  .ad-banner { display: none; }
}
