BLK-115Blocks

Heisei-Era Homepage Skin for an Anniversary Notice — CSS-Only Theme Switch with a Lucky-Number Counter

A toggle above a shop's anniversary notice (name, an anniversary heading, the announcement, one illustration and a sign-up button) that rewrites a single data-era attribute and re-skins the same DOM as a hand-made late-90s/2000s Japanese homepage: polka-dot wallpaper, centred layout, blue underlined links, a scrolling marquee, a blinking NEW! label, a self-drawn 'under construction' SVG banner, 88×31 link-exchange slots and a 'Welcome to <shop>'s homepage' line. The sign-up link stays the same element and URL, turning into a grey outset button with black text (contrast of about 11.5:1). A seven-segment counter shows a sample visitor number on every page load; repdigits, multiples of 1000 and runs like 12345 (about 1 in 20) trigger a 'lucky number — please report it!' message. Enter the shop name, founding year and text to build a 1200×630 PNG with the modern and retro versions side by side, entirely in the browser. The skin is about 70 lines of copy-ready CSS; the marquee uses transform only and stops under prefers-reduced-motion or with the pause button. No real visitor tracking, saving, audio, GIF assets or sending of input.

Preview

BLK-115周年告知の着せ替え

周年告知を平成の手作りHP風にする着せ替え

「平成にする」を押すと、同じ告知に壁紙・流れる文字・キリ番カウンター・相互リンク枠がかかります。店名を入れて、令和と平成を並べた画像を保存できます

いまの表示: 令和

ようこそこもれび手芸教室のHPへ

こもれび手芸教室・創業2011年

祝15周年NEW!

日ごろの感謝をこめて、秋の作品展を開きます。生徒さんの刺しゅう・パッチワーク・編み物など約80点を展示します。 11月28日(土)・29日(日)10:00〜17:00・入場無料


あなたは人目のお客様です

見本の番号です(実際のアクセス数ではありません)

工事中

作品ギャラリーは工事中です。もうしばらくお待ちください

Since 2011© こもれび手芸教室

申込ボタンと作品のリンクは、令和でも平成でも同じリンク先のまま押せます(見本なので移動しません)

令和と平成を並べた画像(1200×630)

画像を用意しています

画像を保存

画像には入力した店名と、いまの見本の番号(当たりなら「キリ番おめでとう」)が入ります

era-skin.css
<div class="era-skin" data-era="heisei">…</div>

/* 平成スキン: 親に data-era="heisei" を付けたときだけ効く(令和側は Tailwind のクラスのまま) */
.era-skin .es-only{display:none}
.era-skin[data-era="heisei"] .es-only{display:block}
.era-skin[data-era="heisei"] .rw-only{display:none}

