/* TFT GW Bingo — parchment + royal styling */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: #1a1228;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(91,42,138,0.35) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(201,161,59,0.18) 0%, transparent 55%),
    linear-gradient(180deg, #1a1228 0%, #0c0818 100%);
  background-attachment: fixed;
  min-height: 100vh;
  font-family: "Shippori Mincho", "Noto Serif JP", "Hiragino Mincho ProN", serif;
  color: #2a1a44;
  -webkit-font-smoothing: antialiased;
}

.page {
  min-height: 100vh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px;
  font-family: var(--font);
  color: var(--ink);
  overflow: hidden;
}

/* Frame around the parchment.
   Height budget: 100vh - 56px(header) - 32px(page-pad) - 66px(fixed bottom bar + margin)
   Card aspect 1080:1350 (4:5), so width = height * 0.8
   --card-scale lets the user shrink/grow interactively. */
.frame-outer {
  width: min(
    calc((100vh - 154px) * 0.8 * var(--card-scale, 1.0)),
    calc(100vw - 32px),
    1080px
  );
  aspect-ratio: 1080 / 1350;
  position: relative;
  filter: drop-shadow(0 30px 80px rgba(0,0,0,0.55))
          drop-shadow(0 8px 24px rgba(91,42,138,0.35));
  flex: 0 0 auto;
  transition: width 0.25s ease;
}

.frame-outer .card { flex: 0 0 auto; }

/* ── X share button (inline — sits in footer next to "やり直す") ─────── */
.x-share-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid #000;
  border-radius: 999px;
  background: #000;
  color: #fff;
  font-family: "Zen Kaku Gothic New", "Noto Sans JP", system-ui, sans-serif;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .15s ease, box-shadow .2s ease, background .2s ease, border-color .2s;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.1),
    0 2px 6px rgba(0,0,0,0.3);
  flex-shrink: 0;
}
.x-share-btn:hover {
  background: #1a1a1a;
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.15),
    0 4px 12px rgba(0,0,0,0.4),
    0 0 14px rgba(201,161,59,0.35);
}
.x-share-btn:active { transform: translateY(0); }
.x-share-btn:disabled { opacity: 0.6; cursor: wait; }
.x-share-btn svg { display: block; }

.x-share-error {
  margin-top: 8px;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(180, 30, 30, 0.92);
  color: #fff;
  font-family: "Zen Kaku Gothic New", "Noto Sans JP", system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  max-width: 480px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}

.x-share-hint {
  margin-top: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(30, 120, 50, 0.92);
  color: #fff;
  font-family: "Zen Kaku Gothic New", "Noto Sans JP", system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  max-width: 520px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
  animation: hint-fade-in 0.3s ease;
}
@keyframes hint-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  padding: 40px 40px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  isolation: isolate;
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,0.18),
    inset 0 0 0 4px var(--accent),
    inset 0 0 0 5px rgba(0,0,0,0.25),
    inset 0 0 80px rgba(122, 90, 42, 0.35),
    inset 0 0 220px rgba(122, 90, 42, 0.25);
}

/* ── Parchment textures ─────────────────────────────────────────────────── */
.parchment-grain {
  position: absolute; inset: 0; pointer-events: none; z-index: 0;
  opacity: 0.55;
  mix-blend-mode: multiply;
  background-image:
    repeating-radial-gradient(circle at 20% 30%, rgba(122,90,42,0.06) 0 1px, transparent 1px 4px),
    repeating-radial-gradient(circle at 70% 70%, rgba(122,90,42,0.05) 0 1px, transparent 1px 5px),
    repeating-linear-gradient(45deg, rgba(122,90,42,0.025) 0 2px, transparent 2px 6px);
}
.parchment-stains {
  position: absolute; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(ellipse 220px 160px at 12% 18%, rgba(122,80,30,0.18) 0%, transparent 70%),
    radial-gradient(ellipse 280px 200px at 88% 72%, rgba(122,80,30,0.16) 0%, transparent 70%),
    radial-gradient(ellipse 160px 120px at 50% 95%, rgba(122,80,30,0.14) 0%, transparent 70%),
    radial-gradient(ellipse 120px 80px at 30% 60%, rgba(180,140,60,0.10) 0%, transparent 70%);
  mix-blend-mode: multiply;
}

