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

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1e1e2e 0%, #2d2d44 100%);
    color: #e0e0e0;
    line-height: 1.6;
}

body.story-page {
    min-height: 100vh;
    display: block;
    overflow-x: hidden;
    overflow-y: auto;
    --story-header-height: 86px;
    padding-top: var(--story-header-height);
}

body.story-page .container {
    display: block;
    min-height: 100vh;
}

.container {
    width: 100%;
    margin: 0 auto;
    padding: 0;
}

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    margin-bottom: 0;
    padding: 6px 12px;
    background: rgba(17, 24, 39, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(148, 163, 184, 0.35);
    will-change: transform, backdrop-filter;
}

body.story-page .header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
}

.header.header-force-redraw {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}


.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: nowrap;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    min-width: 0;
}

.header-toolbar .header-brand {
    padding-right: 6px;
}

.header-toolbar .header-brand h1 {
    margin: 0;
    font-size: 1.05em;
    white-space: nowrap;
}

.header-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    justify-content: flex-end;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 14px;
    padding: 6px 10px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.35);
    -webkit-overflow-scrolling: touch;
}

.header-toolbar::-webkit-scrollbar {
    height: 4px;
}

.header-toolbar::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.5);
    border-radius: 999px;
}

.header-toolbar .toolbar-divider {
    width: 1px;
    height: 26px;
    background: rgba(148, 163, 184, 0.4);
}


.header-toolbar .toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 5px 10px;
    font-size: 0.8em;
    line-height: 1;
    flex: 0 0 auto;
}


.header-toolbar .toolbar-select {
    min-width: 120px;
    max-width: 180px;
    height: 34px;
    flex: 0 0 auto;
}

.header-toolbar .auth-status {
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid rgba(34, 197, 94, 0.45);
    background: rgba(15, 23, 42, 0.55);
    min-width: 0;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-toolbar .auth-user-name {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 640px) {
    .header-top {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .header-toolbar {
        width: 100%;
        justify-content: flex-start;
    }

    .header-toolbar .toolbar-divider {
        display: none;
    }
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.header-controls.header-toolbar {
    flex-wrap: nowrap;
}

.header h1 {
    font-size: 1.2em;
    margin: 0;
    color: #a78bfa;
    text-shadow: 0 1px 3px rgba(167, 139, 250, 0.2);
    white-space: nowrap;
}

.header p {
    display: none;
}

.btn-dev {
    background: rgba(0, 0, 0, 0.4);
    color: #00d4ff;
    padding: 6px 10px;
    border-radius: 4px;
    text-decoration: none;
    border: 1px solid #00d4ff;
    transition: all 0.3s;
    font-size: 0.85em;
    font-weight: 500;
    white-space: nowrap;
}

.btn-dev:hover {
    background: rgba(0, 212, 255, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 212, 255, 0.2);
}

.model-select-header {
    background: rgba(124, 58, 237, 0.2);
    border: 1px solid #7c3aed;
    border-radius: 4px;
    color: #e0e0e0;
    padding: 6px 10px;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.3s ease;
}

.model-select-header:hover,
.model-select-header:focus {
    background: rgba(124, 58, 237, 0.3);
    border-color: #a78bfa;
    outline: none;
}

.auth-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border: 1px solid rgba(34, 197, 94, 0.35);
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.55);
}

.auth-user-name {
    color: #86efac;
    font-size: 0.85em;
    font-weight: 600;
}

.btn-auth-action {
    border: 1px solid rgba(167, 139, 250, 0.4);
    background: rgba(124, 58, 237, 0.16);
    color: #ede9fe;
    border-radius: 999px;
    padding: 5px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-auth-action:hover {
    background: rgba(124, 58, 237, 0.28);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 12px 16px 36px;
    overflow-x: hidden;
    overflow-y: auto;
    width: 100%;
    box-sizing: border-box;
}

body.story-page .main-content {
    padding: 12px 16px 40px;
    overflow: visible;
    display: block;
}

.auth-section {
    margin-bottom: 18px;
    padding: 16px;
    border: 1px solid rgba(124, 58, 237, 0.35);
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.84), rgba(49, 46, 129, 0.5));
}

/* Standalone auth pages (login/register) */
.auth-page-body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e1e2e 0%, #2d2d44 100%);
}

.auth-page-container {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 24px 16px 40px;
}

