/* chat.css - LINE-style ARG chat interface */

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100dvh;
    overflow: hidden;
    background: #1a1a1a;
    font-family: 'Noto Sans JP', 'Hiragino Sans', sans-serif;
}

/* Override Layout wrappers so chat fills viewport */
.site-wrapper,
.main-content {
    height: 100dvh !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
}

.chat-wrapper {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: #0d0d0d;
}

/* ── Header ── */
.chat-header {
    background: linear-gradient(135deg, #1a3a2e 0%, #0f2419 100%);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid #1f3d2b;
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

.back-btn {
    color: #4caf7d;
    text-decoration: none;
    font-size: 1.3rem;
    line-height: 1;
    padding: 4px;
}

.avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #2a2a2a;
    border: 2px solid #3a6b4d;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    overflow: hidden;
    animation: avatarGlitch 8s infinite;
}

@keyframes avatarGlitch {
    0%, 90%, 100% { filter: none; }
    92% { filter: hue-rotate(90deg) saturate(2); transform: translateX(2px); }
    94% { filter: none; transform: translateX(-1px); }
    96% { filter: grayscale(1); }
}

.online-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4caf50;
    border: 2px solid #0f2419;
    animation: dotPulse 2s infinite;
}

@keyframes dotPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.header-info {
    flex: 1;
}

.header-name {
    color: #e0f0e8;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.header-status {
    color: #5aab77;
    font-size: 0.72rem;
    margin-top: 2px;
    font-family: 'Courier New', monospace;
    animation: statusFlicker 4s infinite;
}

@keyframes statusFlicker {
    0%, 85%, 100% { opacity: 0.8; }
    87% { opacity: 0.2; }
    89% { opacity: 0.9; }
}

/* ── Messages area ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 24px,
            rgba(255,255,255,0.012) 24px,
            rgba(255,255,255,0.012) 25px
        );
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #2a3a2f; border-radius: 2px; }

.date-divider {
    text-align: center;
    color: #4a5a50;
    font-size: 0.7rem;
    letter-spacing: 1px;
    margin: 4px 0;
}

/* Message rows */
.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: msgAppear 0.3s ease-out;
}

@keyframes msgAppear {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.msg-row.from-akari { flex-direction: row; }
.msg-row.from-user  { flex-direction: row-reverse; }

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #1e3d2a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    border: 1px solid #2d5a3d;
}

.msg-row.from-user .msg-avatar { display: none; }

.bubble-wrap {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-width: 75%;
}

.msg-row.from-user .bubble-wrap { align-items: flex-end; }

.bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 0.92rem;
    line-height: 1.6;
    word-break: break-word;
    position: relative;
}

/* Akari's bubble */
.msg-row.from-akari .bubble {
    background: #1e2d22;
    color: #c8e8d0;
    border-top-left-radius: 4px;
    border: 1px solid #2a4a32;
}

/* User's bubble */
.msg-row.from-user .bubble {
    background: #1a4a2e;
    color: #d8f0e0;
    border-top-right-radius: 4px;
    border: 1px solid #256635;
}

.msg-time {
    font-size: 0.65rem;
    color: #445a4a;
    padding: 0 4px;
}

/* Garbled text style */
.garbled {
    color: #3d6b4a;
    font-family: 'Courier New', monospace;
    font-size: 0.8em;
}

/* Typing indicator */
.typing-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.typing-bubble {
    background: #1e2d22;
    border: 1px solid #2a4a32;
    border-radius: 18px;
    border-top-left-radius: 4px;
    padding: 12px 16px;
    display: flex;
    gap: 5px;
    align-items: center;
}

