/* Core Structural Variables */
:root {
    --bg-color: #ffffff;
    --text-color: #202124;
    --ui-bg: #f1f3f4;
    --ui-border: #dadce0;
    --modal-overlay: rgba(0, 0, 0, 0.4);
    --margin-line: #e0e0e0;
    --caret-color: #1a73e8;
    /* High visibility vivid cursor */
}

[data-theme="dark"] {
    --bg-color: #202124;
    --text-color: #e8eaed;
    --ui-bg: #303134;
    --ui-border: #5f6368;
    --modal-overlay: rgba(0, 0, 0, 0.7);
    --margin-line: #444;
    --caret-color: #8ab4f8;
}

[data-theme="warm"] {
    --bg-color: #fef7ce;
    --text-color: #3e3314;
    --ui-bg: #f5e695;
    --ui-border: #e3ce68;
    --modal-overlay: rgba(62, 51, 20, 0.4);
    --margin-line: #e3ce68;
    --caret-color: #b08000;
}

/* Reset and Layout Foundations */
* {
    box-sizing: border-box;
}

body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.2s, color 0.2s;
    font-family: system-ui, -apple-system, sans-serif;
    overflow: hidden;
}

#app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
}

/* Fixed Layout Textarea Configuration to prevent Horizontal Overflow */
#editor-wrapper {
    display: flex;
    width: 100%;
    flex-grow: 1;
    overflow: hidden;
    position: relative;
}

#line-numbers {
    width: 65px;
    min-width: 65px;
    padding: 20px 10px 20px 0;
    text-align: right;
    color: var(--text-color);
    opacity: 0.4;
    border-right: 1px solid var(--margin-line);
    font-family: monospace;
    font-size: 1.25rem;
    line-height: 1.6;
    overflow: hidden;
    user-select: none;
    background-color: var(--bg-color);
    transition: width 0.2s, min-width 0.2s, opacity 0.2s, border-color 0.2s;
}

/* Precise line row styling matching textarea line heights */
#line-numbers div {
    height: auto;
    white-space: nowrap;
}

/* Hide Margin Feature class state */
#line-numbers.hidden-margin {
    width: 0 !important;
    min-width: 0 !important;
    padding-right: 0 !important;
    padding-left: 0 !important;
    opacity: 0 !important;
    border-right-color: transparent !important;
}

#editor {
    flex-grow: 1;
    padding: 20px 25px;
    font-size: 1.25rem;
    line-height: 1.6;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    color: inherit;
    font-family: inherit;

    /* Strict Window Bounds: Text wraps cleanly */
    white-space: pre-wrap;
    word-break: break-word;
    overflow-x: hidden;
    overflow-y: auto;

    /* High Visibility Cursor Enhancement */
    caret-color: var(--caret-color);
}

/* Desktop Bottom Controls Positioning */
.status-bar {
    position: absolute;
    bottom: 24px;
    left: 25px;
    font-size: 0.85rem;
    opacity: 0.65;
    pointer-events: none;
    z-index: 10;
}

/* Update Action Bar: Floating Glassmorphism Dock (Original Placement) */
.action-bar {
    position: absolute;
    bottom: 24px;
    right: 25px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;

    /* Frosted Glass Effect */
    background: rgba(241, 243, 244, 0.75);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);

    padding: 8px 12px;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.4);
    z-index: 10;

    max-width: calc(100% - 50px);
}

/* Theme support for the transparent dock */
[data-theme="dark"] .action-bar {
    background: rgba(48, 49, 52, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

[data-theme="warm"] .action-bar {
    background: rgba(245, 230, 149, 0.75);
    border: 1px solid rgba(227, 206, 104, 0.6);
}

/* UI Interactive Control Styling Tweaks */
button,
select {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-color);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 12px;
    transition: background 0.2s, border-color 0.2s, transform 0.1s;
    font-family: inherit;
    white-space: nowrap;
}

button:hover,
select:hover {
    background: var(--bg-color);
    border-color: var(--ui-border);
    transform: scale(1.02);
}

select {
    outline: none;
    appearance: none;
    padding-right: 14px;
    font-weight: 500;
}

.select-wrapper {
    position: relative;
    display: inline-block;
}

#btn-share {
    background: var(--text-color);
    color: var(--bg-color);
    font-weight: 600;
}