.auth-header {
    position: static;
    background: transparent;
    border-bottom: none;
    padding-left: 0;
    padding-right: 0;
}

.auth-main {
    margin-top: 16px;
}

.auth-section-standalone {
    margin-bottom: 0;
}

.auth-switch-copy {
    margin-top: 16px;
    color: #cbd5e1;
    font-size: 0.95em;
}

.auth-link {
    color: #a78bfa;
    text-decoration: underline;
}

.auth-link-btn {
    border: none;
    background: transparent;
    color: #a78bfa;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    font: inherit;
}

.auth-link-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.auth-panel-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 14px;
}

.auth-panel-header h3 {
    color: #e9d5ff;
    margin-bottom: 4px;
}

.auth-panel-header p {
    color: #cbd5e1;
    font-size: 0.95em;
}

.auth-mode-toggle {
    display: inline-flex;
    gap: 8px;
}

.auth-mode-btn {
    border: 1px solid rgba(167, 139, 250, 0.35);
    background: rgba(15, 23, 42, 0.5);
    color: #d8b4fe;
    border-radius: 999px;
    padding: 8px 14px;
    cursor: pointer;
}

.auth-mode-btn.active {
    background: rgba(124, 58, 237, 0.8);
    color: #fff;
}

.auth-form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    align-items: center;
}

.auth-form-grid input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid rgba(167, 139, 250, 0.3);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.55);
    color: #f8fafc;
}

.auth-submit-btn {
    width: 100%;
}

.auth-profile {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.45);
    border: 1px solid rgba(34, 197, 94, 0.25);
}

.auth-profile-copy {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.auth-profile-copy strong {
    color: #86efac;
}

.auth-profile-copy span {
    color: #cbd5e1;
    font-size: 0.92em;
}

.auth-profile-actions {
    display: flex;
    gap: 8px;
}

.account-panel {
    margin-top: 12px;
    padding: 14px;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid rgba(167, 139, 250, 0.2);
}

.account-panel-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 12px;
}

.account-panel-header h4 {
    color: #ede9fe;
    margin-bottom: 4px;
}

.account-panel-header p {
    color: #cbd5e1;
    font-size: 0.9em;
}

.account-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.password-form-grid {
    grid-template-columns: 1fr;
}

.account-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.account-field span {
    color: #d8b4fe;
    font-size: 0.9em;
    font-weight: 600;
}

.account-field input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid rgba(167, 139, 250, 0.3);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.55);
    color: #f8fafc;
}

.account-field input:focus {
    outline: none;
    border-color: #a78bfa;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.18);
}

.account-form-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 14px;
}

.btn-inline {
    width: auto;
    margin-top: 0;
    grid-column: auto;
}

.btn-compact {
    padding: 8px 12px;
}

.auth-message {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.95em;
}

.auth-message.info {
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(96, 165, 250, 0.35);
    color: #bfdbfe;
}

.auth-message.success {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(74, 222, 128, 0.35);
    color: #bbf7d0;
}

.auth-message.error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(248, 113, 113, 0.35);
    color: #fecaca;
}

/* Story Display Section */
.story-display {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    display: none;
    flex-direction: column;
    gap: 0;
    opacity: 0;
    transition: opacity 0.5s ease 0.2s;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    margin: 0;
}

body.story-page .story-display {
    display: block;
    overflow: visible;
}

body.story-page .story-display:not(.hidden) {
    display: block;
}

.story-display:not(.hidden) {
    display: flex;
    opacity: 1;
    pointer-events: auto;
}

.story-display.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

.narrative-text {
    background: transparent;
    padding: 12px;
    border-radius: 0;
    min-height: 0;
    flex: 1;
    overflow-y: auto;
    border: none;
    color: #e0e0e0;
    line-height: 1.65;
}

body.story-page .narrative-text {
    padding-bottom: 24px;
    overflow: visible;
}

.narrative-text p {
    margin-bottom: 12px;
}

.narrative-text hr {
    margin: 10px 0;
    border: none;
    border-top: 1px solid #555;
}

/* Scenario Styling */
.story-scenario {
    margin-bottom: 30px;
    padding: 20px;
    border-radius: 8px;
    background: rgba(59, 130, 246, 0.1);
    border-left: 4px solid #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.scenario-header {
    font-weight: 700;
    font-size: 1.1em;
    color: #60a5fa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.scenario-text {
    font-size: 1em;
    line-height: 1.6;
    color: #d1d5db;
    font-style: italic;
}