.typing-dot {
    width: 7px;
    height: 7px;
    background: #4caf7d;
    border-radius: 50%;
    animation: typingBounce 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Input area ── */
.chat-input-area {
    background: #111a14;
    border-top: 1px solid #1e3020;
    padding: 12px 14px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    background: #1a2a1e;
    border: 1px solid #2a4a32;
    border-radius: 22px;
    padding: 10px 16px;
    color: #c8e8d0;
    font-size: 0.92rem;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
}

.chat-input::placeholder { color: #3a5a42; }
.chat-input:focus { border-color: #4caf7d; }

.send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2e7d52 0%, #1b5c38 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, background 0.2s;
    font-size: 1.1rem;
}

.send-btn:hover { transform: scale(1.08); background: linear-gradient(135deg, #3a9462 0%, #236e44 100%); }
.send-btn:active { transform: scale(0.95); }

/* Scanline overlay for horror effect */
.chat-wrapper::after {
    content: '';
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0,0,0,0.04) 2px,
        rgba(0,0,0,0.04) 4px
    );
    pointer-events: none;
    z-index: 100;
}

/* ── Unlocked Mode (Stable Connection / LINE Style) ── */
.chat-wrapper.unlocked-mode .chat-header {
    background: #06C755; /* Official LINE Green */
    border-bottom: 1px solid #05a647;
}

.chat-wrapper.unlocked-mode .back-btn,
.chat-wrapper.unlocked-mode .header-name {
    color: #ffffff;
}

.chat-wrapper.unlocked-mode .avatar {
    animation: none;
    border-color: #ffffff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}

.chat-wrapper.unlocked-mode .header-status {
    animation: none;
    opacity: 0.9;
    color: #e0fde0;
    font-weight: bold;
}

.chat-wrapper.unlocked-mode .online-dot.stable {
    animation: none;
    opacity: 1;
    background: #ffffff;
    border-color: #06C755;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

.chat-wrapper.unlocked-mode .chat-input-area {
    background: #ffffff;
    border-top: 1px solid #e0e0e0;
}

.chat-wrapper.unlocked-mode .chat-input {
    background: #f4f4f4;
    border: 1px solid #ddd;
    color: #333;
}

.chat-wrapper.unlocked-mode .chat-input::placeholder {
    color: #aaa;
}

.chat-wrapper.unlocked-mode .send-btn {
    background: #06C755;
}

.chat-wrapper.unlocked-mode .chat-messages {
    background: #8cabd9; /* LINE-style blueish background often used in chats */
    background-image: none;
}

.chat-wrapper.unlocked-mode .msg-row.from-user .bubble {
    background: #06C755;
    color: #ffffff;
    border: none;
}

.chat-wrapper.unlocked-mode .msg-row.from-akari .bubble {
    background: #ffffff;
    color: #333333;
    border: none;
}

.chat-wrapper.unlocked-mode .date-divider {
    color: #ffffff;
    background: rgba(0,0,0,0.1);
    padding: 2px 10px;
    border-radius: 10px;
    width: fit-content;
    margin: 10px auto;
}

.chat-wrapper.unlocked-mode .msg-time {
    color: rgba(255,255,255,0.7);
}

.system-msg {
    text-align: center;
    color: #4a5a50;
    font-size: 0.75rem;
    margin: 10px 0;
    font-family: 'Share Tech Mono', monospace;
    animation: msgAppear 0.3s ease-out;
}

.chat-wrapper.unlocked-mode .system-msg {
    color: #ffffff;
    background: rgba(0,0,0,0.1);
    padding: 4px 12px;
    border-radius: 12px;
    width: fit-content;
    margin: 10px auto;
}

.chat-wrapper.unlocked-mode::after {
    display: none;
}

/* ── Hijack Glitch ── */
.chat-wrapper.glitch-active {
    animation: hijackGlitch 0.4s steps(2) infinite;
    filter: invert(1) contrast(200%);
}

@keyframes hijackGlitch {
    0% { transform: translate(-50%, 0) skew(0deg); }
    20% { transform: translate(-51%, 2px) skew(5deg); }
    40% { transform: translate(-49%, -2px) skew(-5deg); }
    60% { transform: translate(-50%, 5px) skew(2deg); }
    80% { transform: translate(-52%, -5px) skew(-2deg); }
    100% { transform: translate(-50%, 0) skew(0deg); }
}

.msg-row.from-director .bubble {
    background: #4a0000;
    color: #ff3e3e;
    border: 1px solid #ff0000;
    border-top-left-radius: 4px;
    box-shadow: 0 0 10px rgba(255, 0, 0, 0.3);
}

.msg-row.from-director .msg-avatar {
    background: #2a0000;
    border-color: #ff0000;
    color: #ff3e3e;
}

/* ── Name Modal ── */
.name-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    animation: modalFadeIn 0.3s ease;
}

.name-modal-content {
    background: #1a1a1a;
    border: 1px solid #3a6b4d;
    padding: 30px;
    width: 90%;
    max-width: 320px;
    text-align: center;
    box-shadow: 0 0 30px rgba(76, 175, 125, 0.2);
}

.name-modal-content h3 {
    color: #4caf7d;
    font-size: 1rem;
    letter-spacing: 2px;
    margin-bottom: 10px;
    font-family: 'Share Tech Mono', monospace;
}

.name-modal-content p {
    color: #c8e8d0;
    font-size: 0.85rem;
    margin-bottom: 20px;
}

.name-modal-content input {
    width: 100%;
    background: #0d0d0d;
    border: 1px solid #2d5a3d;
    padding: 12px;
    color: #fff;
    margin-bottom: 20px;
    outline: none;
    text-align: center;
}

.name-modal-content input:focus {
    border-color: #4caf7d;
}

.name-modal-content button {
    background: #4caf7d;
    color: #000;
    border: none;
    padding: 10px 30px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.name-modal-content button:hover {
    background: #6fcf97;
    transform: translateY(-2px);
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
