/* ========== 変数 ========== */
:root {
    --k-color: #e60012;
    --txt-color: #fff;
    --transition-speed: 0.3s;
}

/* ========== リセット ========== */
* { box-sizing: border-box; }

body {
    background: #000;
    color: #fff;
    font-family: 'Noto Sans JP', "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
    font-weight: 300;
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;   /* dvh非対応ブラウザ向けフォールバック */
    height: 100dvh;
    overflow: hidden;
}

/* ========== レイアウト ========== */
.card-container {
    width: 100%;
    height: auto;
    aspect-ratio: 858 / 588;
    max-height: 50vh;
    background: #1a1a1a;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    border-bottom: 2px solid #333;
    position: relative;
    overflow: hidden;
}

#preview-canvas {
    border: 4px solid #000;
    transform-origin: center;
    image-rendering: crisp-edges;
}

.panel {
    width: 100%;
    flex-grow: 1;
    overflow-y: auto;
    background: #0d0d0d;
    display: flex;
    flex-direction: column;
}

.title-image-area {
    position: relative;
    width: 100%;
    height: 160px;
    background: #000;
    overflow: hidden;
    flex-shrink: 0;
}

.title-image-area .bg-video {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(12px);
    transform: scale(1.1);
    opacity: 0.7;
}

.title-image-area .main-video {
    position: absolute;
    top: 0;
    left: 50%;
    width: 225px;
    height: 100px;
    margin-left: -112.5px;
    margin-top: 0;
    object-fit: cover;
    z-index: 1;
}

/* ========== バナースライドショー（16秒ループ） ========== */
/* テキスト→馬→テキスト→馬 の4フェーズ、各4秒 */
.banner-anim {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: #000;
}

/* 共通スライドレイヤー */
.bp-slide {
    position: absolute;
    inset: 0;
    opacity: 0;
    will-change: opacity;
}

/* ===== フェーズA: テキスト (0-4s / 0%-25%) ===== */
.bp-text-a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    z-index: 2;
    animation: bp-show-a 16s ease-in-out infinite;
}
@keyframes bp-show-a {
    0%   { opacity: 0; }
    4%   { opacity: 1; }
    21%  { opacity: 1; }
    25%  { opacity: 0; }
    100% { opacity: 0; }
}

/* ===== フェーズB: umahidari.jpg (4-8s / 25%-50%) ===== */
.bp-img-a {
    z-index: 1;
    animation: bp-show-b 16s ease-in-out infinite;
}
@keyframes bp-show-b {
    0%   { opacity: 0; }
    25%  { opacity: 0; }
    29%  { opacity: 1; }
    46%  { opacity: 1; }
    50%  { opacity: 0; }
    100% { opacity: 0; }
}

/* ===== フェーズC: テキスト (8-12s / 50%-75%) ===== */
.bp-text-b {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    z-index: 2;
    animation: bp-show-c 16s ease-in-out infinite;
}
@keyframes bp-show-c {
    0%   { opacity: 0; }
    50%  { opacity: 0; }
    54%  { opacity: 1; }
    71%  { opacity: 1; }
    75%  { opacity: 0; }
    100% { opacity: 0; }
}

/* ===== フェーズD: umagoal.png (12-16s / 75%-100%) ===== */
.bp-img-b {
    z-index: 1;
    animation: bp-show-d 16s ease-in-out infinite;
}
@keyframes bp-show-d {
    0%   { opacity: 0; }
    75%  { opacity: 0; }
    79%  { opacity: 1; }
    96%  { opacity: 1; }
    100% { opacity: 0; }
}

/* ===== 画像レイヤー共通 ===== */
.bp-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    /* Ken Burns: わずかにズームイン */
    animation: bp-kenburns 4s ease-in-out infinite alternate;
}
@keyframes bp-kenburns {
    0%   { transform: scale(1.0); }
    100% { transform: scale(1.06); }
}

/* 画像上の左右ビネット（JRA風 高級感） */
.bp-vignette {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(to right,  rgba(0,0,0,0.55) 0%, transparent 28%, transparent 72%, rgba(0,0,0,0.55) 100%),
        linear-gradient(to bottom, rgba(0,0,0,0.35) 0%, transparent 30%, transparent 70%, rgba(0,0,0,0.45) 100%);
    z-index: 2;
    pointer-events: none;
}

