:root {
    --bg-cream: #FAF5E1; 
    --accent-peach: #F4CFAE;
    --main-pink: #F0A9A9;
    --light-pink: #F9DEE2;
    --link-blue: #B6DEE5;
    --text-dark: #333;
    --danger-red: #E87A7A;
    --border-color: #EFEFEF;
}

html, body {
    height: 100%;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-weight: 400; 
    background-color: var(--bg-cream);
    color: var(--text-dark); 
    margin: 0; 
    padding: 20px 5px;
    display: flex; 
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-x: hidden;
    box-sizing: border-box;
}
body.modal-open {
    overflow: hidden;
}

.notice-wrapper {
    width: 100%;
    max-width: 900px;
    margin-bottom: 20px;
    box-sizing: border-box;
}
.usage-notice {
    background-color: var(--accent-peach);
    padding: 10px;
    border-radius: 12px;
    margin-bottom: 10px;
}
.notice-wrapper .usage-notice:last-child .notice-content a {
    color: #c84c5f; 
}
.notice-content {
    padding: 8px;
    font-size: 13px;
    color: var(--text-dark);
    text-align: center;
    position: relative;
    z-index: 1;
    background: rgba(255, 255, 255, 0.35);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.notice-content::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: url('https://i.postimg.cc/597xms4f/1762029853049.png');
    background-size: cover;
    background-position: center;
    opacity: 0.6;
    z-index: -1;
    border-radius: 12px;
}
.notice-content p {
    margin: 4px 0;
    line-height: 1.7;
}
.notice-content a {
    color: var(--main-pink);
    font-weight: 500;
    text-decoration: none;
}
.notice-content a:hover {
    text-decoration: underline;
}

.container {
    width: 100%; max-width: 900px; background: #fff; padding: 20px 40px 40px;
    border-radius: 8px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    position: relative;
    box-sizing: border-box;
}
@media (max-width: 600px) {
    .container { padding-left: 15px; padding-right: 15px; }
}
h1, h2 { 
    text-align: center; color: var(--text-dark); border-bottom: 1px solid #eee; 
    padding-bottom: 15px; display: flex; align-items: center; justify-content: center;
}
.help-icon { 
    font-size: 18px; color: #ccc; margin-left: 10px; 
    cursor: pointer; transition: color 0.3s; 
}
.help-icon:hover { color: var(--main-pink); }

#story-input {
    width: 100%; box-sizing: border-box; padding: 15px; border: 1px solid #ccc;
    border-radius: 8px; font-size: 14px; line-height: 1.7; resize: vertical;
    background-color: #fafafa; height: 150px; transition: height 0.3s ease-in-out;
}
#story-input.expanded { height: 400px; }
.input-controls { display: flex; justify-content: flex-end; margin-top: 10px; }
#expand-btn {
    background: none; border: 1px solid var(--main-pink); color: var(--main-pink); padding: 5px 15px;
    font-size: 14px; cursor: pointer; border-radius: 5px; transition: all 0.2s;
}
#expand-btn:hover { background: var(--main-pink); color: white; }

.floating-actions {
    position: sticky; bottom: 20px; z-index: 10; margin-top: 40px;
    background: rgba(255, 255, 255, 0.85); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    padding: 10px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex; flex-wrap: wrap; justify-content: center; gap: 10px;
}
.floating-actions button {
    background-color: var(--main-pink); color: white; border: none;
    padding: 10px 20px; font-size: 15px; font-weight: 500; border-radius: 8px;
    cursor: pointer; transition: all 0.2s ease-in-out;
}
.floating-actions button:hover { transform: translateY(-2px); box-shadow: 0 2px 8px rgba(240, 169, 169, 0.6); }
.floating-actions button.secondary { background-color: var(--accent-peach); }
.floating-actions button.secondary:hover { box-shadow: 0 2px 8px rgba(244, 207, 174, 0.6); }
.floating-actions button.success { background-color: var(--link-blue); }
.floating-actions button.success:hover { box-shadow: 0 2px 8px rgba(182, 222, 229, 0.6); }
.floating-actions button.danger { background-color: var(--danger-red); }
.floating-actions button.danger:hover { box-shadow: 0 2px 8px rgba(232, 122, 122, 0.6); }
.floating-actions button:disabled { background-color: #cccccc; cursor: not-allowed; transform: none; box-shadow: none; }

.hidden { display: none !important; }
.preview-wrapper {
    width: 100%; max-width: 400px; margin: 20px auto;
    border: 1px solid #ccc; box-shadow: 0 0 15px rgba(0,0,0,0.1);
    overflow: hidden; transition: height 0.2s ease-out; position: relative;
}
#canvas-scaler { transform-origin: top left; }
#chat-canvas {
    width: 1242px; display: flex; flex-direction: column; background-color: #fff;
}