/* Story Meta Information (Objective, Atmosphere, Appearance) */
.story-meta {
    display: none;
    margin-bottom: 30px;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
}

.meta-item {
    padding: 15px;
    border-radius: 8px;
    background: rgba(168, 85, 247, 0.1);
    border-left: 3px solid #a855f7;
    border: 1px solid rgba(168, 85, 247, 0.3);
}

.meta-label {
    font-weight: 600;
    font-size: 0.95em;
    color: #d8b4fe;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 8px;
    display: block;
}

.meta-content {
    font-size: 0.95em;
    line-height: 1.5;
    color: #e5e7eb;
}

.meta-content p {
    margin: 0;
}
    .header-top {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .header-controls {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .model-select-header {
        width: 100%;
    }

    .auth-section {
        padding: 12px;
    }

    .auth-form-grid {
        grid-template-columns: 1fr;
    }

    .auth-submit-btn {
        width: 100%;
    }

    .account-panel-header,
    .auth-panel-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .dashboard-grid {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }

    .dashboard-card-grid {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .main-content {
        overflow: visible;
    }

.meta-character {
    background: rgba(244, 114, 182, 0.08);
    border-left-color: #f472b6;
    border-color: rgba(244, 114, 182, 0.3);
}

.meta-character .meta-label {
    color: #f472b6;
}

.char-details {
    color: #cbd5e1;
    font-weight: normal;
    font-size: 0.9em;
}

.char-traits {
    color: #94a3b8;
    margin-top: 8px !important;
    font-size: 0.9em;
}

/* Story Consequences (Key Events) */
.story-consequences {
    display: none;
    margin-bottom: 30px;
    padding: 15px;
    border-radius: 8px;
    background: rgba(239, 68, 68, 0.1);
    border-left: 3px solid #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.consequences-header {
    font-weight: 700;
    font-size: 1em;
    color: #fca5a5;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.consequences-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.consequence-item {
    display: flex;
    gap: 10px;
    font-size: 0.95em;
    line-height: 1.5;
    color: #f5d;
}

.consequence-turn {
    font-weight: 600;
    color: #fecaca;
    flex-shrink: 0;
    min-width: 70px;
}

.consequence-text {
    color: #f3e8ff;
}

/* Turn Styling */
.turn {
    margin-bottom: 6px;
    padding: 6px 0;
    border-radius: 0;
    border-left: none;
    border-top: 1px solid rgba(124, 58, 237, 0.15);
}

.turn-ai {
    background: transparent;
    border-left-color: transparent;
}

.turn-player {
    background: transparent;
    border-left-color: transparent;
}

.turn-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
    padding-bottom: 0;
    border-bottom: none;
}

.turn-player .turn-header {
    border-bottom-color: transparent;
}

.turn-label {
    font-weight: 600;
    font-size: 0.8em;
    color: #a78bfa;
    text-transform: capitalize;
    letter-spacing: 0;
    white-space: nowrap;
}

.turn-player .turn-label {
    color: #34d399;
}

.turn-meta {
    display: none;
}

.turn-character {
    font-weight: 600;
    font-size: 0.75em;
    color: #f472b6;
    background: rgba(244, 114, 182, 0.15);
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
    letter-spacing: 0.5px;
}

.model-name {
    font-weight: 600;
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.15);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
}

.turn-text {
    color: #e0e0e0;
    line-height: 1.8;
}

.turn-graphics {
    margin-top: 15px;
    padding: 10px 0;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
}

/* Graphics Canvas */
.graphics-canvas {
    width: 100%;
    height: 300px;
    background: #1a1a2e;
    border: 1px solid #444;
    border-radius: 8px;
    display: block;
}

.graphics-canvas.visible {
    display: block;
}

/* Graphics Image */
.graphics-image {
    width: 100%;
    max-height: 400px;
    border-radius: 8px;
    display: block;
    object-fit: contain;
    background: #1a1a2e;
    border: 1px solid #444;
}

/* Input Section */
.input-section {
    margin-top: 30px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    border: 1px solid #7c3aed;
}

/* Old turn-type-selector and turn-model-selector classes removed - using new inline layout */

.input-section label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #a78bfa;
}

.input-section textarea {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid #555;
    border-radius: 5px;
    color: #e0e0e0;
    font-size: 1em;
    font-family: inherit;
    resize: vertical;
    transition: all 0.3s ease;
}