/* ── Corners ────────────────────────────────────────────────────────────── */
.corner {
  position: absolute;
  width: 72px;
  height: 72px;
  color: var(--accent);
  z-index: 2;
  opacity: 0.92;
}
.corner-tl { top: 18px; left: 18px; }
.corner-tr { top: 18px; right: 18px; transform: scaleX(-1); }
.corner-bl { bottom: 18px; left: 18px; transform: scaleY(-1); }
.corner-br { bottom: 18px; right: 18px; transform: scale(-1, -1); }

/* ── Header ─────────────────────────────────────────────────────────────── */
.card-hd {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 0;
  min-width: 0;
}
.hd-text { min-width: 0; }
.hd-flourish { color: var(--accent); display: flex; align-items: center; }
.hd-flourish-l { justify-content: flex-end; }
.hd-flourish-r { justify-content: flex-start; }
.hd-flourish .flourish { width: 100%; max-width: 120px; height: 28px; }
.hd-flourish .flip { transform: scaleX(-1); }

.hd-text { text-align: center; }
.hd-eyebrow {
  font-family: "Cinzel", "Shippori Mincho", serif;
  font-size: 12px;
  letter-spacing: 0.32em;
  color: var(--accent);
  text-transform: uppercase;
  font-weight: 600;
}
.hd-title {
  margin: 6px 0 4px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.0;
  color: var(--ink);
  text-shadow:
    0 1px 0 rgba(255,255,255,0.4),
    0 2px 6px rgba(122,90,42,0.25);
}
.title-line { display: block; }
.title-line-1 {
  font-size: 20px;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--accent2);
  white-space: nowrap;
}
.title-line-2 {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: linear-gradient(180deg,
    color-mix(in oklab, var(--accent) 30%, var(--ink)) 0%,
    var(--accent2) 45%,
    color-mix(in oklab, var(--accent2) 60%, #000) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 1px rgba(0,0,0,0.08);
  display: inline-block;
  padding: 0 4px;
  white-space: nowrap;
}
.title-line-2 em {
  font-style: normal;
  background: linear-gradient(180deg, #f0d97a 0%, var(--accent) 50%, #8a6a20 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 1px rgba(0,0,0,0.12);
  padding: 0 8px;
}
.hd-sub {
  margin-top: 6px;
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--ink-soft);
  font-weight: 500;
}

/* ── Divider ────────────────────────────────────────────────────────────── */
.hd-divider {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 8px;
  margin: 0;
  color: var(--accent);
}
.hd-divider .rule {
  flex: 1;
  height: 2px;
  background: linear-gradient(90deg, transparent, currentColor, transparent);
  opacity: 0.7;
}
.hd-divider .diamond {
  width: 8px; height: 8px;
  background: currentColor;
  transform: rotate(45deg);
  flex-shrink: 0;
}
.hd-divider .center-diamond {
  width: 14px; height: 14px;
  box-shadow: 0 0 0 3px rgba(0,0,0,0.0), 0 0 0 4px rgba(255,255,255,0.18);
}

/* ── Grid ───────────────────────────────────────────────────────────────── */
.grid {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-auto-rows: 1fr;
  gap: 8px;
  flex: 0 0 auto;
  aspect-ratio: 1 / 1;
}

/* Cell base */
.cell {
  position: relative;
  appearance: none;
  border: 1px solid var(--cell-border);
  border-radius: 6px;
  background: var(--cell-bg);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.5),
    inset 0 1px 0 rgba(255,255,255,0.4),
    inset 0 -8px 18px rgba(122,90,42,0.08),
    0 1px 0 rgba(255,255,255,0.3);
  padding: 14px 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .2s ease, background .25s ease;
  font-family: inherit;
  color: var(--ink);
  overflow: hidden;
  aspect-ratio: 1 / 1;
  min-width: 0;
}
.cell:hover {
  transform: translateY(-1px);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.6),
    inset 0 1px 0 rgba(255,255,255,0.5),
    0 4px 14px rgba(91,42,138,0.18),
    0 0 0 1px var(--accent);
}
.cell:active { transform: translateY(0); }
.cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cell-corner {
  position: absolute;
  font-size: 8px;
  color: var(--accent);
  opacity: 0.55;
  line-height: 1;
}
.cell-corner-tl { top: 4px; left: 5px; }
.cell-corner-br { bottom: 4px; right: 5px; }

