/* リセット */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ダークモード強制 */
html {
    color-scheme: dark;
}

/* 全体のスタイル */
body {
    font-family: 'YuMincho', 'Yu Mincho', 'Noto Serif JP', serif;
    font-weight: 300;
    background: linear-gradient(135deg, #0A0F24 0%, #0D1428 25%, #06091A 50%, #0A0F24 75%, #0D1428 100%);
    background-size: 400% 400%;
    animation: gradient-shift 20s ease infinite;
    color: #E0E0E0;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    position: relative;
    /* システムのダークモード設定に関わらず、背景と文字色を強制 */
    background-color: #0A0F24 !important;
}

/* グラデーションの動的アニメーション */
@keyframes gradient-shift {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

/* フィルムグレイン（砂嵐）オーバーレイ */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><filter id="noise"><feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="4" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23noise)" opacity="0.05"/></svg>');
    background-repeat: repeat;
    animation: grain 0.5s steps(6) infinite;
    pointer-events: none;
    z-index: 1;
    opacity: 0.4;
}

@keyframes grain {
    0%, 100% { transform: translate(0, 0); }
    10% { transform: translate(-2%, -2%); }
    20% { transform: translate(2%, 0); }
    30% { transform: translate(-2%, 2%); }
    40% { transform: translate(0, -2%); }
    50% { transform: translate(2%, 2%); }
    60% { transform: translate(-2%, 0); }
    70% { transform: translate(0, 2%); }
    80% { transform: translate(2%, -2%); }
    90% { transform: translate(-2%, -2%); }
}

/* 背景の斜めライン（追加の装飾） */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(135deg, transparent 48%, rgba(224, 224, 224, 0.015) 48%, rgba(224, 224, 224, 0.015) 52%, transparent 52%),
        linear-gradient(-45deg, transparent 48%, rgba(224, 224, 224, 0.01) 48%, rgba(224, 224, 224, 0.01) 52%, transparent 52%);
    background-size: 80px 80px, 120px 120px;
    background-position: 0 0, 40px 40px;
    pointer-events: none;
    z-index: 1;
}

/* スクロールバーを完全に非表示 */
::-webkit-scrollbar {
    display: none;
}

body {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* メインコンテンツ */
#main-content {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    z-index: 2;
}

/* アクティブユーザー数カウンター */
#active-users-counter {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 102;
    font-size: 11px;
    color: rgba(224, 224, 224, 0.35);
    letter-spacing: 0.1em;
    opacity: 0.6;
    pointer-events: none;
    user-select: none;
    text-shadow: 0 0 6px rgba(224, 224, 224, 0.1);
    transition: opacity 0.3s ease;
}

#active-count {
    color: rgba(224, 224, 224, 0.5);
    font-weight: 400;
    margin: 0 4px;
}

/* 滞在時間カウンター（チャット画面） */
#stay-time-counter {
    position: fixed;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 102;
    font-size: 10px;
    color: rgba(224, 224, 224, 0.3);
    letter-spacing: 0.1em;
    opacity: 0.5;
    pointer-events: none;
    user-select: none;
    text-shadow: 0 0 4px rgba(224, 224, 224, 0.1);
    transition: opacity 0.3s ease;
}

#stay-time-value {
    color: rgba(224, 224, 224, 0.4);
    font-weight: 400;
    margin-left: 4px;
}

/* 新着メッセージボタン */
#new-message-btn {
    position: fixed;
    bottom: 130px;
    right: 30px;
    z-index: 98;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease, bottom 0.2s ease;
    pointer-events: none;
}

#new-message-btn:not(.hidden) {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#new-message-btn.hidden {
    display: none;
}

#new-message-btn button {
    padding: 10px 18px;
    background-color: rgba(15, 20, 35, 0.9);
    color: rgba(224, 224, 224, 0.7);
    font-family: 'YuMincho', 'Yu Mincho', 'Noto Serif JP', serif;
    font-size: 12px;
    letter-spacing: 0.05em;
    border: 1px solid rgba(224, 224, 224, 0.25);
    border-radius: 20px;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    outline: none;
}

#new-message-btn button:hover {
    background-color: rgba(20, 25, 40, 0.95);
    border-color: rgba(224, 224, 224, 0.4);
    color: rgba(224, 224, 224, 0.9);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}

