body {
    margin: 0;
    font-family: Arial, sans-serif;
    background-color: #f0f2f5;
}

#container {
    display: flex;
    flex-direction: column;
    min-height: 100vh; /* Allow container to grow */
}

#toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 8px;
    background-color: #ffffff;
    border-bottom: 1px solid #d1d1d1;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    gap: 5px;
}

.toolbar-group {
    display: flex;
    align-items: center;
    border-right: 1px solid #d1d1d1;
    padding: 0 10px;
    gap: 5px;
}

.toolbar-group:last-child {
    border-right: none;
}

.toolbar-button, .toolbar-select {
    background-color: transparent;
    border: 1px solid transparent;
    border-radius: 3px;
    padding: 5px;
    cursor: pointer;
    font-size: 16px;
    height: 32px;
}

.toolbar-button:hover, .toolbar-select:hover {
    background-color: #e0e0e0;
    border-color: #c0c0c0;
}

.toolbar-select {
    padding: 5px;
    min-width: 120px;
}

#doc-selector {
    min-width: 200px;
}

#fontSize {
    min-width: 70px;
}

.toolbar-label {
    display: none; /* Hide old labels */
}

.toolbar-color-picker {
    border: 1px solid transparent;
    background: none;
    width: 28px;
    height: 28px;
    padding: 0;
    cursor: pointer;
    border-radius: 3px;
}

.toolbar-color-picker:hover {
    border-color: #c0c0c0;
}

.toolbar-button.active {
    background-color: #cce5ff;
    border-color: #99caff;
}

.living-word {
    display: inline-block;
    position: absolute; /* Changed from inline-block to absolute for chaos mode */
    transition: opacity 0.5s ease-out, transform 0.1s linear;
}

.living-word.sprinting {
    box-shadow: 0 0 8px 2px #f0e68c; /* Khaki-colored glow */
    z-index: 5;
    border-radius: 2px;
}

.health-bar-container {
    position: absolute;
    top: -10px; /* Position above the word, moved down for power level */
    left: 0;
    width: 100%;
    height: 4px;
    background-color: rgba(255, 0, 0, 0.7); /* Red background for depleted health */
    border: 1px solid #333;
    border-radius: 2px;
    box-sizing: border-box;
    overflow: hidden;
    z-index: 1;
}

.health-bar {
    width: 100%;
    height: 100%;
    background-color: rgba(0, 255, 0, 0.8); /* Green for current health */
    transition: width 0.2s linear;
}

.power-level {
    position: absolute;
    top: -22px; /* Position above health bar */
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(75, 0, 130, 0.9); /* Indigo */
    color: #fff;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: bold;
    white-space: nowrap;
    z-index: 2;
    text-shadow: 1px 1px 1px rgba(0,0,0,0.5);
}

#chaos-settings {
    background-color: #f8f9fa;
    padding: 10px 20px;
    border-bottom: 1px solid #d1d1d1;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

#chaos-settings.hidden {
    display: none;
}

#chaos-settings h4 {
    margin: 0;
    font-weight: 500;
    color: #333;
}

.setting {
    display: flex;
    align-items: center;
    gap: 8px;
}

.setting label {
    font-size: 14px;
}

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

.fighting {
    animation: shake 0.3s ease-in-out;
    color: red;
}

.speech-bubble {
    position: absolute;
    bottom: 110%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 10px;
    padding: 5px 10px;
    font-size: 10px;
    white-space: nowrap;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
    opacity: 0;
    animation: bubble-fade 4s ease-in-out;
    z-index: 10;
    pointer-events: none;
}

.speech-bubble::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #f0f0f0 transparent transparent transparent;
}

@keyframes bubble-fade {
    0%, 100% { opacity: 0; transform: translate(-50%, 5px); }
    10%, 90% { opacity: 1; transform: translate(-50%, 0); }
}

.blood-splatter {
    position: absolute;
    pointer-events: none;
    z-index: 100;
    animation: fade-out 1.5s forwards;
}

.blood-drop {
    position: absolute;
    background-color: #8b0000;
    border-radius: 50%;
}

@keyframes fade-out {
    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

/* --- Nuke Effect Styles --- */
#nuke-flash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: white;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    animation: nuke-flash-animation 2s ease-out;
}

@keyframes nuke-flash-animation {
    0% { opacity: 0; }
    5% { opacity: 1; }
    25% { opacity: 1; }
    100% { opacity: 0; }
}

.shockwave {
    position: absolute;
    border-radius: 50%;
    border: 10px solid rgba(255, 165, 0, 0.8);
    box-shadow: 0 0 30px rgba(255, 69, 0, 0.6), inset 0 0 40px rgba(255, 200, 0, 0.5);
    transform: translate(-50%, -50%) scale(0);
    opacity: 1;
    animation: shockwave-animation 2s ease-out forwards;
    pointer-events: none;
    z-index: 1001; /* Above words, below flash */
}

@keyframes shockwave-animation {
    from {
        transform: translate(-50%, -50%) scale(0);
        opacity: 1;
    }
    to {
        transform: translate(-50%, -50%) scale(4); /* Expand beyond editor */
        opacity: 0;
    }
}

.mushroom-cloud {
    position: absolute;
    z-index: 1002;
    transform: translate(-50%, -50%) scale(0.1);
    opacity: 0;
    animation: mushroom-cloud-animation 12s ease-out forwards;
    pointer-events: none;
    width: 500px;
    height: auto;
}

