/* portal.css - Styles for the main unified console */

.portal-container {
    width: 100%;
    max-width: 480px;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    margin: 0 auto;
}

#app.portal-app {
    padding-top: 32px !important;
}

.portal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 0;
}

.portal-logo {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 2px;
}

.logo-sep {
    color: #FFFFFF;
    margin: 0 4px;
}

.logo-sub {
    color: var(--text-muted);
    font-weight: 600;
    opacity: 0.6;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.level-pill {
    padding: 6px 14px;
    background: #112240;
    border: 1px solid rgba(94, 234, 212, 0.4);
    border-radius: 8px;
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
}

.header-icons {
    display: flex;
    gap: 12px;
}

.header-icon {
    color: var(--accent);
    opacity: 0.9;
    cursor: pointer;
    transition: opacity 0.2s;
}

.header-icon:hover {
    opacity: 1;
}

/* Stats Section */
.stats-section {
    width: 100%;
    margin-top: auto;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.section-title {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 32px;
    text-align: center;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 48px;
}

.stat-card {
    background: #112240;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 24px 10px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}

.stat-card.learned {
    border-color: rgba(69, 170, 242, 0.2);
}

.stat-card.depth {
    border-color: rgba(43, 203, 186, 0.2);
}

.stat-card.due {
    border-color: rgba(250, 130, 49, 0.2);
}

.stat-value {
    font-size: 40px;
    font-weight: 500;
    margin-bottom: 8px;
}

.stat-value.blue {
    color: #FFFFFF;
}

.stat-value.teal {
    color: #2bcbba;
}

.stat-value.orange {
    color: #FFA502;
}

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* XP Card */
.xp-row-container {
    width: 100%;
}

.xp-card {
    background-color: var(--surface);
    height: 70px;
    width: 100%;
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
}

.xp-progress-bg {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    /* Dynamic width controlled by JS */
    background: linear-gradient(to right, rgba(94, 234, 212, 0.1), rgba(94, 234, 212, 0.35));
    transition: width 2s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 0 0 20px rgba(94, 234, 212, 0.2);
    z-index: 1;
}

.xp-content-layer {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    z-index: 2;
    width: 100%;
}

.xp-card-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.xp-star {
    font-size: 20px;
    display: flex;
    gap: 4px;
    filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.4));
}

.xp-level-label {
    font-family: 'Roboto Mono', monospace;
    font-weight: 500;
    font-size: 15px;
    color: #FFFFFF;
    letter-spacing: -0.5px;
}

.xp-card-right {
    font-family: 'Roboto Mono', monospace;
    font-size: 14px;
    font-weight: 500;
    color: rgba(94, 234, 212, 0.8);
    letter-spacing: -0.2px;
}

/* Action Area */
.action-area {
    width: 100%;
    margin-top: 96px;
    margin-bottom: auto;
    padding-bottom: 24px;
}

.main-action-btn {
    width: 100%;
    height: 80px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid transparent;
}

.main-action-btn.start {
    background: rgba(94, 234, 212, 0.1);
    color: var(--accent);
    border: 2px solid var(--accent);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px var(--accent-glow);
}

.main-action-btn.priority {
    background: rgba(255, 165, 2, 0.1);
    color: #FFA502;
    border: 2px solid #FFA502;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(255, 165, 2, 0.2);
}

.main-action-btn:active {
    transform: scale(0.96);
}

.btn-icon-svg {
    margin-bottom: 4px;
}

.btn-text {
    font-family: 'Roboto Mono', monospace;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 2px;
}

/* ── Library Overlay ── */
#libraryOverlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 5000;
    display: flex;
    flex-direction: column;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#libraryOverlay.show {
    opacity: 1;
    pointer-events: auto;
}

.library-container {
    width: 100%;
    max-width: 960px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 24px;
    padding-top: max(32px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    box-sizing: border-box;
}

.lib-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.lib-close-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    padding: 0;
}

.lib-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--text);
}

