:root {
    --bg: #10131a;
    --panel: rgba(23, 27, 36, 0.88);
    --panel-solid: #171b24;
    --panel-soft: #202634;
    --text: #f5efe2;
    --muted: #b8b2a7;
    --gold: #d9a441;
    --gold-dark: #9b6b22;
    --green: #66c2a5;
    --line: rgba(255, 255, 255, 0.12);
    --danger: #ff8a8a;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        linear-gradient(180deg, rgba(16, 19, 26, 0.7), #10131a 620px),
        url("/assets/hero-fantasy.png") top center / min(1500px, 100vw) auto no-repeat,
        var(--bg);
}

button,
input,
textarea,
select {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

.shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    min-height: 80px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border: 1px solid rgba(217, 164, 65, 0.55);
    border-radius: 8px;
    color: #17110a;
    background: linear-gradient(145deg, #f0c76b, #ba7b28);
    font-weight: 900;
}

.brand strong,
.brand small {
    display: block;
}

.brand small,
.hint,
.meter small,
.profile small,
.plan-card p,
.lead {
    color: var(--muted);
}

.nav {
    display: flex;
    align-items: center;
    gap: 18px;
    color: var(--muted);
}

.nav a:hover {
    color: var(--text);
}

.hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 32px;
    align-items: end;
    min-height: calc(100vh - 150px);
    padding: 58px 0 84px;
}

.hero-copy {
    min-width: 0;
    max-width: 680px;
    padding-bottom: 18px;
}

.eyebrow,
.panel-kicker {
    margin: 0 0 10px;
    color: var(--green);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

.hero h1 {
    margin-bottom: 18px;
    font-family: Georgia, "Times New Roman", serif;
    max-width: 100%;
    font-size: clamp(4rem, 7vw, 5.9rem);
    line-height: 0.92;
    letter-spacing: 0;
    overflow-wrap: normal;
}

.lead {
    max-width: 620px;
    font-size: clamp(1.05rem, 2vw, 1.35rem);
    line-height: 1.65;
}

.hero-actions,
.composer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.primary-button,
.secondary-button,
.ghost-button,
.plan-card button,
.quick-list button {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 800;
}

.primary-button {
    padding: 0 22px;
    color: #160f08;
    background: linear-gradient(145deg, #f3cd73, #c5842f);
    box-shadow: 0 12px 28px rgba(217, 164, 65, 0.2);
}

.primary-button:hover {
    transform: translateY(-1px);
}

.primary-button:disabled {
    cursor: wait;
    opacity: 0.7;
    transform: none;
}

.secondary-button,
.ghost-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 18px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--line);
}

.ghost-button {
    min-height: 38px;
}

.login-panel,
.sidebar,
.story-stage,
.plan-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.login-panel {
    padding: 28px;
}

.login-panel h2,
.section-head h2,
.story-header h1 {
    margin-bottom: 18px;
    font-size: clamp(1.7rem, 4vw, 2.4rem);
    letter-spacing: 0;
}

.login-form {
    display: grid;
    gap: 12px;
}

label {
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 700;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    background: rgba(9, 11, 15, 0.64);
    outline: none;
}

input,
select {
    height: 46px;
    padding: 0 14px;
}

textarea {
    min-height: 118px;
    resize: vertical;
    padding: 14px;
    line-height: 1.5;
}

input:focus,
textarea:focus,
select:focus {
    border-color: rgba(217, 164, 65, 0.8);
    box-shadow: 0 0 0 3px rgba(217, 164, 65, 0.14);
}

.full {
    width: 100%;
}

.error {
    padding: 10px 12px;
    border: 1px solid rgba(255, 138, 138, 0.35);
    border-radius: 8px;
    color: var(--danger);
    background: rgba(255, 138, 138, 0.08);
}

.app-layout {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 22px;
    min-height: calc(100vh - 126px);
    padding: 28px 0 46px;
}

.sidebar {
    align-self: start;
    padding: 18px;
}

.profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.avatar {
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    border-radius: 8px;
    color: #10131a;
    background: var(--green);
    font-weight: 900;
    text-transform: uppercase;
}

.meter {
    margin: 18px 0;
    padding: 16px;
    border: 1px solid rgba(217, 164, 65, 0.28);
    border-radius: 8px;
    background: rgba(217, 164, 65, 0.08);
}

.meter span,
.meter strong,
.meter small,
.profile strong,
.profile small {
    display: block;
}