@keyframes mushroom-cloud-animation {
    0% { opacity: 0; transform: translate(-50%, 0%) scale(0.1); }
    15% { opacity: 1; transform: translate(-50%, -20%) scale(0.6); }
    80% { opacity: 0.9; transform: translate(-50%, -100%) scale(1.5); }
    100% { opacity: 0; }
}

#status-bar {
    background-color: #f1f3f5;
    border-top: 1px solid #d1d1d1;
    padding: 5px 20px;
    font-size: 13px;
    color: #495057;
    display: flex;
    justify-content: flex-end;
    gap: 25px;
    flex-shrink: 0; /* Prevents status bar from shrinking */
    box-shadow: 0 -1px 3px rgba(0,0,0,0.05);
}

#main-content {
    display: flex;
    flex-grow: 1;
}

#editor {
    flex-grow: 1;
    padding: 2.5cm;
    margin: 20px auto; /* Centered with auto margin */
    width: 21cm; /* A4 width */
    min-height: 29.7cm; /* A4 height, content will overflow and scroll body */
    box-sizing: border-box;
    background-color: white;
    border: 1px solid #d1d1d1;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    outline: none;
    font-family: 'Times New Roman', serif;
    font-size: 12pt;
    line-height: 1.5;
    transition: margin-right 0.3s ease-in-out;
}

#editor.chaos-active {
    border: 3px dashed #ff4136; /* A nice, chaotic red border */
    overflow: hidden; /* Hide scrollbars and contain the words */
    height: calc(100vh - 120px); /* Example fixed height for chaos */
    min-height: unset;
    transition: background-color 2s ease-in-out; /* Add transition for nuke effect */
}

#editor.nuked {
    background-color: #5d4954; /* A dusty, dark fallout color */
}

#editor.sniper-active {
    cursor: crosshair;
}

#editor blockquote {
    border-left: 4px solid #ccc;
    margin-left: 0;
    margin-right: 0;
    padding-left: 1.5em;
    color: #666;
    font-style: italic;
}

#editor pre {
    background-color: #f4f4f4;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 1em;
    white-space: pre-wrap;
    font-family: 'Courier New', Courier, monospace;
}

#main-content.assistant-open #editor {
    /* Adjust margin when AI panel is open, keeps it centered in its space */
    margin-right: 20px;
    margin-left: 20px;
}

#ai-assistant-panel {
    width: 350px;
    flex-shrink: 0;
    border-left: 1px solid #d1d1d1;
    background-color: #f8f9fa;
    display: flex;
    flex-direction: column;
    /* position: sticky and top ensure it stays in view while scrolling */
    position: sticky;
    top: 0;
    height: 100vh;
    transition: width 0.3s ease-in-out;
    box-shadow: -2px 0 5px rgba(0,0,0,0.05);
}

#ai-assistant-panel.hidden {
    width: 0;
    overflow: hidden;
    border-left: none;
}

.ai-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid #d1d1d1;
    background-color: #f1f3f5;
}

.ai-panel-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

#ai-assistant-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6c757d;
    line-height: 1;
    padding: 0 5px;
}
#ai-assistant-close:hover {
    color: #343a40;
}

#ai-chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-message {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    word-wrap: break-word;
}

.ai-message.user {
    background-color: #007bff;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.ai-message.assistant {
    background-color: #e9ecef;
    color: #343a40;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.ai-message p {
    margin: 0;
    white-space: pre-wrap;
}

.ai-message .insert-button {
    background-color: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.5);
    color: white;
    padding: 3px 8px;
    margin-top: 8px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
}

.ai-message.assistant .insert-button {
    background-color: #d1d9e0;
    border: 1px solid #b8c2cc;
    color: #343a40;
}

.ai-message.assistant .insert-button:hover {
    background-color: #c4cdd5;
}

#ai-chat-input-container {
    display: flex;
    align-items: flex-end;
    padding: 10px;
    border-top: 1px solid #d1d1d1;
    background-color: #f1f3f5;
}

#ai-chat-input {
    flex-grow: 1;
    border: 1px solid #ced4da;
    border-radius: 15px;
    padding: 8px 12px;
    font-size: 14px;
    resize: none;
    line-height: 1.4;
    max-height: 100px;
    overflow-y: auto;
}
#ai-chat-input:focus {
    outline: none;
    border-color: #80bdff;
    box-shadow: 0 0 0 0.2rem rgba(0,123,255,.25);
}

#ai-chat-send {
    flex-shrink: 0;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 16px;
    cursor: pointer;
    margin-left: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#ai-chat-send:hover {
    background-color: #0069d9;
}

#ai-chat-send:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
}

/* --- .doc Import Modal Styles --- */
.modal-body {
    padding: 20px;
    text-align: center;
}

.modal-body h4 {
    margin-top: 0;
    font-size: 1.2em;
}

.modal-body p {
    color: #666;
    margin-bottom: 20px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

#doc-file-input {
    display: block;
    margin: 20px auto;
}

.import-button {
    background-color: #28a745;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
}

.import-button:hover {
    background-color: #218838;
}

.import-button:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
}

.import-status {
    margin-top: 15px;
    font-weight: bold;
    color: #007bff;
}

/* --- Converter Modal Styles --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    width: 90%;
    height: 90%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid #d1d1d1;
    background-color: #f1f3f5;
}

.modal-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.modal-close-button {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6c757d;
    line-height: 1;
    padding: 0 5px;
}

.modal-close-button:hover {
    color: #343a40;
}

#converter-iframe {
    flex-grow: 1;
    width: 100%;
    border: none;
}