@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* =========================================================
 * BAKUSYO.COM 共通UI ui.css
 *
 * 依存: css/tokens.css（必ず先に読み込む）
 * 対象: アプリシェル（app-bar / tab-bar）・ボタン・カード・
 *       リアクションレール・シェアシート・空状態・ベントーグリッド。
 *
 * 原則（CONCEPT.md §2）:
 *   - UIは絵文字主体。文字が読めなくても押せるサイズ・形にする。
 *   - タップ対象は最小44x44px。
 *   - 演出は短く（150-220ms）。人工的なローディングを作らない。
 *   - モバイルファースト。@media は 768px / 1080px の2段だけ。
 *
 * 絵文字ポリシー（2026-08 リファイン）:
 *   UIクローム内の絵文字は最大28px目安。「絵文字が画面の主役」になる
 *   配置は作らない。主役はイラスト・ネタ（＝コンテンツ）。
 * ========================================================= */

/* ===================== リセット ===================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font-body);
    color: var(--ink);
    background: var(--canvas);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

* {
    -webkit-tap-highlight-color: transparent;
}

img,
svg,
video {
    max-width: 100%;
    height: auto;
    display: block;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

a {
    color: inherit;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 800;
    letter-spacing: var(--track-tight);
    margin: 0;
    line-height: 1.25;
}

p {
    margin: 0;
}

[hidden] {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ===================== ページ骨格 ===================== */

/* 全画面固定・スクロールしない体験ページ（ガチャ/コレナニ/大喜利…）。
   100dvh を後書きしてモバイルのURLバー伸縮に追従させる。 */
body.app-shell {
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    user-select: none;
    /* .tab-bar は position:fixed。その分を body の padding で確保する。 */
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

body.app-shell > main {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
}

/* 通常スクロールページ（トップ/殿堂/漫談…）。 */
body.page-scroll {
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

.page-wrap {
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--space-4);
}

/* ===================== アプリバー ===================== */

.app-bar {
    flex: 0 0 auto;
    height: var(--appbar-h);
    min-height: var(--appbar-h);   /* 注入前もCLSゼロ */
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-3);
    background: var(--surface);
    border-bottom: 1px solid var(--hairline);
    position: relative;
    z-index: 30;
}

body.page-scroll .app-bar {
    position: sticky;
    top: 0;
}

.app-bar__logo {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(0.78rem, 3.4vw, 1rem);
    letter-spacing: var(--track-tight);
    color: var(--ink);
    text-decoration: none;
    white-space: nowrap;
}

.app-bar__logo-mark {
    font-size: 1.05em;
    line-height: 1;
}

.app-bar__page {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
}

.app-bar__page-emoji {
    font-size: 1.15rem;
    line-height: 1;
}

.app-bar__page-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(0.8rem, 3.4vw, 1rem);
    color: var(--ink-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-bar__actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* app-bar 右側の丸ボタン（音・言語）。44px タップ領域を疑似要素で確保。 */
.round-btn {
    position: relative;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    color: var(--ink);
    font-size: 1rem;
    font-family: var(--font-display);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: transform var(--motion-fast) var(--ease-pop), background var(--motion-fast);
}

.round-btn::after {
    content: '';
    position: absolute;
    inset: -4px;
}

.round-btn:active {
    transform: scale(0.88);
    background: var(--hairline);
}

.round-btn--lang {
    width: auto;
    min-width: 44px;
    padding: 0 10px;
    gap: 3px;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
}

.round-btn--lang .round-btn__globe {
    font-size: 0.95rem;
}

/* ===================== タブバー ===================== */

.tab-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    min-height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--hairline);
}

.tab-bar__inner {
    display: flex;
    align-items: stretch;
    max-width: var(--content-max);
    margin: 0 auto;
    height: var(--tabbar-h);
}

.tab {
    position: relative;
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-decoration: none;
    color: var(--ink-subtle);
    font-family: var(--font-display);
    font-weight: 700;
    transition: color var(--motion-fast), transform var(--motion-fast) var(--ease-pop);
}

.tab:active {
    transform: scale(0.94);
}

