/* Import Bitcount Grid Single font */
@import url('https://fonts.googleapis.com/css2?family=Bitcount+Grid+Single&display=swap');
/* Import Plus Jakarta Sans font */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600&display=swap');

/* light and airy color scheme */
:root {
    --term-bg: #ffffff;
    --term-text: #333333;
    --term-dim: #999999;
    --term-alert: #ff6666; /* softer red */
    --term-gold: #ffcc00;
    --term-cyan: #33b5e5;
    --grid-line: #dddddd;
    --grid-node: #f5f5f5;

    --font-family: "JetBrains Mono", "Fira Code", monospace;
    --font-size: 13px;
    --line-height: 1.7;
}

body {
    margin: 0;
    padding: 0;
    background: var(--term-bg);
    color: var(--term-text);
    font-family: var(--font-family);
    font-size: var(--font-size);
    line-height: var(--line-height);
}

a { color: var(--term-text); text-decoration: none; }

.app-header {
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 0;
}

.app-header h1 {
    font-family: 'Bitcount Grid Single', 'Courier New', monospace;
    font-size: 100px;
    font-style: normal;
    font-weight: normal;
    color: #f0f0f0;
    margin: 0;
    position: relative;
    z-index: -1;
}

.top-latent-panel {
    padding: 0 1rem 1rem;
    position: relative;
    z-index: 1;
    max-width: 600px;
    margin: 0 auto;
}

.cast-panel {
    padding: 0 1rem 0.5rem;
    position: relative;
    z-index: 1;
    max-width: 600px;
    margin: 0 auto;
}

.cast-emojis {
    background: #fafafa;
    border: 1px solid var(--term-dim);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    gap: 0.5rem;
    font-size: 32px;
}

#latentActions {
    display: block;
}

.latent-options-row {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: stretch;
    gap: 0.5rem;
    width: 100%;
}

.latent-options-row .latent-entry {
    flex: 0 0 45%;
    max-width: 45%;
    min-width: 0;
    margin-bottom: 0;
}

.entity-pool h2 {
    margin-top: 0;
}

/* hide latent library title */
.latent-panel h2 { display: none; }
/* hide scenario selector */
.scenario-select { display: none; }
.entity-pool li.selected {
    font-weight: bold;
    text-decoration: underline;
    background: var(--term-gold);
    color: var(--term-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
}
#addEntityBtn {
    margin-top: 0.5rem;
    padding: 0.3rem 0.6rem;
    font-size: 0.9rem;
    background: var(--term-cyan);
    color: #000;
    border: none;
    cursor: pointer;
    transition: opacity 0.15s;
}
#addEntityBtn:disabled { opacity: 0.4; cursor: default; }

.lock-control {
    margin-top: 0.5rem;
    width: 100%;
    text-align: center;
}
.lock-control button {
    display: inline-block;
    margin: 0 auto;
    padding: 0.4rem 0.8rem;
    font-family: 'Bitcount Grid Single', 'Courier New', monospace;
    font-size: 42px;
    color: var(--term-gold);
    background: #e0e0e0;
    border: 2px solid var(--term-gold);
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.15s;
}
.lock-control button:disabled { opacity: 0.4; cursor: default; }

.api-key-input {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--term-text);
    font-size: 0.9rem;
}
.api-key-input input {
    background: #fff;
    color: var(--term-text);
    border: 1px solid var(--term-dim);
    padding: 0.2rem 0.4rem;
    font-family: inherit;
    font-size: inherit;
}
.api-key-btn {
    padding: 0.2rem 0.5rem;
    font-size: 0.9rem;
    background: var(--term-gold);
    border: none;
    color: #222;
    cursor: pointer;
}
.api-key-btn:disabled {
    opacity: 0.5;
    cursor: default;
}
.api-key-status {
    font-size: 0.8rem;
    color: var(--term-green);
    margin-left: 0.25rem;
}