/* ===== テキストスタイル（JRA公式風） ===== */
.bp-title {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: clamp(18px, 4.5vw, 38px);
    font-weight: 700;
    letter-spacing: 0.28em;
    white-space: nowrap;
    text-align: center;
    line-height: 1.1;
    background: linear-gradient(
        160deg,
        #c8a96e 0%, #e8d5a3 30%, #ffffff 50%, #e8d5a3 70%, #c8a96e 100%
    );
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter:
        drop-shadow(0 1px 0 rgba(100,70,0,0.6))
        drop-shadow(0 4px 12px rgba(180,130,30,0.25));
    animation: bp-gold-shimmer 5s linear infinite;
}
@keyframes bp-gold-shimmer {
    0%   { background-position: 200% center; }
    100% { background-position: -200% center; }
}

/* タイトル下のゴールドライン */
.bp-title::after {
    content: '';
    display: block;
    width: 40%;
    height: 1px;
    margin: 8px auto 0;
    background: linear-gradient(to right, transparent, #c8a96e, transparent);
}

.bp-sub {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: clamp(8px, 1.7vw, 13px);
    font-weight: 300;
    letter-spacing: 0.42em;
    white-space: nowrap;
    text-align: center;
    color: rgba(200,169,110,0.75);
    text-transform: uppercase;
}

.input-container {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.input-block {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 24px 0;
    background: transparent;
    border-radius: 0;
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.input-block:first-child {
    border-top: none;
}

/* ========== コンポーネント ========== */
label.g-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 11px;
    font-weight: 400;
    color: var(--k-color);
    letter-spacing: 0.45em;
    text-transform: uppercase;
    border-left: none;
    padding-left: 0;
    transition: color var(--transition-speed);
}

label.g-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--k-color);
    opacity: 0.2;
}

input,
select,
textarea {
    padding: 10px 0;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: transparent;
    color: #fff;
    font-size: 16px;
    width: 100%;
    font-family: inherit;
    font-weight: 300;
    transition: border-bottom-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-bottom-color: var(--k-color);
    background: transparent;
}

.upload-hint {
    font-size: 13px;
    color: #888;
    margin: 0 0 10px 0;
}

.char-counter {
    font-size: 11px;
    color: #888;
    text-align: right;
    margin-top: -8px;
}

.char-counter.warning {
    color: #f39800;
}

.char-counter.danger {
    color: #e60012;
}

.save-btn {
    padding: 22px;
    background: transparent;
    color: var(--k-color);
    border: 1px solid var(--k-color);
    font-weight: 400;
    cursor: pointer;
    border-radius: 6px;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 16px;
    margin-top: 10px;
    letter-spacing: 0.4em;
    transition: background var(--transition-speed), color var(--transition-speed), transform 0.1s;
}

.save-btn:hover {
    background: var(--k-color);
    color: #0c0c0c;
    box-shadow: none;
}

.save-btn:active {
    transform: scale(0.98);
}

.save-btn:disabled {
    background: #666;
    cursor: not-allowed;
    box-shadow: none;
}

.save-btn.saving {
    background: #666;
    cursor: wait;
}

.m-copyright {
    text-align: center;
    margin: 20px 0 40px;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 12px;
    color: #555;
    line-height: 1.6;
    font-style: italic;
    letter-spacing: 0.05em;
}

.m-copyright a {
    color: var(--k-color);
    opacity: 0.5;
    text-decoration: none;
    transition: opacity 0.2s;
}

.m-copyright a.hub-link {
    opacity: 0.85;
    font-weight: 600;
}

.m-copyright a:hover {
    opacity: 1;
}

.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 20px;
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #333;
    border-top-color: var(--k-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    color: #fff;
    font-size: 18px;
    font-weight: 900;
}

.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: #222;
    color: #fff;
    padding: 16px 24px;
    border-radius: 8px;
    border-left: 4px solid var(--k-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    font-weight: 700;
    z-index: 10000;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s, transform 0.3s;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.success {
    border-left-color: #009944;
}

.toast.error {
    border-left-color: #e60012;
}

/* ========== トリミングモーダル ========== */
.crop-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 9998;
    align-items: center;
    justify-content: center;
}

