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

html,
body {
    width: 100%;
    overflow-x: hidden;
}

body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #fafafb;
    color: #18181b;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

[hidden] {
    display: none !important;
}

#settings-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 32px;
    height: 32px;
    padding: 4px;
    object-fit: contain;
    cursor: pointer;
    z-index: 10;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#settings-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.page-wrap {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px 16px;
}

.reader-card {
    width: min(1000px, 100%);
    background: transparent;
    padding: 20px 0;
}

.reader-card h1 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #18181b;
}

.subtitle {
    margin: 6px 0 24px;
    font-size: 0.95rem;
    color: #71717a;
}

.reader-controls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    align-items: end;
    padding-bottom: 24px;
    margin-bottom: 32px;
    border-bottom: 1px solid #e4e4e7;
}

.reader-controls label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #a1a1aa;
}

.reader-controls select {
    width: 100%;
    height: 48px;
    padding: 0 12px;
    border: 1px solid #e4e4e7;
    border-radius: 10px;
    background: #ffffff;
    color: #18181b;
    font-size: 1.05rem;
    font-weight: 500;
    outline: none;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2371717a'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}

.reader-controls select:focus,
.reader-controls select:hover {
    border-color: #a1a1aa;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.ai-overview {
    margin: 0 auto 32px;
    padding: 16px 20px;
    border: 1px solid #d4d4d8;
    border-radius: 12px;
    background: #f4f4f5;
}

.ai-overview h2 {
    margin: 0 0 4px;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #3f3f46;
}

.ai-overview p {
    font-size: 0.95rem;
    color: #52525b;
}

.reader-output {
    margin: 0 auto;
    border: 0;
    padding: 0 0 40px;
    min-height: 60vh;
}

.reference {
    margin: 0 0 40px;
    text-align: center;
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    color: #18181b;
}

.verse {
    margin: 0 0 6px;
    padding: 6px 10px;
    line-height: 1.8;
    font-size: 1.25rem;
    font-weight: 400;
    color: #27272a;
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.verse:hover {
    background: #f4f4f5;
}

.verse-number {
    font-size: 0.85rem;
    font-weight: 600;
    color: #a1a1aa;
    vertical-align: super;
    margin-right: 6px;
    user-select: none;
}

.verse-tools-modal,
.settings-modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.verse-tools-modal.is-open,
.settings-modal:not([hidden]) {
    opacity: 1;
    pointer-events: auto;
}

.verse-tools-backdrop,
.settings-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.verse-tools-panel,
.settings-panel {
    position: relative;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: translateY(16px) scale(0.98);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.verse-tools-modal.is-open .verse-tools-panel,
.settings-modal:not([hidden]) .settings-panel {
    transform: translateY(0) scale(1);
}

.verse-tools-panel {
    width: min(1100px, 100%);
    height: min(88vh, 850px);
    padding: 24px 32px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.verse-tools-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.verse-tools-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #18181b;
}

.verse-tools-reference {
    margin-top: -14px;
    font-size: 1.05rem;
    font-weight: 500;
    color: #71717a;
}

#verse-tools-close,
#settings-close {
    border: 0;
    background: #f4f4f5;
    color: #71717a;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
}

#verse-tools-close:hover,
#settings-close:hover {
    background: #e4e4e7;
    color: #18181b;
}

.verse-tools-actions {
    display: flex;
    gap: 4px;
    padding: 6px;
    background: #f4f4f5;
    border-radius: 12px;
    width: max-content;
}

.verse-tools-actions .tool-tab {
    border: 0;
    background: transparent;
    color: #71717a;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.verse-tools-actions .tool-tab:hover:not(.is-active) {
    color: #18181b;
}

.verse-tools-actions .tool-tab.is-active {
    background: #ffffff;
    color: #18181b;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.verse-tools-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid #e4e4e7;
    border-radius: 14px;
    overflow: hidden;
    background: #ffffff;
}

#verse-tools-frame {
    flex: 1;
    width: 100%;
    height: 100%;
    border: none;
    background: #fafafb;
}

.bibleref-commentary {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    background: #fafafb;
    font-size: 0.97rem;
    line-height: 1.7;
    color: #27272a;
}

.bibleref-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px 12px;
    background: #ffffff;
    border-bottom: 1px solid #e4e4e7;
    font-weight: 600;
    font-size: 1rem;
    position: sticky;
    top: 0;
    z-index: 2;
}

.bibleref-badge {
    background: #3b82f6;
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 9px;
    border-radius: 20px;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.bibleref-ext-link {
    margin-left: auto;
    font-size: 1.1rem;
    color: #71717a;
    text-decoration: none;
    line-height: 1;
    transition: color 0.15s;
}

.bibleref-ext-link:hover {
    color: #3b82f6;
}

.bibleref-body {
    padding: 20px 24px;
    flex: 1;
}

.bibleref-body h1,
.bibleref-body h2,
.bibleref-body h3,
.bibleref-body h4 {
    font-size: 1rem;
    font-weight: 700;
    margin: 18px 0 6px;
    color: #18181b;
}

.bibleref-body p {
    margin: 0 0 12px;
}

.bibleref-body a {
    color: #3b82f6;
    text-decoration: none;
}

.bibleref-body a:hover {
    text-decoration: underline;
}

.bibleref-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.93rem;
}