.lib-search {
    width: 100%;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-size: 15px;
    font-family: 'Inter', sans-serif;
    margin-bottom: 14px;
    outline: none;
    flex-shrink: 0;
    box-sizing: border-box;
    -webkit-appearance: none;
}

.lib-search:focus {
    border-color: rgba(94, 234, 212, 0.5);
}

.lib-search::placeholder {
    color: var(--text-muted);
}

.lib-filter-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.lib-tab {
    padding: 7px 18px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
}

.lib-tab.active {
    background: var(--accent);
    color: #0A0E17;
    border-color: var(--accent);
}

.lib-grid-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.lib-grid-wrapper::-webkit-scrollbar {
    display: none;
}

.lib-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding-bottom: 16px;
}

@media (min-width: 500px) {
    .lib-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.lib-word-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    cursor: default;
}

.lib-word {
    font-family: 'Noto Serif', serif;
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
    word-break: break-word;
    line-height: 1.3;
}

.lib-stage {
    font-size: 11px;
    color: var(--text-muted);
    font-family: 'Roboto Mono', monospace;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.lib-progress-track {
    height: 3px;
    background: var(--surface-2);
    border-radius: 2px;
    overflow: hidden;
    margin-top: auto;
}

.lib-progress-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.5s ease;
}

.lib-status {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 0 16px;
    font-size: 13px;
}

/* ── Smart Reader Overlay ── */
#readerOverlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 5000;
    display: flex;
    flex-direction: column;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#readerOverlay.show {
    opacity: 1;
    pointer-events: auto;
}

.reader-container {
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 480px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 24px;
    padding-top: max(32px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    box-sizing: border-box;
}

.reader-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0;
    flex-shrink: 0;
}

.reader-close-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    padding: 0;
}

.reader-title-bar {
    font-size: 20px;
    font-weight: 800;
    color: var(--accent);
}

.reader-history-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    padding: 0;
    transition: color 0.2s;
}

.reader-history-btn:hover {
    color: var(--accent);
}

/* History Panel */
.reader-history-panel {
    position: absolute;
    inset: 0;
    background: var(--card-bg, #0d1117);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    border-radius: inherit;
}

.reader-history-panel.open {
    transform: translateX(0);
}

.history-panel-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
}

.history-back-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    padding: 0;
}

.history-panel-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    transition: background 0.15s;
}

.history-item:hover {
    background: rgba(94, 234, 212, 0.05);
}

.history-item-time {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 12px;
    color: var(--text-muted);
    font-family: 'Roboto Mono', monospace;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 100px;
}

.history-item-date {
    font-size: 11px;
    opacity: 0.7;
}

.history-item-title {
    font-size: 15px;
    color: var(--text);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    padding: 48px 24px;
    line-height: 1.8;
}

/* Entry State */
.reader-entry {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 0 0;
}

.reader-entry-main {
    margin-top: auto;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    text-align: center;
    width: 100%;
}

.reader-energy-badge {
    padding: 9px 28px;
    border-radius: 32px;
    border: 1.5px solid var(--accent);
    background: rgba(94, 234, 212, 0.05);
    color: var(--accent);
    font-family: 'Roboto Mono', monospace;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.5px;
    transition: border-color 0.4s, color 0.4s, background 0.4s;
}

.reader-energy-badge.energy-depleted {
    border-color: #f87171;
    background: rgba(248, 113, 113, 0.08);
    color: #f87171;
}

