:root {
    --bg-dark-start: #0b1512;
    --bg-dark-end: #1a2332;
    --parchment: #f5e6c8;
    --ink: #2a1d0f;
    --text-light: #f3ead8;
    --gold: #d4af37;
    --gold-glow: #ffe9a8;

    --font-display: 'Cinzel', 'Uncial Antiqua', serif;
    --font-body: Georgia, 'Times New Roman', serif;
    --font-handwritten: 'Caramel', cursive;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    background: linear-gradient(180deg, var(--bg-dark-start), var(--bg-dark-end));
    color: var(--text-light);
    font-family: var(--font-body);
    line-height: 1.5;
}

h1,
h2,
h3,
.banner-ribbon,
button {
    font-family: var(--font-display);
    letter-spacing: 0.03em;
}

h1,
h2,
h3 {
    font-variant: small-caps;
    color: var(--gold-glow);
}

a {
    color: var(--gold);
}

/* Banner Ribbon: parchment ribbon used for buttons, page titles, and badge names */
.banner-ribbon {
    display: inline-block;
    padding: 0.6em 1.4em;
    background: var(--parchment);
    color: var(--ink);
    text-transform: uppercase;
    font-size: 0.95rem;
    font-weight: 700;
    text-align: center;
    border: 1px solid var(--theme-primary, var(--gold));
    box-shadow: 0 0 8px var(--theme-primary, var(--gold-glow));
    clip-path: polygon(4% 0%, 96% 0%, 100% 50%, 96% 100%, 4% 100%, 0% 50%);
}

.banner-ribbon.is-button {
    cursor: pointer;
    background: none;
    color: var(--text-light);
}

.banner-ribbon.is-button:hover {
    box-shadow: 0 0 14px var(--theme-primary, var(--gold-glow));
}

/* Parchment Card: translucent so a story's theme canvas stays visible behind forms/prompts */
.parchment-card {
    position: relative;
    background: rgba(245, 230, 200, 0.35);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: var(--ink);
    border-radius: 12px;
    border: 1px solid var(--theme-primary, var(--gold));
    padding: 1.5rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45), 0 0 22px var(--theme-primary, var(--gold-glow));
}

.parchment-card h1,
.parchment-card h2,
.parchment-card h3 {
    color: var(--ink);
}

/* Buttons on the parchment background need dark text, unlike the dark-page banner-ribbon default */
.parchment-card .banner-ribbon.is-button {
    background: rgba(245, 230, 200, 0.55);
    color: var(--ink);
}

.parchment-card form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.parchment-card label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.9rem;
}

.parchment-card input,
.parchment-card select {
    padding: 0.5em;
    border: 1px solid var(--theme-primary, var(--gold));
    border-radius: 6px;
    font-family: var(--font-body);
    background: rgba(255, 255, 255, 0.2);
    color: var(--ink);
}

.parchment-card textarea {
    padding: 0.5em;
    border: 1px solid var(--theme-primary, var(--gold));
    border-radius: 6px;
    font-family: var(--font-body);
    font-size: 1.15rem;
    background: rgba(245, 230, 200, 0.25);
    color: var(--ink);
    resize: vertical;
}

.form-error {
    color: #8b1e1e;
    font-size: 0.85rem;
    min-height: 1.2em;
}

.intro-steps {
    margin: 0 0 1.25rem;
    padding-left: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.turn-counter {
    font-size: 0.85rem;
    color: #c9a66b;
    margin: 0;
}

.turn-counter.is-ready {
    color: #4fb37a;
    font-weight: 700;
}

.tab-bar {
    display: flex;
    gap: 0.75rem;
    margin: 1.5rem 0 1rem;
}

/* Matches .story-list's max-height so switching tabs never resizes the card */
#tab-content {
    min-height: 420px;
}

.dashboard-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1.5rem;
}

.checkbox-label {
    flex-direction: row !important;
    align-items: center;
    gap: 0.5rem !important;
}

.checkbox-label input {
    width: auto;
}

.story-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 420px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.story-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5em 0.75em;
    border: 1px solid var(--gold);
    border-radius: 6px;
}

.story-list li a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    color: inherit;
    text-decoration: none;
}

.story-state {
    text-transform: capitalize;
    font-size: 0.85rem;
    opacity: 0.8;
}

.join-code-display {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1rem 0;
    padding: 0.75em 1em;
    border: 1px solid var(--gold);
    border-radius: 6px;
}

.join-code-label {
    text-transform: uppercase;
    font-size: 0.8rem;
    opacity: 0.8;
}

.join-code-value {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.15em;
}

.state-banner {
    padding: 0.6em 1em;
    border-radius: 6px;
    font-size: 0.9rem;
}

.state-banner:empty {
    display: none;
}

.state-banner.is-error {
    color: #8b1e1e;
    border: 1px solid #8b1e1e;
}

.state-banner.is-cancelled {
    color: #6b4a1f;
    background: rgba(212, 175, 55, 0.15);
    border: 1px solid var(--gold);
}

.state-banner.is-final-turn {
    color: #6b4a1f;
    background: rgba(212, 175, 55, 0.25);
    border: 1px solid var(--gold);
    font-weight: 700;
}

.creator-controls {
    display: flex;
    gap: 0.5rem;
    margin: 1rem 0;
}