.tab__emoji {
    font-size: 20px;
    line-height: 1;
    filter: grayscale(0.55) opacity(0.75);
    transition: filter var(--motion-fast), transform var(--motion-fast) var(--ease-pop);
}

.tab__label {
    font-size: 11px;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.tab.is-active {
    color: var(--primary-ink);
    font-weight: 800;
}

.tab.is-active .tab__emoji {
    filter: none;
    transform: translateY(-1px) scale(1.06);
}

/* アクティブタブ上部のインジケータバー */
.tab.is-active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 3px;
    border-radius: var(--radius-pill);
    background: var(--primary);
}

/* ===================== ボタン ===================== */

/* ソリッド塗り＋薄い影の現代的ボタン。押すと少し縮む。
   （旧: Duolingo式の 0 4px 0 3Dボタンは 2026-08 リファインで廃止） */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: 12px 20px;
    border: 0;
    border-radius: var(--radius-m);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: var(--track-tight);
    line-height: 1;
    color: var(--ink-invert);
    background: var(--ink);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    white-space: nowrap;
    transition: transform var(--motion-fast) var(--ease-out),
                box-shadow var(--motion-fast) var(--ease-out),
                background var(--motion-fast);
}

.btn:active,
.btn.is-pressed {
    transform: scale(0.98);
    box-shadow: none;
}

.btn:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
    .btn:hover {
        box-shadow: var(--shadow-raise);
    }
}

/* 白文字×コーラル。大サイズCTA・主要導線のみに使う。 */
.btn-primary {
    background: var(--primary);
    color: var(--ink-invert);
}

.btn-secondary {
    background: var(--secondary);
    color: var(--ink-invert);
}

.btn-ghost {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--hairline-strong);
    box-shadow: none;
}

@media (hover: hover) and (pointer: fine) {
    .btn-ghost:hover {
        background: var(--surface-2);
        box-shadow: none;
    }
}

/* メインCTA（1画面に1つだけ）。 */
.btn-big {
    min-height: 56px;
    padding: clamp(15px, 3.6vw, 20px) clamp(24px, 7vw, 38px);
    font-size: clamp(1rem, 4.4vw, 1.25rem);
    font-weight: 800;
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-raise);
}

.btn-big:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-sm);
}

/* ===================== カード ===================== */

.card {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-m);
    box-shadow: var(--shadow-sm);
    padding: var(--space-4);
}

@media (hover: hover) and (pointer: fine) {
    .card.is-interactive:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-raise);
        border-color: var(--hairline-strong);
        transition: transform var(--motion-fast) var(--ease-out),
                    box-shadow var(--motion-fast) var(--ease-out);
    }
}

/* ===================== リアクションレール ===================== */

/* 「💥BAKUSYO / 📤シェア / ▶️次へ」の横並びピル群。
   画面下部中央に置く前提だが、配置は各ページの責務。 */
.reaction-rail {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.rail-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 46px;
    padding: 10px 18px;
    border: 0;
    border-radius: var(--radius-pill);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: var(--track-tight);
    line-height: 1;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--hairline-strong);
    box-shadow: var(--shadow-sm);
    transition: transform var(--motion-fast) var(--ease-out),
                box-shadow var(--motion-fast) var(--ease-out);
}

.rail-btn:active {
    transform: scale(0.97);
    box-shadow: none;
}

.rail-btn__emoji {
    font-size: 1.15rem;
    line-height: 1;
}

.rail-btn--bakusyo {
    color: var(--ink-invert);
    background: var(--primary);
    border-color: transparent;
    padding: 10px 20px;
}

.rail-btn--next {
    color: var(--ink-invert);
    background: var(--ink);
    border-color: transparent;
}

.rail-btn__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 24px;
    padding: 0 7px;
    border-radius: var(--radius-pill);
    background: rgba(255, 255, 255, 0.28);
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
}

.rail-btn:not(.rail-btn--bakusyo):not(.rail-btn--next) .rail-btn__count {
    background: var(--surface-2);
    color: var(--ink-muted);
}

.rail-btn.is-bounce {
    animation: railBounce 0.35s var(--ease-pop);
}