.latent-entry.processing {
    opacity: 0.6;
    animation: pulse 1s infinite alternate;
}
@keyframes pulse {
    from { opacity: 0.6; }
    to { opacity: 1; }
}

.app-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* keep sidebar from shrinking and creating layout shifts */
.sidebar {
    width: 220px;
    min-width: 300px;
    flex-shrink: 0;
    display: none;
}

/* grid section limited to 600px so it never expands */
.grid-section {
    max-width: 600px;
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto;
}

/* hide the entities list visually but keep it in DOM for logic */
.entity-pool {
    display: none;
}

.grid-section {
    padding: 1rem;
}

.grid {
    display: grid;
    grid-template-columns: repeat(var(--cols,8), 1fr);
    gap: 2px;
    background: var(--grid-line);
    border-radius: 12px;
    overflow: hidden;
    padding: 2px;
}

.grid-cell {
    aspect-ratio: 1;
    background: var(--term-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    font-size: 26px;
    border-radius: 6px;
}

.grid-cell.has-entity { background: var(--grid-node); }
.grid-cell.selected {
    background: #fffbdd;      /* light gold highlight */
    border: 2px solid var(--term-gold);
    animation: none !important;
    box-shadow: 0 0 8px var(--term-gold);
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}


.latent-entry {
    display: block;
    text-align: left;
    border: 1px solid var(--term-dim);
    border-radius: 8px;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    /* allow full height and wrap instead of clipping */
    max-height: none;
    overflow: visible;
    white-space: normal;
    word-wrap: break-word;
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 20px;
    background: #fafafa;
    cursor: pointer;
    transition: background 0.15s;
}
.latent-entry.goal { border-left: 4px solid var(--term-gold); }
.latent-entry.obstacle { border-left: 4px solid var(--term-alert); }
.latent-entry.shift { border-left: 4px solid var(--term-cyan); }
.latent-entry:hover { background: #f0f0f0; }
.latent-entry.selected { background: #fffbdd; border-color: var(--term-gold); }

.latent-context-box {
    display: block;
    text-align: center;
    border: 1px solid var(--term-dim);
    border-radius: 8px;
    padding: 0.5rem;
    margin-bottom: 0.75rem;
    background: #e8e8e8;
    color: #666;
    font-family: 'Bitcount Grid Single', 'Courier New', monospace;
    font-size: 16px;
    font-style: italic;
    white-space: normal;
    word-wrap: break-word;
    cursor: default;
    opacity: 0.75;
}

.worldtext-view {
    display: none; /* hidden */
    padding: 1rem;
    border: 1px solid var(--term-dim);
    min-height: 8rem;
    background: #fdfdfd;
    white-space: pre-wrap;
}
.worldtext .entity-link {
    color: var(--term-gold);
    font-weight: bold;
    cursor: pointer;
    text-decoration: underline;
}

.audit-log {
    max-height: 12rem;
    overflow-y: auto;
    font-size: 0.85rem;
    margin-top: 1rem;
    display: none; /* hidden by default */
}
.audit-log li { margin-bottom: 0.3rem; cursor: pointer; }
.audit-log li:hover { text-decoration: underline; }

.autoplay-control {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 100;
    display: none;
}

.autoplay-control button {
    font-size: 20px;
    padding: 0.5rem 1rem;
    border: none;
    background: var(--term-cyan);
    cursor: pointer;
    border-radius: 8px;
}

.app-footer {
    text-align: center;
    display: none;
}

/* ripple animation helper */
@keyframes ripple-expand {
  0% { transform: scale(0.5); opacity: 1; }
  100% { transform: scale(3); opacity: 0; }
}

.ripple {
    position: absolute;
    border: 2px solid currentColor;
    border-radius: 50%;
    animation: ripple-expand 0.8s ease-out;
}

/* scrollbars for retro look */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--term-bg); }
::-webkit-scrollbar-thumb { background: var(--term-dim); }
