:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --text: #1c1b19;
  --muted: #6f6a63;
  --line: #e4dfd6;
  --accent: #b3261e;
  --accent-soft: #f6e3e1;
  --chip: #efece5;
  --ja: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Hebrew", sans-serif;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151413; --card: #1f1e1c; --text: #ece8e1; --muted: #a09a91; --line: #2e2c29;
    --accent: #e0574d; --accent-soft: #3a1f1d; --chip: #2a2825;
  }
}
:root[data-theme="dark"] {
  --bg: #151413; --card: #1f1e1c; --text: #ece8e1; --muted: #a09a91; --line: #2e2c29;
  --accent: #e0574d; --accent-soft: #3a1f1d; --chip: #2a2825;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; direction: rtl; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans);
  line-height: 1.5; overflow-x: hidden;
}
body.locked { overflow: hidden; }
[dir="ltr"] { direction: ltr; }
button { font: inherit; color: inherit; }

/* ---------- hero ---------- */
.hero { position: relative; height: 52vw; max-height: 300px; min-height: 210px; overflow: hidden; background: #111; }
.hero-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0.55; filter: grayscale(1); }
.hero-text { position: absolute; inset: 0; padding: 20px 16px; display: flex; flex-direction: column; justify-content: flex-end; color: #fff;
  background: linear-gradient(to top, rgba(0,0,0,0.65), rgba(0,0,0,0) 70%); }
.hero-kicker { margin: 0 0 4px; font-size: 12px; letter-spacing: 0.22em; opacity: 0.85; text-align: right; }
.hero h1 { margin: 0; font-size: 34px; font-weight: 800; letter-spacing: -0.01em; }
.hero-sub { margin: 6px 0 0; font-size: 14px; max-width: 34ch; opacity: 0.92; }
.hero-credit { position: absolute; top: 8px; left: 12px; margin: 0; font-size: 10px; color: rgba(255,255,255,0.7); }

/* ---------- tabs ---------- */
.tabs { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: flex; gap: 8px; padding: 10px 16px; overflow-x: auto; scrollbar-width: none;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: 14px; white-space: nowrap; }
.tab .ja { font-family: var(--ja); font-size: 12px; margin-inline-start: 6px; color: var(--muted); }
.tab.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.tab.on .ja { color: inherit; opacity: 0.8; }

/* ---------- search ---------- */
.search { padding: 12px 16px 0; }
.search input { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 16px; outline: none; }
.search input:focus { border-color: var(--accent); }

/* ---------- category intro ---------- */
.cat-intro { padding: 14px 16px 4px; }
.cat-intro h2 { margin: 0; font-size: 22px; display: flex; align-items: baseline; gap: 10px; }
.cat-intro h2 .ja { font-family: var(--ja); font-weight: 500; color: var(--accent); font-size: 20px; }
.cat-intro h2 .en { font-weight: 400; color: var(--muted); font-size: 15px; }
.cat-intro p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- grid ---------- */
main { padding-bottom: calc(24px + var(--safe-b)); }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 12px 16px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 960px) { .grid { grid-template-columns: repeat(4, 1fr); max-width: 1100px; margin: 0 auto; } }
.card { position: relative; display: block; width: 100%; text-align: right; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); overflow: hidden; cursor: pointer;
  transition: transform 0.12s ease; -webkit-tap-highlight-color: transparent; }
.card:active { transform: scale(0.98); }
.card canvas { display: block; width: 100%; aspect-ratio: 1; background: var(--card); }
.card .cap { padding: 8px 10px 12px; border-top: 1px solid var(--line); }
.card .he { display: block; font-weight: 700; font-size: 15px; line-height: 1.25; }
.card .en { display: block; font-size: 12px; color: var(--muted); text-align: left; margin-top: 2px; }
.card .ja { position: absolute; top: 8px; left: 10px; font-family: var(--ja); font-size: 13px; color: var(--muted); }
.card .grade { position: absolute; top: 8px; right: 10px; font-size: 10px; color: var(--muted); background: var(--chip); padding: 2px 7px; border-radius: 999px; }
.empty { padding: 30px 16px; color: var(--muted); text-align: center; }