.rail-btn__count.count-pop {
    animation: countPop 0.35s var(--ease-pop);
}

/* 世界計（APIが値を返した時だけ表示）。 */
.world-count {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--ink-subtle);
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
}

/* ===================== シェアシート ===================== */

.share-sheet {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
}

.share-sheet.is-open {
    display: block;
}

.share-sheet__scrim {
    position: absolute;
    inset: 0;
    background: var(--scrim);
    opacity: 0;
    transition: opacity var(--motion-base) var(--ease-out);
}

.share-sheet.is-shown .share-sheet__scrim {
    opacity: 1;
}

.share-sheet__panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--surface);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-sheet);
    padding: var(--space-3) var(--space-5)
             calc(var(--space-6) + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform var(--motion-base) var(--ease-pop);
}

.share-sheet.is-shown .share-sheet__panel {
    transform: translateY(0);
}

.share-sheet__handle {
    width: 42px;
    height: 4px;
    margin: 0 auto var(--space-5);
    border-radius: var(--radius-pill);
    background: var(--hairline-strong);
}

.share-sheet__options {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-5);
}

.share-opt {
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: var(--radius-pill);
    color: #fff;
    font-size: 1.5rem;
    font-family: var(--font-display);
    font-weight: 800;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-card);
    transition: transform var(--motion-fast) var(--ease-pop);
}

.share-opt:active {
    transform: scale(0.9);
}

.share-opt--x { background: #111111; }
.share-opt--wa { background: #25D366; }
.share-opt--copy { background: var(--ink-muted); }
.share-opt--copy.is-copied { background: var(--secondary); }

.share-sheet__close {
    display: block;
    width: 100%;
    margin-top: var(--space-5);
    min-height: 48px;
    border: 0;
    border-radius: var(--radius-m);
    background: var(--surface-2);
    color: var(--ink-muted);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.05rem;
    transition: transform var(--motion-fast) var(--ease-pop);
}

.share-sheet__close:active {
    transform: scale(0.97);
}

/* ===================== 空状態 ===================== */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    text-align: center;
    padding: var(--space-8) var(--space-5);
}

/* 絵文字ポリシー: 空状態でも絵文字は「主役級サイズ」にしない。 */
.empty-state__emoji {
    font-size: clamp(28px, 8vw, 40px);
    line-height: 1;
    opacity: 0.7;
}

.empty-state__title {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(1.05rem, 4.6vw, 1.35rem);
    letter-spacing: var(--track-tight);
    color: var(--ink);
}

.empty-state__text {
    font-size: 0.95rem;
    color: var(--ink-muted);
    max-width: 30ch;
}

.empty-state .btn {
    margin-top: var(--space-2);
}

/* ===================== ベントーグリッド ===================== */

.bento-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
}

.bento-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
    gap: var(--space-1);
    min-height: 148px;
    padding: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-m);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    text-decoration: none;
    color: var(--ink);
    transition: transform var(--motion-fast) var(--ease-out),
                box-shadow var(--motion-fast) var(--ease-out),
                border-color var(--motion-fast);
}

.bento-card:active {
    transform: scale(0.985);
}

@media (hover: hover) and (pointer: fine) {
    .bento-card:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-raise);
        border-color: var(--hairline-strong);
    }
}

/* 絵文字ポリシー: ベントー内の絵文字は「小さなチップ」までに留める。 */
.bento-card__emoji {
    font-size: 26px;
    line-height: 1;
    margin-bottom: auto;
}

.bento-card__title {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: var(--track-tight);
}