.watermark {
    position: relative; padding: 30px 0; display: flex; align-items: center;
    justify-content: center; gap: 15px; font-size: 36px; color: #000;
    font-weight: 500; white-space: nowrap; text-shadow: 0 0 8px rgba(255, 255, 255, 0.9);
    width: 100%; box-sizing: border-box; background-color: #fff;
}
.watermark-logo-container {
    width: 50px; height: 50px; border-radius: 50%; border: 2px solid var(--link-blue);
    display: flex; align-items: center; justify-content: center; padding: 2px;
    box-sizing: border-box; background-color: #fff; flex-shrink: 0;
}
.watermark-logo { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

.chat-header {
    display: flex; justify-content: space-between; align-items: center; position: relative;
    padding: 40px 50px; background-color: #fff; flex-shrink: 0;
    border-bottom: 1px solid #eee;
}
.header-left { display: flex; align-items: center; gap: 20px; }
.header-left .fa-chevron-left { font-size: 50px; color: #333; }
.contact-info { display: flex; flex-direction: column; }
.contact-name-line { display: flex; align-items: center; gap: 15px; }
.contact-name { font-size: 50px; font-weight: bold; color: #000; }
.contact-status { display: flex; align-items: center; gap: 10px; font-size: 35px; color: #888; }
.online-dot { width: 20px; height: 20px; background-color: #4caf50; border-radius: 50%;}
.chat-header .fa-bars { font-size: 50px; color: #333; }

.chat-body {
    flex-grow: 1; padding: 40px; display: flex; flex-direction: column;
    background-color: #f0f2f5; position: relative; transition: padding 0.3s ease; min-height: 200px;
}
.chat-body > * { margin-bottom: 40px; position: relative; }
.chat-body > *:last-child { margin-bottom: 0; }

#add-first-message-btn {
    background-color: #fff; color: var(--main-pink); border: 2px dashed var(--main-pink);
    padding: 40px; font-size: 45px; cursor: pointer; border-radius: 15px;
    transition: all 0.2s ease; margin: auto;
}
#add-first-message-btn:hover { background-color: #f8f9fa; border-color: #d88989; }

.message-row.is-consecutive { margin-top: -25px; }
.message-row.is-consecutive .avatar { visibility: hidden; }

.message-row { display: flex; width: 100%; }
.message-row.sender { justify-content: flex-start; }
.message-row.receiver { justify-content: flex-end; }

.system-message-row { justify-content: center; }
.system-message { align-self: center; color: #aaa; font-size: 36px; }

.recall-hint-message-row { justify-content: center; }
.recall-hint-message { display: flex; align-items: center; gap: 15px; color: #aaa; font-size: 36px;}
.recall-hint-message .re-edit { color: #007bff; cursor: pointer; }

.message-turn { display: flex; gap: 30px; align-items: flex-start; max-width: 85%; }
.message-turn.receiver { flex-direction: row-reverse; }
.avatar {
    width: 120px; height: 120px; border-radius: 50%;
    background-color: #ccc; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
    cursor: pointer; background-repeat: no-repeat; background-size: cover; background-position: center;
}
.avatar i { font-size: 60px; color: #fff; }
.message-wrapper { display: flex; align-items: center; gap: 20px; }
.message-turn.receiver .message-wrapper { flex-direction: row-reverse; }
.message-bubble {
    padding: 27px 40px; border-radius: 20px; font-size: 45px;
    line-height: 1.5; word-break: break-word; position: relative;
    max-width: 100%; display: flex; align-items: center;
}
.message-bubble.recalled { opacity: 0.6; }
.message-turn.sender .message-bubble { background: #fff; color: #000; }
.message-turn.receiver .message-bubble { background: #00A7FF; color: #fff; }

.new-voice-bubble { padding: 25px 35px; border-radius: 20px; display: inline-flex; align-items: center; gap: 20px; }
.new-voice-bubble.recalled, .transcription-bubble.recalled { opacity: 0.6; }
.voice-message-wrapper { display: flex; flex-direction: column; gap: 15px; }
.message-turn.sender .voice-message-wrapper { align-items: flex-start; }
.message-turn.receiver .voice-message-wrapper { align-items: flex-end; }
.play-button-container { width: 80px; height: 80px; border-radius: 50%; display: flex; justify-content: center; align-items: center; flex-shrink: 0; }
.play-button-container svg { width: 55px; height: 55px; }
.waveform { display: flex; align-items: flex-end; height: 60px; gap: 6px; }
.waveform-bar { width: 6px; border-radius: 3px; }
.voice-duration { font-size: 45px; font-weight: 500; white-space: nowrap; }
.transcription-bubble { background: #fff !important; color: #000 !important; border: 1px solid #eee; }
.message-turn.receiver .new-voice-bubble { background-color: #00A7FF; }
.message-turn.receiver .play-button-container { background-color: #00C6FF; }
.message-turn.receiver .play-button-container svg { fill: white; }
.message-turn.receiver .waveform-bar { background-color: white; }
.message-turn.receiver .voice-duration { color: white; }
.message-turn.sender .new-voice-bubble { background-color: #fff; border: 1px solid #eee; }
.message-turn.sender .play-button-container { background-color: #f0f0f0; }
.message-turn.sender .play-button-container svg { fill: #555; }
.message-turn.sender .waveform-bar { background-color: #ccc; }
.message-turn.sender .voice-duration { color: #555; }

.image-bubble-content { display: flex; align-items: baseline; gap: 20px; }
.image-bubble-content .fa-image { font-size: 45px; }

.adjacent-recall-hint {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    font-size: 32px; color: #aaa; white-space: nowrap;
}
.adjacent-recall-hint .fa-rotate-right { font-size: 38px; margin-bottom: 5px; }

.chat-footer { background-color: #fff; padding: 20px 40px 40px; border-top: 1px solid #eee; flex-shrink: 0; }
.input-area { display: flex; align-items: center; gap: 30px; }
.chat-input { flex-grow: 1; background-color: #f0f2f5; border: none; border-radius: 20px; padding: 25px 35px; font-size: 45px; }
.send-button { background-color: #00A7FF; color: #fff; border: none; border-radius: 20px; padding: 25px 50px; font-size: 45px; }
.icon-bar { display: flex; justify-content: space-around; align-items: center; padding-top: 30px; }
.icon-bar i { font-size: 60px; color: #555; }

.selection-mode .chat-body { padding-left: 140px; padding-right: 20px; }
.selection-mode .message-row:not(.non-selectable) { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.selection-mode .recall-hint-message-row { cursor: default; }
.selection-indicator { position: absolute; left: -100px; top: 25px; width: 70px; height: 70px; border: 4px dashed #ccc; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; font-size: 40px; transition: all 0.2s ease-in-out; pointer-events: none; opacity: 0; }
.selection-mode .selection-indicator { opacity: 1; }
.is-selected > .selection-indicator { border: none; background-color: var(--link-blue); }
.is-selected > .selection-indicator .fa-check { display: block; }
.selection-indicator .fa-check { display: none; }
.recall-hint-message-row.is-selected .recall-hint-message { background-color: #e0eaff; border-radius: 10px; padding: 5px 10px; }

.split-preview-mode .chat-body { cursor: copy; }
#split-lines-container { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
.split-line { position: absolute; width: 100%; height: 2px; pointer-events: auto; }
.split-line-visual { width: 100%; height: 100%; background-image: repeating-linear-gradient(to right, red 0, red 10px, transparent 10px, transparent 20px); }
.split-line-handle { position: absolute; top: 50%; left: 0; width: 100%; height: 40px; transform: translateY(-50%); cursor: grab; }
.delete-split-btn { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; background-color: red; color: white; border: none; border-radius: 50%; cursor: pointer; font-size: 20px; line-height: 32px; text-align: center; padding: 0; font-family: monospace; }

.avatar-modal, .custom-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); z-index: 1000; display: flex; justify-content: center; align-items: center; padding: 20px; box-sizing: border-box; }
.avatar-modal-content, .custom-modal-content { background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3); display: flex; flex-direction: column; align-items: center; gap: 15px; width: 90vw; max-width: 350px; box-sizing: border-box; }
.avatar-preview-container { width: 100%; height: auto; aspect-ratio: 1/1; border-radius: 50%; overflow: hidden; position: relative; border: 2px solid #eee; background-color: #f0f0f0; user-select: none; touch-action: none; }
#avatar-preview-img { position: absolute; transform-origin: center center; cursor: grab; max-width: none; }
.avatar-controls, .custom-modal-actions { display: flex; justify-content: center; gap: 10px; width: 100%; }
.custom-modal-content input { width: 100%; padding: 10px; font-size: 16px; border-radius: 5px; border: 1px solid #ccc; box-sizing: border-box; }
.custom-modal-actions button { padding: 10px 20px; font-size: 16px; border-radius: 5px; border: none; cursor: pointer; }
#confirm-role-btn { background-color: var(--link-blue); color: white; }
#cancel-role-btn { background-color: #6c757d; color: white; }

.editable-text { cursor: text; }
[contenteditable="true"] { outline: 2px solid #007bff; border-radius: 5px; box-shadow: 0 0 5px rgba(0, 123, 255, 0.5); }

.row-controls {
    position: absolute; top: -80px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 20px; opacity: 0;
    transition: opacity: 0.2s; z-index: 10; pointer-events: none;
}
.system-message-row .row-controls { top: -70px; }
.chat-body:not(.editing-text):not(.selection-mode):not(.split-preview-mode) > *:hover .row-controls { opacity: 1; pointer-events: auto; }
.control-btn {
    border: none; border-radius: 50%; width: 120px; height: 120px; font-size: 60px;
    display: flex; align-items: center; justify-content: center; cursor: pointer; color: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.delete-msg-btn { background-color: var(--danger-red); }
.insert-msg-btn { background-color: var(--link-blue); }
.modify-msg-btn { background-color: var(--accent-peach); }
.control-btn:hover { opacity: 0.8; }
.control-btn .fa-wand-magic-sparkles { font-size: 54px; }
.system-message-row .modify-msg-btn, .recall-hint-message-row .modify-msg-btn { display: none; }

/* --- START: UPDATED INSERT MENU STYLES --- */
.insert-menu {
    position: absolute;
    display: flex; flex-direction: column; gap: 4px;
    background: #fff;
    padding: 8px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    border: 1px solid #f0f0f0;
    z-index: 1001;
    min-width: 160px;
}
.insert-menu-header {
    font-size: 15px;
    color: #999;
    padding-bottom: 6px;
    border-bottom: 1px solid #eee;
    margin-bottom: 2px;
}
.insert-menu button {
    background: transparent;
    color: var(--text-dark);
    border: none;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    font-size: 10px;
    text-align: left;
    transition: background-color 0.2s ease;
}
.insert-menu button:hover {
    background-color: var(--light-pink);
}
/* --- END: UPDATED INSERT MENU STYLES --- */

.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(5px); z-index: 1000; display: flex; justify-content: center; align-items: center; padding: 20px; box-sizing: border-box; }
.modal-content { background: #fff; padding: 25px; border-radius: 16px; display: flex; flex-direction: column; align-items: center; gap: 20px; width: 90vw; max-width: 450px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); box-sizing: border-box; }
.modal-content h3 { margin: 0; color: var(--text-dark); width: 100%; text-align: center; border-bottom: 1px solid var(--border-color); padding-bottom: 15px; font-size: clamp(18px, 4vw, 22px); }
.help-modal-content { max-width: 650px; width: 90vw; height: auto; align-items: flex-start; text-align: left; gap: 15px; overflow-y: auto; max-height: 90vh; box-sizing: border-box; }
.help-modal-content p, .help-modal-content pre { width: 100%; box-sizing: border-box; margin: 0; }
.help-modal-content p { line-height: 1.7; font-size: 14px;}
.help-modal-content pre { background-color: #f5f5f5; padding: 15px; border-radius: 8px; white-space: pre-wrap; word-break: break-all; font-size: 13px; line-height: 1.6; margin-top: 5px;}
.help-modal-content code { font-family: 'Courier New', Courier, monospace; color: #d63384; }
.modal-button { background-color: var(--main-pink); color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 8px; cursor: pointer; transition: background-color 0.2s; }
.modal-button:hover { background-color: #d88989; }