.cell-num {
  position: absolute;
  top: 5px; right: 7px;
  font-family: "Cinzel", "Shippori Mincho", serif;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--accent);
  opacity: 0.7;
}

.cell-text {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.28;
  letter-spacing: 0.005em;
  color: var(--ink);
  text-wrap: balance;
  word-break: keep-all;
  overflow-wrap: anywhere;
  hyphens: none;
  max-width: 100%;
}

/* Center cell distinction (subtle, since user picked "same as others") */
.cell.is-center .cell-text {
  font-style: italic;
  color: var(--accent2);
}

/* ── Editable cells (center + free cell 25) ─────────────────────────────── */
.cell-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: rgba(255,248,224,0.94);
  border: none;
  outline: 2px solid var(--accent);
  border-radius: 6px;
  padding: 16px 8px 8px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.28;
  color: var(--ink);
  text-align: center;
  resize: none;
  cursor: text;
  z-index: 10;
}

.cell-edit {
  position: absolute;
  bottom: 4px;
  left: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(201,161,59,0.18);
  color: var(--accent);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 5;
}
.cell.is-editable:hover .cell-edit { opacity: 0.85; }
.cell.is-editable .cell-edit:hover { opacity: 1; background: rgba(201,161,59,0.32); }

/* Stamp overlay */
.cell-stamp {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: stamp-in 0.45s cubic-bezier(.2, 1.5, .4, 1);
}
.stamp-svg {
  width: 78%; height: 78%;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.35))
          drop-shadow(0 0 8px var(--bingo-glow));
}
@keyframes stamp-in {
  0% { transform: scale(2.5) rotate(-18deg); opacity: 0; }
  60% { transform: scale(0.85) rotate(-6deg); opacity: 1; }
  100% { transform: scale(1) rotate(-4deg); opacity: 1; }
}

/* Stamped state — fade the text behind the stamp */
.cell.is-stamped .cell-text { opacity: 0.32; }
.cell.is-stamped {
  background: color-mix(in oklab, var(--cell-bg) 60%, var(--accent) 8%);
}

/* Pulse on click */
.cell.is-pulse::after {
  content: "";
  position: absolute; inset: -1px;
  border-radius: 6px;
  border: 2px solid var(--accent);
  animation: pulse 0.6s ease-out;
  pointer-events: none;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 var(--bingo-glow); opacity: 1; }
  100% { box-shadow: 0 0 0 14px transparent; opacity: 0; }
}

/* Winning line highlight */
.cell.is-winner {
  background:
    linear-gradient(135deg,
      color-mix(in oklab, var(--bingo) 18%, var(--cell-bg)) 0%,
      color-mix(in oklab, var(--bingo) 32%, var(--cell-bg)) 100%);
  border-color: var(--bingo);
  box-shadow:
    inset 0 0 0 1px var(--bingo),
    inset 0 0 24px var(--bingo-glow),
    0 0 16px var(--bingo-glow);
  animation: winner-glow 1.6s ease-in-out infinite alternate;
}
@keyframes winner-glow {
  0%   { box-shadow: inset 0 0 0 1px var(--bingo), inset 0 0 18px var(--bingo-glow), 0 0 8px var(--bingo-glow); }
  100% { box-shadow: inset 0 0 0 1px var(--bingo), inset 0 0 30px var(--bingo-glow), 0 0 22px var(--bingo-glow); }
}
.cell.is-winner .cell-text { color: var(--ink); opacity: 0.55; }
.cell.is-winner .cell-corner,
.cell.is-winner .cell-num { color: var(--bingo); opacity: 1; }