.era-skin[data-era="heisei"]{
  color:#000;
  font-family:"MS PGothic","Osaka","Hiragino Kaku Gothic ProN","Noto Sans JP",sans-serif;
  background-color:#fff4fa;
  background-image:radial-gradient(#ffc2df 22%,transparent 23%),radial-gradient(#bfe0ff 22%,transparent 23%);
  background-size:28px 28px;
  background-position:0 0,14px 14px;
  text-align:center;
}
.era-skin[data-era="heisei"] .es-page{
  max-width:34rem;margin:0 auto;padding:14px 14px 18px;
  background:#fff;border:6px ridge #ff8fc4;
}
.era-skin[data-era="heisei"] .es-welcome{margin:2px 0 8px;font-size:20px;font-weight:700;color:#000080;line-height:1.5}
.era-skin[data-era="heisei"] .es-welcome b{color:#d6005a}

/* 流れる文字(transform だけで動かす) */
.era-skin[data-era="heisei"] .es-marquee{
  margin:0 -14px 14px;padding:5px 0;overflow:hidden;white-space:nowrap;
  background:#000080;color:#ffff66;font-size:14px;font-weight:700;
}
.es-marquee-in{display:inline-block;padding-left:100%;animation:es-marquee 14s linear infinite}
@keyframes es-marquee{to{transform:translateX(-100%)}}
.era-skin[data-still] .es-marquee-in{animation:none;padding-left:0}

.era-skin[data-era="heisei"] .es-title{
  font-size:40px;line-height:1.25;font-weight:900;letter-spacing:.06em;
  color:#d6005a;text-shadow:3px 3px 0 #ffd400;
}
.era-skin[data-era="heisei"] .es-title .es-new{
  display:inline-block;margin-left:8px;padding:1px 5px;vertical-align:middle;
  font-size:13px;letter-spacing:0;color:#fff;background:#e00000;text-shadow:none;
  animation:es-blink 1s steps(1) infinite;
}
@keyframes es-blink{50%{opacity:0}}
.era-skin[data-still] .es-new{animation:none}

.era-skin[data-era="heisei"] .es-body{display:block;margin-top:10px}
.era-skin[data-era="heisei"] .es-photo{width:200px;margin:0 auto 10px;border:4px ridge #c0c0c0}
.era-skin[data-era="heisei"] .es-text{font-size:15px;line-height:1.8;color:#000}

/* リンクは青い下線、申込ボタンは灰色の立体枠(リンク先は同じ) */
.era-skin[data-era="heisei"] a.es-link{color:#0000ee;text-decoration:underline;text-underline-offset:2px}
.era-skin[data-era="heisei"] a.es-link:visited{color:#551a8b}
.era-skin[data-era="heisei"] .es-cta{
  background:#c0c0c0;color:#000;border:3px outset #f5f5f5;box-shadow:none;letter-spacing:0;
}
.era-skin[data-era="heisei"] .es-cta:hover{background:#d4d4d4}
.era-skin[data-era="heisei"] .es-cta:active{border-style:inset}
.era-skin[data-era="heisei"] .es-cta::before{content:"★";margin-right:6px}
.era-skin[data-era="heisei"] .es-cta::after{content:"★";margin-left:6px}

.era-skin[data-era="heisei"] .es-hr{margin:16px 0;border:0;border-top:4px ridge #ff8fc4}
.era-skin[data-era="heisei"] .es-counter{font-size:15px;line-height:1.7}
.era-skin[data-era="heisei"] .es-note{font-size:14px;color:#444}
.era-skin[data-era="heisei"] .es-kiri{
  display:inline-block;margin-top:6px;padding:4px 10px;
  border:3px double #e00000;background:#ffff99;color:#b00000;font-weight:900;font-size:16px;
}
.era-skin[data-era="heisei"] .es-wip-svg{display:block;max-width:100%;height:auto;margin:14px auto 4px}
.era-skin[data-era="heisei"] .es-links-title{margin-top:14px;font-weight:700;color:#000080}
.era-skin[data-era="heisei"] .es-foot{margin-top:14px;padding-top:0;border:0;font-size:14px;color:#333}

@media (prefers-reduced-motion:reduce){
  .es-marquee-in{animation:none;padding-left:0}
  .era-skin[data-era="heisei"] .es-title .es-new{animation:none}
}

親の data-era を書き換えるだけで切り替わります。平成だけの部品に es-only、令和だけの部品に rw-only を付けます

Share on X

Read the full description

A toggle above a shop's anniversary notice (name, an anniversary heading, the announcement, one illustration and a sign-up button) that rewrites a single data-era attribute and re-skins the same DOM as a hand-made late-90s/2000s Japanese homepage: polka-dot wallpaper, centred layout, blue underlined links, a scrolling marquee, a blinking NEW! label, a self-drawn 'under construction' SVG banner, 88×31 link-exchange slots and a 'Welcome to <shop>'s homepage' line. The sign-up link stays the same element and URL, turning into a grey outset button with black text (contrast of about 11.5:1). A seven-segment counter shows a sample visitor number on every page load; repdigits, multiples of 1000 and runs like 12345 (about 1 in 20) trigger a 'lucky number — please report it!' message. Enter the shop name, founding year and text to build a 1200×630 PNG with the modern and retro versions side by side, entirely in the browser. The skin is about 70 lines of copy-ready CSS; the marquee uses transform only and stops under prefers-reduced-motion or with the pause button. No real visitor tracking, saving, audio, GIF assets or sending of input.

Added:
2026-11-12
Dependencies:
None
tags
#block #theme-switch #skin #data-attribute #css-only #retro #heisei #y2k #anniversary #campaign #marquee #seven-segment #counter #canvas #share-image #reduced-motion #hairline #no-dependency
"use client";

import { useEffect, useId, useRef, useState, useSyncExternalStore, type MouseEvent } from "react";

/**
 * 周年告知を平成の手作りHP風にする着せ替え(キリ番くじ付き)
 *
 * 差別化: theme-switch-reveal は同じ組みのまま配色(明暗)を入れ替える部品。本ブロックは配色ではなく組み方そのもの
 * (中央寄せ・壁紙・流れる文字・カウンター・相互リンク枠)を data-era の CSS だけで差し替え、周年告知という1つの用途で
 * 令和/平成を並べた共有画像まで作る。英字の小見出し・末尾の矢印リンク・角丸・読み込み時の出現アニメは置かない。
 *
 * 汎用技法メモ:
 * 1. **スキンは「同じDOM+属性1つ」**。親に data-era を置き、平成側の CSS は [data-era="heisei"] の子孫セレクタだけで書く。
 *    令和側は Tailwind のクラスのまま。<style> に書いた CSS は @layer の外にあるので、層に入った Tailwind の utilities より
 *    詳細度に関係なく優先される(!important が要らない)。片方の時代だけの要素は es-only/rw-only の2クラスで出し分ける。
 *    es-only の要素は display を CSS 側で決めるため、Tailwind の flex・grid は内側の要素に付ける。
 * 2. **申込ボタンは1つの <a> のまま見た目だけ変える**。平成側は灰色の outset 枠と黒字(コントラスト比 約11.5:1・11:1 超)、
 *    飾りの★は ::before/::after の content で足し、リンク先・フォーカス・押した後の処理は時代で変えない。
 * 3. **流れる文字は transform だけ**。内側を inline-block+padding-left:100% にして translateX(0)→(-100%) で流す。
 *    prefers-reduced-motion: reduce と「流れる文字を止める」(data-still)では animation を外して止めた位置で読ませる。
 * 4. **7セグは1つの座標表から SVG と canvas の両方を描く**。六角形の線分7本を点列で持ち、SVG は polygon、
 *    canvas は同じ点列を fill する。画面と共有画像の数字の形がずれない。
 * 5. **ページを開いたときだけ決まる値は useSyncExternalStore で読む**。サーバーでは null を返し、
 *    ブラウザでは最初の1回だけ乱数を引いて保持する(水和の不一致を起こさない・再描画で番号が変わらない)。
 *
 * 店名・告知文・数字はすべて架空の見本。入力はブラウザの中だけで扱い、送信・保存・アクセス計測はしない。
 */

const AMBER = "#d97706";
const AMBER_DEEP = "#b45309";
const INK = "#1c1917";
const MUTED = "#57534e";
const RULE = "#e7e5e4";

const BASE_YEAR = 2026;
const SHOP = "こもれび手芸教室";
const FOUNDED = "2011";
const NOTICE =
  "日ごろの感謝をこめて、秋の作品展を開きます。生徒さんの刺しゅう・パッチワーク・編み物など約80点を展示します。\n11月28日(土)・29日(日)10:00〜17:00・入場無料";
const APPLY_HREF = "#apply";
const URL_TEXT = "designs.first-ch.com/d/heisei-retro-skin";
const SHOP_MAX = 16;
const NOTICE_MAX = 140;

export type Era = "reiwa" | "heisei";
export type KiriKind = "zorome" | "kiri" | "renban";

/** 「祝○周年」の見出し。創業年が読めない・未来なら ○ のまま、同じ年なら開業 */
export function anniversaryLabel(founded: string, year: number): string {
  const y = Number(founded.trim());
  if (!/^\d{4}$/.test(founded.trim()) || y < year - 300 || y > year) return "祝○周年";
  const n = year - y;
  return n === 0 ? "祝 開業" : `祝${n}周年`;
}

/** キリ番の判定。ゾロ目(777・4444…)、キリのよい数(1000の倍数)、連番(1234・23456…) */
export function kiriKind(n: number): KiriKind | null {
  if (!Number.isInteger(n) || n < 100) return null;
  const s = String(n);
  if (/^(\d)\1+$/.test(s)) return "zorome";
  if (n >= 1000 && n % 1000 === 0) return "kiri";
  if (s.length >= 4 && "1234567890".includes(s)) return "renban";
  return null;
}

/** 当たりの候補(1000〜999999) */
export const KIRI_LIST: number[] = (() => {
  const out = new Set<number>();
  for (let len = 4; len <= 6; len++) for (let d = 1; d <= 9; d++) out.add(Number(String(d).repeat(len)));
  for (let k = 1; k <= 99; k++) out.add(k * 1000);
  for (let len = 4; len <= 6; len++)
    for (let st = 1; st + len <= 10; st++) out.add(Number("1234567890".slice(st - 1, st - 1 + len)));
  return [...out].filter((n) => kiriKind(n) !== null).sort((a, b) => a - b);
})();

/** 見本の番号を1つ引く。当たりは 1/20、外れは当たりにならない数から選ぶ */
export function drawSample(rng: () => number): number {
  if (rng() < 0.05) return KIRI_LIST[Math.floor(rng() * KIRI_LIST.length) % KIRI_LIST.length];
  for (let i = 0; i < 50; i++) {
    const n = 1000 + Math.floor(rng() * 98000);
    if (!kiriKind(n)) return n;
  }
  return 10247;
}

export const KIRI_NAME: Record<KiriKind, string> = { zorome: "ゾロ目", kiri: "キリのよい数", renban: "連番" };

/** 6桁にそろえる */
export const pad6 = (n: number) => String(Math.max(0, Math.min(999999, n))).padStart(6, "0");

/* ---------- 7セグ(SVG と canvas で共有する座標) ---------- */

const SEG_W = 22;
const SEG_H = 40;
const T = 4;
type Pt = [number, number];
const hSeg = (x1: number, x2: number, y: number): Pt[] => [
  [x1, y], [x1 + T / 2, y - T / 2], [x2 - T / 2, y - T / 2], [x2, y], [x2 - T / 2, y + T / 2], [x1 + T / 2, y + T / 2],
];
const vSeg = (x: number, y1: number, y2: number): Pt[] => [
  [x, y1], [x + T / 2, y1 + T / 2], [x + T / 2, y2 - T / 2], [x, y2], [x - T / 2, y2 - T / 2], [x - T / 2, y1 + T / 2],
];
/** a b c d e f g の順 */
const SEGS: Pt[][] = [
  hSeg(4, 18, 3),
  vSeg(19, 4, 19),
  vSeg(19, 21, 36),
  hSeg(4, 18, 37),
  vSeg(3, 21, 36),
  vSeg(3, 4, 19),
  hSeg(4, 18, 20),
];
const DIGIT_ON: Record<string, string> = {
  "0": "abcdef", "1": "bc", "2": "abged", "3": "abgcd", "4": "fgbc",
  "5": "afgcd", "6": "afgedc", "7": "abc", "8": "abcdefg", "9": "abcdfg",
};
const SEG_ON = "#ff3b30";
const SEG_OFF = "#3b0d0b";
const isOn = (digit: string, i: number) => (DIGIT_ON[digit] ?? "").includes("abcdefg"[i]);

function SevenSeg({ text }: { text: string }) {
  return (
    <svg viewBox={`0 0 ${SEG_W * text.length + 8} ${SEG_H + 8}`} className="es-seg block h-11 w-auto" aria-hidden="true">
      <rect width="100%" height="100%" fill="#0c0a09" />
      {Array.from(text).map((ch, d) => (
        <g key={d} transform={`translate(${4 + d * SEG_W} 4)`}>
          {SEGS.map((pts, i) => (
            <polygon key={i} points={pts.map((p) => p.join(",")).join(" ")} fill={isOn(ch, i) ? SEG_ON : SEG_OFF} />
          ))}
        </g>
      ))}
    </svg>
  );
}

/* ---------- 自作の SVG(工事中・刺しゅう枠) ---------- */

function WipBanner() {
  return (
    <svg viewBox="0 0 240 64" width="240" height="64" role="img" aria-label="工事中" className="es-wip-svg">
      <defs>
        <pattern id="es-stripe" width="16" height="16" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
          <rect width="8" height="16" fill="#111" />
          <rect x="8" width="8" height="16" fill="#facc15" />
        </pattern>
      </defs>
      <rect width="240" height="64" fill="#facc15" />
      <rect width="240" height="10" fill="url(#es-stripe)" />
      <rect y="54" width="240" height="10" fill="url(#es-stripe)" />
      {/* コーン */}
      <path d="M30 48 L38 18 L46 48 Z" fill="#f97316" />
      <rect x="33" y="30" width="10" height="4" fill="#fff" />
      <rect x="24" y="46" width="28" height="4" fill="#111" />
      {/* スコップを持つ人 */}
      <circle cx="206" cy="22" r="5" fill="#111" />
      <path d="M206 27 L206 40 M206 31 L198 36 M206 31 L214 30 M206 40 L200 48 M206 40 L212 48" stroke="#111" strokeWidth="2.5" fill="none" strokeLinecap="round" />
      <path d="M214 30 L222 44" stroke="#111" strokeWidth="2" />
      <path d="M219 43 L226 46 L223 50 Z" fill="#111" />
      <text x="124" y="40" textAnchor="middle" fontSize="22" fontWeight="900" fill="#111" letterSpacing="4">工事中</text>
    </svg>
  );
}

function HoopArt({ className = "" }: { className?: string }) {
  const stitches = Array.from({ length: 10 }, (_, i) => {
    const a = (i / 10) * Math.PI * 2;
    return { x: 160 + Math.cos(a) * 48, y: 118 + Math.sin(a) * 48, r: (a * 180) / Math.PI };
  });
  return (
    <svg viewBox="0 0 320 240" role="img" aria-label="刺しゅう枠に糸で花を縫ったイラスト" className={className}>
      <rect width="320" height="240" fill="#fff7ed" />
      <circle cx="160" cy="118" r="92" fill="#fffdf8" stroke="#a16207" strokeWidth="10" />
      <circle cx="160" cy="118" r="80" fill="none" stroke="#ca8a04" strokeWidth="3" />
      <rect x="150" y="16" width="20" height="16" fill="#a16207" />
      {stitches.map((s, i) => (
        <ellipse key={i} cx={s.x} cy={s.y} rx="16" ry="6" transform={`rotate(${s.r} ${s.x} ${s.y})`} fill={i % 2 ? "#f59e0b" : AMBER} />
      ))}
      <circle cx="160" cy="118" r="14" fill="#b91c1c" />
      <path d="M220 186 C 250 170, 270 200, 300 176" stroke="#b91c1c" strokeWidth="3" fill="none" strokeDasharray="7 5" />
      <path d="M232 196 L300 150" stroke="#78716c" strokeWidth="3" strokeLinecap="round" />
      <ellipse cx="297" cy="152" rx="3" ry="1.4" fill="#fff" transform="rotate(-34 297 152)" />
    </svg>
  );
}

/* ---------- スキンの CSS(画面に効かせる本体=コピーされる本体) ---------- */

export const SKIN_CSS = `/* 平成スキン: 親に data-era="heisei" を付けたときだけ効く(令和側は Tailwind のクラスのまま) */
.era-skin .es-only{display:none}
.era-skin[data-era="heisei"] .es-only{display:block}
.era-skin[data-era="heisei"] .rw-only{display:none}

.era-skin[data-era="heisei"]{
  color:#000;
  font-family:"MS PGothic","Osaka","Hiragino Kaku Gothic ProN","Noto Sans JP",sans-serif;
  background-color:#fff4fa;
  background-image:radial-gradient(#ffc2df 22%,transparent 23%),radial-gradient(#bfe0ff 22%,transparent 23%);
  background-size:28px 28px;
  background-position:0 0,14px 14px;
  text-align:center;
}
.era-skin[data-era="heisei"] .es-page{
  max-width:34rem;margin:0 auto;padding:14px 14px 18px;
  background:#fff;border:6px ridge #ff8fc4;
}
.era-skin[data-era="heisei"] .es-welcome{margin:2px 0 8px;font-size:20px;font-weight:700;color:#000080;line-height:1.5}
.era-skin[data-era="heisei"] .es-welcome b{color:#d6005a}

/* 流れる文字(transform だけで動かす) */
.era-skin[data-era="heisei"] .es-marquee{
  margin:0 -14px 14px;padding:5px 0;overflow:hidden;white-space:nowrap;
  background:#000080;color:#ffff66;font-size:14px;font-weight:700;
}
.es-marquee-in{display:inline-block;padding-left:100%;animation:es-marquee 14s linear infinite}
@keyframes es-marquee{to{transform:translateX(-100%)}}
.era-skin[data-still] .es-marquee-in{animation:none;padding-left:0}

.era-skin[data-era="heisei"] .es-title{
  font-size:40px;line-height:1.25;font-weight:900;letter-spacing:.06em;
  color:#d6005a;text-shadow:3px 3px 0 #ffd400;
}
.era-skin[data-era="heisei"] .es-title .es-new{
  display:inline-block;margin-left:8px;padding:1px 5px;vertical-align:middle;
  font-size:13px;letter-spacing:0;color:#fff;background:#e00000;text-shadow:none;
  animation:es-blink 1s steps(1) infinite;
}
@keyframes es-blink{50%{opacity:0}}
.era-skin[data-still] .es-new{animation:none}

.era-skin[data-era="heisei"] .es-body{display:block;margin-top:10px}
.era-skin[data-era="heisei"] .es-photo{width:200px;margin:0 auto 10px;border:4px ridge #c0c0c0}
.era-skin[data-era="heisei"] .es-text{font-size:15px;line-height:1.8;color:#000}

/* リンクは青い下線、申込ボタンは灰色の立体枠(リンク先は同じ) */
.era-skin[data-era="heisei"] a.es-link{color:#0000ee;text-decoration:underline;text-underline-offset:2px}
.era-skin[data-era="heisei"] a.es-link:visited{color:#551a8b}
.era-skin[data-era="heisei"] .es-cta{
  background:#c0c0c0;color:#000;border:3px outset #f5f5f5;box-shadow:none;letter-spacing:0;
}
.era-skin[data-era="heisei"] .es-cta:hover{background:#d4d4d4}
.era-skin[data-era="heisei"] .es-cta:active{border-style:inset}
.era-skin[data-era="heisei"] .es-cta::before{content:"★";margin-right:6px}
.era-skin[data-era="heisei"] .es-cta::after{content:"★";margin-left:6px}

.era-skin[data-era="heisei"] .es-hr{margin:16px 0;border:0;border-top:4px ridge #ff8fc4}
.era-skin[data-era="heisei"] .es-counter{font-size:15px;line-height:1.7}
.era-skin[data-era="heisei"] .es-note{font-size:14px;color:#444}
.era-skin[data-era="heisei"] .es-kiri{
  display:inline-block;margin-top:6px;padding:4px 10px;
  border:3px double #e00000;background:#ffff99;color:#b00000;font-weight:900;font-size:16px;
}
.era-skin[data-era="heisei"] .es-wip-svg{display:block;max-width:100%;height:auto;margin:14px auto 4px}
.era-skin[data-era="heisei"] .es-links-title{margin-top:14px;font-weight:700;color:#000080}
.era-skin[data-era="heisei"] .es-foot{margin-top:14px;padding-top:0;border:0;font-size:14px;color:#333}

@media (prefers-reduced-motion:reduce){
  .es-marquee-in{animation:none;padding-left:0}
  .era-skin[data-era="heisei"] .es-title .es-new{animation:none}
}`;

/* ---------- 共有画像(1200×630・左に令和、右に平成) ---------- */

const W = 1200;
const H = 630;

type Card = { shop: string; title: string; notice: string; founded: string; no: number | null };

/** 和文を1字ずつ測って折り返す */
function wrap(ctx: CanvasRenderingContext2D, text: string, width: number, maxLines: number): string[] {
  const lines: string[] = [];
  for (const para of text.split("\n")) {
    let cur = "";
    for (const ch of Array.from(para)) {
      if (ctx.measureText(cur + ch).width > width && cur) {
        lines.push(cur);
        cur = ch;
      } else cur += ch;
    }
    lines.push(cur);
  }
  if (lines.length > maxLines) {
    const cut = lines.slice(0, maxLines);
    cut[maxLines - 1] = cut[maxLines - 1].slice(0, -1) + "…";
    return cut;
  }
  return lines;
}

function drawSeg(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, scale: number) {
  ctx.fillStyle = "#0c0a09";
  ctx.fillRect(x, y, (SEG_W * text.length + 8) * scale, (SEG_H + 8) * scale);
  Array.from(text).forEach((ch, d) => {
    SEGS.forEach((pts, i) => {
      ctx.beginPath();
      pts.forEach(([px, py], k) => {
        const X = x + (4 + d * SEG_W + px) * scale;
        const Y = y + (4 + py) * scale;
        if (k) ctx.lineTo(X, Y);
        else ctx.moveTo(X, Y);
      });
      ctx.closePath();
      ctx.fillStyle = isOn(ch, i) ? SEG_ON : SEG_OFF;
      ctx.fill();
    });
  });
}

function tag(ctx: CanvasRenderingContext2D, label: string, x: number, y: number, bg: string, fg: string, family: string) {
  ctx.font = `700 20px ${family}`;
  const w = ctx.measureText(label).width + 24;
  ctx.fillStyle = bg;
  ctx.fillRect(x, y, w, 34);
  ctx.fillStyle = fg;
  ctx.textAlign = "left";
  ctx.textBaseline = "middle";
  ctx.fillText(label, x + 12, y + 18);
}

async function renderCompare(c: Card, family: string): Promise<string | null> {
  const sample = [c.shop, c.title, c.notice, "令和平成ようこそのHPへあなたは人目のお客様です見本の番号ですキリ番おめでとう報告してね工事中相互リンク作品展に申し込む", URL_TEXT].join("");
  if (document.fonts) {
    await Promise.all([document.fonts.load(`700 80px ${family}`, sample), document.fonts.load(`500 22px ${family}`, sample)]).catch(() => undefined);
  }
  const cv = document.createElement("canvas");
  cv.width = W;
  cv.height = H;
  const ctx = cv.getContext("2d");
  if (!ctx) return null;

  // 令和(左)
  ctx.fillStyle = "#fff";
  ctx.fillRect(0, 0, W, H);
  tag(ctx, "令和", 48, 40, INK, "#fff", family);
  ctx.textBaseline = "alphabetic";
  ctx.textAlign = "left";
  ctx.fillStyle = MUTED;
  ctx.font = `500 22px ${family}`;
  ctx.fillText(`${c.shop} 創業${c.founded}年`, 48, 130);
  ctx.fillStyle = AMBER;
  ctx.fillRect(48, 148, 40, 3);
  ctx.fillStyle = INK;
  ctx.font = `700 80px ${family}`;
  ctx.fillText(c.title, 44, 240);
  ctx.font = `500 22px ${family}`;
  ctx.fillStyle = "#292524";
  wrap(ctx, c.notice, 330, 6).forEach((l, i) => ctx.fillText(l, 48, 296 + i * 36));
  ctx.fillStyle = AMBER_DEEP;
  ctx.fillRect(48, 500, 250, 54);
  ctx.fillStyle = "#fff";
  ctx.font = `700 22px ${family}`;
  ctx.textAlign = "center";
  ctx.fillText("作品展に申し込む", 173, 535);
  // 刺しゅう枠
  ctx.lineWidth = 8;
  ctx.strokeStyle = "#a16207";
  ctx.beginPath();
  ctx.arc(486, 330, 70, 0, Math.PI * 2);
  ctx.stroke();
  for (let i = 0; i < 10; i++) {
    const a = (i / 10) * Math.PI * 2;
    ctx.save();
    ctx.translate(486 + Math.cos(a) * 36, 330 + Math.sin(a) * 36);
    ctx.rotate(a);
    ctx.fillStyle = i % 2 ? "#f59e0b" : AMBER;
    ctx.beginPath();
    ctx.ellipse(0, 0, 13, 5, 0, 0, Math.PI * 2);
    ctx.fill();
    ctx.restore();
  }
  ctx.fillStyle = "#b91c1c";
  ctx.beginPath();
  ctx.arc(486, 330, 11, 0, Math.PI * 2);
  ctx.fill();

  // 平成(右): 水玉の壁紙
  ctx.fillStyle = "#fff4fa";
  ctx.fillRect(600, 0, 600, 570);
  ctx.save();
  ctx.beginPath();
  ctx.rect(600, 0, 600, 570);
  ctx.clip();
  for (let y = 0; y < 584; y += 28)
    for (let x = 600; x < 1214; x += 28) {
      ctx.fillStyle = "#ffc2df";
      ctx.beginPath();
      ctx.arc(x, y, 6, 0, Math.PI * 2);
      ctx.fill();
      ctx.fillStyle = "#bfe0ff";
      ctx.beginPath();
      ctx.arc(x + 14, y + 14, 6, 0, Math.PI * 2);
      ctx.fill();
    }
  ctx.restore();
  // 枠(ridge 風に2色)
  const bx = 640, by = 30, bw = 520, bh = 520;
  ctx.fillStyle = "#fff";
  ctx.fillRect(bx, by, bw, bh);
  ctx.lineWidth = 4;
  ctx.strokeStyle = "#ffb8da";
  ctx.strokeRect(bx - 4, by - 4, bw + 8, bh + 8);
  ctx.strokeStyle = "#e0609c";
  ctx.strokeRect(bx, by, bw, bh);
  tag(ctx, "平成", 1104 - 20, 40, "#000080", "#ffff66", family);

  const cx = bx + bw / 2;
  ctx.textAlign = "center";
  ctx.textBaseline = "alphabetic";
  ctx.font = `700 26px ${family}`;
  const welcome = `ようこそ${c.shop}のHPへ`;
  ctx.fillStyle = "#000080";
  const ww = Math.min(ctx.measureText(welcome).width, 440);
  ctx.fillText(welcome, cx, 104, 440);
  ctx.fillRect(cx - ww / 2, 110, ww, 2);
  ctx.font = `900 64px ${family}`;
  ctx.fillStyle = "#ffd400";
  ctx.fillText(c.title, cx + 3, 183, 460);
  ctx.fillStyle = "#d6005a";
  ctx.fillText(c.title, cx, 180, 460);
  // 流れる文字の帯
  ctx.fillStyle = "#000080";
  ctx.fillRect(bx, 200, bw, 34);
  ctx.fillStyle = "#ffff66";
  ctx.font = `700 18px ${family}`;
  ctx.textAlign = "left";
  ctx.textBaseline = "middle";
  ctx.save();
  ctx.beginPath();
  ctx.rect(bx, 200, bw, 34);
  ctx.clip();
  ctx.fillText(`★☆ ${c.title}! ${c.notice.replace(/\n/g, " ")} ☆★`, bx + 60, 218);
  ctx.restore();
  // カウンター
  const no = pad6(c.no ?? 0);
  ctx.fillStyle = "#000";
  ctx.font = `500 20px ${family}`;
  ctx.textAlign = "right";
  ctx.fillText("あなたは", cx - 88, 278);
  drawSeg(ctx, no, cx - 76, 254, 1.1);
  ctx.textAlign = "left";
  ctx.fillText("人目のお客様です", cx + 90, 278);
  ctx.fillStyle = "#57534e";
  ctx.font = `500 16px ${family}`;
  ctx.textAlign = "center";
  ctx.fillText("見本の番号です(実際のアクセス数ではありません)", cx, 330);
  const kind = c.no != null ? kiriKind(c.no) : null;
  if (kind) {
    ctx.fillStyle = "#ffff99";
    ctx.fillRect(cx - 210, 344, 420, 42);
    ctx.strokeStyle = "#e00000";
    ctx.lineWidth = 3;
    ctx.strokeRect(cx - 210, 344, 420, 42);
    ctx.fillStyle = "#b00000";
    ctx.font = `900 24px ${family}`;
    ctx.fillText("キリ番おめでとう!報告してね", cx, 366);
  }
  // 工事中
  const wy = 400;
  ctx.fillStyle = "#facc15";
  ctx.fillRect(cx - 120, wy, 240, 60);
  for (let i = -2; i < 34; i++) {
    ctx.fillStyle = "#111";
    ctx.save();
    ctx.beginPath();
    ctx.rect(cx - 120, wy, 240, 60);
    ctx.clip();
    ctx.beginPath();
    for (const [y0, y1] of [[wy, wy + 9], [wy + 51, wy + 60]] as const) {
      ctx.moveTo(cx - 120 + i * 16, y1);
      ctx.lineTo(cx - 120 + i * 16 + 9, y0);
      ctx.lineTo(cx - 120 + i * 16 + 17, y0);
      ctx.lineTo(cx - 120 + i * 16 + 8, y1);
    }
    ctx.fill();
    ctx.restore();
  }
  ctx.fillStyle = "#111";
  ctx.font = `900 26px ${family}`;
  ctx.fillText("工事中", cx, wy + 31);
  // 88×31 の相互リンク枠
  const names = [c.shop.slice(0, 6), "LINK FREE", "募集中"];
  names.forEach((n, i) => {
    const x = cx - 213 + i * 146;
    const y = 482;
    if (i === 0) {
      const g = ctx.createLinearGradient(x, y, x + 132, y);
      g.addColorStop(0, "#ff8fc4");
      g.addColorStop(1, "#8fc4ff");
      ctx.fillStyle = g;
      ctx.fillRect(x, y, 132, 46);
    } else if (i === 1) {
      ctx.fillStyle = "#000080";
      ctx.fillRect(x, y, 132, 46);
    } else {
      ctx.fillStyle = "#fff";
      ctx.fillRect(x, y, 132, 46);
      ctx.setLineDash([6, 4]);
      ctx.strokeStyle = "#555";
      ctx.lineWidth = 2;
      ctx.strokeRect(x + 1, y + 1, 130, 44);
      ctx.setLineDash([]);
    }
    ctx.fillStyle = i === 0 ? "#000" : i === 1 ? "#ffff66" : "#333";
    ctx.font = `700 ${i === 1 ? 18 : 17}px ${family}`;
    ctx.fillText(n, x + 66, y + 24, 120);
  });

  // 下の帯
  ctx.fillStyle = "#fff";
  ctx.fillRect(0, 570, W, 60);
  ctx.fillStyle = RULE;
  ctx.fillRect(0, 570, W, 1);
  ctx.fillStyle = AMBER;
  ctx.fillRect(598, 0, 4, 570);
  ctx.textBaseline = "middle";
  ctx.textAlign = "left";
  ctx.fillStyle = INK;
  ctx.font = `700 20px ${family}`;
  ctx.fillText("周年告知を平成のHPにする着せ替え", 48, 601);
  ctx.textAlign = "right";
  ctx.fillStyle = MUTED;
  ctx.font = `500 18px ${family}`;
  ctx.fillText(URL_TEXT, W - 48, 601);

  const blob = await new Promise<Blob | null>((r) => cv.toBlob(r, "image/png"));
  return blob ? URL.createObjectURL(blob) : null;
}

async function copyText(text: string) {
  try {
    await navigator.clipboard.writeText(text);
    return true;
  } catch {
    const ta = document.createElement("textarea");
    ta.value = text;
    ta.setAttribute("readonly", "");
    ta.style.position = "fixed";
    ta.style.opacity = "0";
    document.body.appendChild(ta);
    ta.focus({ preventScroll: true });
    ta.select();
    const ok = document.execCommand("copy");
    ta.remove();
    return ok;
  }
}

/* ---------- ページを開いたときだけ決まる値 ---------- */

const noop = () => () => {};
let firstNo: number | null = null;
const getFirstNo = () => (firstNo ??= drawSample(Math.random));
const getYear = () => new Date().getFullYear();
const getReduce = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches;

const RELATED = [
  { href: "/d/theme-switch-reveal", title: "ダークモード切り替え", note: "押した位置から円形に配色が広がる" },
  { href: "/d/omikuji-shake-card", title: "縦書きおみくじ", note: "筒を振って引き、紙を画像で保存" },
  { href: "/d/halloween-flashlight-reveal", title: "懐中電灯で隠し文字を探す", note: "暗い画面をなぞって照らす" },
  { href: "/d/before-after-slider", title: "ビフォーアフタースライダー", note: "境目を動かして2枚を見比べる" },
];

const btn =
  "inline-flex min-h-11 items-center justify-center border px-4 text-sm font-bold outline-none transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#d97706] motion-reduce:transition-none";
const field =
  "mt-1.5 block w-full min-h-11 border border-stone-300 bg-white px-3 py-2 text-[16px] text-stone-900 outline-none focus-visible:border-[#d97706] focus-visible:ring-2 focus-visible:ring-[#d97706]/40";

export default function HeiseiRetroSkin() {
  const uid = useId();
  const [era, setEra] = useState<Era>("reiwa");
  const [still, setStill] = useState(false);
  const [shop, setShop] = useState(SHOP);
  const [founded, setFounded] = useState(FOUNDED);
  const [notice, setNotice] = useState(NOTICE);
  const [override, setOverride] = useState<number | null>(null);
  const [live, setLive] = useState("");
  const [log, setLog] = useState("");
  const [image, setImage] = useState<string | null>(null);
  const [copied, setCopied] = useState<"" | "css" | "share">("");
  const stageRef = useRef<HTMLDivElement>(null);
  const familyRef = useRef<HTMLDivElement>(null);
  const imageRef = useRef<string | null>(null);

  const first = useSyncExternalStore(noop, getFirstNo, () => null);
  const year = useSyncExternalStore(noop, getYear, () => BASE_YEAR);
  const no = override ?? first;
  const kind = no != null ? kiriKind(no) : null;
  const shopName = shop.trim() || "わたしのお店";
  const title = anniversaryLabel(founded, year);
  const foundedText = /^\d{4}$/.test(founded.trim()) ? founded.trim() : "○○○○";
  const heisei = era === "heisei";

  // 共有画像は入力が落ち着いてから作り直す
  useEffect(() => {
    let alive = true;
    const t = window.setTimeout(async () => {
      const el = familyRef.current;
      const family = el ? getComputedStyle(el).fontFamily : "sans-serif";
      const url = await renderCompare({ shop: shopName, title, notice: notice.trim(), founded: foundedText, no }, family);
      if (!alive) {
        if (url) URL.revokeObjectURL(url);
        return;
      }
      if (imageRef.current) URL.revokeObjectURL(imageRef.current);
      imageRef.current = url;
      setImage(url);
    }, 220);
    return () => {
      alive = false;
      window.clearTimeout(t);
    };
  }, [shopName, title, notice, foundedText, no]);

  useEffect(() => () => {
    if (imageRef.current) URL.revokeObjectURL(imageRef.current);
  }, []);

  const flash = () => {
    const el = stageRef.current;
    if (!el || getReduce()) return;
    el.animate([{ opacity: 0.35 }, { opacity: 1 }], { duration: 200, easing: "ease-out" });
  };

  const toggle = () => {
    const next: Era = heisei ? "reiwa" : "heisei";
    setEra(next);
    flash();
    setLive(next === "heisei" ? `平成のスキンにしました。見本の番号 ${no != null ? pad6(no) : ""}${kind ? "、キリ番です" : ""}` : "令和の表示に戻しました");
  };

  const reroll = (force: boolean) => {
    const n = force ? KIRI_LIST[Math.floor(Math.random() * KIRI_LIST.length)] : drawSample(Math.random);
    setOverride(n);
    if (!heisei) {
      setEra("heisei");
      flash();
    }
    const k = kiriKind(n);
    setLive(`見本の番号 ${pad6(n)}。${k ? `キリ番おめでとう(${KIRI_NAME[k]})` : "キリ番ではありません"}`);
  };

  const onLink = (e: MouseEvent<HTMLAnchorElement>, what: string) => {
    e.preventDefault();
    const href = e.currentTarget.getAttribute("href");
    setLog(`${heisei ? "平成" : "令和"}の表示で「${what}」を押しました(リンク先 ${href} は時代を替えても同じ)`);
  };

  const doCopy = async (what: "css" | "share") => {
    const text =
      what === "css"
        ? SKIN_CSS
        : `${shopName}のHPを平成にしてみた。${title}${no != null ? `・あなたは ${pad6(no)} 人目${kind ? "(キリ番!)" : ""}` : ""}\n${URL_TEXT}`;
    const ok = await copyText(text);
    if (!ok) return;
    setCopied(what);
    setLive(what === "css" ? "スキンのCSSをコピーしました" : "共有の文をコピーしました");
    window.setTimeout(() => setCopied(""), 1500);
  };

  return (
    <section className="relative mx-auto w-full max-w-6xl border border-stone-200 bg-white text-stone-900" aria-labelledby={`${uid}-title`}>
      <style>{SKIN_CSS}</style>
      <div ref={familyRef} aria-hidden="true" className="hidden font-sans" />

      {/* 見出し(広い画面では右に令和/平成を並べた画像を出し、押す前に変わり方を見せる) */}
      <div className="grid gap-3 px-5 py-4 sm:px-8 sm:py-5 lg:grid-cols-[minmax(0,1fr)_minmax(0,24rem)] lg:items-center lg:gap-10">
        <div>
          <p className="font-display text-xs font-semibold tracking-[0.12em] text-stone-500">
            BLK-115<span className="mx-2 inline-block h-px w-5 bg-stone-300 align-middle" />
            <span className="font-sans tracking-normal">周年告知の着せ替え</span>
          </p>
          <h2 id={`${uid}-title`} className="mt-2 text-[clamp(1.25rem,3.2vw,1.75rem)] font-bold leading-snug tracking-tight">
            <span className="inline-block">周年告知を</span>
            <span className="inline-block">平成の手作りHP風に</span>
            <span className="inline-block">する着せ替え</span>
          </h2>
          <p className="mt-3 border-l-2 border-[#d97706] pl-3 text-[14px] leading-relaxed text-stone-600 sm:text-[15px]">
            「平成にする」を押すと、同じ告知に壁紙・流れる文字・キリ番カウンター・相互リンク枠がかかります。店名を入れて、令和と平成を並べた画像を保存できます
          </p>
        </div>
        <figure className="hidden lg:block" aria-hidden="true">
          <div className="aspect-[1200/630] w-full border border-stone-200 bg-stone-50">
            {image && (
              // eslint-disable-next-line @next/next/no-img-element
              <img src={image} alt="" className="block h-full w-full" />
            )}
          </div>
          <figcaption className="mt-1.5 text-[12px] text-stone-500">左が令和、右が平成(下で保存できる画像と同じ)</figcaption>
        </figure>
      </div>

      <div className="grid border-t border-stone-200 lg:grid-cols-[minmax(0,1fr)_21rem]">
        {/* 舞台 */}
        <div className="min-w-0">
          <div className="flex flex-wrap items-center gap-3 border-b border-stone-200 bg-stone-50/70 px-4 py-3 sm:px-6">
            <button
              type="button"
              onClick={toggle}
              aria-pressed={heisei}
              className={`${btn} era-toggle gap-3 border-stone-900 bg-white pl-1.5 pr-4 text-stone-900 hover:border-[#d97706]`}
            >
              <span aria-hidden="true" className="relative grid h-8 w-[5.5rem] grid-cols-2 border border-stone-300 bg-stone-100 text-[12px] font-bold">
                <span
                  className={`absolute inset-y-0 left-0 w-1/2 bg-[#d97706] transition-transform duration-200 ease-out motion-reduce:transition-none ${heisei ? "translate-x-full" : "translate-x-0"}`}
                />
                <span className={`relative grid place-items-center ${heisei ? "text-stone-500" : "text-white"}`}>令和</span>
                <span className={`relative grid place-items-center ${heisei ? "text-white" : "text-stone-500"}`}>平成</span>
              </span>
              <span className="grid">
                <span className={`[grid-area:1/1] ${heisei ? "invisible" : ""}`}>平成にする</span>
                <span className={`[grid-area:1/1] ${heisei ? "" : "invisible"}`}>令和に戻す</span>
              </span>
            </button>
            <button
              type="button"
              onClick={() => setStill((s) => !s)}
              aria-pressed={still}
              disabled={!heisei}
              className={`${btn} still min-h-10 border-stone-300 bg-white px-3 text-[13px] text-stone-800 hover:border-[#d97706] disabled:cursor-not-allowed disabled:opacity-40`}
            >
              {still ? "流れる文字を動かす" : "流れる文字を止める"}
            </button>
            <span className="ml-auto text-[13px] text-stone-600">
              いまの表示: <strong className="font-bold text-stone-900">{heisei ? "平成" : "令和"}</strong>
            </span>
          </div>

          <div
            ref={stageRef}
            data-era={era}
            data-still={still ? "" : undefined}
            className="era-skin @container min-h-[30rem] bg-white px-3 py-4 sm:px-6 sm:py-6"
          >
            <article className="es-page mx-auto max-w-3xl px-2 py-4 sm:px-6 sm:py-8" aria-label={`${shopName}の周年告知`}>
              <p className="es-only es-welcome">
                ようこそ<b>{shopName}</b>のHPへ
              </p>
              <p className="es-only es-marquee" aria-hidden="true">
                <span className="es-marquee-in">
                  ★☆ {title}! {notice.replace(/\n/g, " ")} 遊びに来てね♪ ☆★
                </span>
              </p>
              <p className="rw-only flex items-center gap-3 text-[14px] font-medium text-stone-600">
                <span className="inline-block h-px w-8 bg-[#d97706]" aria-hidden="true" />
                {shopName}・創業{foundedText}年
              </p>
              <h3 className="es-title mt-3 text-[clamp(2.25rem,7cqw,3.5rem)] font-bold leading-tight tracking-tight text-stone-900">
                {title}
                <span className="es-only es-new">NEW!</span>
              </h3>
              <div className="es-body mt-6 grid gap-6 @xl:grid-cols-[minmax(0,1fr)_minmax(0,1.15fr)] @xl:items-center">
                <HoopArt className="es-photo block aspect-[4/3] w-full border border-stone-200" />
                <div>
                  <p className="es-text whitespace-pre-line text-[16px] leading-[1.9] text-stone-800">{notice}</p>
                  <div className="mt-5 flex flex-wrap items-center gap-x-5 gap-y-3">
                    <a
                      href={APPLY_HREF}
                      onClick={(e) => onLink(e, "作品展に申し込む")}
                      className="es-cta inline-flex min-h-12 items-center justify-center border border-[#b45309] bg-[#b45309] px-6 text-[15px] font-bold text-white outline-none transition-colors hover:bg-[#92400e] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#d97706] motion-reduce:transition-none"
                    >
                      作品展に申し込む
                    </a>
                    <a
                      href="#works"
                      onClick={(e) => onLink(e, "これまでの作品を見る")}
                      className="es-link text-[15px] font-medium text-stone-700 underline decoration-stone-300 underline-offset-4 outline-none hover:decoration-[#d97706] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#d97706]"
                    >
                      これまでの作品を見る
                    </a>
                  </div>
                </div>
              </div>

              <hr className="es-only es-hr" />
              <div className="es-only es-counter">
                <div className="flex flex-wrap items-center justify-center gap-2">
                  <span>あなたは</span>
                  <span role="img" aria-label={`見本の番号 ${no != null ? pad6(no) : "読み込み中"}`}>
                    <SevenSeg text={no != null ? pad6(no) : "------"} />
                  </span>
                  <span>人目のお客様です</span>
                </div>
                <p className="es-note mt-1">見本の番号です(実際のアクセス数ではありません)</p>
                {kind && (
                  <p className="es-kiri">
                    キリ番おめでとう!報告してね
                    <span className="block text-[13px] font-bold">
                      {KIRI_NAME[kind]}の {pad6(no!)} 番
                    </span>
                  </p>
                )}
              </div>
              <div className="es-only es-wip">
                <WipBanner />
                <p className="es-note">作品ギャラリーは工事中です。もうしばらくお待ちください</p>
              </div>
              <div className="es-only es-links">
                <p className="es-links-title">相互リンク</p>
                <ul className="mt-2 flex list-none flex-wrap justify-center gap-2 p-0" aria-label="相互リンクのバナー枠(見本)">
                  <li className="grid h-[31px] w-[88px] place-items-center overflow-hidden bg-gradient-to-r from-[#ff8fc4] to-[#8fc4ff] px-1 text-[11px] font-bold leading-none text-black">
                    {shopName.slice(0, 6)}
                  </li>
                  <li className="grid h-[31px] w-[88px] place-items-center bg-[#000080] font-display text-[11px] font-bold text-[#ffff66]">LINK FREE</li>
                  <li className="grid h-[31px] w-[88px] place-items-center border-2 border-dashed border-stone-500 bg-white text-[11px] font-bold text-stone-700">募集中</li>
                </ul>
                <p className="es-note mt-1">バナーは88×31です。直リンクはご遠慮ください</p>
              </div>
              <p className="es-foot mt-8 border-t border-stone-200 pt-4 text-[13px] text-stone-500">
                <span className="es-only">Since {foundedText}</span>© {shopName}
              </p>
            </article>
          </div>
          <p className="min-h-11 border-t border-stone-200 px-4 py-3 text-[13px] text-stone-600 sm:px-6" aria-live="polite">
            {log || "申込ボタンと作品のリンクは、令和でも平成でも同じリンク先のまま押せます(見本なので移動しません)"}
          </p>
        </div>

        {/* 入力と出力 */}
        <aside className="min-w-0 border-t border-stone-200 lg:border-l lg:border-t-0">
          <div className="px-5 py-5 sm:px-6">
            <h3 className="text-[15px] font-bold">自分の店に差し替える</h3>
            <p className="mt-1 text-[13px] text-stone-600">入力はこのブラウザの中だけで使い、送信も保存もしません</p>
            <label className="mt-4 block text-[14px] font-medium">
              店名
              <input className={`${field} shop-name`} value={shop} maxLength={SHOP_MAX} onChange={(e) => setShop(e.target.value)} />
            </label>
            <label className="mt-3 block text-[14px] font-medium">
              創業年(西暦)
              <input
                className={`${field} founded font-display tabular-nums`}
                inputMode="numeric"
                value={founded}
                maxLength={4}
                onChange={(e) => setFounded(e.target.value.replace(/[^\d]/g, "").slice(0, 4))}
              />
            </label>
            <label className="mt-3 block text-[14px] font-medium">
              告知文
              <textarea
                className={`${field} notice min-h-32 resize-y leading-relaxed`}
                value={notice}
                maxLength={NOTICE_MAX}
                onChange={(e) => setNotice(e.target.value)}
              />
              <span className="mt-1 block text-right font-display text-[12px] tabular-nums text-stone-500">
                {Array.from(notice).length}/{NOTICE_MAX}
              </span>
            </label>
          </div>
          <div className="border-t border-stone-200 px-5 py-5 sm:px-6">
            <h3 className="text-[15px] font-bold">キリ番くじ</h3>
            <p className="mt-1 text-[13px] leading-relaxed text-stone-600">
              ページを開くたびに見本の番号が出ます。ゾロ目・1000の倍数・連番が当たりで、出る確率は約1/20です
            </p>
            <div className="mt-3 flex flex-wrap gap-2">
              <button type="button" onClick={() => reroll(false)} className={`${btn} reroll border-stone-900 bg-stone-900 text-white hover:bg-stone-700`}>
                もう一度ひらく
              </button>
              <button type="button" onClick={() => reroll(true)} className={`${btn} force-kiri border-stone-300 bg-white text-stone-900 hover:border-[#d97706]`}>
                当たりの画面を見る
              </button>
            </div>
            <p className="mt-3 flex items-center gap-2 text-[13px] text-stone-600">
              いまの番号
              <strong className={`font-display text-[17px] tabular-nums ${kind ? "text-[#b00000]" : "text-stone-900"}`}>{no != null ? pad6(no) : "------"}</strong>
              {kind && <span className="bg-[#ffff99] px-1.5 text-[12px] font-bold text-[#b00000]">{KIRI_NAME[kind]}</span>}
            </p>
          </div>
        </aside>
      </div>

      {/* 共有画像と CSS */}
      <div className="grid gap-8 border-t border-stone-200 px-5 py-6 sm:px-8 lg:grid-cols-[minmax(0,6fr)_minmax(0,5fr)] lg:gap-10">
        <div className="min-w-0">
          <h3 className="text-[15px] font-bold">令和と平成を並べた画像(1200×630)</h3>
          <div className="mt-3 aspect-[1200/630] w-full border border-stone-200 bg-stone-50">
            {image ? (
              // eslint-disable-next-line @next/next/no-img-element
              <img src={image} alt={`${shopName}の周年告知を、左に令和、右に平成のHP風で並べた画像`} className="share-image block h-full w-full" />
            ) : (
              <p className="grid h-full place-items-center text-[13px] text-stone-500">画像を用意しています</p>
            )}
          </div>
          <div className="mt-3 flex flex-wrap gap-2">
            {image ? (
              <a href={image} download={`heisei-skin-${no != null ? pad6(no) : "sample"}.png`} className={`${btn} save border-[#b45309] bg-[#b45309] text-white hover:bg-[#92400e]`}>
                画像を保存
              </a>
            ) : (
              <span className={`${btn} border-stone-200 bg-stone-100 text-stone-400`}>画像を保存</span>
            )}
            <button type="button" onClick={() => doCopy("share")} className={`${btn} copy-share border-stone-300 bg-white text-stone-900 hover:border-[#d97706]`}>
              <span className="grid">
                <span className={`[grid-area:1/1] ${copied === "share" ? "invisible" : ""}`}>共有の文をコピー</span>
                <span className={`[grid-area:1/1] ${copied === "share" ? "" : "invisible"}`}>コピーしました ✓</span>
              </span>
            </button>
          </div>
          <p className="mt-2 text-[13px] text-stone-600">画像には入力した店名と、いまの見本の番号(当たりなら「キリ番おめでとう」)が入ります</p>
        </div>
        <div className="min-w-0">
          <div className="flex items-center justify-between border border-b-0 border-stone-200 px-3 py-2">
            <span className="font-mono text-xs text-stone-500">era-skin.css</span>
            <button type="button" onClick={() => doCopy("css")} className={`${btn} copy-css min-h-9 border-stone-300 bg-white px-3 text-xs text-stone-900 hover:border-[#d97706]`}>
              {copied === "css" ? "コピーしました ✓" : "スキンのCSSをコピー"}
            </button>
          </div>
          <pre className="max-h-80 overflow-auto border border-stone-200 bg-stone-950 p-4 font-mono text-[12px] leading-relaxed text-stone-100">
            <code>{`<div class="era-skin" data-era="heisei">…</div>\n\n${SKIN_CSS}`}</code>
          </pre>
          <p className="mt-2 text-[13px] leading-relaxed text-stone-600">
            親の data-era を書き換えるだけで切り替わります。平成だけの部品に es-only、令和だけの部品に rw-only を付けます
          </p>
        </div>
      </div>

      {/* 関連 */}
      <nav className="border-t border-stone-200 px-5 py-5 sm:px-8" aria-label="ほかの切り替え・季節の作品">
        <p className="text-[13.5px] font-bold">ほかの切り替え・季節の作品</p>
        <ul className="mt-3 grid list-none gap-x-8 gap-y-3 p-0 sm:grid-cols-2 lg:grid-cols-4">
          {RELATED.map((l) => (
            <li key={l.href} className="border-t border-stone-200 pt-2">
              <a href={l.href} className="group flex flex-col outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#d97706]">
                <span className="text-[14px] font-bold underline decoration-stone-300 underline-offset-4 group-hover:decoration-[#d97706]">{l.title}</span>
                <span className="mt-0.5 text-[13px] text-stone-500">{l.note}</span>
              </a>
            </li>
          ))}
        </ul>
      </nav>

      <p className="sr-only" aria-live="polite">
        {live}
      </p>
    </section>
  );
}

Add to your project via shadcn CLI

npx shadcn@latest add https://designs.first-ch.com/r/heisei-retro-skin.json