.progress-trail {
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    font-weight: bold;
    color: var(--ink);
}

.visible-prompt {
    margin: 1rem 0;
    padding: 0.75em 1em;
    border-left: 3px solid var(--theme-primary, var(--gold));
    font-style: italic;
}

.dashboard-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.75rem;
}

.dashboard-title {
    position: absolute;
    top: 0;
    left: 1.75rem;
    transform: translateY(-50%);
    margin: 0;
    padding: 0 0.4em;
    font-family: var(--font-handwritten);
    font-size: 3rem;
    font-variant: normal;
    white-space: nowrap;
    color: #ffd84a;
    text-shadow: 0 0 10px var(--gold-glow), 0 0 20px var(--gold-glow);
}

/* Gives views that use a standalone dashboard-title (no header-icons row) room below the glow */
.dashboard-title + form,
.dashboard-title + .settings-row,
.dashboard-title + h2 {
    margin-top: 1.5rem;
}

.header-icons {
    display: flex;
    gap: 0.5rem;
}

.header-icons[hidden] {
    display: none;
}

.icon-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--gold);
    background: rgba(245, 230, 200, 0.55);
    color: var(--ink);
    font-size: 1.25rem;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
}

.icon-button:hover,
.icon-button.is-active {
    box-shadow: 0 0 10px var(--theme-primary, var(--gold-glow));
}

.icon-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #b43c3c;
    color: #fff;
    font-size: 0.65rem;
    font-weight: bold;
    border-radius: 999px;
}

.icon-badge[hidden] {
    display: none;
}

.notification-panel-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
    margin: 1.5rem 0 1rem;
}

.notification-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 420px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.notification-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5em 0.75em;
    border: 1px solid var(--gold);
    border-radius: 6px;
}

.notification-item.is-read {
    opacity: 0.6;
}

.badge-shelf {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.badge-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5em;
    text-align: center;
}

.badge-trigger {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    background: none;
    border: none;
    padding: 0;
    color: inherit;
    font: inherit;
}

.badge-item.is-earned .badge-trigger {
    cursor: pointer;
}

.badge-icon {
    width: 96px;
    height: 96px;
    object-fit: contain;
    border-radius: 50%;
    border: 1px solid var(--gold);
}

.badge-icon-wrap {
    position: relative;
    display: inline-flex;
}

.badge-item.is-earned .badge-icon {
    box-shadow: 0 0 10px var(--theme-primary, var(--gold-glow));
}

.badge-item.is-locked .badge-icon {
    filter: grayscale(70%) brightness(0.85);
    opacity: 0.8;
}

.badge-item.is-locked .badge-icon-wrap::after {
    content: '\1F512';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
}

.badge-item.is-locked .badge-name {
    opacity: 0.6;
}

.badge-name {
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--ink);
}

.badge-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 100;
}

.badge-modal {
    position: relative;
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    text-align: center;
}

.badge-modal-close {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    background: none;
    border: none;
    color: var(--ink);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.badge-modal-icon {
    width: 180px;
    height: 180px;
    object-fit: contain;
    border-radius: 50%;
    border: 2px solid var(--gold);
}

.badge-modal-earned {
    font-size: 0.85rem;
    opacity: 0.7;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 1rem 0;
    padding: 0.6em 0.9em;
    background: rgba(245, 230, 200, 0.55);
    border: 1px solid var(--gold);
    border-radius: 6px;
}

.settings-label {
    font-weight: bold;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background: rgba(42, 29, 15, 0.35);
    border: 1px solid var(--gold);
    border-radius: 999px;
    transition: background-color 0.2s ease;
}

.switch-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--parchment);
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.switch input:checked + .switch-slider {
    background: var(--theme-primary, var(--gold));
}

.switch input:checked + .switch-slider::before {
    transform: translateX(20px);
}

.switch input:disabled + .switch-slider {
    opacity: 0.6;
    cursor: not-allowed;
}

.stat-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin: 1rem 0;
}

.stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.5em 0.3em;
    width: 90px;
    background: rgba(245, 230, 200, 0.55);
    border: 1px solid var(--gold);
    border-radius: 6px;
    text-align: center;
}

.stat-value {
    font-size: 1.15rem;
    font-weight: bold;
    color: var(--ink);
}

.stat-label {
    font-size: 0.7rem;
    line-height: 1.2;
}

.full-story {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gold);
}

.full-story .story-text {
    font-size: 1.2rem;
    line-height: 1.7;
    white-space: pre-wrap;
}

/* Each turn renders inline so the story reads as one continuous passage, color-coded per author */
.turn-segment {
    cursor: help;
}

.turn-segment.author-color-0 { color: var(--ink); }
.turn-segment.author-color-1 { color: #8b1e1e; font-style: italic; }
.turn-segment.author-color-2 { color: #1f5c3a; }
.turn-segment.author-color-3 { color: #1f3c8b; font-style: italic; }
.turn-segment.author-color-4 { color: #6b4a1f; }
.turn-segment.author-color-5 { color: #6a1f8b; font-style: italic; }

/* PWA: offline banner + install prompt button, both injected by pwa-ui.js */
#offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    padding: 0.5em 1em;
    background: #8b1e1e;
    color: var(--text-light);
    text-align: center;
    font-size: 0.9rem;
}

#install-app-button {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 1000;
}