#new-message-btn button:active {
    transform: scale(0.95);
}

/* タイムライン表示エリア */
#timeline {
    width: 100%;
    height: 100%;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    padding: 40px 20px 140px 20px;
    transition: padding-bottom 0.2s ease;
}

/* 個別メッセージのスタイル（テキストコンテナ） */
.message {
    max-width: 500px;
    width: fit-content;
    min-width: 100px;
    padding: 20px 30px;
    margin: 30px 0;
    font-size: 15px;
    line-height: 1.9;
    letter-spacing: 0.05em;
    opacity: 0;
    position: relative;
    animation: fade-in-glitch 1s ease-out forwards;
    z-index: 3;
    /* テキストは常に水平 */
    transform: rotate(0deg);
}

/* 奥のズレた影レイヤー（::before） */
.message::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 8px;
    left: -8px;
    z-index: -2;
    transform: rotate(-1.5deg) skewY(-1deg);
    opacity: 0.85;
}

/* 手前のメイン背景レイヤー（::after） */
.message::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: -1;
    transform: rotate(0.5deg) skewY(0.5deg);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.5);
}

/* 他人のメッセージ（左寄せ・黒背景） */
.message.other {
    align-self: flex-start;
    margin-left: 40px;
    margin-right: auto;
    text-align: left;
    color: #FFFFFF;
    font-weight: 400;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}

/* 他人：メイン背景は黒 */
.message.other::after {
    background: #000000;
    clip-path: polygon(
        20px 0,
        100% 0,
        calc(100% - 5px) 100%,
        0 100%,
        0 20px
    );
}

/* 他人：影レイヤーは白 */
.message.other::before {
    background: #FFFFFF;
    clip-path: polygon(
        25px 0,
        100% 0,
        calc(100% - 8px) 100%,
        0 100%,
        0 25px
    );
}

/* システム生成メッセージ（過去の残響・霧の塊） */
.message.system {
    color: rgba(200, 210, 220, 0.75);
    text-shadow:
        0 0 3px rgba(200, 210, 220, 0.3),
        0 0 8px rgba(150, 160, 180, 0.2);
}

/* システム：メイン背景は半透明のスモークグレー */
.message.system::after {
    background: rgba(120, 130, 150, 0.25);
    backdrop-filter: blur(6px);
    box-shadow:
        0 6px 25px rgba(0, 0, 0, 0.3),
        inset 0 0 30px rgba(180, 190, 210, 0.08);
}

/* システム：影レイヤーも半透明のスモークグレー */
.message.system::before {
    background: rgba(100, 110, 130, 0.2);
    backdrop-filter: blur(4px);
}

/* 自分のメッセージ（右寄せ・白背景） */
.message.user {
    align-self: flex-end;
    margin-right: 40px;
    margin-left: auto;
    text-align: right;
    color: #0A0F24;
    font-weight: 400;
}

/* 自分：メイン背景は白 */
.message.user::after {
    background: #FFFFFF;
    clip-path: polygon(
        0 0,
        calc(100% - 20px) 0,
        100% 20px,
        100% 100%,
        5px 100%
    );
}

/* 自分：影レイヤーは黒 */
.message.user::before {
    background: #000000;
    clip-path: polygon(
        0 0,
        calc(100% - 25px) 0,
        100% 25px,
        100% 100%,
        8px 100%
    );
}

/* グリッチ付きフェードインアニメーション */
@keyframes fade-in-glitch {
    0% {
        opacity: 0;
        transform: translateY(15px) scale(0.98);
        filter: blur(2px);
    }
    5% {
        opacity: 0.3;
        transform: translateX(-3px) scale(0.99);
        filter: blur(1px);
    }
    10% {
        opacity: 0.5;
        transform: translateX(2px) scale(1.01);
    }
    15% {
        opacity: 0.7;
        transform: translateX(-1px) scale(0.995);
    }
    20% {
        opacity: 0.9;
        transform: translateX(0) scale(1);
        filter: blur(0);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

/* 入力コンテナ */
#input-container {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 500px;
    z-index: 100;
    transition: bottom 0.2s ease;
}

/* 文字数カウンター */
#char-counter {
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    font-size: 11px;
    color: rgba(224, 224, 224, 0.3);
    letter-spacing: 0.05em;
    pointer-events: none;
    font-family: 'Courier New', monospace;
    user-select: none;
    background: rgba(15, 20, 35, 0.6);
    padding: 2px 6px;
    border-radius: 3px;
}

