:root {
  --ink: #25211d;
  --paper: #fff4df;
  --cream: #fff9ec;
  --accent: #e9463f;
  --gold: #ffd86b;
  --blue: #67b7dc;
  --green: #83c768;
  --purple: #a88be6;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 10% 0%, #ffe7a8, transparent 24rem), linear-gradient(180deg, #fff7de, #ffe6d8);
}
.app { width: min(1080px, calc(100% - 24px)); margin: 0 auto; padding: 28px 0 60px; }
.hero { text-align: center; }
.eyebrow { font-weight: 800; letter-spacing: .2em; }
h1 {
  margin: 0;
  font-size: clamp(42px, 8.8vw, 96px);
  line-height: .9;
  letter-spacing: -.04em;
  text-shadow: 4px 4px 0 #fff, 7px 7px 0 rgba(0,0,0,.16);
}
.panel { background: rgba(255,255,255,.78); border: 3px solid var(--ink); border-radius: 22px; box-shadow: 8px 8px 0 rgba(0,0,0,.14); padding: 20px; }
.setup { margin: 24px auto; max-width: 740px; }
.setup h2 { margin: 0 0 6px; }
.hint, .privacy { color: #685f56; font-size: 14px; }
.genre-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin: 16px 0; }
.genre-list label { display: flex; align-items: center; gap: 8px; border: 2px solid #2a2722; border-radius: 999px; padding: 9px 12px; background: var(--cream); font-weight: 700; cursor: pointer; }
.genre-list input { width: 20px; height: 20px; accent-color: var(--accent); }
.meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 12px; }
.meta-grid label { display: grid; gap: 6px; font-weight: 700; }
select { font: inherit; padding: 10px; border: 2px solid var(--ink); border-radius: 10px; background: #fff; }
button { font: inherit; font-weight: 900; border: 3px solid var(--ink); border-radius: 999px; padding: 11px 18px; background: #fff; color: var(--ink); box-shadow: 4px 4px 0 rgba(0,0,0,.18); cursor: pointer; }
button:active { transform: translate(2px,2px); box-shadow: 2px 2px 0 rgba(0,0,0,.18); }
.primary { display: block; width: min(100%, 360px); margin: 18px auto 0; background: var(--accent); color: #fff; font-size: 22px; }
.card-wrap { display: grid; justify-items: center; gap: 18px; }
.bingo-card { width: min(760px, 100%); background: var(--paper); border: 5px solid var(--ink); border-radius: 28px; padding: 18px; box-shadow: 10px 12px 0 rgba(0,0,0,.18); }
.card-title {
  display: block;
  max-width: calc(100% - 24px);
  text-align: center;
  font-weight: 1000;
  font-size: clamp(20px, 4.2vw, 34px);
  line-height: 1;
  letter-spacing: -.025em;
  margin: 0 auto 12px;
  padding-inline: 8px;
  color: var(--accent);
  text-shadow: 1px 1px 0 #fff, 2px 2px 0 var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}
.letters { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 8px; }
.letters span { aspect-ratio: 1.8 / 1; display: grid; place-items: center; border: 3px solid var(--ink); border-radius: 14px; color: #fff; font-size: clamp(28px, 7vw, 58px); font-weight: 1000; -webkit-text-stroke: 1px var(--ink); }
.letters span:nth-child(1){background:#e9463f}.letters span:nth-child(2){background:#f6a83c}.letters span:nth-child(3){background:#76bf5b}.letters span:nth-child(4){background:#4aa8d8}.letters span:nth-child(5){background:#9a77df}
.board { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.cell { position: relative; aspect-ratio: 1 / 1; overflow: hidden; border: 3px solid var(--ink); border-radius: 16px; background: #fffdf3; display: grid; grid-template-rows: auto 1fr; isolation: isolate; transition: filter .2s ease, transform .2s ease, box-shadow .2s ease; }
.cell .label { z-index: 3; text-align: center; font-weight: 900; font-size: clamp(12px, 2.5vw, 18px); padding: 5px 2px; background: rgba(255,255,255,.82); border-bottom: 2px solid rgba(0,0,0,.18); }
.cell .icon { font-size: clamp(34px, 7vw, 68px); display: grid; place-items: center; transform: rotate(-4deg); }
.cell.closed .icon { filter: grayscale(.25); opacity: .7; }
.cell.shuffle .icon, .cell.shuffle .label { animation: jitter .12s linear infinite; }
.cell.open::after { content: ""; position: absolute; left: 50%; top: 58%; width: 72%; aspect-ratio: 1 / 1; border-radius: 50%; transform: translate(-50%, -50%); background: radial-gradient(circle at 38% 35%, rgba(65,48,39,.78) 0%, rgba(25,18,14,.82) 62%, rgba(5,4,3,.88) 100%); box-shadow: inset 0 6px 13px rgba(0,0,0,.76), 0 0 0 6px #f9edcf, 0 2px 0 9px rgba(37,33,29,.35); z-index: 2; animation: punch .28s cubic-bezier(.1, 1.7, .32, 1); }
.cell.free { background: #fff1a6; }
.cell.free .icon { font-size: clamp(28px, 5.5vw, 56px); font-weight: 1000; color: var(--accent); text-align: center; line-height: 1; }
.cell.bingo { transform: scale(1.03); box-shadow: 0 0 0 5px var(--gold), 0 0 22px 8px rgba(255,216,107,.85); }
.cell.bingo .label { background: var(--gold); color: #111; font-weight: 1000; }
.cell.bingo::after { box-shadow: inset 0 6px 13px rgba(0,0,0,.86), 0 0 0 6px #fff3bd, 0 0 0 11px var(--gold), 0 0 24px 12px rgba(255,216,107,.92); }
.result { width: min(760px, 100%); text-align: center; }
.result-main { font-size: clamp(20px, 5vw, 38px); font-weight: 1000; }
.result-main small { display: block; font-size: .48em; margin-top: 8px; color: #5b5249; }
.share-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 16px; }
@keyframes jitter { 0%{transform:translateX(0)} 50%{transform:translateX(2px)} 100%{transform:translateX(-2px)} }
@keyframes punch { 0%{transform:translate(-50%,-50%) scale(.1); opacity:0} 70%{transform:translate(-50%,-50%) scale(1.12); opacity:1} 100%{transform:translate(-50%,-50%) scale(1)} }
@media (max-width: 640px) { .genre-list { grid-template-columns: 1fr; } .meta-grid { grid-template-columns: 1fr; } .bingo-card { padding: 10px; border-radius: 18px; } .board, .letters { gap: 5px; } .cell { border-width: 2px; border-radius: 10px; } .cell .label { font-size: 11px; } }

@media (max-width: 820px) { .card-title {
  display: block;
  max-width: calc(100% - 24px);
  text-align: center;
  font-weight: 1000;
  font-size: clamp(20px, 4.2vw, 34px);
  line-height: 1;
  letter-spacing: -.025em;
  margin: 0 auto 12px;
  padding-inline: 8px;
  color: var(--accent);
  text-shadow: 1px 1px 0 #fff, 2px 2px 0 var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
} }

/* 108クリック式 */
.board button.cell {
  font: inherit;
  color: inherit;
  padding: 0;
  box-shadow: none;
  border-radius: 16px;
}
.cell.clickable {
  cursor: pointer;
}
.cell.clickable:hover {
  transform: translateY(-2px) scale(1.015);
  box-shadow: 0 0 0 3px rgba(255,216,107,.55), 0 8px 16px rgba(0,0,0,.12);
}
.cell.clickable:active {
  transform: translateY(0) scale(.99);
}
.cell .label {
  font-size: clamp(10px, 1.8vw, 16px);
  min-height: 30px;
  display: grid;
  place-items: center;
  line-height: 1.05;
}
.result-main {
  line-height: 1.15;
}
.bingo-toast {
  position: fixed;
  inset: auto 16px 28px 16px;
  width: min(620px, calc(100% - 32px));
  margin: 0 auto;
  z-index: 9999;
  text-align: center;
  background: #ffd86b;
  color: #241d18;
  border: 5px solid #241d18;
  border-radius: 28px;
  box-shadow: 10px 12px 0 rgba(0,0,0,.22), 0 0 36px rgba(255,216,107,.9);
  padding: 22px 18px;
  animation: bingoPop 1.8s ease both;
}
.bingo-toast div {
  font-size: clamp(42px, 11vw, 96px);
  line-height: .9;
  font-weight: 1000;
  color: #e9463f;
  text-shadow: 3px 3px 0 #fff, 6px 6px 0 #241d18;
  letter-spacing: -.05em;
}
.bingo-toast small {
  display: block;
  margin-top: 10px;
  font-size: 22px;
  font-weight: 900;
}
@keyframes bingoPop {
  0% { transform: translateY(30px) scale(.75); opacity: 0; }
  15% { transform: translateY(0) scale(1.08); opacity: 1; }
  25% { transform: translateY(0) scale(1); opacity: 1; }
  80% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(24px) scale(.95); opacity: 0; }
}
@media (max-width: 640px) {
  .board button.cell { border-radius: 10px; }
  .cell .label { font-size: 10px; }
}

/* 64クリック式 */
.start-screen {
  display: grid;
  place-items: center;
  min-height: 34vh;
}
.start-only {
  width: min(92vw, 460px);
  min-height: 92px;
  font-size: clamp(26px, 6vw, 48px);
  letter-spacing: .02em;
}
.game-screen[hidden] {
  display: none !important;
}
.board button.cell {
  font: inherit;
  color: inherit;
  padding: 0;
  box-shadow: none;
  border-radius: 16px;
}
.cell.clickable {
  cursor: pointer;
}
.cell.clickable:hover {
  transform: translateY(-2px) scale(1.015);
  box-shadow: 0 0 0 3px rgba(255,216,107,.55), 0 8px 16px rgba(0,0,0,.12);
}
.cell.clickable:active {
  transform: translateY(0) scale(.99);
}
.cell .label {
  font-size: clamp(10px, 1.7vw, 15px);
  min-height: 30px;
  display: grid;
  place-items: center;
  line-height: 1.05;
  padding-inline: 3px;
}
.result-main { line-height: 1.15; }
.bingo-toast {
  position: fixed;
  inset: auto 16px 28px 16px;
  width: min(620px, calc(100% - 32px));
  margin: 0 auto;
  z-index: 9999;
  text-align: center;
  background: #ffd86b;
  color: #241d18;
  border: 5px solid #241d18;
  border-radius: 28px;
  box-shadow: 10px 12px 0 rgba(0,0,0,.22), 0 0 36px rgba(255,216,107,.9);
  padding: 22px 18px;
  animation: bingoPop 1.8s ease both;
}
.bingo-toast div {
  font-size: clamp(42px, 11vw, 96px);
  line-height: .9;
  font-weight: 1000;
  color: #e9463f;
  text-shadow: 3px 3px 0 #fff, 6px 6px 0 #241d18;
  letter-spacing: -.05em;
}
.bingo-toast small {
  display: block;
  margin-top: 10px;
  font-size: 22px;
  font-weight: 900;
}
@keyframes bingoPop {
  0% { transform: translateY(30px) scale(.75); opacity: 0; }
  15% { transform: translateY(0) scale(1.08); opacity: 1; }
  25% { transform: translateY(0) scale(1); opacity: 1; }
  80% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(24px) scale(.95); opacity: 0; }
}
@media (max-width: 640px) {
  .board button.cell { border-radius: 10px; }
  .card-title {
  display: block;
  max-width: calc(100% - 24px);
  text-align: center;
  font-weight: 1000;
  font-size: clamp(20px, 4.2vw, 34px);
  line-height: 1;
  letter-spacing: -.025em;
  margin: 0 auto 12px;
  padding-inline: 8px;
  color: var(--accent);
  text-shadow: 1px 1px 0 #fff, 2px 2px 0 var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}
  .cell .label { font-size: 10px; }
}

/* 共有ボタン補足 */
.share-row button {
  min-width: 110px;
}
@media (max-width: 640px) {
  .card-title {
    font-size: clamp(18px, 4.6vw, 28px);
    max-width: calc(100% - 16px);
  }
}

/* モード選択 */
.mode-buttons {
  display: grid;
  gap: 18px;
  width: min(92vw, 520px);
}
.start-only.alt {
  background: #4aa8d8;
}
.card-title {
  font-size: clamp(18px, 3.8vw, 30px) !important;
  max-width: calc(100% - 36px) !important;
}
/* 共有画像はcanvasで別描画。ボタンを少し整理 */
.share-row button {
  min-width: 110px;
}
@media (max-width: 640px) {
  .mode-buttons { gap: 12px; }
  .start-only { min-height: 78px; }
}

/* v2: screen/card cleanup */
.bingo-card .card-title {
  display: none !important;
}
.bingo-card {
  padding-top: 20px;
}
.share-row button .sub {
  display: block;
  font-size: 11px;
  font-weight: 800;
  opacity: .78;
  line-height: 1.1;
}

/* finalfix: 64 only, no duplicated card title */
.bingo-card .card-title {
  display: none !important;
}
.bingo-card {
  width: min(760px, 100%);
  padding: 18px;
  overflow: visible;
}
.letters {
  margin-top: 0 !important;
}
.board button.cell {
  font: inherit;
  color: inherit;
  padding: 0;
  box-shadow: none;
  border-radius: 16px;
}
.cell.clickable { cursor: pointer; }
.cell.clickable:hover {
  transform: translateY(-2px) scale(1.015);
  box-shadow: 0 0 0 3px rgba(255,216,107,.55), 0 8px 16px rgba(0,0,0,.12);
}
.cell.clickable:active {
  transform: translateY(0) scale(.99);
}
.cell .label {
  font-size: clamp(10px, 1.7vw, 15px);
  min-height: 30px;
  display: grid;
  place-items: center;
  line-height: 1.05;
  padding-inline: 3px;
}
.start-screen {
  display: grid;
  place-items: center;
  min-height: 34vh;
}
.start-only {
  width: min(92vw, 460px);
  min-height: 92px;
  font-size: clamp(26px, 6vw, 48px);
  letter-spacing: .02em;
}
.game-screen[hidden] { display: none !important; }
.result-main { line-height: 1.15; }
.share-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}
.share-row button {
  min-width: 0;
  padding: 10px 8px;
  line-height: 1.1;
}
.bingo-toast {
  position: fixed;
  inset: auto 16px 28px 16px;
  width: min(620px, calc(100% - 32px));
  margin: 0 auto;
  z-index: 9999;
  text-align: center;
  background: #ffd86b;
  color: #241d18;
  border: 5px solid #241d18;
  border-radius: 28px;
  box-shadow: 10px 12px 0 rgba(0,0,0,.22), 0 0 36px rgba(255,216,107,.9);
  padding: 22px 18px;
  animation: bingoPop 1.8s ease both;
}
.bingo-toast div {
  font-size: clamp(42px, 11vw, 96px);
  line-height: .9;
  font-weight: 1000;
  color: #e9463f;
  text-shadow: 3px 3px 0 #fff, 6px 6px 0 #241d18;
  letter-spacing: -.05em;
}
.bingo-toast small {
  display: block;
  margin-top: 10px;
  font-size: 22px;
  font-weight: 900;
}
@keyframes bingoPop {
  0% { transform: translateY(30px) scale(.75); opacity: 0; }
  15% { transform: translateY(0) scale(1.08); opacity: 1; }
  25% { transform: translateY(0) scale(1); opacity: 1; }
  80% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(24px) scale(.95); opacity: 0; }
}
@media (max-width: 720px) {
  .share-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .board button.cell { border-radius: 10px; }
  .cell .label { font-size: 10px; }
}


/* finalfix2: keep the BINGO row inside the frame on every viewport */
.bingo-card {
  width: min(760px, 100%);
  padding: 16px !important;
  box-sizing: border-box;
  overflow: hidden !important;
}

.letters {
  display: grid !important;
  grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
  gap: 10px !important;
  width: 100% !important;
  box-sizing: border-box;
  margin: 0 0 10px 0 !important;
}

.letters > span {
  min-width: 0 !important;
  width: 100% !important;
  box-sizing: border-box;
  padding: 8px 0 !important;
  font-size: clamp(28px, 5vw, 56px) !important;
  line-height: 1 !important;
  border-radius: 16px !important;
}

.board {
  width: 100% !important;
  box-sizing: border-box;
  display: grid !important;
  grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
  gap: 8px !important;
}

.cell {
  min-width: 0 !important;
  width: 100% !important;
  box-sizing: border-box;
}

@media (max-width: 640px) {
  .bingo-card {
    padding: 12px !important;
  }
  .letters {
    gap: 8px !important;
  }
  .letters > span {
    font-size: clamp(24px, 7vw, 44px) !important;
    border-radius: 12px !important;
  }
}


/* finalfix3: share guide */
.share-guide {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  width: min(680px, calc(100% - 28px));
  z-index: 10000;
  background: #fffdf3;
  color: #25211d;
  border: 4px solid #25211d;
  border-radius: 22px;
  box-shadow: 10px 12px 0 rgba(0,0,0,.18);
  padding: 18px 52px 18px 18px;
  animation: shareGuidePop .18s ease-out both;
}
.share-guide h3 {
  margin: 0 0 8px;
  font-size: 20px;
}
.share-guide p {
  margin: 0 0 6px;
  line-height: 1.55;
}
.share-guide .mini {
  color: #655d55;
  font-size: 14px;
}
.share-guide kbd {
  border: 2px solid #25211d;
  border-radius: 6px;
  padding: 1px 6px;
  background: #fff;
  font-weight: 900;
}
.share-guide-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border-width: 2px;
  box-shadow: none;
  background: #25211d;
  color: #fff;
}
@keyframes shareGuidePop {
  from { opacity: 0; transform: translate(-50%, 18px) scale(.98); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}
@media (max-width: 640px) {
  .share-guide {
    bottom: 12px;
    padding: 14px 46px 14px 14px;
  }
  .share-guide h3 { font-size: 18px; }
  .share-guide p { font-size: 14px; }
}

/* finalfix4: share entry points */
.share-row {
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
}
#pcShareBtn {
  background: #ffd86b;
}
#mobileShareBtn {
  background: #4aa8d8;
  color: #fff;
}
@media (max-width: 720px) {
  .share-row {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

/* finalfix5: X open button inside PC share guide */
.share-guide-action {
  margin-top: 10px;
  background: #25211d;
  color: #fff;
  box-shadow: 4px 4px 0 rgba(0,0,0,.18);
}
