/* Which Way Next - Mobile-first styles */

:root {
    --bg: #0f0f12;
    --bg-card: #1a1a1f;
    --bg-input: #25252d;
    --text: #e8e6e3;
    --text-muted: #9a9a9a;
    --accent: #c9a227;
    --accent-hover: #e0b83d;
    --border: #2d2d35;
    --error: #c75c5c;
    --success: #5c9e6b;
    --radius: 8px;
    --shadow: 0 4px 20px rgba(0,0,0,0.3);
    --font-sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-display: 'Georgia', 'Times New Roman', serif;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.main {
    flex: 1;
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    padding: 1rem 1.25rem 2rem;
}

/* Header */
.site-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.logo {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--accent);
    text-decoration: none;
    font-family: var(--font-display);
}

.logo:hover {
    color: var(--accent-hover);
}

.nav-toggle {
    display: none;
    width: 2rem;
    height: 2rem;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    position: relative;
}

.nav-toggle::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 1rem;
    height: 2px;
    background: currentColor;
    box-shadow: 0 -4px 0 currentColor, 0 4px 0 currentColor;
}

.nav-toggle[aria-expanded="true"]::before {
    height: 0;
    box-shadow: none;
}

.nav-toggle[aria-expanded="true"]::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(45deg);
    width: 1rem;
    height: 2px;
    background: currentColor;
}

.nav-toggle[aria-expanded="true"] {
    font-size: 0;
}

.nav {
    display: flex;
    align-items: center;
    gap: 0.5rem 1rem;
    flex-wrap: wrap;
}

.nav a {
    color: var(--text-muted);
    text-decoration: none;
    padding: 0.35rem 0.5rem;
    border-radius: 4px;
}

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

.nav-form {
    margin: 0;
}

.btn-link {
    background: none;
    border: none;
    color: var(--text-muted);
    font: inherit;
    cursor: pointer;
    padding: 0.35rem 0.5rem;
    border-radius: 4px;
}

.btn-link:hover {
    color: var(--accent);
}

@media (max-width: 600px) {
    .nav-toggle {
        display: block;
    }

    .nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--bg-card);
        border-bottom: 1px solid var(--border);
        flex-direction: column;
        align-items: stretch;
        padding: 1rem;
        gap: 0.25rem;
    }

    .nav.is-open {
        display: flex;
    }

    .nav-form {
        padding-top: 0.5rem;
        border-top: 1px solid var(--border);
    }
}

/* Buttons & forms */
.btn {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    font: inherit;
    font-size: 0.95rem;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background 0.2s, color 0.2s;
    min-height: 44px;
    line-height: 1.3;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: var(--error);
    color: #fff;
}

.btn-danger:hover {
    opacity: 0.9;
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    font: inherit;
    font-size: 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

textarea {
    min-height: 120px;
    resize: vertical;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.help-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}

.flash-message {
    margin-top: 0;
}

.alert-error {
    background: rgba(199, 92, 92, 0.15);
    border: 1px solid var(--error);
    color: #e8a0a0;
}

.alert-success {
    background: rgba(92, 158, 107, 0.15);
    border: 1px solid var(--success);
    color: #a8d4b0;
}

.alert-notice {
    background: rgba(201, 162, 39, 0.12);
    border: 1px solid var(--accent);
    color: var(--text);
}

/* Cards & book list */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.card h2,
.card h3 {
    margin-top: 0;
    font-family: var(--font-display);
}

.book-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.book-list li {
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
}

.book-list li:last-child {
    border-bottom: none;
}

.book-list a {
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
}

.book-list a:hover {
    color: var(--accent);
}

.book-list .meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Book grid with cover / placeholder */
.book-grid {
    display: grid;
    gap: 1.5rem;
}

.book-list-item {
    display: grid;
    grid-template-columns: 100px 1fr;
    gap: 1rem;
    align-items: start;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

.book-list-item:last-child {
    border-bottom: none;
}

.book-cover-link {
    display: block;
    text-decoration: none;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-input);
}

.book-cover-img {
    width: 100%;
    height: auto;
    aspect-ratio: 2/3;
    object-fit: cover;
    display: block;
}

.book-cover-placeholder {
    aspect-ratio: 2/3;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: linear-gradient(135deg, var(--border) 0%, var(--bg-input) 100%);
    border: 1px solid var(--border);
}

.book-cover-placeholder-text {
    font-size: 0.7rem;
    font-weight: 600;
    text-align: center;
    color: var(--text-muted);
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-title-link {
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
}

.book-title-link:hover {
    color: var(--accent);
}

.book-list-info {
    min-width: 0;
}

.book-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.tag-pill {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    color: var(--accent);
    background: rgba(201, 162, 39, 0.15);
    border-radius: 999px;
    text-decoration: none;
}

.tag-pill:hover {
    background: rgba(201, 162, 39, 0.25);
    color: var(--accent-hover);
}

@media (min-width: 500px) {
    .book-list-item {
        grid-template-columns: 110px 1fr;
    }
}

/* Reader: chapter view */
.chapter-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    margin-bottom: 1rem;
    line-height: 1.4;
}

.chapter-content {
    white-space: pre-wrap;
    margin-bottom: 2rem;
    font-size: 1.05rem;
}

.chapter-image {
    width: 100%;
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    display: block;
}

.choices {
    list-style: none;
    padding: 0;
    margin: 0;
}

.choices li {
    margin-bottom: 0.75rem;
}

.choices a {
    display: block;
    padding: 0.85rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--accent);
    text-decoration: none;
    transition: background 0.2s, border-color 0.2s;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

.choices a:hover {
    background: var(--border);
    border-color: var(--accent);
}

.ending-notice {
    margin-top: 1.5rem;
    padding: 1rem;
    background: rgba(201, 162, 39, 0.1);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    text-align: center;
}

.ending-notice a {
    color: var(--accent);
}

/* Author: dashboard & forms */
.author-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.author-actions .btn {
    font-size: 0.9rem;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.75rem;
}

/* Chapter graph */
.graph-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin: 1rem 0;
    min-height: 320px;
    height: 60vmin;
    max-height: 560px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.graph-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.graph-legend span {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.graph-legend .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.graph-legend .dot-start {
    background: var(--success);
}

.graph-legend .dot-ending {
    background: var(--accent);
}

.graph-legend .dot-chapter {
    background: var(--text-muted);
}

/* Account */
.settings-section {
    margin-bottom: 2rem;
}

.settings-section h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    font-family: var(--font-display);
}

/* Footer */
.site-footer {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.footer-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 1.25rem;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 4px;
    margin-left: 0.5rem;
}

.badge-hidden {
    background: rgba(199, 92, 92, 0.3);
    color: #e8a0a0;
}

.badge-draft {
    background: rgba(154, 154, 154, 0.4);
    color: var(--text-muted);
}

/* Flag section (reader) */
.flag-section {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.flag-details {
    font-size: 0.95rem;
}

.flag-details summary {
    cursor: pointer;
    color: var(--text-muted);
}

.flag-details .flag-form {
    margin-top: 0.75rem;
}

/* Flags list (author/admin) */
.flags-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.flag-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.flag-item:last-child {
    border-bottom: none;
}

.flag-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.flag-desc {
    margin: 0.35rem 0 0.5rem;
}

.flag-item-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.flag-delete-form {
    display: inline;
    margin: 0;
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    min-height: 0;
}

/* Utilities */
.text-muted {
    color: var(--text-muted);
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-2 { margin-bottom: 1rem; }