.input-section textarea:focus {
    outline: none;
    border-color: #7c3aed;
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

/* Input Section */
.input-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    padding: 6px 12px 8px;
    background: transparent;
    border-radius: 0;
    border: none;
    flex-shrink: 0;
}

body.story-page .input-section {
    background: rgba(15, 23, 42, 0.93);
    border: 1px solid rgba(167, 139, 250, 0.35);
    box-shadow: 0 15px 40px rgba(15, 23, 42, 0.55);
    padding: 12px 16px 16px;
    margin-top: 20px;
    border-radius: 16px;
    width: 100%;
    align-self: stretch;
}

/* Player Action Row - Horizontal Layout */
.player-action-row {
    display: flex;
    gap: 6px;
    align-items: center;
    width: 100%;
}

/* Player Controls Row - Buttons */
.player-controls-row {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
    align-items: stretch;
    width: 100%;
    margin-top: 6px;
    overflow: hidden;
}

.player-controls-row > button {
    flex: 0 0 auto;
    height: 48px;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    align-self: stretch;
    transition: none !important;
    animation: none !important;
    transform: none !important;
    box-shadow: none !important;
}

.player-controls-row > .btn-suggestions,
.player-controls-row > .btn-suggestions-settings {
    width: 48px;
    min-width: 48px;
}

.player-controls-row > .submit-btn {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    padding: 0 14px;
    justify-content: space-between;
    gap: 0;
}

.player-controls-row > .submit-btn .submit-btn-icon {
    flex: 0 0 auto;
    margin: 0 auto 0 0;
    line-height: 1;
}

.player-controls-row > .submit-btn .spinner-inline {
    flex: 0 0 auto;
    margin: 0 0 0 auto;
    transform: scale(0.6);
}

.player-controls-row > .submit-btn.loading .spinner-inline {
    transform: scale(1);
}

/* Action Type with Submit - Combined */
.action-type-with-submit {
    flex: 0 0 auto;
    display: flex;
    gap: 0;
    align-items: center;
    border-radius: 5px;
    overflow: hidden;
}

.action-type-with-submit .inline-select {
    flex: 0 0 130px;
    min-width: 130px;
    height: 48px;
    border-radius: 0;
    padding: 0 8px;
    margin: 0;
    line-height: 40px;
    box-sizing: border-box;
}

.action-type-with-submit .submit-btn {
    flex: 0 0 50px;
    min-width: 50px;
    height: 48px;
    padding: 0;
    border-radius: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    box-sizing: border-box;
}

/* Action Input */
.action-input {
    flex: 1;
    min-width: 200px;
    padding: 0 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid #555;
    border-radius: 5px;
    color: #e0e0e0;
    font-size: 0.95em;
    font-family: inherit;
    transition: all 0.3s ease;
    height: 48px;
    line-height: 48px;
    box-sizing: border-box;
}

.action-input::placeholder {
    color: #888;
}

