# -*- coding: utf-8 -*-
"""サイトの数字を聞く（ショート専用・舞台型・2026-11-07）
エイイチの言葉: 計測を Claude につなぐ部品（MCP）も作る「どうせいずれ必要そう」（2026-11-06）
事実: 主に見る数字は3つ（AIの利用者の依頼で読みに来た数・AIのサービスのリンクから来た人・サイト名で検索して来た人）。日ごとに集計して R2 に残す（MASTER の保存先テーブル）"""
from butai_parts import *
OUTRO_K = 6

NAME, VER = "サイトの数字を聞く", 3
HEAD = "サイトの数字<br>Claudeに聞く"
T_ON = (0, 0.6)


def scene(T, S):
    h = CSS
    # 0: サイトの数字、Claude から見られる？
    t0 = T(*T_ON)
    h += win(t0, T(1, 0), kick("サイトの計測")
             + f'<div class="card" style="left:150px;top:120px;width:600px;height:420px;justify-content:flex-start;padding-top:30px">'
               f'<span style="font-size:40px">pixelstomotors<span style="color:{ORANGE}">.com</span></span></div>'
             + "".join(f'<div class="line" style="left:200px;top:{240 + k * 60}px;width:{[460, 380, 420, 300][k]}px"></div>' for k in range(4))
             + f'<div class="hero" style="right:40px;top:280px;font-size:240px;opacity:0;animation:{a("pop", t0 + 1.4, .35)}">?</div>')
    # 1: 計測をつなぐ部品を作った（Claude ← 部品 → 計測）
    t1, s1 = T(1, 0), S(1)
    names = [("Claude", ""), ("つなぐ部品", "or"), ("計測", "")]
    fl = "".join(f'<div class="card {c}" style="left:{48 + k * 276}px;top:230px;width:252px;height:170px;font-size:42px;align-items:center;padding:0;white-space:nowrap;'
                 f'opacity:0;animation:{a("pop" if c else "up", t1 + (s1 - 0.9 if c else 0.2 + k * 0.2), .35)}">{nm}</div>' for k, (nm, c) in enumerate(names))
    h += win(t1, T(2, 0), kick("作ったもの") + fl)
    # 2: 見る数字は、3つだけ
    t2 = T(2, 0)
    h += win(t2, T(3, 0), kick("見る数字")
             + f'<div class="hero" style="left:0;right:0;text-align:center;top:110px;font-size:400px;opacity:0;animation:{a("slam", t2 + 0.6, .3)}">3<span>つだけ</span></div>')
    # 3: 3つの中身（話している1つだけオレンジ）
    t3, s3 = T(3, 0), S(3)
    rows = ["AIが読みに来た数", "AIから来た人", "サイト名の検索"]
    st = [0.1, s3 * 0.42, s3 * 0.7]
    rr = ""
    for k, nm in enumerate(rows):
        an = a("up", t3 + st[k]) + ", " + a("on", t3 + st[k], .2)
        if k < 2:
            an += f", off{k} .2s linear {t3 + st[k + 1]:.3f}s forwards"
        rr += (f'<div class="card" style="left:48px;top:{110 + k * 150}px;width:804px;height:126px;flex-direction:row;align-items:center;justify-content:flex-start;gap:28px;font-size:48px;'
               f'opacity:0;animation:{an}"><span style="font-size:56px;width:50px">{k + 1}</span>{nm}</div>')
    h += win(t3, T(4, 0), f'<style>@keyframes off0 {{ to {{ background:{FACE_C}; color:{INK}; }} }} @keyframes off1 {{ to {{ background:{FACE_C}; color:{INK}; }} }}</style>' + rr)
    # 4: どうせ、いずれ必要そう
    t4 = T(4, 0)
    h += win(t4, T(5, 0), kick("作った理由")
             + f'<div class="msg" style="top:200px;text-align:center;font-size:84px;opacity:0;animation:{a("pop", t4 + 0.2, .35)}">どうせ<br>いずれ必要</div>')
    # 5: 毎日集計して、残している（日ごとの箱が積み上がる。数は出さない）
    t5, s5 = T(5, 0), S(5)
    days = ["月", "火", "水", "木", "金", "土", "日"]
    cols = ""
    for k, d in enumerate(days):
        x = 48 + k * 116
        cols += f'<div style="position:absolute;left:{x}px;top:392px;width:104px;text-align:center;font-size:28px;font-weight:800;color:{DIM}">{d}</div>'
        for j in range(3):
            tt = t5 + 0.3 + (k * 3 + j) * (s5 - 0.6) / 21
            c = ORANGE if j == 0 else FACE_2
            cols += (f'<div style="position:absolute;left:{x}px;top:{316 - j * 76}px;width:104px;height:64px;border-radius:10px;background:{c};'
                     f'opacity:0;animation:{a("pop", tt, .2)}"></div>')
    h += win(t5, None, kick("毎日の集計") + '<div class="msg" style="font-size:48px">3つの数を、日ごとに残す</div>' + cols)
    h += outro(T, OUTRO_K)
    return h


def OVER(T):
    return stage_fx(T, shakes=[(T(2, 0.6), 0.4)], fx=[dict(kind="shock", t=T(2, 0.6), d=1.4), dict(kind="rise", t=T(5, 0.2), d=2.6)])


FACE = [(-1, 0.0, 1.0, "smile"), (1, 0.0, 2.4, "joy"), (2, 0.0, 1.9, "wink"), (3, 0.0, 4.7, "smile"), (4, 0.0, 2.2, "think"), (5, 0.0, 2.6, "joy"), ("end", 0.0, 3.0, "smile")]
POSE = [(-1, 0.0, 1), (0, 0.0, 1), (2, 0.0, 3), (3, 0.0, 1), (4, 0.0, 2), (5, 0.6, 4)]
LEAN = []
INTRO = "dash"
MOVES = [(1, 0.2, "hop", 1.0), (2, 0.5, "jump", 0.9), (4, 0.4, "tilt", 1.0), (5, 0.3, "spin", 1.2)]
SE = [(-1, 0.0, "se_whoosh", -9), (0, 0.6, "se_boot", -12), (0, 2.0, "se_pop", -12), (1, 0.2, "se_pop", -14), (1, 1.5, "se_ding", -11),
      (2, 0.6, "se_pechin", -9), (3, 0.1, "se_tick", -12), (3, 2.0, "se_tick", -12), (3, 3.35, "se_tick", -12),
      (4, 0.2, "se_pop", -12), (5, 0.3, "se_rise", -12), (5, 1.8, "se_ding", -10)]
ENDING = dict(kind="none")   # 下の段（曜日）にエイイチの頭がかかるので、締めで跳ばせない
