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

:root {
    --bg: #f8f6f3;
    --surface: #ffffff;
    --text: #2c2c2c;
    --text-muted: #777;
    --accent: #8b5e3c;
    --accent-hover: #6d4a2f;
    --border: #e0dcd7;
    --selected: #f5efe8;
    --include-on: #5a8f5a;
    --include-off: #bbb;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

body {
    font-family: Georgia, 'Times New Roman', serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

header {
    text-align: center;
    padding: 1.2rem 1rem 0.8rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

header h1 {
    font-size: 1.5rem;
    letter-spacing: 0.05em;
    color: var(--text);
}

header .subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 0.2rem;
}

main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* --- Left panel: poem list --- */

.panel-list {
    width: 420px;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--surface);
}

.list-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--border);
    background: #faf9f7;
}

.list-toolbar button {
    font-family: inherit;
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.list-toolbar button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.counter {
    margin-left: auto;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
}

.poem-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem 0;
}

.poem-item {
    display: flex;
    align-items: center;
    padding: 0.55rem 0.8rem;
    cursor: pointer;
    border-bottom: 1px solid #f0ede8;
    transition: background 0.12s;
    user-select: none;
}

.poem-item:hover {
    background: #faf7f2;
}

.poem-item.active {
    background: var(--selected);
    border-left: 3px solid var(--accent);
}

.poem-item.excluded {
    opacity: 0.5;
}

.poem-item .drag-handle {
    cursor: grab;
    color: #ccc;
    margin-right: 0.5rem;
    font-size: 1.1rem;
    line-height: 1;
}

.poem-item .drag-handle:active {
    cursor: grabbing;
}

.poem-item .poem-number {
    width: 2rem;
    text-align: right;
    margin-right: 0.6rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.poem-item .poem-title {
    flex: 1;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.poem-item .toggle-include {
    width: 18px;
    height: 18px;
    border-radius: 3px;
    border: 2px solid var(--include-off);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: 0.5rem;
    transition: all 0.15s;
    padding: 0;
    font-size: 0;
}

.poem-item .toggle-include.included {
    background: var(--include-on);
    border-color: var(--include-on);
}

.poem-item .toggle-include.included::after {
    content: "✓";
    color: white;
    font-size: 12px;
    line-height: 1;
}

.sortable-ghost {
    opacity: 0.4;
    background: var(--selected);
}

.sortable-chosen {
    background: #f0ebe3;
}

/* --- Right panel: preview --- */

.panel-preview {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 3rem;
    background: var(--bg);
}

.preview-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.2rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--border);
}

.btn-edit,
.btn-cancel-edit,
.btn-save-edit {
    font-family: inherit;
    font-size: 0.8rem;
    padding: 0.35rem 0.9rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-edit {
    border: 1px solid var(--accent);
    background: transparent;
    color: var(--accent);
}

.btn-edit:hover {
    background: var(--accent);
    color: white;
}

.btn-save-edit {
    border: none;
    background: var(--include-on);
    color: white;
    font-weight: bold;
}

.btn-save-edit:hover {
    background: #4a7f4a;
}

.btn-cancel-edit {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
}

.btn-cancel-edit:hover {
    border-color: #c66;
    color: #c66;
}

.edit-status {
    font-size: 0.8rem;
    color: var(--include-on);
    font-style: italic;
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.3s;
}

.edit-status.visible {
    opacity: 1;
}

.editable {
    outline: 2px dashed var(--accent);
    outline-offset: 4px;
    border-radius: 4px;
    padding: 0.5rem;
    background: white;
    min-height: 2rem;
}

.editable:focus {
    outline-color: var(--include-on);
}

.preview-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-style: italic;
    font-size: 1.1rem;
}

.preview-content h2 {
    font-size: 1.6rem;
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--text);
}

.preview-poem {
    white-space: pre-wrap;
    line-height: 1.8;
    text-align: center;
    font-size: 1.05rem;
    margin-bottom: 1.5rem;
}

.preview-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.5rem 0;
}

.preview-content h3 {
    font-size: 1.1rem;
    color: var(--accent);
    margin-bottom: 1rem;
}

.preview-comment {
    white-space: pre-wrap;
    line-height: 1.7;
    font-size: 0.95rem;
    color: #555;
}