.bento-card__text {
    font-size: 0.78rem;
    color: var(--ink-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.bento-card.span-2 {
    grid-column: span 2;
}

.bento-card.span-tall {
    grid-row: span 2;
    min-height: 220px;
}

/* 色バリエーション（旧: パステルのベタ面）。
   2026-08 リファインで淡色カード地を廃止し、白カードに統一した。
   未移行ページが参照しても崩れないようクラス自体は残す。 */
.bento-card.tone-primary,
.bento-card.tone-secondary,
.bento-card.tone-accent {
    background: var(--surface);
    border-color: var(--hairline);
}

/* ---------- サムネイル型ベントー（コンテンツ主役） ---------- */

/* 上部に実イラストのサムネ、下部にタイトル＋説明1行。
   イラストは白地の線画なので、薄いグレー台に multiply で乗せて
   「白い余白が浮く」のを避ける。 */
.bento-card--thumb {
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
    padding: 0;
}

.bento-card__thumb {
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    background: var(--surface-2);
    border-bottom: 1px solid var(--hairline);
}

.bento-card__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* 原画の外周の余白を少しだけ食う */
    transform: scale(1.06);
    mix-blend-mode: multiply;
}

/* サムネ左下に置く小さな絵文字チップ（20px目安）。 */
.bento-card__chip {
    position: absolute;
    left: var(--space-2);
    bottom: var(--space-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-pill);
    background: var(--surface);
    border: 1px solid var(--hairline);
    box-shadow: var(--shadow-sm);
    font-size: 16px;
    line-height: 1;
}

.bento-card__meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: var(--space-3);
}

/* サムネ2枚を左右に並べる「VS」型。
   multiply の台色は親が持つ必要があるので、中央の仕切り線は
   背景色ではなく擬似要素で引く。 */
.bento-card__thumb--split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;   /* 行高を確定させ img の height:100% を効かせる */
    background: var(--surface-2);
}

.bento-card__thumb--split::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--hairline);
    z-index: 1;
}

.bento-card__thumb--split img {
    transform: scale(1.12);
}

.bento-card__vs {
    position: absolute;
    z-index: 2;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 24px;
    padding: 0 8px;
    border-radius: var(--radius-pill);
    background: var(--ink);
    color: var(--ink-invert);
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    line-height: 1;
}

/* ---------- タイポグラフィ型ベントー（画像を使わない） ---------- */

.bento-card--type {
    justify-content: space-between;
    gap: var(--space-3);
    background: var(--surface-2);
}

.bento-card__quote {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(1.05rem, 4.4vw, 1.35rem);
    letter-spacing: var(--track-tight);
    line-height: 1.35;
    color: var(--ink);
    text-wrap: balance;
}

.bento-card__quote::before {
    content: '“';
    color: var(--ink-subtle);
    margin-right: 1px;
}

.bento-card__quote::after {
    content: '”';
    color: var(--ink-subtle);
}

/* ===================== フロートリアクション ===================== */

/* 💥タップ時に絵文字が1秒ふわっと上がって消える。全ページ共通。 */
.float-reaction {
    position: fixed;
    font-size: 1.6rem;
    pointer-events: none;
    z-index: 999;
    animation: floatUp 1s var(--ease-out) forwards;
}

/* ===================== キーフレーム ===================== */

@keyframes railBounce {
    0%   { transform: scale(1); }
    45%  { transform: scale(1.16) rotate(-4deg); }
    100% { transform: scale(1); }
}

@keyframes countPop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.5); }
    100% { transform: scale(1); }
}

@keyframes floatUp {
    0%   { transform: translateY(0) scale(1); opacity: 1; }
    100% { transform: translateY(-90px) scale(1.6); opacity: 0; }
}

/* ===================== レスポンシブ ===================== */

@media (min-width: 768px) {
    :root {
        --appbar-h: 60px;
        --tabbar-h: 66px;
    }

    .app-bar {
        padding: 0 var(--space-5);
    }

    .bento-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: var(--space-4);
    }

    .bento-card {
        min-height: 170px;
    }

    .bento-card.span-tall {
        min-height: 250px;
    }

    .page-wrap {
        padding: var(--space-6);
    }

    .share-sheet__panel {
        max-width: 460px;
        left: 50%;
        right: auto;
        transform: translate(-50%, 100%);
        border-radius: var(--radius-xl);
        bottom: var(--space-6);
    }

    .share-sheet.is-shown .share-sheet__panel {
        transform: translate(-50%, 0);
    }
}

@media (min-width: 1080px) {
    .page-wrap {
        max-width: var(--content-max-wide);
    }

    .tab-bar__inner {
        max-width: 560px;
    }
}
