:root {
  --bg: #fff8e7;
  --ink: #2b2b3a;
  --main: #ff7a3d;
  --main-dark: #e25a1c;
  --sub: #3fa7f5;
  --green: #4cbf6b;
  --card: #ffffff;
  --muted: #7a7a8c;
  --radius: 16px;
  --font: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.8;
}
a { color: var(--sub); }
img { max-width: 100%; }

/* ---------- header / footer ---------- */
.site-header {
  background: linear-gradient(90deg, #ff9a52, #ff6a6a);
  color: #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,.08);
}
.site-header .inner {
  max-width: 1080px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.logo { color: #fff; text-decoration: none; font-weight: 900; font-size: 1.35rem; letter-spacing: .03em; }
.logo span { font-size: .8rem; display: block; font-weight: 700; opacity: .9; line-height: 1.2; }
.site-nav a { color: #fff; text-decoration: none; font-weight: 700; margin-left: 14px; font-size: .95rem; }
.site-nav a:hover { text-decoration: underline; }

.site-footer {
  margin-top: 48px; padding: 24px 16px; background: #2b2b3a; color: #ddd; text-align: center; font-size: .85rem;
}
.site-footer a { color: #fff; margin: 0 8px; }

main { max-width: 1080px; margin: 0 auto; padding: 16px; }

/* ---------- game ---------- */
.game-wrap { position: relative; max-width: 960px; margin: 8px auto 0; }
#game {
  width: 100%; aspect-ratio: 2 / 1; display: block;
  border-radius: var(--radius);
  box-shadow: 0 6px 0 #d9c9a3, 0 10px 24px rgba(0,0,0,.12);
  background: #7fd3ff;
  touch-action: manipulation;
}
.overlay {
  position: absolute; inset: 0; border-radius: var(--radius);
  display: none; align-items: center; justify-content: center; flex-direction: column;
  background: rgba(20, 24, 50, .72); color: #fff; text-align: center; padding: 16px;
}
.overlay.show { display: flex; }
.overlay h1, .overlay h2 { margin: 0 0 6px; line-height: 1.3; text-shadow: 0 3px 0 rgba(0,0,0,.3); }
.overlay h1 { font-size: clamp(1.4rem, 4.2vw, 2.6rem); }
.overlay h2 { font-size: clamp(1.2rem, 3.5vw, 2rem); }
.overlay p { margin: 4px 0; font-size: clamp(.8rem, 1.8vw, 1rem); }
.select-row { display: flex; gap: 8px; margin: 6px 0; flex-wrap: wrap; justify-content: center; }
.select-row .label { align-self: center; font-weight: 700; margin-right: 4px; font-size: .9rem; }
.chip {
  border: 3px solid #fff; background: transparent; color: #fff; font-family: inherit;
  font-weight: 800; font-size: clamp(.8rem, 1.8vw, 1rem);
  padding: 4px 14px; border-radius: 999px; cursor: pointer;
}
.chip.on { background: #fff; color: var(--ink); }
.btn {
  display: inline-block; border: none; cursor: pointer; font-family: inherit; font-weight: 900;
  background: var(--main); color: #fff; font-size: clamp(1rem, 2.4vw, 1.4rem);
  padding: 8px 32px; border-radius: 999px; margin: 8px 6px 0;
  box-shadow: 0 5px 0 var(--main-dark); text-decoration: none;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--main-dark); }
.btn.sub { background: var(--sub); box-shadow: 0 5px 0 #237fc4; }
.btn.x { background: #111; box-shadow: 0 5px 0 #000; font-size: clamp(.8rem, 1.8vw, 1rem); padding: 6px 18px; }
.best { font-size: .85rem; opacity: .9; }
.result-grid {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 20px; max-width: 600px; margin: 6px 0;
  font-size: clamp(.8rem, 1.8vw, 1.05rem);
}
.result-grid b { font-size: 1.25em; color: #ffe066; }
.rank { font-size: clamp(1rem, 2.6vw, 1.5rem); color: #ffe066; font-weight: 900; }
.newrecord { color: #ff6b9d; font-weight: 900; animation: blink .6s infinite alternate; }
@keyframes blink { from { opacity: 1; } to { opacity: .4; } }

.toolbar { max-width: 960px; margin: 10px auto 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .9rem; }
.toolbar button { font-family: inherit; border: 2px solid #ccb98a; background: #fff; border-radius: 999px; padding: 2px 14px; cursor: pointer; font-weight: 700; }

/* on-screen numpad */
.pad-area { display: flex; gap: 24px; justify-content: center; align-items: flex-start; margin: 14px auto 0; max-width: 960px; flex-wrap: wrap; }
.numpad {
  display: grid; grid-template-columns: repeat(4, 58px); grid-template-rows: repeat(5, 52px); gap: 6px;
  background: #3a3a4f; padding: 10px; border-radius: 14px; user-select: none;
}
.numpad button {
  font-family: inherit; font-size: 1.3rem; font-weight: 900; border: none; border-radius: 9px;
  background: #f4f4f8; color: var(--ink); box-shadow: 0 4px 0 #b7b7c6; cursor: pointer; position: relative; padding: 0;
}
.numpad button small { position: absolute; bottom: 1px; left: 0; right: 0; font-size: .55rem; font-weight: 700; color: var(--main-dark); line-height: 1.2; }
.numpad button.dim { background: #c9c9d6; color: #777; }
.numpad button.on, .numpad button:active { transform: translateY(3px); box-shadow: 0 1px 0 #b7b7c6; background: #ffe066; }
.numpad .k-plus { grid-row: span 2; }
.numpad .k-enter { grid-row: span 2; background: var(--main); color: #fff; box-shadow: 0 4px 0 var(--main-dark); font-size: .95rem; }
.numpad .k-zero { grid-column: span 2; }
.pad-help { max-width: 380px; font-size: .9rem; background: var(--card); border-radius: var(--radius); padding: 12px 18px; }
.pad-help kbd { display: inline-block; min-width: 1.8em; text-align: center; background: #f0f0f5; border: 1px solid #ccc; border-bottom-width: 3px; border-radius: 6px; padding: 0 6px; font-family: inherit; font-weight: 800; }
.pad-help ul { margin: 6px 0; padding-left: 1.2em; }

/* ---------- ads ---------- */
.ad-slot { max-width: 970px; margin: 40px auto; text-align: center; min-height: 0; }
.ad-slot .ad-label { font-size: .7rem; color: var(--muted); display: block; }

/* ---------- content / article ---------- */
.content { max-width: 820px; margin: 0 auto; }
.card { background: var(--card); border-radius: var(--radius); padding: 22px 26px; margin: 22px 0; box-shadow: 0 3px 0 #eadfc4; }
.card h2, .article h2 {
  font-size: 1.35rem; margin: 0 0 12px; padding: 4px 0 4px 14px; border-left: 8px solid var(--main); line-height: 1.5;
}
.article h3 { font-size: 1.15rem; margin: 26px 0 8px; border-bottom: 3px dotted #f3c79f; padding-bottom: 2px; }
.article h1 { font-size: clamp(1.4rem, 4vw, 2rem); line-height: 1.45; margin: 10px 0 6px; }
.meta { color: var(--muted); font-size: .85rem; }
.pr-label { display: inline-block; background: #eee; color: #555; font-size: .75rem; padding: 0 8px; border-radius: 4px; margin-right: 6px; }
.toc { background: #fffdf5; border: 2px solid #f3e2b6; border-radius: 12px; padding: 12px 20px; }
.toc ol { margin: 4px 0; }
.point { background: #fff3e6; border-radius: 12px; padding: 12px 18px; margin: 14px 0; }
.point::before { content: "💡 ポイント"; display: block; font-weight: 900; color: var(--main-dark); }
.cta {
  text-align: center; background: linear-gradient(135deg, #ffefd9, #e3f4ff); border-radius: var(--radius); padding: 22px; margin: 28px 0;
}
.product {
  background: var(--card); border: 3px solid #f3e2b6; border-radius: var(--radius); padding: 18px 22px; margin: 18px 0;
}
.product .ptitle { font-size: 1.15rem; font-weight: 900; margin: 0 0 4px; }
.product .tag { display: inline-block; background: var(--green); color: #fff; font-size: .75rem; font-weight: 800; padding: 0 10px; border-radius: 999px; margin-right: 6px; }
.product ul { margin: 6px 0; padding-left: 1.2em; }
.aff-buttons { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.aff { flex: 1 1 180px; text-align: center; text-decoration: none; color: #fff; font-weight: 900; padding: 10px; border-radius: 10px; }
.aff.amazon { background: #ff9900; box-shadow: 0 4px 0 #c77700; }
.aff.rakuten { background: #bf0000; box-shadow: 0 4px 0 #8a0000; }
table.compare { width: 100%; border-collapse: collapse; font-size: .9rem; background: #fff; }
table.compare th, table.compare td { border: 1px solid #e5dcc4; padding: 8px; text-align: center; }
table.compare th { background: #fff3e0; }
.table-scroll { overflow-x: auto; }
.faq dt { font-weight: 900; margin-top: 12px; }
.faq dt::before { content: "Q. "; color: var(--main); }
.faq dd { margin: 4px 0 0 0; }
.faq dd::before { content: "A. "; color: var(--sub); font-weight: 900; }

@media (max-width: 640px) {
  .site-nav a { margin-left: 8px; font-size: .85rem; }
  .numpad { grid-template-columns: repeat(4, 54px); grid-template-rows: repeat(5, 50px); }
  .card { padding: 18px; }
}

/* ---------- name / ranking ---------- */
.overlay { overflow-y: auto; }
.name-row input {
  font-family: inherit; font-size: clamp(.9rem, 2vw, 1.1rem); font-weight: 800; width: 11em;
  border: 3px solid #fff; border-radius: 999px; padding: 3px 14px; text-align: center; color: var(--ink);
}
.name-row input.bad { border-color: #ff6b9d; }
.name-note { font-size: clamp(.7rem, 1.5vw, .85rem) !important; opacity: .9; }
.name-note.err { color: #ffb3c9; font-weight: 800; opacity: 1; }
.r-ranking { font-weight: 800; color: #9ff0b5; font-size: clamp(.8rem, 1.9vw, 1.05rem); min-height: 1.4em; }
.ranking { max-width: 960px; margin: 14px auto 0; background: var(--card); border-radius: var(--radius); padding: 12px 20px; box-shadow: 0 3px 0 #eadfc4; }
.ranking-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.ranking h2 { font-size: 1.15rem; margin: 0; }
.ranking h2 small { font-size: .8rem; color: var(--muted); font-weight: 700; }
.ranking-tabs button { font-family: inherit; font-weight: 800; border: 2px solid var(--main); background: #fff; color: var(--main-dark); border-radius: 999px; padding: 2px 16px; cursor: pointer; margin-left: 4px; }
.ranking-tabs button.on { background: var(--main); color: #fff; }
.ranking-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: .95rem; }
.ranking-table th { background: #fff3e0; font-size: .8rem; padding: 4px 8px; border-bottom: 2px solid #f3c79f; white-space: nowrap; }
.ranking-table td { padding: 5px 8px; border-bottom: 1px solid #f0e6cc; text-align: center; }
.ranking-table tbody tr:nth-child(even) td { background: #fffaf0; }
.ranking-table td.no { width: 4.5em; font-weight: 900; color: var(--muted); }
.ranking-table tr:nth-child(-n+3) td.no { color: var(--main-dark); font-size: 1.1em; }
.ranking-table td.nm { text-align: left; font-weight: 800; max-width: 12em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-table td.sc { text-align: right; font-weight: 900; white-space: nowrap; }
.ranking-table td.st { width: 5em; color: var(--muted); }
.ranking-table tr.me td { background: #fff3c4; }
.ranking-table tr.empty td { color: var(--muted); text-align: center; background: none; padding: 12px 8px; }
.ranking-note { font-size: .75rem; color: var(--muted); margin: 6px 0 0; }
.spec th { width: 34%; white-space: nowrap; } .spec td { text-align: left; }
.ranking-table th:nth-child(2) { text-align: left; } .ranking-table th:nth-child(3) { text-align: right; }

/* ---------- スマホ ---------- */
.numpad button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
/* タッチ端末（スマホ・タブレット）：ゲームのすぐ下にテンキーを出し、1画面に収める */
@media (max-width: 700px), (hover: none) and (pointer: coarse) {
  main { display: flex; flex-direction: column; }
  main > * { order: 9; }
  main > .game-wrap { order: 1; scroll-margin-top: 4px; width: 100%; max-width: min(960px, calc((100vh - 360px) * 2)); max-width: min(960px, calc((100dvh - 360px) * 2)); min-width: min(100%, 520px); }
  main > .pad-area { order: 2; margin-top: 8px; gap: 0; }
  main > .toolbar { order: 3; justify-content: center; }
  main > .ranking { order: 4; }
  .pad-help, .toolbar .tip { display: none; }
  .numpad { width: 100%; max-width: 380px; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(5, clamp(46px, 6.5vh, 60px)); gap: 7px; padding: 8px; }
  .numpad button { font-size: 1.5rem; }
}
@media (max-width: 700px) {
  main { padding: 8px; }
  /* タイトル・ポーズ・結果のときは、キャンバスのかわりにメニューを広く出す */
  .game-wrap.menu #game { display: none; }
  .game-wrap.menu .overlay.show {
    position: relative; inset: auto; min-height: 300px; padding: 18px 12px;
    background: linear-gradient(160deg, #3b4b8f, #22264d); overflow: visible;
  }
  .overlay h1 { font-size: 1.6rem; }
  .overlay p, .chip, .select-row .label { font-size: .9rem; }
  .btn { font-size: 1.15rem; }
  .numpad { grid-template-rows: repeat(5, clamp(48px, 7.5vh, 62px)); }
  .ranking { padding: 10px 12px; }
  .ranking-table { font-size: .88rem; }
  .ranking-table td, .ranking-table th { padding: 4px 5px; }
  .ranking-table td.no { width: 3em; }
}