/* ── Footer ─────────────────────────────────────────────────────────────── */
.card-ft {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
}
.ft-stat { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.ft-stat-num {
  font-family: "Cinzel", "Shippori Mincho", serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.ft-stat-den { font-size: 16px; color: var(--ink-soft); font-weight: 500; }
.ft-stat-zero { font-size: 28px; color: var(--ink-soft); }
.ft-stat-lbl {
  font-size: 11px;
  letter-spacing: 0.24em;
  color: var(--ink-soft);
  text-transform: uppercase;
  font-weight: 600;
}
.ft-divider {
  width: 1px;
  height: 38px;
  background: linear-gradient(180deg, transparent, var(--accent), transparent);
  opacity: 0.6;
}
.bingo-badge {
  display: inline-block;
  padding: 5px 14px;
  font-family: "Cinzel", "Shippori Mincho", serif;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--accent);
  background: linear-gradient(180deg,
    color-mix(in oklab, var(--accent2) 80%, #000) 0%,
    var(--accent2) 100%);
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.18),
    0 0 14px var(--bingo-glow);
  animation: badge-pulse 1.4s ease-in-out infinite alternate;
}
@keyframes badge-pulse {
  from { box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 0 8px var(--bingo-glow); }
  to   { box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 0 22px var(--bingo-glow); }
}

.ft-stat-action {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

/* ── Page-level actions — fixed bottom bar, always visible, draggable ───── */
.page-actions {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  background: rgba(10, 4, 24, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(201,161,59,0.2);
  border-radius: 999px;
  padding: 6px 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.page-actions.is-dragging {
  box-shadow: 0 8px 40px rgba(0,0,0,0.6), 0 0 0 1px rgba(201,161,59,0.4);
  border-color: rgba(201,161,59,0.45);
}

.bar-grip {
  font-size: 14px;
  color: rgba(201,161,59,0.4);
  line-height: 1;
  padding-right: 2px;
  cursor: grab;
}

.size-btn-group {
  display: flex;
  gap: 2px;
  align-items: center;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(201,161,59,0.25);
  border-radius: 999px;
  padding: 2px;
}
.size-btn {
  appearance: none;
  padding: 4px 11px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: rgba(201,161,59,0.65);
  font-family: "Zen Kaku Gothic New", system-ui, sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.size-btn:hover { background: rgba(201,161,59,0.12); color: rgba(201,161,59,0.9); }
.size-btn.active {
  background: rgba(201,161,59,0.2);
  color: #e6c258;
}

.page-sep {
  width: 1px;
  height: 18px;
  background: rgba(201,161,59,0.2);
}

.save-img-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  border: 1px solid rgba(201,161,59,0.5);
  border-radius: 999px;
  background: transparent;
  color: rgba(201,161,59,0.85);
  font-family: "Zen Kaku Gothic New", "Noto Sans JP", system-ui, sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  cursor: pointer;
  white-space: nowrap;
  transition: background .2s, color .2s, border-color .2s;
}
.save-img-btn:hover { background: rgba(201,161,59,0.12); border-color: #c9a13b; color: #e6c258; }
.save-img-btn:disabled { opacity: 0.5; cursor: wait; }

/* ── Share overlay ───────────────────────────────────────────────────────── */
.share-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 4, 24, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: overlay-in 0.2s ease;
}
@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.share-overlay-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px 40px;
  background: rgba(26, 18, 40, 0.96);
  border: 1px solid rgba(201,161,59,0.4);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6), 0 0 0 1px rgba(201,161,59,0.15);
}
.share-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(201,161,59,0.25);
  border-top-color: #c9a13b;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.share-overlay-text {
  font-family: "Zen Kaku Gothic New", "Noto Sans JP", system-ui, sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: rgba(201,161,59,0.9);
}

.reset-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.reset-btn:hover {
  background: var(--accent2);
  color: #fff;
  border-color: var(--accent2);
}
.reset-btn svg { stroke-width: 2; }

.card-sig {
  position: relative; z-index: 1;
  margin-top: 6px;
  text-align: center;
  font-family: "Cinzel", monospace;
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--ink-soft);
  opacity: 0.7;
}