.bibleref-body th,
.bibleref-body td {
    padding: 8px 12px;
    border: 1px solid #e4e4e7;
    text-align: left;
}

.bibleref-body th {
    background: #f4f4f5;
    font-weight: 600;
}

.bibleref-loading {
    padding: 32px 24px;
    color: #71717a;
    font-style: italic;
}

.verse-ai {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #fafafb;
}

.verse-ai-actions {
    padding: 16px 20px;
    background: #ffffff;
    border-bottom: 1px solid #e4e4e7;
}

#ai-summarize {
    border: 1px solid #e4e4e7;
    border-radius: 8px;
    padding: 8px 16px;
    background: #ffffff;
    color: #18181b;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

#ai-summarize:hover {
    background: #f4f4f5;
    border-color: #d4d4d8;
}

.verse-ai-log {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.verse-ai-msg {
    max-width: 85%;
    background: #ffffff;
    border: 1px solid #e4e4e7;
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 0.98rem;
    line-height: 1.5;
    color: #27272a;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.verse-ai-input-row {
    padding: 16px 20px;
    background: #ffffff;
    border-top: 1px solid #e4e4e7;
    display: flex;
    gap: 12px;
}

#ai-chat-input {
    flex: 1;
    height: 44px;
    padding: 0 16px;
    border: 1px solid #d4d4d8;
    border-radius: 10px;
    font-size: 0.95rem;
    background: #fafafb;
    transition: all 0.2s ease;
    outline: none;
}

#ai-chat-input:focus {
    background: #ffffff;
    border-color: #a1a1aa;
    box-shadow: 0 0 0 3px rgba(161, 161, 170, 0.1);
}

#ai-chat-send {
    border: 0;
    border-radius: 10px;
    padding: 0 24px;
    background: #18181b;
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

#ai-chat-send:hover {
    background: #27272a;
}

.settings-panel {
    width: min(440px, 100%);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.settings-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.settings-field {
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #52525b;
}

.settings-check {
    flex-direction: row;
    align-items: center;
    background: #f4f4f5;
    padding: 16px;
    border-radius: 10px;
    cursor: pointer;
}

.settings-check input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

#gemini-api-key {
    height: 48px;
    padding: 0 16px;
    border: 1px solid #d4d4d8;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    outline: none;
    transition: all 0.2s ease;
}

#gemini-api-key:focus {
    border-color: #a1a1aa;
    box-shadow: 0 0 0 3px rgba(161, 161, 170, 0.1);
}

.reader-output.startup-loading {
    display: grid;
    place-items: center;
    overflow: hidden;
}

.reader-output.startup-loading .container {
    --uib-size: 100px;
    --uib-color: #18181b;
    --uib-speed: 1s;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    width: var(--uib-size);
    height: calc(var(--uib-size) * 0.6);
}

.reader-output.startup-loading .cube {
    flex-shrink: 0;
    width: calc(var(--uib-size) * 0.2);
    height: calc(var(--uib-size) * 0.2);
    animation: jump var(--uib-speed) ease-in-out infinite;
}

.reader-output.startup-loading .cube__inner {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 25%;
    background-color: var(--uib-color);
    transform-origin: center bottom;
    animation: morph var(--uib-speed) ease-in-out infinite;
}

.reader-output.startup-loading .cube:nth-child(2) { animation-delay: calc(var(--uib-speed) * -0.36); }
.reader-output.startup-loading .cube:nth-child(2) .cube__inner { animation-delay: calc(var(--uib-speed) * -0.36); }
.reader-output.startup-loading .cube:nth-child(3) { animation-delay: calc(var(--uib-speed) * -0.2); }
.reader-output.startup-loading .cube:nth-child(3) .cube__inner { animation-delay: calc(var(--uib-speed) * -0.2); }

@keyframes jump {
    0%, 30%, 75% { transform: translateY(0); animation-timing-function: ease-out; }
    50% { transform: translateY(-200%); animation-timing-function: ease-in; }
}

@keyframes morph {
    0%, 10%, 40%, 70%, 85%, 100% { transform: scaleY(1); }
    20%, 25% { transform: scaleY(0.6) scaleX(1.3); animation-timing-function: ease-in-out; }
    30% { transform: scaleY(1.15) scaleX(0.9); animation-timing-function: ease-in-out; }
    75% { transform: scaleY(0.8) scaleX(1.2); }
}

@media (max-width: 768px) {
    .page-wrap { padding: 16px 12px; }
    
    .reader-controls {
        grid-template-columns: 1fr;
        gap: 16px;
        margin-bottom: 24px;
        padding-bottom: 20px;
    }

    .reference {
        font-size: 1.6rem;
        margin-bottom: 24px;
    }

    .verse {
        font-size: 1.15rem;
        padding: 4px 6px;
    }

    .verse-tools-modal,
    .settings-modal {
        padding: 12px;
    }

    .verse-tools-panel {
        height: 92vh;
        padding: 20px 16px;
        gap: 16px;
        border-radius: 16px;
    }

    .verse-tools-actions {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }
    
    .verse-tools-actions .tool-tab {
        text-align: center;
        padding: 8px;
        font-size: 0.8rem;
    }

    .verse-ai-input-row {
        flex-direction: column;
    }

    #ai-chat-send {
        height: 44px;
    }
}