:root {
    --bg: #f6f5f1;
    --surface: #ffffff;
    --border: #e2ddd2;
    --text: #1f1d18;
    --muted: #6e6a60;
    --accent: #9a5d28;
    --accent-dark: #7a4818;
    --success: #2d7a3e;
    --warn: #b8860b;
    --danger: #b03030;
    --info-bg: #fdf6e3;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 6px 18px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
    line-height: 1.55;
    font-size: 16px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.6rem; margin: 0 0 .8rem; }
h3 { font-size: 1.2rem; margin: 0 0 .4rem; }

button, .btn {
    font: inherit;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .45rem .9rem;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
button:hover, .btn:hover { background: #f0ece2; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary {
    background: var(--accent);
    border-color: var(--accent-dark);
    color: #fff;
}
button.primary:hover { background: var(--accent-dark); }
button.danger {
    color: var(--danger);
    border-color: #d3b8b8;
}
button.danger:hover { background: #f7e8e8; }

input[type=text], input:not([type]), textarea, select {
    font: inherit;
    width: 100%;
    padding: .55rem .7rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}
textarea { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .95rem; min-height: 320px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

/* ---- topbar ---- */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: .8rem 1.2rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}
#main-nav { display: flex; gap: 1rem; margin-right: auto; }
#main-nav a {
    color: var(--muted);
    padding: .25rem 0;
    border-bottom: 2px solid transparent;
}
#main-nav a.active { color: var(--text); border-color: var(--accent); }
#auth-area { display: flex; align-items: center; gap: .8rem; }
.user-info { display: flex; align-items: center; gap: .6rem; }
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.user-name { color: var(--muted); font-size: .9rem; }
.admin-link {
    background: #eef2ee;
    border: 1px solid #cfd9cf;
    color: #2d5a35;
    padding: .15rem .55rem;
    border-radius: 4px;
    font-size: .8rem;
}
.gis-disabled { color: var(--muted); font-size: .85rem; font-style: italic; }

/* ---- main ---- */
main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.2rem 4rem;
}
.loading { color: var(--muted); }
.error { color: var(--danger); background: #fbeaea; padding: .8rem 1rem; border-radius: 6px; }
.info { background: var(--info-bg); border: 1px solid #ecdfa9; padding: .6rem .9rem; border-radius: 6px; margin: 0 0 1rem; }
.hint { color: var(--muted); font-size: .9rem; }

.config-warning {
    background: #fff6e0;
    border-bottom: 1px solid #ecdfa9;
    padding: .7rem 1.2rem;
    text-align: center;
    color: #6b5310;
}
.demo-banner {
    background: #e8f0fb;
    border-bottom: 1px solid #c8dbf0;
    padding: .55rem 1.2rem;
    text-align: center;
    color: #2b4a73;
    font-size: .9rem;
}
.demo-tag {
    background: #e8f0fb;
    color: #2b4a73;
    border: 1px solid #c8dbf0;
    padding: 0 .35rem;
    border-radius: 3px;
    font-size: .7rem;
    font-style: normal;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-left: .3rem;
    vertical-align: middle;
}
.demo-login-form {
    display: flex;
    align-items: center;
    gap: .4rem;
}
.demo-login-form input[name="name"] {
    width: auto;
    padding: .3rem .55rem;
    font-size: .9rem;
}
.demo-admin-toggle {
    display: flex;
    align-items: center;
    gap: .25rem;
    font-size: .85rem;
    color: var(--muted);
}
.demo-admin-toggle input { width: auto; }
.demo-login-form button {
    padding: .3rem .8rem;
    font-size: .9rem;
}

/* ---- hero ---- */
.hero {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 2rem 2.2rem;
    box-shadow: var(--shadow);
}
.phase-msg { color: var(--accent-dark); font-weight: 500; }

/* Standalone sign-in container (submit page when logged out) */
.standalone-signin {
    margin: 1.2rem 0;
    min-height: 40px;
}
.standalone-signin .inline-signin {
    display: inline-block;
    line-height: 0;
}

/* Sign-in button rendered mid-sentence inside the phase message */
.inline-signin {
    display: inline-block;
    vertical-align: middle;
    margin: 0 .2rem;
    min-height: 32px;
    line-height: 0;
}
.inline-signin .inline-demo {
    display: inline-flex;
    gap: .35rem;
    align-items: center;
    margin: 0;
    vertical-align: middle;
}
.inline-signin .inline-demo input {
    width: auto;
    min-width: 10rem;
    padding: .25rem .5rem;
    font-size: .9rem;
}
.inline-signin .inline-demo button {
    padding: .25rem .7rem;
    font-size: .9rem;
}
.phase-msg {
    line-height: 2.2;       /* leave room for the inline button */
}

/* ---- email notification signup ---- */
.notify-signup {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.4rem 1.8rem;
    margin-top: 1.5rem;
    box-shadow: var(--shadow);
}
.notify-signup h3 { margin: 0 0 .4rem; font-size: 1.15rem; }
.notify-signup p { margin: 0 0 .8rem; color: var(--muted); }
.notify-signup form {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
    align-items: center;
    margin: .6rem 0 .4rem;
}
.notify-signup input[type=email] {
    flex: 1 1 18rem;
    max-width: 26rem;
}
.notify-signup button {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent-dark);
}
.notify-signup button:hover { background: var(--accent-dark); }
.notify-signup .small { font-size: .82rem; margin-top: .4rem; }
.notify-signup #notify-status:empty { display: none; }

/* ---- entry list ---- */
.entries h2 { margin-bottom: 1.2rem; }
.entry-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 1.2rem; }
.entry-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.4rem 1.6rem;
    box-shadow: var(--shadow);
    transition: border-color .15s;
}
.entry-card.voted { border-color: var(--accent); }
.byline { margin: 0 0 1rem; color: var(--muted); font-size: .9rem; }
.story-body {
    max-height: 26rem;
    overflow-y: scroll;
    scrollbar-gutter: stable;
    padding-right: 1rem;
}
.vote-btn { margin-top: 1rem; }
.voted-btn { background: var(--accent); color: #fff; border-color: var(--accent-dark); }

/* ---- literary-magazine column layout (browse / voting page) ---- */
.entries .story-body {
    /* drop the scroll box so the full story flows into balanced columns */
    max-height: none;
    overflow: visible;
    scrollbar-gutter: auto;
    padding-right: 0;
    margin-top: 1rem;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.02rem;
    line-height: 1.65;
    text-align: justify;
    -webkit-hyphens: auto;
    hyphens: auto;
    columns: 18rem;            /* narrow ~18rem columns, as many as fit */
    column-gap: 2.6rem;
    column-rule: 1px solid var(--border);
}
.entries .story-body > :first-child { margin-top: 0; }
.entries .story-body p { margin: 0 0 .85rem; }
.entries .story-body h1,
.entries .story-body h2,
.entries .story-body h3,
.entries .story-body blockquote,
.entries .story-body pre,
.entries .story-body img,
.entries .story-body ul,
.entries .story-body ol {
    break-inside: avoid;
}
/* Magazine-style drop cap on the opening paragraph (first page only) */
.entries .story-page:first-child .story-body > p:first-of-type::first-letter {
    float: left;
    font-size: 3.1rem;
    line-height: .8;
    padding: .12rem .5rem 0 0;
    font-weight: 600;
    color: var(--accent-dark);
}

.status { display: inline-block; padding: .05rem .5rem; border-radius: 99px; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; margin-left: .4rem; vertical-align: middle; }
.status-pending  { background: #fff1cc; color: #7d5a00; }
.status-approved { background: #e0f1e3; color: #2d6a3a; }
.status-rejected { background: #f7dada; color: #8b2727; }

/* ---- submit form ---- */
.submit form { display: grid; gap: 1rem; }
.field { display: grid; gap: .3rem; }
.field > span { color: var(--muted); font-size: .9rem; }
.field.checkbox { flex-direction: row; align-items: center; display: flex; gap: .5rem; }
.field.checkbox input { width: auto; }
.field-row { display: flex; gap: 1.2rem; flex-wrap: wrap; }
.field-row .field { flex: 1 1 200px; }

/* ---- rich-text editor (Quill snow theme) integration ---- */
.rich-field {
    display: grid;
    gap: .3rem;
    margin-bottom: 1rem;
}
.rich-field .field-label {
    color: var(--muted);
    font-size: .9rem;
}
.rich-field .field-label em {
    font-style: italic;
    font-weight: normal;
    opacity: .85;
}
.rich-editor { background: #fff; border-radius: 6px; }
.rich-editor .ql-toolbar.ql-snow {
    border: 1px solid var(--border);
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    background: #fafaf6;
}
.rich-editor .ql-container.ql-snow {
    border: 1px solid var(--border);
    border-top: none;
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 6px;
    min-height: 360px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    font-size: 1rem;
}
.rich-editor .ql-editor {
    min-height: 360px;
    line-height: 1.55;
}
.rich-editor .ql-editor.ql-blank::before {
    color: var(--muted);
    font-style: normal;
}
.rich-editor-short .ql-container.ql-snow,
.rich-editor-short .ql-editor { min-height: 8rem; }
.rich-field .word-count {
    color: var(--muted);
    font-size: .85rem;
    margin-top: .15rem;
    align-self: flex-end;
}

/* ---- submit page: two-column form + live preview ---- */
.submit-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    gap: 2rem;
    align-items: start;
}
.submit-form-side { min-width: 0; }
.submit-preview-side {
    min-width: 0;
    position: sticky;
    top: 5rem;
}
.preview-label {
    color: var(--muted);
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    margin: 0 0 .6rem;
    font-weight: 500;
}
.preview-hint {
    margin-top: .6rem;
    font-size: .8rem;
}
.preview-entries { margin: 0; }
.preview-entries .entry-card { margin: 0; }
.preview-placeholder {
    color: var(--muted);
    font-style: italic;
}
.preview-card #preview-title:empty::before {
    content: 'Untitled';
    color: var(--muted);
    font-style: italic;
}
@media (max-width: 960px) {
    .submit-layout { grid-template-columns: 1fr; }
    .submit-preview-side { position: static; }
}

/* ---- legacy markdown editor styles (kept for backwards compat; unused) ---- */
.editor-wrap { border: 1px solid var(--border); border-radius: 8px; background: #fff; overflow: hidden; }
.editor-toolbar {
    display: flex; gap: .25rem; align-items: center;
    background: #fafaf6; border-bottom: 1px solid var(--border); padding: .35rem .5rem;
}
.editor-toolbar button {
    padding: .2rem .55rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
}
.editor-toolbar button:hover { border-color: var(--border); background: #fff; }
.word-count { margin-left: auto; color: var(--muted); font-size: .85rem; }
.editor-split { display: grid; grid-template-columns: 1fr 1fr; min-height: 360px; }
.editor-split textarea {
    border: none; border-right: 1px solid var(--border); border-radius: 0;
    min-height: 360px;
    overflow-y: scroll;
    scrollbar-gutter: stable;
    padding-right: 1.2rem;
}
.editor-split textarea:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.preview {
    padding: 1rem 2rem 1rem 1.2rem;
    overflow-y: scroll;
    scrollbar-gutter: stable;
    background: #fafaf6;
}

.form-actions { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.status-msg { color: var(--muted); font-size: .9rem; }

/* ---- markdown rendering ---- */
.markdown p { margin: 0 0 .8rem; }
.markdown h1, .markdown h2, .markdown h3 { font-family: Georgia, serif; margin: 1rem 0 .5rem; }
.markdown h1 { font-size: 1.4rem; }
.markdown h2 { font-size: 1.2rem; }
.markdown h3 { font-size: 1.05rem; }
.markdown blockquote {
    margin: .8rem 0; padding: .2rem 1rem;
    border-left: 3px solid var(--accent); color: var(--muted); background: #faf6ec;
}
.markdown code { background: #efe9d8; padding: 0 .25rem; border-radius: 3px; font-size: .92em; }
.markdown pre { background: #efe9d8; padding: .7rem 1rem; border-radius: 6px; overflow: auto; }
.markdown ul, .markdown ol { padding-left: 1.4rem; }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.markdown img { max-width: 100%; height: auto; }

/* ---- results ---- */
.results-list { list-style: none; padding: 0; margin: 0; }
.results-list li {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .9rem 1.2rem;
    margin-bottom: .8rem;
    box-shadow: var(--shadow);
}
.results-list .winner { border-color: var(--accent); background: #fffaf2; }
.results-list .row { display: flex; align-items: baseline; gap: .8rem; }
.results-list .rank { font-weight: 600; color: var(--muted); width: 1.6rem; }
.results-list .title { flex: 1; }
.results-list .by { color: var(--muted); font-size: .9rem; margin-left: .3rem; }
.results-list .vote-count { color: var(--accent-dark); font-weight: 600; }
.bar { height: 6px; background: #efe9d8; border-radius: 3px; margin-top: .5rem; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); transition: width .3s; }

/* ---- admin ---- */
.admin-body { background: #ecebe5; }
.admin-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.4rem 1.6rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}
.admin-section h2 { font-size: 1.25rem; }
.admin-section .counts { color: var(--muted); font-weight: normal; font-size: .85rem; margin-left: .5rem; }
.admin-form { display: grid; gap: 1rem; }
.admin-entry-list { list-style: none; padding: 0; margin: 0; }
.admin-entry {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.2rem;
    margin-bottom: .8rem;
    background: #fcfbf7;
}
.admin-entry.status-pending { border-left: 4px solid var(--warn); }
.admin-entry.status-approved { border-left: 4px solid var(--success); }
.admin-entry.status-rejected { border-left: 4px solid var(--danger); opacity: .8; }
.admin-entry header h3 { display: flex; align-items: center; gap: .5rem; }
.admin-entry details { margin: .6rem 0; }
.admin-entry summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.admin-entry .story-body { max-height: 20rem; }
.admin-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.admin-actions button { font-size: .85rem; padding: .3rem .7rem; }

.author-toggle-section { background: #fffaf2; }
.author-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    flex-wrap: wrap;
}
.author-toggle h2 { margin: 0 0 .2rem; }
.author-toggle .hint { margin: 0; max-width: 40rem; }
.authors-on  { color: var(--success); }
.authors-off { color: var(--accent-dark); }
.toggle-btn { min-width: 12rem; }
.toggle-btn[data-state="on"]  { background: #6e6a60; border-color: #4d493f; }
.toggle-btn[data-state="on"]:hover  { background: #4d493f; }

.anonymous-banner { background: #ede4d3; border-color: #d4c79e; color: #5b4910; }
.submission-notice { background: var(--info-bg); border-color: #ecdfa9; }
.submission-notice p:last-child { margin-bottom: 0; }
.hidden-note { color: var(--muted); font-style: italic; font-size: .9rem; margin: .4rem 0 0; }
.entry-list.titles-only .entry-card { padding-top: 1.1rem; padding-bottom: 1.1rem; }
.entry-list.titles-only .entry-card h3 { margin-bottom: .3rem; }

/* ---- intra-entry page breaks (equal-height magazine pages) ---- */
.story-pages { margin-top: 1rem; }
.story-page { position: relative; }
.story-pages .story-body { margin-top: 0; }
.story-pages.paged .story-page {
    padding: 1.4rem 1.2rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fffdf8;
    box-shadow: inset 0 0 0 1px #fff, 0 1px 2px rgba(0,0,0,.04);
}
.page-folio {
    text-align: center;
    color: var(--muted);
    font-family: Georgia, "Times New Roman", serif;
    font-size: .9rem;
    letter-spacing: .12em;
    margin-top: 1rem;
}
.page-break {
    text-align: center;
    color: var(--accent);
    font-size: 1.2rem;
    margin: 1.1rem 0;
    line-height: 1;
    user-select: none;
}
.order-hint { color: var(--muted); font-size: .85rem; margin: -.4rem 0 1rem; font-style: italic; }

/* Collapsible markdown cheatsheet shown next to every markdown-capable field. */
.md-guide {
    background: #fafaf6;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0;
    margin: 0 0 .5rem;
    font-size: .9rem;
}
.md-guide > summary {
    cursor: pointer;
    padding: .5rem .8rem;
    color: var(--muted);
    list-style: none;
    user-select: none;
}
.md-guide > summary::-webkit-details-marker { display: none; }
.md-guide > summary::before {
    content: '▸';
    display: inline-block;
    margin-right: .4rem;
    transition: transform .15s;
    font-size: .85em;
}
.md-guide[open] > summary::before { transform: rotate(90deg); }
.md-guide > summary:hover { color: var(--text); background: #f3efe2; border-radius: 6px; }
.md-guide[open] > summary { border-bottom: 1px solid var(--border); border-radius: 6px 6px 0 0; }
.md-guide-body { padding: .6rem .9rem; }
.md-guide-body table {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
}
.md-guide-body th {
    text-align: left;
    color: var(--muted);
    font-weight: 500;
    padding: .25rem .5rem .35rem 0;
    border-bottom: 1px solid var(--border);
}
.md-guide-body td {
    padding: .3rem .5rem .3rem 0;
    border-bottom: 1px solid #f0ecdf;
    vertical-align: top;
}
.md-guide-body tr:last-child td { border-bottom: none; }
.md-guide-body code {
    background: #efe9d8;
    padding: 0 .3rem;
    border-radius: 3px;
    font-size: .92em;
}

/* Always-visible scrollbars for scrollable content areas.
   macOS auto-hides scrollbars by default; these rules force them visible
   so users can see scroll affordance without hovering or scrolling first. */
html {
    overflow-y: scroll;                          /* page scrollbar always reserved */
    scrollbar-width: thin;
    scrollbar-color: #b8b3a6 #efe9d8;
}
html::-webkit-scrollbar {
    -webkit-appearance: none;
    width: 12px;
}
html::-webkit-scrollbar-track { background: #efe9d8; }
html::-webkit-scrollbar-thumb {
    background: #b8b3a6;
    border: 2px solid #efe9d8;
    border-radius: 6px;
}
html::-webkit-scrollbar-thumb:hover { background: #8a8578; }

.preview,
.editor-split textarea {
    scrollbar-width: thin;                       /* Firefox */
    scrollbar-color: #b8b3a6 #efe9d8;
}
.preview::-webkit-scrollbar,
.editor-split textarea::-webkit-scrollbar {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
}
.preview::-webkit-scrollbar-track,
.editor-split textarea::-webkit-scrollbar-track {
    background: #efe9d8;
    border-radius: 5px;
}
.preview::-webkit-scrollbar-thumb,
.editor-split textarea::-webkit-scrollbar-thumb {
    background: #b8b3a6;
    border-radius: 5px;
    border: 2px solid #efe9d8;
}
.preview::-webkit-scrollbar-thumb:hover,
.editor-split textarea::-webkit-scrollbar-thumb:hover {
    background: #8a8578;
}

/* Browse-page entry cards: stronger, always-visible scrollbar. */
.story-body {
    scrollbar-width: auto;
    scrollbar-color: #8a8578 #efe9d8;
}
.story-body::-webkit-scrollbar {
    -webkit-appearance: none;
    width: 14px;
    background: #efe9d8;
}
.story-body::-webkit-scrollbar-track {
    background: #efe9d8;
    border-radius: 7px;
    border-left: 1px solid #d9d2bf;
}
.story-body::-webkit-scrollbar-thumb {
    background: #8a8578;
    border-radius: 7px;
    border: 3px solid #efe9d8;
    min-height: 40px;
}
.story-body::-webkit-scrollbar-thumb:hover {
    background: #5e5a52;
}

@media (max-width: 720px) {
    .editor-split { grid-template-columns: 1fr; }
    .editor-split textarea { border-right: none; border-bottom: 1px solid var(--border); }
    .topbar-inner { gap: .8rem; }
    main { padding: 1.2rem 1rem 3rem; }
    .hero, .entry-card, .admin-section { padding: 1.2rem; }
}