#btn-share:hover {
    opacity: 0.9;
}

.nav-link {
    text-decoration: none;
    display: inline-block;
}

/* Dropdown Menus */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    background-color: var(--ui-bg);
    min-width: 210px;
    box-shadow: 0px -8px 24px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--ui-border);
    border-radius: 6px;
    z-index: 20;
    flex-direction: column;
    padding: 4px 0;
}

.dropdown.active .dropdown-content {
    display: flex;
}

.dropdown-content button {
    text-align: left;
    border-radius: 0;
    border: none;
    padding: 10px 14px;
    width: 100%;
}

.dropdown-content button:hover {
    background: var(--bg-color);
}

/* Zen/Focus Presentation States */
body.focus-mode .status-bar,
body.focus-mode .action-bar {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: translateY(20px);
}

.status-bar,
.action-bar,
#line-numbers {
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
}

/* Modal Infrastructure Overlay */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 15px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-color);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid var(--ui-border);
    width: 100%;
    max-width: 350px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.modal-content h3,
.modal-subtitle {
    margin: 0;
}

.modal-subtitle {
    font-size: 0.85rem;
    opacity: 0.7;
    line-height: 1.4;
}

.retention-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.retention-options label {
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

#btn-generate-link {
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    padding: 10px;
    font-weight: 500;
}

#link-container {
    display: flex;
    gap: 6px;
}

#share-link {
    flex-grow: 1;
    padding: 8px;
    background: var(--ui-bg);
    color: var(--text-color);
    border: 1px solid var(--ui-border);
    border-radius: 6px;
    outline: none;
    font-size: 0.85rem;
}

.close-btn {
    color: #d9534f;
    margin-top: 5px;
}

/* Hidden Layout Mirror Container for Line Wrapping Calculations */
#line-mirror {
    position: absolute;
    visibility: hidden;
    height: auto;
    width: 0;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-y: hidden;
}

/* Semantic Screen Reader Shield */
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Floating Focus Mode Exit Button */
#btn-exit-focus {
    position: fixed;
    bottom: 24px;
    right: 25px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;

    /* Hidden by default */
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
    transition: opacity 0.3s ease, transform 0.3s ease, background 0.2s;
}

#btn-exit-focus:hover {
    background: rgba(0, 0, 0, 0.7);
    transform: scale(1.05);
}

body.focus-mode #btn-exit-focus {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}

/* Complete Responsive Interface Viewport Adaptations */
@media (max-width: 768px) {
    #editor-wrapper {
        padding-bottom: 90px;
    }

    #editor {
        padding: 15px;
        font-size: 1.15rem;
    }

    #line-numbers {
        font-size: 1.15rem;
        width: 45px;
        min-width: 45px;
        padding-top: 15px;
    }

    .status-bar {
        display: none;
    }

    /* Mobile placement logic */
    .action-bar {
        bottom: 10px;
        left: 10px;
        right: 10px;
        max-width: calc(100% - 20px);
        justify-content: center;
        padding: 8px;
    }

    /* Hide text & shortcuts on small screens */
    .hide-mobile {
        display: none;
    }

    /* Tighten button padding to create squares/circles for icons */
    .action-bar button:not(.dropdown-content button) {
        padding: 8px 10px;
    }
}

@media print {

    .status-bar,
    .action-bar,
    .modal,
    #btn-exit-focus {
        display: none !important;
    }

    #line-numbers {
        display: none !important;
    }

    #editor {
        padding: 0;
        overflow: visible;
    }

    body {
        background: white;
        color: black;
    }
}