.reader-fp-wrap {
    position: relative;
    width: 160px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reader-fp-glow {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: radial-gradient(circle at center,
        rgba(94, 234, 212, 0.18) 0%,
        rgba(94, 234, 212, 0.08) 45%,
        transparent 70%
    );
}

.reader-fp-glow::after {
    content: '';
    position: absolute;
    inset: 24px;
    border-radius: 50%;
    background: radial-gradient(circle at center,
        rgba(94, 234, 212, 0.12) 0%,
        transparent 70%
    );
    animation: fp-pulse 2.8s ease-in-out infinite;
}

@keyframes fp-pulse {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50%       { opacity: 1;   transform: scale(1.08); }
}

.reader-fp-icon {
    width: 88px;
    height: 88px;
    position: relative;
    z-index: 1;
    opacity: 0.82;
    filter:
        drop-shadow(0 0 6px rgba(94, 234, 212, 0.9))
        drop-shadow(0 0 18px rgba(94, 234, 212, 0.5))
        drop-shadow(0 0 36px rgba(94, 234, 212, 0.25));
}

.reader-entry-title {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    margin-top: -4px;
}

.reader-entry-desc {
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.7;
    max-width: 280px;
}

.reader-entry-footer {
    width: 100%;
    margin-top: 96px;
    margin-bottom: auto;
    padding-bottom: 24px;
    flex-shrink: 0;
}

.reader-gen-btn {
    width: 100%;
    height: 80px;
    background: rgba(94, 234, 212, 0.1);
    color: var(--accent);
    border: 2px solid var(--accent);
    border-radius: 16px;
    font-weight: 700;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px var(--accent-glow);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-family: 'Roboto Mono', monospace;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    letter-spacing: 2px;
}

.reader-gen-btn:hover {
    background: rgba(94, 234, 212, 0.15);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 30px var(--accent-glow);
}

.reader-gen-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.reader-gen-btn.btn-depleted {
    background: rgba(107, 114, 128, 0.1);
    border-color: #6b7280;
    color: #6b7280;
    box-shadow: none;
    cursor: not-allowed;
}

.reader-gen-btn.btn-depleted:hover {
    background: rgba(107, 114, 128, 0.1);
    box-shadow: none;
}

/* Neural Loading State */
.reader-neural {
    flex: 1;
    position: relative;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.reader-neural.active {
    display: flex;
}

#neuralSvg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#neuralNodes {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.neural-node {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transform: translate(-50%, -50%);
}

.neural-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent), 0 0 20px var(--accent-glow);
    animation: neuralPulse 2s ease-in-out infinite;
}

@keyframes neuralPulse {
    0%, 100% { transform: scale(1); opacity: 0.7; }
    50% { transform: scale(1.7); opacity: 1; }
}

.neural-word-label {
    font-family: 'Roboto Mono', monospace;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    background: rgba(10, 14, 23, 0.85);
    border: 1px solid rgba(94, 234, 212, 0.25);
    border-radius: 5px;
    padding: 4px 10px;
}

.neural-status-text {
    font-family: 'Roboto Mono', monospace;
    font-size: 13px;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    z-index: 2;
    position: relative;
}

/* Story State */
.reader-story {
    flex: 1;
    display: none;
    flex-direction: column;
    overflow: hidden;
    padding-top: 32px;
}

.reader-story.active {
    display: flex;
}

.story-scroll {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.story-scroll::-webkit-scrollbar { display: none; }

.story-title {
    font-family: 'Noto Serif', serif;
    font-size: 30px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.3;
    margin-bottom: 12px;
}

.story-title-line {
    width: 64px;
    height: 3px;
    background: var(--accent);
    border-radius: 2px;
    margin-bottom: 24px;
    flex-shrink: 0;
}

.story-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 8px;
}

.story-body {
    font-size: 16px;
    line-height: 2;
    color: var(--text);
}

.story-keyword {
    color: var(--accent);
    font-weight: 700;
    text-decoration: underline;
    text-decoration-color: rgba(94, 234, 212, 0.5);
    text-underline-offset: 3px;
}

.reader-end-btn {
    width: 100%;
    height: 56px;
    margin-top: 20px;
    margin-bottom: 40px;
    flex-shrink: 0;
    background: transparent;
    border: 1.5px solid var(--accent);
    border-radius: 14px;
    color: var(--accent);
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.reader-end-btn:hover {
    background: rgba(94, 234, 212, 0.08);
}