/* ---------- building blocks page ---------- */
.parts { padding: 8px 16px; max-width: 720px; margin: 0 auto; }
.parts h3 { font-size: 15px; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.part-row { display: grid; grid-template-columns: 56px 1fr; gap: 12px; align-items: center; padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; }
.part-row .ja { font-family: var(--ja); font-size: 26px; text-align: center; color: var(--accent); }
.part-row .ro { font-size: 13px; color: var(--muted); text-align: left; }
.part-row .he { font-weight: 600; }
.level-row { padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; }
.level-row .top { display: flex; justify-content: space-between; align-items: baseline; }
.level-row .top .ja { font-family: var(--ja); color: var(--accent); }
.level-row .top .en { color: var(--muted); font-size: 13px; }
.level-row .m { font-size: 14px; color: var(--muted); }

/* ---------- footer ---------- */
.foot { padding: 20px 16px calc(28px + var(--safe-b)); border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; max-width: 720px; margin: 0 auto; }
.foot p { margin: 0 0 10px; }
.foot-small { font-size: 12px; }

/* ---------- detail ---------- */
.detail { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.detail[hidden] { display: none; }
.detail-bar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: 10px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.btn-icon { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 20px; cursor: pointer; }
.detail-nav { display: flex; gap: 6px; }
.btn-mini { padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 13px; cursor: pointer; }
.btn-mini:disabled { opacity: 0.35; }
.stage { position: relative; margin: 0 16px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); overflow: hidden; }
#stage3d { display: block; width: 100%; aspect-ratio: 4 / 5; touch-action: pan-y; cursor: grab; }
#stage3d:active { cursor: grabbing; }
.views { display: flex; gap: 6px; justify-content: center; padding: 10px; border-top: 1px solid var(--line); background: var(--card); }
.views button { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); font-size: 13px; cursor: pointer; }
.views button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.stage-hint { position: absolute; top: 8px; left: 12px; margin: 0; font-size: 11px; color: var(--muted); }
.detail-body { padding: 16px 16px calc(40px + var(--safe-b)); max-width: 720px; margin: 0 auto; }
.names { margin-bottom: 8px; }
.names .he { font-size: 30px; font-weight: 800; line-height: 1.15; margin: 0; }
.names .row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 4px; }
.names .en { font-size: 17px; color: var(--muted); }
.names .ja { font-family: var(--ja); font-size: 24px; color: var(--accent); }
.meaning { font-size: 15px; color: var(--muted); margin: 0 0 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.chip { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; padding: 6px 10px; background: var(--chip); border-radius: 12px; }
.chip .ja { font-family: var(--ja); font-size: 20px; grid-row: span 2; color: var(--accent); }
.chip .ro { font-size: 11px; color: var(--muted); text-align: left; line-height: 1.1; }
.chip .he { font-size: 13px; font-weight: 600; line-height: 1.2; }
.chip .plus { align-self: center; color: var(--muted); }
.desc { font-size: 16px; margin: 0 0 16px; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.tag { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--chip); color: var(--muted); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }
.weight { margin: 0 0 18px; }
.weight .bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--chip); }
.weight .bar span { display: block; height: 100%; }
.weight .bar .f { background: var(--accent); }
.weight .bar .b { background: var(--text); opacity: 0.55; }
.weight .lbl { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }
.photo { margin: 0 0 18px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: #000; }
.photo img { display: block; width: 100%; }
.photo figcaption { font-size: 11px; color: var(--muted); padding: 6px 10px; background: var(--card); }
.video { position: relative; margin: 0 0 18px; border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: 16 / 9; cursor: pointer; }
.video img { width: 100%; height: 100%; object-fit: cover; opacity: 0.85; display: block; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video .play { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; gap: 8px; }
.video .play .tri { width: 60px; height: 60px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; font-size: 22px; padding-inline-start: 4px; }
.video .play .t { font-size: 13px; background: rgba(0,0,0,0.55); padding: 4px 10px; border-radius: 999px; }
.sources { font-size: 13px; color: var(--muted); }
.sources h4 { margin: 0 0 6px; font-size: 13px; font-weight: 600; }
.sources ul { margin: 0; padding: 0; list-style: none; }
.sources li { margin-bottom: 4px; }
.sources a { color: var(--accent); text-decoration: none; }
.sources a:hover { text-decoration: underline; }