.meter strong {
    margin: 4px 0;
    color: var(--gold);
    font-size: 2.6rem;
}

.quick-list {
    display: grid;
    gap: 10px;
}

.story-menu {
    display: grid;
    gap: 12px;
    margin: 18px 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
}

.story-menu form {
    margin: 0;
}

.story-menu-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.story-menu-head span,
.story-row small,
.empty-stories {
    color: var(--muted);
}

.story-menu-head span,
.story-menu-head strong {
    display: block;
}

.story-menu-head span {
    margin-bottom: 2px;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
}

.story-menu-head strong {
    color: var(--text);
}

.story-new-button,
.story-row-actions button {
    min-height: 34px;
    border: 1px solid rgba(217, 164, 65, 0.35);
    border-radius: 8px;
    color: #160f08;
    background: linear-gradient(145deg, #f3cd73, #c5842f);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 800;
}

.story-new-button {
    padding: 0 12px;
}

.story-list {
    display: grid;
    gap: 10px;
    max-height: 330px;
    overflow-y: auto;
    padding-right: 2px;
}

.story-row {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(9, 11, 15, 0.28);
}

.story-row.is-active {
    border-color: rgba(102, 194, 165, 0.46);
    background: rgba(102, 194, 165, 0.08);
}

.story-row-main strong,
.story-row-main small {
    display: block;
}

.story-row-main strong {
    overflow: hidden;
    color: var(--text);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.story-row-main small {
    margin-top: 4px;
    font-size: 0.78rem;
}

.story-row-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.story-row-actions button {
    width: 100%;
    padding: 0 8px;
}

.story-row-actions button:disabled {
    cursor: default;
    color: var(--green);
    background: rgba(102, 194, 165, 0.12);
    border-color: rgba(102, 194, 165, 0.34);
}

.story-row-actions .danger-button {
    color: var(--danger);
    background: rgba(255, 138, 138, 0.08);
    border-color: rgba(255, 138, 138, 0.24);
}

.empty-stories {
    margin: 0;
    line-height: 1.45;
}

.compact-error {
    margin: 0;
    font-size: 0.86rem;
}

.quick-list button {
    min-height: 46px;
    padding: 0 12px;
    color: var(--text);
    text-align: left;
    background: var(--panel-soft);
    border: 1px solid var(--line);
}

.quick-list button:hover {
    border-color: rgba(102, 194, 165, 0.5);
}

.story-stage {
    display: grid;
    grid-template-rows: auto minmax(360px, 1fr) auto;
    min-height: 680px;
    overflow: hidden;
}

.story-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 22px 24px;
    border-bottom: 1px solid var(--line);
}

.story-header h1 {
    margin: 0;
}

.status-pill {
    flex: 0 0 auto;
    padding: 8px 12px;
    border-radius: 999px;
    color: var(--green);
    background: rgba(102, 194, 165, 0.12);
    border: 1px solid rgba(102, 194, 165, 0.35);
    font-size: 0.86rem;
    font-weight: 800;
}

.status-pill.is-busy {
    color: var(--gold);
    border-color: rgba(217, 164, 65, 0.4);
    background: rgba(217, 164, 65, 0.1);
}

.story-log {
    display: grid;
    align-content: start;
    gap: 14px;
    padding: 24px;
    overflow-y: auto;
}

.story-entry {
    max-width: 760px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.055);
}

.story-entry.player {
    justify-self: end;
    background: rgba(102, 194, 165, 0.1);
}

.story-entry.system {
    border-color: rgba(255, 138, 138, 0.25);
}

.story-entry span {
    display: block;
    margin-bottom: 8px;
    color: var(--gold);
    font-size: 0.82rem;
    font-weight: 900;
    text-transform: uppercase;
}

.story-entry p {
    margin: 0;
    line-height: 1.7;
    white-space: pre-wrap;
}

.story-meta {
    display: block;
    margin-top: 12px;
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.4;
}

.choice-list {
    display: grid;
    gap: 8px;
    margin-top: 14px;
}

.choice-button {
    width: 100%;
    min-height: 38px;
    padding: 8px 12px;
    border: 1px solid rgba(217, 164, 65, 0.28);
    border-radius: 8px;
    color: var(--text);
    background: rgba(217, 164, 65, 0.08);
    cursor: pointer;
    font-weight: 700;
    text-align: left;
}

.choice-button:hover {
    border-color: rgba(217, 164, 65, 0.55);
    background: rgba(217, 164, 65, 0.14);
}