.crop-modal.active {
    display: flex;
}

.crop-modal-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 28px 24px;
    background: #0d0d0d;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    width: min(304px, 92vw);
    user-select: none;
}

.crop-hint {
    font-size: 11px;
    color: #555;
    letter-spacing: 0.05em;
    margin: 0;
    text-align: center;
    font-style: italic;
}

#crop-canvas {
    border: none;
    border-radius: 50%;
    cursor: grab;
    touch-action: none;
    display: block;
}

#crop-canvas:active {
    cursor: grabbing;
}

.crop-slider-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.crop-zoom-icon {
    color: #555;
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
    width: 14px;
    text-align: center;
}

#crop-slider {
    flex: 1;
    padding: 0;
    border: none;
    border-bottom: none;
    background: transparent;
    accent-color: var(--k-color);
    cursor: pointer;
    height: 4px;
    font-weight: 300;
}

.crop-buttons {
    display: flex;
    gap: 12px;
    width: 100%;
}

.crop-btn {
    flex: 1;
    padding: 14px;
    border-radius: 4px;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 14px;
    letter-spacing: 0.2em;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.crop-cancel-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #666;
}

.crop-cancel-btn:hover {
    border-color: rgba(255, 255, 255, 0.3);
    color: #ccc;
}

.crop-confirm-btn {
    background: transparent;
    border: 1px solid var(--k-color);
    color: var(--k-color);
}

.crop-confirm-btn:hover {
    background: var(--k-color);
    color: #0c0c0c;
}

/* ========== アニメーション ========== */
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========== レスポンシブ ========== */
/* min-width条件: 縦持ちスマホでソフトキーボード表示中に横向き誤判定されるのを防ぐ */
@media screen and (orientation: landscape) and (min-width: 600px) {
    body {
        flex-direction: row;
    }
    .card-container {
        width: 45%;
        height: 100vh;
        height: 100dvh;
        max-height: none;   /* 縦向け50vh上限の打ち消し */
        aspect-ratio: auto;
        border-right: 2px solid #333;
        border-bottom: none;
    }
    .panel {
        width: 55%;
        height: 100vh;
        height: 100dvh;
    }
}

@media screen and (max-width: 480px) {
    .input-container {
        padding: 15px;
    }
    .input-block {
        padding: 15px;
    }
    .save-btn {
        letter-spacing: 0.15em;
    }
}

/* ========== 使い方アコーディオン ========== */
.howto-accordion {
    margin: 0 0 4px 0;
    border-bottom: 1px solid #333;
}

.howto-toggle {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background: #1a1a1a;
    border: none;
    color: #e8e8e8;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.05em;
    cursor: pointer;
    text-align: left;
}

.howto-toggle:hover {
    background: #222;
}

.howto-arrow {
    font-size: 11px;
    color: var(--k-color);
    transition: transform 0.2s;
}

.howto-body {
    display: none;
    flex-direction: column;
    gap: 0;
    background: #111;
    padding: 0 16px;
}

.howto-body.open {
    display: flex;
    padding: 12px 16px 16px;
}

.howto-step {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 12px 14px;
    background: #1e1e1e;
    border-left: 3px solid var(--k-color);
    border-radius: 4px;
    margin-bottom: 8px;
}

.howto-num {
    font-size: 28px;
    font-weight: 900;
    color: var(--k-color);
    line-height: 1;
    min-width: 28px;
    padding-top: 2px;
}

.howto-text {
    flex: 1;
}

.howto-ja {
    font-size: 13px;
    font-weight: 700;
    color: #e8e8e8;
    margin: 0 0 2px 0;
}

.howto-en {
    font-size: 11px;
    font-weight: 600;
    color: var(--k-color);
    margin: 0 0 8px 0;
    letter-spacing: 0.04em;
}

.howto-desc {
    font-size: 12px;
    color: #aaa;
    margin: 0 0 2px 0;
    line-height: 1.5;
}

.howto-desc.en {
    color: #888;
    margin-top: 4px;
}

.howto-desc a {
    color: var(--k-color);
    text-decoration: none;
}

.howto-desc a:hover {
    text-decoration: underline;
}