/* --- Footer --- */

footer {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.8rem 1.2rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 8px rgba(0,0,0,0.05);
}

.btn-publish {
    font-family: inherit;
    font-size: 1rem;
    font-weight: bold;
    padding: 0.7rem 2.5rem;
    border: none;
    border-radius: 6px;
    background: var(--accent);
    color: white;
    cursor: pointer;
    letter-spacing: 0.05em;
    transition: background 0.15s;
}

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

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

.btn-save {
    font-family: inherit;
    font-size: 0.85rem;
    padding: 0.5rem 1.2rem;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s;
}

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

.save-status {
    font-size: 0.8rem;
    color: var(--include-on);
    font-style: italic;
    opacity: 0;
    transition: opacity 0.3s;
}

.save-status.visible {
    opacity: 1;
}

/* --- Loading overlay --- */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(248,246,243,0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.loading-overlay p {
    font-size: 1.1rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 1rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Mobile tabs (hidden on desktop) --- */

.mobile-tabs {
    display: none;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.mobile-tabs .tab {
    flex: 1;
    font-family: inherit;
    font-size: 0.85rem;
    padding: 0.6rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}

.mobile-tabs .tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: bold;
}

/* --- Rotate overlay for portrait --- */

.rotate-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--surface);
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
}

.rotate-overlay .rotate-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    animation: wiggle 1.5s ease-in-out infinite;
}

.rotate-overlay p {
    font-size: 1.1rem;
    color: var(--text);
    line-height: 1.6;
}

.rotate-overlay .hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-20deg); }
    75% { transform: rotate(20deg); }
}

/* --- Scrollbar --- */

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

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

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

/* ========================================
   RESPONSIVE: Tablets (< 900px)
   ======================================== */

@media (max-width: 900px) {
    .panel-list {
        width: 280px;
        min-width: 240px;
    }

    .panel-preview {
        padding: 1.5rem 2rem;
    }

    .btn-publish {
        padding: 0.6rem 1.5rem;
        font-size: 0.9rem;
    }
}

/* ========================================
   RESPONSIVE: Mobile landscape (< 768px)
   ======================================== */

@media (max-width: 768px) {
    .mobile-tabs {
        display: flex;
    }

    header {
        padding: 0.6rem 0.8rem 0.4rem;
    }

    header h1 {
        font-size: 1rem;
    }

    header .subtitle {
        font-size: 0.75rem;
    }

    main {
        flex-direction: row;
    }

    .panel-list {
        width: 100%;
        min-width: 0;
        border-right: none;
    }

    .panel-preview {
        display: none;
        width: 100%;
        padding: 1rem 1.2rem;
    }

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

    .panel-preview.visible {
        display: block;
    }

    .list-toolbar {
        padding: 0.4rem 0.6rem;
        flex-wrap: wrap;
    }

    .list-toolbar button {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
    }

    .poem-item {
        padding: 0.65rem 0.6rem;
    }

    .poem-item .drag-handle {
        font-size: 1.3rem;
        margin-right: 0.4rem;
        padding: 0.2rem;
    }

    .poem-item .toggle-include {
        width: 24px;
        height: 24px;
        margin-left: 0.4rem;
    }

    .poem-item .toggle-include.included::after {
        font-size: 14px;
    }

    .preview-content h2 {
        font-size: 1.2rem;
        margin-bottom: 1rem;
    }

    .preview-poem {
        font-size: 0.9rem;
        line-height: 1.6;
    }

    .preview-comment {
        font-size: 0.85rem;
        line-height: 1.5;
    }

    .preview-toolbar {
        margin-bottom: 0.8rem;
        padding-bottom: 0.5rem;
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    footer {
        padding: 0.5rem 0.8rem;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .btn-publish {
        font-size: 0.8rem;
        padding: 0.5rem 1.2rem;
        flex: 1;
    }

    .btn-save {
        font-size: 0.75rem;
        padding: 0.4rem 0.8rem;
    }
}

/* ========================================
   FORCE LANDSCAPE on mobile portrait
   ======================================== */

@media (max-width: 768px) and (orientation: portrait) {
    .rotate-overlay {
        display: flex;
    }
}