#char-count {
    color: rgba(224, 224, 224, 0.45);
}

/* 入力中インジケーター */
#typing-indicator {
    position: fixed;
    bottom: 110px;
    left: 50%;
    transform: translateX(-50%) translateY(5px);
    font-size: 12px;
    color: rgba(224, 224, 224, 0.4);
    letter-spacing: 0.05em;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease, bottom 0.2s ease;
    pointer-events: none;
    user-select: none;
    z-index: 99;
    white-space: nowrap;
}

#typing-indicator:not(.hidden) {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#typing-indicator.hidden {
    display: none;
}

/* ドットアニメーション */
.typing-dots {
    display: inline-block;
    animation: typing-dots 1.4s infinite;
}

@keyframes typing-dots {
    0%, 20% {
        opacity: 0.2;
    }
    40% {
        opacity: 0.6;
    }
    60% {
        opacity: 1;
    }
    80%, 100% {
        opacity: 0.2;
    }
}

/* 入力フィールド */
#message-input {
    width: 100%;
    padding: 16px 70px 16px 24px; /* 右側に文字数カウンター用のスペース確保 */
    background-color: rgba(15, 20, 35, 0.85);
    color: #E0E0E0;
    font-family: 'YuMincho', 'Yu Mincho', 'Noto Serif JP', serif;
    font-size: 16px; /* iOS自動ズーム防止のため16px以上に設定 */
    outline: none;
    transition: all 0.3s ease;
    backdrop-filter: blur(12px);
    text-shadow: 0 0 6px rgba(224, 224, 224, 0.1);
    border-left: 2px solid rgba(224, 224, 224, 0.3);
    border-top: 1px solid rgba(224, 224, 224, 0.2);
    border-right: 3px solid rgba(224, 224, 224, 0.35);
    border-bottom: 1px solid rgba(224, 224, 224, 0.15);
    clip-path: polygon(
        14px 0,
        100% 0,
        100% calc(100% - 14px),
        calc(100% - 14px) 100%,
        0 100%,
        0 14px
    );
    box-shadow:
        inset 0 0 0 1px rgba(224, 224, 224, 0.05),
        0 4px 15px rgba(0, 0, 0, 0.3);
}

#message-input::placeholder {
    color: rgba(224, 224, 224, 0.35);
    font-style: italic;
}

#message-input:focus {
    background-color: rgba(15, 20, 35, 0.95);
    border-left-color: rgba(224, 224, 224, 0.5);
    border-right-color: rgba(224, 224, 224, 0.55);
    box-shadow:
        inset 0 0 0 1px rgba(224, 224, 224, 0.1),
        0 0 25px rgba(224, 224, 224, 0.12),
        0 4px 20px rgba(0, 0, 0, 0.4);
    text-shadow: 0 0 8px rgba(224, 224, 224, 0.15);
}

/* 連投制限中（クールダウン中）の入力フィールド */
#message-input.cooldown {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

/* 投げ銭リンク */
#donation-link {
    position: fixed;
    bottom: 20px;
    right: 25px;
    z-index: 101;
    opacity: 0.5;
    transition: opacity 0.3s ease;
    pointer-events: auto;
}

#donation-link:hover {
    opacity: 0.9;
}

#donation-link a {
    color: #E0E0E0;
    text-decoration: none;
    font-size: 11px;
    letter-spacing: 0.05em;
    border-bottom: 1px solid rgba(224, 224, 224, 0.3);
    padding-bottom: 2px;
}

/* 常設Xシェアボタン（右下固定） */
.fixed-share-x-button {
    position: fixed;
    bottom: 70px;
    right: 25px;
    z-index: 101;
    width: 44px;
    height: 44px;
    padding: 0;
    background-color: rgba(15, 20, 35, 0.7);
    color: rgba(224, 224, 224, 0.5);
    border: 1px solid rgba(224, 224, 224, 0.2);
    border-radius: 50%;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease, bottom 0.2s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
}

.fixed-share-x-button:hover {
    background-color: rgba(20, 25, 40, 0.85);
    border-color: rgba(224, 224, 224, 0.4);
    color: rgba(224, 224, 224, 0.8);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    opacity: 1;
    transform: translateY(-2px);
}

