:root {
    color-scheme: light;
    --ink: #294438;
    --muted: #65766d;
    --line: #f0e4b5;
    --paper: #fffefa;
    --canvas: #fffdf2;
    --accent: #3e6251;
    --accent-dark: #294438;
    --active: #d8f1e7;
    --yellow: #ffe487;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding: 42px 24px; background: var(--canvas); color: var(--ink); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.admin-shell { width: min(1440px, 100%); margin: 0 auto; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 48px; }
.back-link { color: var(--muted); font-size: 14px; text-decoration: none; }
.back-link:hover { text-decoration: underline; }
h1 { margin: 22px 0 0; font-size: clamp(36px, 5vw, 58px); line-height: 1.05; letter-spacing: -.04em; }
.intro { margin: 12px 0 0; color: var(--muted); font-size: clamp(16px, 2vw, 21px); }
.eyebrow { margin: 0 0 8px; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .16em; }

.primary-button, .quiet-button { min-height: 48px; border: 0; border-radius: 12px; padding: 0 20px; font-weight: 700; white-space: nowrap; }
.primary-button { background: var(--accent); color: #fff; }
.primary-button:hover { background: var(--accent-dark); }
.primary-button:disabled { opacity: .6; cursor: wait; }
.new-button { min-height: 64px; padding: 0 28px; font-size: 18px; }
.quiet-button { background: #fff; color: var(--muted); border: 1px solid var(--line); }
.quiet-button:hover { background: #fffaf0; }

.browse-bar { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.search-box { display: flex; align-items: center; gap: 12px; width: min(460px, 100%); min-height: 58px; padding: 0 18px; border: 1px solid var(--line); border-radius: 15px; background: #fff; color: var(--ink); }
.search-box span { font-size: 26px; line-height: 1; }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 16px; }
.tag-filters { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.tag-chip { min-height: 42px; padding: 0 18px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--muted); }
.tag-chip:hover, .tag-chip[aria-pressed="true"] { border-color: transparent; background: var(--active); color: var(--ink); font-weight: 700; }

.essay-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.essay-card { min-width: 0; padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); text-align: left; color: inherit; cursor: pointer; transition: transform .16s ease, box-shadow .16s ease; }
.essay-card:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(41, 68, 56, .09); }
.card-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; color: var(--muted); font-size: 12px; }
.card-tag { border-radius: 999px; padding: 5px 10px; background: var(--active); color: var(--ink); font-weight: 650; }
.essay-card h2 { margin: 0; font-size: 20px; line-height: 1.4; }
.essay-card p { display: -webkit-box; overflow: hidden; margin: 11px 0 0; color: var(--muted); font-size: 14px; line-height: 1.65; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.empty-state { margin: 64px 0; color: var(--muted); text-align: center; }
.logout-button { display: block; margin: 34px 0 0 auto; }
.message { min-height: 20px; margin: 12px 0; color: var(--muted); font-size: 14px; }
.message.error { color: #a12d42; }
.message.success { color: #2d7250; }

.login-panel { width: min(460px, 100%); margin: min(14vh, 120px) auto; padding: 34px; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); box-shadow: 0 12px 36px rgba(38, 55, 45, .08); }
.login-panel h1 { margin-top: 26px; font-size: 40px; }
.login-panel .intro { margin-bottom: 28px; font-size: 15px; }
.login-panel label, .essay-dialog label { display: block; margin: 18px 0 8px; font-size: 14px; font-weight: 700; }
.login-row { display: flex; gap: 10px; }
.login-row input { min-width: 0; flex: 1; }
input, textarea { min-height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); }
input:focus, textarea:focus { outline: 3px solid rgba(62, 98, 81, .18); border-color: var(--accent); }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 12px; }

.essay-dialog { width: min(900px, calc(100% - 28px)); max-width: none; max-height: min(94vh, 1100px); padding: 0; overflow: visible; border: 0; border-radius: 20px; background: transparent; color: var(--ink); }
.essay-dialog::backdrop { background: rgba(35, 47, 40, .38); backdrop-filter: blur(4px); }
.dialog-card { position: relative; max-height: min(94vh, 1100px); overflow-y: auto; padding: clamp(24px, 5vw, 44px); border: 1px solid rgba(240, 228, 181, .8); border-radius: 20px; background: #fff; box-shadow: 0 24px 80px rgba(22, 36, 28, .18); }
.close-button { position: absolute; top: 18px; right: 24px; width: 38px; height: 38px; border: 0; background: transparent; color: var(--muted); font-size: 30px; }
.dialog-card h2 { margin: 0 44px 26px 0; font-size: clamp(25px, 4vw, 34px); letter-spacing: -.03em; }
.dialog-card label span { color: #aa6948; }
.dialog-card label small { color: var(--muted); font-size: 12px; font-weight: 400; }
.dialog-card input, .dialog-card textarea { width: 100%; }
.dialog-card textarea { min-height: 240px; padding: 14px; line-height: 1.75; resize: vertical; }
.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 18px; padding-top: 24px; border-top: 1px solid var(--line); }
.dialog-actions .primary-button { min-width: 150px; }

@media (max-width: 900px) {
    .browse-bar { align-items: stretch; flex-direction: column; }
    .search-box { width: 100%; }
    .tag-filters { justify-content: flex-start; }
    .essay-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
    body { padding: 26px 15px; }
    .page-header { align-items: flex-start; flex-direction: column; margin-bottom: 30px; }
    .new-button { width: 100%; }
    .essay-grid { grid-template-columns: 1fr; }
    .two-column { grid-template-columns: 1fr; gap: 0; }
    .login-panel { padding: 24px; }
    .login-row { align-items: stretch; flex-direction: column; }
    .login-row button { width: 100%; }
    .dialog-actions { flex-direction: column-reverse; }
    .dialog-actions button { width: 100%; }
}
