/* テーマ変数: data-theme 属性(auto は prefers-color-scheme に追従) */
:root {
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #1a2233;
    --muted: #64748b;
    --accent: #4f6df5;
    --accent-soft: rgba(79, 109, 245, 0.12);
    --pulse: #38bdf8;
    --border: #e2e8f0;
    --shadow: 0 4px 24px rgba(30, 41, 59, 0.08);
    --plot-grid: #e2e8f0;
    --viewer-bg: #ffffff;
}

[data-theme="dark"] {
    --bg: #0f1420;
    --card: #1a2233;
    --text: #e8edf7;
    --muted: #8b98b8;
    --accent: #7c93ff;
    --accent-soft: rgba(124, 147, 255, 0.16);
    --pulse: #7dd3fc;
    --border: #2a3550;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --plot-grid: #2a3550;
    --viewer-bg: #1a2233;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Hiragino Sans", "BIZ UDPGothic", -apple-system, BlinkMacSystemFont,
        "Segoe UI", Roboto, sans-serif;
    line-height: 1.6;
    transition: background 0.3s, color 0.3s;
}

.page {
    max-width: 1080px;
    margin: 0 auto;
    padding: 28px 20px 40px;
}

/* ---- ヘッダー ---- */
.header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.header h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 0.01em;
    background: linear-gradient(120deg, var(--accent), #9f6df5);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.theme-toggle {
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    width: 42px;
    height: 42px;
    border-radius: 12px;
    font-size: 20px;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform 0.15s;
    flex-shrink: 0;
}

.theme-toggle:hover {
    transform: scale(1.08);
}

/* ---- タブ ---- */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.tab {
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--muted);
    padding: 10px 20px;
    border-radius: 999px;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
}

.tab .formula {
    font-size: 12px;
    opacity: 0.75;
    margin-left: 6px;
}

.tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 4px 14px rgba(79, 109, 245, 0.35);
}

.tab:not(.active):hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ---- カード ---- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 20px 22px;
    margin-bottom: 22px;
    transition: background 0.3s, border-color 0.3s;
}

.card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.card-head h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 650;
}

.method-info {
    color: var(--muted);
    font-size: 12.5px;
}

.paper-link {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.2s, transform 0.15s;
}

.paper-link:hover {
    background: var(--accent);
    color: #fff;
    transform: translateY(-1px);
}

.hint {
    color: var(--muted);
    font-size: 13px;
    margin: 10px 2px 0;
}

.hint-current {
    color: #e11d48;
    font-weight: 650;
}

[data-theme="dark"] .hint-current {
    color: #ff5d7a;
}

[data-theme="dark"] #current-marker {
    border-color: #0f1420;
}

/* ---- プロットとポップアップ ---- */
#plot-container {
    position: relative;
}

/* 現在の回転角を示す赤い点。Plotly のトレースではなく独立した DOM 要素
   として実装している(アニメーション中に高頻度で位置更新しても、
   Plotly 本体のクリック/ホバー検出を一切乱さないようにするため)。
   実際のドラッグ・クリック判定は座標計算(nearMarker等)で行うため
   pointer-events は無効にしてよい。 */
#current-marker {
    position: absolute;
    display: none;
    width: 15px;
    height: 15px;
    margin: -8.5px 0 0 -8.5px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
    pointer-events: none;
    z-index: 400;
}

/* ホバー中の点に重ねる「押して欲しそう」なパルス表示 */
#point-pulse {
    position: absolute;
    display: none;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 500;
}

#point-pulse::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--pulse);
    animation: pulse-ring 1.1s ease-out infinite;
}

#point-pulse::after {
    content: "";
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: var(--pulse);
    box-shadow: 0 0 12px var(--pulse);
    animation: pulse-core 1.1s ease-in-out infinite;
}

@keyframes pulse-ring {
    0% {
        transform: scale(0.6);
        opacity: 0.9;
    }

    100% {
        transform: scale(2.3);
        opacity: 0;
    }
}

@keyframes pulse-core {
    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.35);
    }
}

#plotly-div {
    width: 100%;
    height: 480px;
}

.popup {
    position: absolute;
    display: none;
    width: min(340px, 88vw);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    padding: 8px;
    z-index: 1000;
}

#close-button {
    position: absolute;
    top: 8px;
    right: 8px;
    border: none;
    background: var(--accent-soft);
    color: var(--accent);
    width: 26px;
    height: 26px;
    border-radius: 8px;
    cursor: pointer;
    z-index: 1010;
    font-size: 13px;
}

#close-button:hover {
    background: var(--accent);
    color: #fff;
}

#viewer-container {
    height: 280px;
    width: 100%;
    position: relative;
    border-radius: 8px;
    overflow: hidden;
}

#point-info {
    margin-top: 8px;
    padding: 8px 10px;
    background: var(--accent-soft);
    border-radius: 8px;
    font-size: 12.5px;
    display: none;
}

/* ---- アニメーション ---- */
.anim-grid {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 20px;
    align-items: center;
}

#anim-viewer {
    height: 300px;
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.anim-controls {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.playback-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

.play {
    border: none;
    background: var(--accent);
    color: #fff;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(79, 109, 245, 0.35);
    transition: transform 0.15s;
    flex-shrink: 0;
}

.play:hover {
    transform: scale(1.1);
}

#theta-slider {
    flex: 1;
    min-width: 160px;
    accent-color: var(--accent);
    height: 6px;
}

.mode-control {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
    flex-wrap: wrap;
}

.mode-control-label {
    color: var(--text);
    font-weight: 650;
    white-space: nowrap;
}

.mode-buttons {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.mode-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 32px;
    border: none;
    border-right: 1px solid var(--border);
    background: var(--card);
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.mode-btn:last-child {
    border-right: none;
}

.mode-btn:hover:not(.active) {
    color: var(--accent);
    background: var(--accent-soft);
}

.mode-btn.active {
    background: var(--accent);
    color: #fff;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    flex-wrap: wrap;
}

.speed-control-label {
    color: var(--text);
    font-weight: 650;
    margin-right: 2px;
    white-space: nowrap;
}

.speed-icon {
    font-size: 13px;
    line-height: 1;
    opacity: 0.8;
}

.speed-control input[type="range"] {
    flex: 1;
    min-width: 140px;
    accent-color: var(--accent);
    height: 6px;
}

.speed-label {
    min-width: 34px;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    font-weight: 650;
}

.anim-info {
    width: 100%;
    font-size: 14px;
    color: var(--text);
}

.anim-info .value {
    font-variant-numeric: tabular-nums;
    font-weight: 650;
    color: var(--accent);
}

/* ---- フッター ---- */
.footer {
    text-align: center;
    color: var(--muted);
    font-size: 12px;
}

@media (max-width: 760px) {
    .anim-grid {
        grid-template-columns: 1fr;
    }

    #plotly-div {
        height: 380px;
    }
}