.fixed-share-x-button:active {
    transform: translateY(0) scale(0.95);
}

.fixed-share-x-button svg {
    width: 16px;
    height: 16px;
}

/* 時間制限レイヤー（強制退出画面） */
#time-restriction {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #0A0F24 0%, #0D1428 25%, #06091A 50%, #0A0F24 75%, #0D1428 100%);
    background-size: 400% 400%;
    animation: gradient-shift 20s ease infinite;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

#time-restriction.hidden {
    display: none;
}

.restriction-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    max-width: 90%;
}

.restriction-message {
    font-size: 24px;
    letter-spacing: 0.15em;
    opacity: 0.9;
    animation: pulse 3s ease-in-out infinite;
    text-shadow: 0 0 15px rgba(224, 224, 224, 0.3);
}

.restriction-subtitle {
    font-size: 14px;
    letter-spacing: 0.1em;
    opacity: 0.6;
    margin-top: -20px;
}

/* 滞在時間表示（強制退出画面） */
.stay-time {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-top: 20px;
    padding: 30px 40px;
    background: rgba(15, 20, 35, 0.5);
    border: 1px solid rgba(224, 224, 224, 0.2);
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

.stay-time-label {
    font-size: 12px;
    letter-spacing: 0.1em;
    opacity: 0.6;
    color: rgba(224, 224, 224, 0.7);
}

.stay-time-value {
    font-size: 28px;
    letter-spacing: 0.05em;
    font-weight: 400;
    color: #E0E0E0;
    text-shadow: 0 0 10px rgba(224, 224, 224, 0.2);
}

/* Xシェアボタン */
.share-x-button {
    padding: 14px 32px;
    background-color: rgba(15, 20, 35, 0.85);
    color: rgba(224, 224, 224, 0.8);
    font-family: 'YuMincho', 'Yu Mincho', 'Noto Serif JP', serif;
    font-size: 14px;
    letter-spacing: 0.08em;
    border: 1px solid rgba(224, 224, 224, 0.3);
    border-radius: 25px;
    cursor: pointer;
    backdrop-filter: blur(12px);
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    outline: none;
    margin-top: 10px;
}

.share-x-button:hover {
    background-color: rgba(20, 25, 40, 0.95);
    border-color: rgba(224, 224, 224, 0.5);
    color: rgba(224, 224, 224, 1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
    transform: translateY(-2px);
}

.share-x-button:active {
    transform: translateY(0) scale(0.98);
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.7;
    }
    50% {
        opacity: 1;
    }
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .message {
        max-width: 85%;
        min-width: 80px;
        font-size: 14px;
        padding: 16px 24px;
    }

    .message::before {
        top: 6px;
        left: -6px;
    }

    .message.other {
        margin-left: 20px;
    }

    .message.user {
        margin-right: 20px;
    }

    #message-input {
        font-size: 16px; /* iOS自動ズーム防止のため16px以上に設定 */
        padding: 14px 65px 14px 20px; /* 右側に文字数カウンター用のスペース */
    }

    #donation-link a {
        font-size: 10px;
    }

    #char-counter {
        font-size: 10px;
        right: 12px;
        padding: 2px 5px;
    }

    #typing-indicator {
        bottom: 100px;
        font-size: 11px;
    }

    #active-users-counter {
        top: 15px;
        font-size: 10px;
    }

    #new-message-btn {
        bottom: 120px;
        right: 20px;
    }

    #new-message-btn button {
        padding: 8px 14px;
        font-size: 11px;
    }

    #stay-time-counter {
        top: 40px;
        font-size: 9px;
    }

    .restriction-message {
        font-size: 20px;
    }

    .restriction-subtitle {
        font-size: 12px;
    }

    .stay-time {
        padding: 25px 30px;
    }

    .stay-time-label {
        font-size: 11px;
    }

    .stay-time-value {
        font-size: 24px;
    }

    .share-x-button {
        padding: 12px 28px;
        font-size: 13px;
    }

    /* 常設Xシェアボタンのスマホ調整 */
    .fixed-share-x-button {
        bottom: 65px;
        right: 20px;
        width: 40px;
        height: 40px;
    }

    .fixed-share-x-button svg {
        width: 14px;
        height: 14px;
    }

    #donation-link {
        bottom: 15px;
        right: 20px;
    }
}