.action-input:focus {
    outline: none;
    border-color: #7c3aed;
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

/* Submit Button */
.submit-btn {
    flex: 0 0 auto;
    min-width: 64px;
    height: 48px;
    padding: 0 14px;
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    border: 1px solid transparent;
    border-radius: 5px;
    color: white;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    gap: 12px;
}

.submit-btn.loading {
    cursor: wait;
    pointer-events: none;
    background: linear-gradient(135deg, #6b21a8, #9333ea);
}

.submit-btn .spinner-inline {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.submit-btn.loading .spinner-inline {
    opacity: 1;
    transform: scale(1);
}

.submit-btn .submit-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25em;
    transition: opacity 0.2s ease;
}

.submit-btn.loading .submit-btn-icon {
    opacity: 0.4;
}

.submit-btn:hover {
    background: linear-gradient(135deg, #8b5cf6, #c084fc);
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(124, 58, 237, 0.5);
}

.submit-btn:active {
    transform: scale(0.98);
}

/* Suggestions Button */
.btn-suggestions {
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    min-width: 48px;
    padding: 0;
    background: linear-gradient(135deg, #10b981, #14b8a6);
    border: 1px solid rgba(16, 185, 129, 0.5);
    border-radius: 5px;
    color: white;
    font-size: 1.3em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.btn-suggestions:hover {
    background: linear-gradient(135deg, #059669, #0d9488);
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.5);
}

.btn-suggestions:active {
    transform: scale(0.98);
}

/* Suggestions Settings Button */
.btn-suggestions-settings {
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    min-width: 48px;
    padding: 0;
    background: linear-gradient(135deg, #8b5cf6, #a855f7);
    border: 1px solid rgba(139, 92, 246, 0.5);
    border-radius: 5px;
    color: white;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.btn-suggestions-settings:hover {
    background: linear-gradient(135deg, #7c3aed, #9333ea);
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.5);
}

.btn-suggestions-settings:active {
    transform: scale(0.98);
}

/* Suggestions Settings Modal */
.suggestions-settings-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    background: rgba(15, 23, 42, 0.98);
    border: 1px solid rgba(167, 139, 250, 0.5);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    min-width: 320px;
    max-width: 420px;
    animation: slideInUp 0.3s ease;
}

.suggestions-settings-modal:not(.hidden) {
    display: block;
}

.suggestions-settings-modal.hidden {
    display: none;
}

@keyframes slideInUp {
    from {
        transform: translate(-50%, -40%);
        opacity: 0;
    }
    to {
        transform: translate(-50%, -50%);
        opacity: 1;
    }
}

.settings-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.settings-overlay:not(.hidden) {
    display: block;
}

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

.settings-content {
    display: flex;
    flex-direction: column;
    gap: 0;
    height: 100%;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid rgba(167, 139, 250, 0.2);
}

.settings-header h2 {
    margin: 0;
    font-size: 1.1em;
    color: #a78bfa;
    font-weight: 600;
}

.settings-close {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    color: #a78bfa;
    font-size: 1.8em;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.settings-close:hover {
    color: #e0e0e0;
}

.settings-body {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 16px;
    flex: 1;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-group label {
    font-weight: 600;
    color: #d8b4fe;
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.count-selector {
    display: flex;
    gap: 8px;
}

.count-btn {
    flex: 1;
    padding: 10px;
    background: rgba(124, 58, 237, 0.2);
    border: 1px solid rgba(124, 58, 237, 0.4);
    border-radius: 6px;
    color: #a78bfa;
    font-weight: 600;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s ease;
}

.count-btn:hover {
    background: rgba(124, 58, 237, 0.35);
    border-color: rgba(124, 58, 237, 0.7);
}

.count-btn.active {
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    border-color: #a78bfa;
    color: white;
    box-shadow: 0 0 12px rgba(124, 58, 237, 0.4);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background 0.2s ease;
}

.toggle-label:hover {
    background: rgba(124, 58, 237, 0.1);
}

.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #a855f7;
}

.toggle-label span {
    color: #d8b4fe;
    font-size: 0.9em;
    font-weight: 500;
}

.settings-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid rgba(167, 139, 250, 0.2);
}

.btn-settings-apply {
    padding: 10px 20px;
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    border: none;
    border-radius: 6px;
    color: white;
    font-weight: 600;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-settings-apply:hover {
    background: linear-gradient(135deg, #8b5cf6, #c084fc);
    box-shadow: 0 0 12px rgba(124, 58, 237, 0.4);
}

.btn-settings-apply:active {
    transform: scale(0.98);
}

/* Suggestions Panel */
.suggestions-panel {
    display: none;
    width: 100%;
    margin-top: 8px;
    padding: 12px;
    background: rgba(5, 46, 42, 0.8);
    border: 1px solid rgba(16, 185, 129, 0.35);
    border-radius: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.suggestions-panel:not(.hidden) {
    display: block;
}

.suggestions-panel.hidden {
    display: none;
}

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

.suggestions-title {
    font-weight: 600;
    font-size: 0.9em;
    color: #6ee7b7;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.suggestions-loading {
    display: none;
    align-items: center;
    gap: 8px;
    font-size: 0.85em;
    color: #a7f3d0;
}

.suggestions-loading:not(.hidden) {
    display: flex;
}

.suggestions-spinner {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(167, 243, 208, 0.3);
    border-top-color: #a7f3d0;
    animation: spin 0.8s linear infinite;
}

.suggestions-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.suggestion-item {
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-radius: 5px;
    color: #d1fae5;
    font-size: 0.9em;
    line-height: 1.4;
    cursor: pointer;
    transition: all 0.2s ease;
}

.suggestion-meta {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
}

.suggestion-type {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75em;
    font-weight: 600;
    letter-spacing: 0.2px;
    border: 1px solid transparent;
}

.suggestion-type-act {
    color: #bbf7d0;
    background: rgba(34, 197, 94, 0.18);
    border-color: rgba(34, 197, 94, 0.35);
}

.suggestion-type-say {
    color: #bfdbfe;
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.35);
}

.suggestion-type-free_line {
    color: #fde68a;
    background: rgba(245, 158, 11, 0.2);
    border-color: rgba(245, 158, 11, 0.35);
}

.suggestion-text {
    color: #d1fae5;
    line-height: 1.45;
}

.suggestion-item.suggestion-match {
    border-color: rgba(16, 185, 129, 0.65);
    box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.25), inset 0 0 6px rgba(16, 185, 129, 0.08);
}

.suggestion-item.suggestion-mismatch {
    opacity: 0.45;
}

.suggestion-item:hover {
    background: rgba(16, 185, 129, 0.15);
    border-color: rgba(16, 185, 129, 0.5);
    box-shadow: inset 0 0 8px rgba(16, 185, 129, 0.1);
    opacity: 1;
}

.suggestion-item:active {
    transform: scale(0.98);
}

.suggestions-error {
    display: none;
    padding: 10px 12px;
    background: rgba(220, 38, 38, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.35);
    border-radius: 5px;
    color: #fecaca;
    font-size: 0.9em;
}

.suggestions-error:not(.hidden) {
    display: block;
}

/* Turn Type Select */
.turn-type-select {
    flex: 0 0 auto;
    min-width: 60px;
    max-width: 180px;
    height: 48px;
    padding: 0 8px;
    border: 1px solid #7c3aed;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.55);
    color: #ffffff;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 46px;
    box-sizing: border-box;
}

.turn-type-select:hover {
    background: rgba(0, 0, 0, 0.6);
    border-color: #a78bfa;
}

.turn-type-select:focus {
    outline: none;
    background: rgba(0, 0, 0, 0.6);
    border-color: #a78bfa;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2);
}

.turn-type-select:disabled {
    cursor: not-allowed;
    opacity: 0.7;
    background: rgba(15, 23, 42, 0.6);
    border-color: rgba(167, 139, 250, 0.4);
}

/* Inline Select Styling */
.inline-select {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #7c3aed;
    border-radius: 5px;
    color: #ffffff;
    padding: 0 12px;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.3s ease;
    height: 48px;
    line-height: 46px;
    box-sizing: border-box;
    box-shadow: none;
}

.inline-select:hover {
    background: rgba(0, 0, 0, 0.6);
    border-color: #a78bfa;
}

.inline-select:focus {
    outline: none;
    background: rgba(0, 0, 0, 0.6);
    border-color: #a78bfa;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2);
}

/* Input Section label (remove if used) */
.input-section label {
    font-weight: 600;
    color: #a78bfa;
}

.input-section textarea {
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid #555;
    color: #e0e0e0;
    padding: 12px;
    border-radius: 8px;
    font-family: inherit;
    resize: vertical;
}

.input-section textarea:focus {
    outline: none;
    border-color: #7c3aed;
    box-shadow: 0 0 10px rgba(124, 58, 237, 0.3);
}

.dashboard-section {
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: 100%;
}

.dashboard-hero,
.dashboard-panel {
    border: 1px solid rgba(148, 163, 184, 0.16);
    background: rgba(15, 23, 42, 0.56);
    border-radius: 16px;
    padding: 18px;
    backdrop-filter: blur(10px);
}

.dashboard-hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
}

.dashboard-eyebrow {
    color: #fbbf24;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.76em;
    font-weight: 700;
    margin-bottom: 8px;
}

.dashboard-hero h2 {
    color: #f8fafc;
    font-size: clamp(1.7rem, 2vw, 2.3rem);
    margin-bottom: 8px;
}

.dashboard-copy {
    color: #cbd5e1;
    max-width: 720px;
}

.dashboard-hero-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.dashboard-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.btn-danger-inline {
    border-color: rgba(248, 113, 113, 0.45);
    background: rgba(127, 29, 29, 0.24);
    color: #fecaca;
}

.btn-danger-inline:hover {
    background: rgba(153, 27, 27, 0.38);
    border-color: rgba(252, 165, 165, 0.65);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.dashboard-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
}

.dashboard-panel-header h3,
.dashboard-panel h3 {
    color: #e9d5ff;
    margin-bottom: 4px;
}

.dashboard-panel-header p,
.dashboard-empty,
.dashboard-loading {
    color: #cbd5e1;
}

.dashboard-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 14px;
}

.dashboard-card {
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.88), rgba(15, 23, 42, 0.72));
    border: 1px solid rgba(167, 139, 250, 0.18);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 220px;
}

.dashboard-card h4 {
    color: #f8fafc;
    font-size: 1.05rem;
}

.dashboard-card-topline,
.dashboard-meta-row,
.dashboard-card-actions {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.dashboard-pill {
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(124, 58, 237, 0.18);
    border: 1px solid rgba(167, 139, 250, 0.35);
    color: #d8b4fe;
    font-size: 0.78rem;
    font-weight: 600;
}

.dashboard-card-date,
.dashboard-meta-row,
.dashboard-last-turn {
    color: #94a3b8;
    font-size: 0.88rem;
}

.dashboard-submeta {
    color: #94a3b8;
    font-size: 0.84rem;
    margin: -6px 0 0;
}

.dashboard-card-body {
    color: #e2e8f0;
    line-height: 1.6;
    flex: 1;
}

.dashboard-last-turn {
    border-top: 1px solid rgba(148, 163, 184, 0.12);
    padding-top: 10px;
}

.dashboard-empty,
.dashboard-loading {
    border: 1px dashed rgba(148, 163, 184, 0.25);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    background: rgba(15, 23, 42, 0.35);
}

/* Buttons */
button {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
    color: white;
    grid-column: 1 / -1;
    width: 100%;
    margin-top: 10px;
    padding: 10px 20px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(124, 58, 237, 0.3);
}

.btn-secondary {
    background: rgba(124, 58, 237, 0.2);
    color: #7c3aed;
    border: 1px solid #7c3aed;
    padding: 0.6rem 1rem;
    border-radius: 4px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-secondary:hover {
    background: rgba(124, 58, 237, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 5px 10px rgba(124, 58, 237, 0.2);
}

#submitBtn {
    background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%);
    color: white;
    width: 100%;
    margin-top: 10px;
}

#submitBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(124, 58, 237, 0.3);
}

/* Loading Indicator */
/* Non-blocking toast notification for loading state */
.loading-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(124, 58, 237, 0.95);
    padding: 12px 16px;
    border-radius: 6px;
    text-align: center;
    z-index: 1000;
    border: 1px solid rgba(168, 85, 247, 0.5);
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
    font-size: 0.9em;
    color: #e9d5ff;
    animation: slideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.loading-toast.hidden {
    animation: slideOut 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

.loading-toast span {
    font-weight: 500;
    letter-spacing: 0.3px;
}

/* Small spinner for non-blocking toast */
.spinner-small {
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top: 2px solid #e9d5ff;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    animation: spin 1s linear infinite;
    flex-shrink: 0;
}

.spinner {
    border: 4px solid #444;
    border-top: 4px solid #7c3aed;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
/* Utilities */
.hidden {
    display: none !important;
}

/* Non-critical sections fade smoothly */
.init-section.hidden {
    display: none;
}

.story-display.hidden {
    display: none;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

::-webkit-scrollbar-thumb {
    background: #7c3aed;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a855f7;
}

/* Responsive */
@media (max-width: 768px) {
    .header h1 {
        font-size: 1.8em;
    }

    .header-top,
    .auth-panel-header,
    .auth-profile {
        flex-direction: column;
        align-items: stretch;
    }

    .header-controls,
    .auth-profile-actions {
        flex-wrap: wrap;
    }

    .auth-form-grid {
        grid-template-columns: 1fr;
    }

    .auth-profile {
        flex-direction: column;
        align-items: stretch;
    }

    .auth-profile-actions {
        flex-direction: column;
    }

    .account-panel-header {
        flex-direction: column;
    }

    .account-form-grid {
        grid-template-columns: 1fr;
    }

    .account-form-actions {
        justify-content: stretch;
    }

    .btn-inline {
        width: 100%;
    }

    .init-section {
        width: calc(100% - 16px);
        padding: 16px;
    }

    .story-display {
        padding: 20px;
    }

    .dashboard-hero,
    .dashboard-panel-header {
        flex-direction: column;
        align-items: stretch;
    }

    .dashboard-grid,
    .account-form-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-card-grid {
        grid-template-columns: 1fr;
    }

    .narrative-text {
        min-height: 200px;
    }

    .graphics-canvas {
        height: 200px;
    }
}