.choice-button:disabled {
    cursor: wait;
    opacity: 0.6;
}

.composer {
    display: grid;
    gap: 12px;
    padding: 20px 24px 24px;
    border-top: 1px solid var(--line);
    background: rgba(9, 11, 15, 0.32);
}

.composer select {
    width: min(250px, 100%);
}

.plans {
    padding: 38px 0 70px;
}

.section-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

.section-head h2 {
    margin: 0;
}

.plan-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.token-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.pricing-note {
    max-width: 880px;
    margin-bottom: 18px;
    padding: 18px 20px;
    border: 1px solid rgba(102, 194, 165, 0.24);
    border-radius: 8px;
    background: rgba(102, 194, 165, 0.07);
}

.pricing-note strong {
    display: block;
    margin-bottom: 6px;
    color: var(--green);
}

.pricing-note p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.token-head {
    margin-top: 28px;
}

.plan-card {
    padding: 20px;
}

.plan-card.featured {
    border-color: rgba(217, 164, 65, 0.5);
    background: rgba(42, 34, 22, 0.88);
}

.plan-card span {
    color: var(--green);
    font-weight: 800;
}

.plan-card h3 {
    margin: 10px 0;
    font-size: 1.65rem;
}

.plan-card button {
    width: 100%;
    margin-top: 8px;
    color: #160f08;
    background: linear-gradient(145deg, #f3cd73, #c5842f);
    box-shadow: 0 12px 28px rgba(217, 164, 65, 0.18);
}

.plan-card button:hover {
    transform: translateY(-1px);
}

.plan-card button:disabled,
.plan-card .muted-plan-button {
    cursor: default;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: none;
    transform: none;
}

.plan-card.compact h3 {
    font-size: 1.35rem;
}

.purchase-modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 20px;
}

.purchase-modal[hidden] {
    display: none;
}

.purchase-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(5, 7, 10, 0.72);
    backdrop-filter: blur(10px);
}

.purchase-dialog {
    position: relative;
    z-index: 1;
    width: min(560px, 100%);
    padding: 26px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-solid);
    box-shadow: var(--shadow);
}

.purchase-dialog h2 {
    margin-bottom: 10px;
    font-size: clamp(1.8rem, 5vw, 2.45rem);
}

.purchase-description {
    color: var(--muted);
    line-height: 1.6;
}

.purchase-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.07);
    cursor: pointer;
    font-size: 1.35rem;
    line-height: 1;
}

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

.term-option {
    min-height: 86px;
    padding: 14px;
    border: 1px solid rgba(217, 164, 65, 0.28);
    border-radius: 8px;
    color: var(--text);
    background: rgba(217, 164, 65, 0.08);
    cursor: pointer;
    text-align: left;
}

.term-option strong,
.term-option span {
    display: block;
}

.term-option strong {
    margin-bottom: 6px;
    color: var(--gold);
}

.term-option span {
    color: var(--muted);
    font-size: 0.9rem;
}

.term-option.is-selected,
.term-option:hover {
    border-color: rgba(217, 164, 65, 0.72);
    background: rgba(217, 164, 65, 0.14);
}

.purchase-summary {
    min-height: 46px;
    margin-bottom: 14px;
    padding: 12px 14px;
    border: 1px solid rgba(102, 194, 165, 0.22);
    border-radius: 8px;
    color: var(--muted);
    background: rgba(102, 194, 165, 0.07);
    line-height: 1.5;
}

@media (max-width: 900px) {
    .hero,
    .app-layout,
    .plan-grid,
    .token-grid {
        grid-template-columns: 1fr;
    }

    .hero {
        align-items: start;
        min-height: auto;
        padding-top: 42px;
    }

    .story-stage {
        min-height: 620px;
    }
}

@media (max-width: 640px) {
    .shell {
        width: min(100% - 20px, 1180px);
    }

    .topbar,
    .story-header,
    .section-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .nav {
        width: 100%;
        justify-content: space-between;
    }

    .hero h1 {
        font-size: clamp(3.2rem, 15vw, 5.1rem);
        overflow-wrap: anywhere;
    }

    .login-panel,
    .story-log,
    .composer,
    .story-header {
        padding: 18px;
    }

    .composer-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .composer select,
    .composer .primary-button {
        width: 100%;
    }

    .purchase-dialog {
        padding: 22px;
    }

    .term-grid {
        grid-template-columns: 1fr;
    }
}
