:root {
  --forest: #1f4a3d;
  --forest-2: #2d6653;
  --ink: #1f2a26;
  --muted: #68736e;
  --paper: #fffdf7;
  --sand: #f2ecdf;
  --line: #ddd4c4;
  --gold: #d89b36;
  --coral: #b95942;
  --shadow: 0 16px 48px rgba(31, 42, 38, .14);
  --reader-size: 26px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; color: var(--ink); background: var(--sand); font-family: "Trebuchet MS", "Gill Sans", sans-serif; overflow: hidden; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button, a, input, select, textarea { outline-color: var(--gold); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.ui-icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.splash { position: fixed; inset: 0; z-index: 1000; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--paper); background: radial-gradient(circle at 65% 25%, #39705d 0, transparent 35%), linear-gradient(145deg, #173a31, #235343 62%, #17392f); transition: opacity .55s ease, visibility .55s; }
.splash.leaving { opacity: 0; visibility: hidden; }
.splash-mark { position: relative; width: 88px; height: 88px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.45); border-radius: 50% 50% 46% 54%; transform: rotate(-5deg); }
.splash-mark::before { content: ""; position: absolute; inset: 8px; border-radius: inherit; border: 1px solid rgba(255,255,255,.2); }
.splash-mark span { font: 700 48px/1 Georgia, serif; transform: rotate(5deg); }
.splash-mark i { position: absolute; width: 2px; height: 29px; background: var(--gold); right: 18px; top: -10px; transform: rotate(17deg); }
.splash-name { font: 700 33px/1 Georgia, serif; letter-spacing: .04em; }
.splash-pulse { width: 58px; height: 2px; overflow: hidden; background: rgba(255,255,255,.16); }
.splash-pulse::after { content: ""; display: block; width: 50%; height: 100%; background: var(--gold); animation: pulse 1.2s ease-in-out infinite alternate; }
.splash small { position: fixed; bottom: max(24px, env(safe-area-inset-bottom)); opacity: .72; letter-spacing: .08em; }
@keyframes pulse { to { transform: translateX(100%); } }

.auth-screen { height: 100dvh; min-height: 0; overflow-x: hidden; overflow-y: auto; display: flex; align-items: flex-start; justify-content: center; padding: max(24px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom)); overscroll-behavior: contain; background: radial-gradient(circle at 20% 10%, rgba(216,155,54,.23), transparent 26%), linear-gradient(135deg, #e9e1d1, #f7f3ea 52%, #e6eee8); }
.auth-card { flex: none; width: min(440px, 100%); margin-block: auto; padding: 28px; border: 1px solid rgba(31,74,61,.14); border-radius: 18px 18px 48px 18px; background: rgba(255,253,247,.94); box-shadow: var(--shadow); }
.brand-row { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.mini-mark, .wordmark span { display: grid; place-items: center; width: 42px; height: 42px; color: white; background: var(--forest); border-radius: 50% 50% 44% 56%; font: 700 24px Georgia, serif; }
.brand-row strong { display: block; font: 700 25px Georgia, serif; }
.brand-row span { color: var(--muted); font-size: 13px; }
.auth-tabs, .admin-tabs { display: flex; gap: 4px; padding: 4px; background: var(--sand); border-radius: 10px; }
.auth-tabs button, .admin-tabs button { flex: 1; min-height: 40px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; font-size: 13px; }
.auth-tabs button.active, .admin-tabs button.active { background: var(--paper); color: var(--forest); box-shadow: 0 2px 8px rgba(31,42,38,.09); font-weight: 700; }
.auth-form, .stack-form { display: grid; gap: 14px; margin-top: 18px; }
.auth-step { display: grid; gap: 14px; }
.auth-step-copy { display: grid; gap: 4px; line-height: 1.4; }
.auth-step-copy strong { font: 700 20px Georgia, serif; }
.auth-step-copy span { color: var(--muted); font-size: 13px; }
.auth-step-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: var(--ink); background: #fff; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--forest-2); box-shadow: 0 0 0 3px rgba(45,102,83,.12); }
.primary, .secondary { min-height: 44px; border-radius: 8px; padding: 0 16px; cursor: pointer; font-weight: 700; }
.primary { border: 1px solid var(--forest); color: white; background: var(--forest); }
.primary:hover { background: var(--forest-2); }
.secondary { border: 1px solid var(--line); background: var(--paper); }
.primary:disabled, .secondary:disabled, .text-button:disabled { cursor: wait; opacity: .62; }
.form-message { min-height: 20px; margin: 10px 0 0; color: var(--coral); font-size: 13px; }

.app-shell { height: 100%; display: grid; grid-template: 64px 1fr / 310px 1fr; grid-template-areas: "top top" "side reader"; }
.topbar { grid-area: top; z-index: 20; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; color: white; background: var(--forest); box-shadow: 0 3px 16px rgba(16,45,36,.18); }
.wordmark { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.wordmark span { width: 36px; height: 36px; color: var(--forest); background: #f4e8c7; font-size: 21px; }
.wordmark strong { font: 700 22px Georgia, serif; letter-spacing: .02em; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-action { min-height: 40px; padding: 0 12px; border: 1px solid rgba(255,255,255,.2); border-radius: 8px; color: white; background: rgba(255,255,255,.07); cursor: pointer; }
.top-action.accent { border-color: var(--gold); background: var(--gold); color: #2f2616; }
.avatar-button { width: 40px; height: 40px; border: 2px solid rgba(255,255,255,.65); border-radius: 50%; color: var(--forest); background: #f6e9c6; cursor: pointer; font-weight: 800; }
.icon-button { display: grid; place-items: center; min-width: 40px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); cursor: pointer; font-size: 20px; }
#menu-button { color: var(--forest); }
.text-button { min-height: 40px; border: 0; padding: 0 6px; color: var(--forest-2); background: transparent; cursor: pointer; font-weight: 700; text-align: left; }
.danger { color: var(--coral); }

.library-panel { grid-area: side; z-index: 15; min-width: 0; overflow: hidden; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: #f7f2e8; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 12px; }
.eyebrow { display: block; margin-bottom: 3px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.panel-head strong { font: 700 19px Georgia, serif; }
.search-field { position: relative; display: block; margin: 0 14px 12px; }
.search-field span { position: absolute; left: 12px; top: 12px; display: grid; color: var(--muted); }
.search-field input { padding-left: 34px; background: rgba(255,255,255,.76); }
.category-list { display: flex; gap: 6px; padding: 0 14px 10px; overflow-x: auto; scrollbar-width: none; }
.category-list button { flex: none; min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 20px; background: transparent; cursor: pointer; }
.category-list button.active { color: white; border-color: var(--forest); background: var(--forest); }
.library-panel > .text-button { margin: 0 14px 8px; }
.song-list { flex: 1; overflow: auto; padding: 0 10px 24px; }
.song-row { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 12px 10px; border: 0; border-bottom: 1px solid rgba(221,212,196,.72); background: transparent; cursor: pointer; text-align: left; }
.song-row:hover, .song-row.active { border-radius: 8px; background: #fffdf7; }
.song-row.active { box-shadow: inset 3px 0 var(--gold); }
.song-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 700 16px Georgia, serif; }
.song-row small { grid-column: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.song-row .star { color: var(--gold); }

.reader { grid-area: reader; min-width: 0; overflow: auto; scroll-behavior: smooth; background: radial-gradient(circle at 90% 5%, rgba(216,155,54,.10), transparent 25%), var(--paper); }
.empty-reader { min-height: 100%; display: grid; place-content: center; justify-items: center; gap: 10px; padding: 30px; text-align: center; }
.empty-symbol { width: 78px; height: 78px; display: grid; place-items: center; border-radius: 50%; color: var(--forest); background: var(--sand); font-size: 38px; }
.empty-reader h1 { margin: 8px 0 0; font: 700 34px Georgia, serif; }
.empty-reader p { max-width: 480px; margin: 0 0 12px; color: var(--muted); line-height: 1.55; }
.empty-reader div:last-child { display: flex; gap: 8px; }
.song-reader { min-height: 100%; }
.reader-toolbar { position: sticky; top: 0; z-index: 10; min-height: 56px; display: flex; align-items: center; gap: 8px; padding: 8px 22px; border-bottom: 1px solid var(--line); background: rgba(255,253,247,.92); backdrop-filter: blur(12px); }
.reader-spacer { flex: 1; }
.font-control { display: flex; grid: none; align-items: center; gap: 7px; color: var(--muted); }
.font-control input { width: 100px; min-height: auto; padding: 0; accent-color: var(--forest); }
.font-control b { font-size: 18px; }
.switch { display: flex; grid: none; align-items: center; gap: 7px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 38px; height: 22px; padding: 2px; border-radius: 12px; background: #b8bdb9; transition: .2s; }
.switch span::after { content: ""; display: block; width: 18px; height: 18px; border-radius: 50%; background: white; transition: .2s; }
.switch input:checked + span { background: var(--forest-2); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch b { font-size: 12px; }
.song-heading, .lyrics, .video-wrap { width: min(830px, calc(100% - 40px)); margin-inline: auto; }
.song-heading { padding: 46px 0 26px; border-bottom: 1px solid var(--line); }
.song-heading h1 { margin: 12px 0 8px; font: 700 clamp(34px, 5vw, 56px)/1.05 Georgia, serif; color: #183c32; }
.song-heading p { margin: 0; color: var(--muted); }
.language-pill, .status-pill { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; margin-right: 6px; border-radius: 12px; color: var(--forest); background: #dfeadf; font-size: 11px; font-weight: 800; }
.status-pill.review { color: #754324; background: #f5dfc3; }
.song-actions { display: flex; gap: 14px; margin-top: 14px; }
.lyrics { padding: 36px 0 70px; white-space: pre-wrap; font: 400 var(--reader-size)/1.65 "Palatino Linotype", Palatino, Georgia, serif; letter-spacing: .005em; }
.video-wrap { padding-bottom: 80px; }
.video-wrap iframe { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 12px; background: #1b211f; box-shadow: var(--shadow); }

dialog { color: var(--ink); }
dialog[open] { overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
dialog::backdrop { background: rgba(18,31,27,.55); backdrop-filter: blur(3px); }
.workspace-dialog, .form-dialog { width: min(960px, calc(100% - 28px)); max-height: calc(100dvh - 28px); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); box-shadow: var(--shadow); }
.form-dialog { width: min(720px, calc(100% - 28px)); }
.compact-dialog { width: min(460px, calc(100% - 28px)); padding-bottom: 20px; }
dialog > header { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); background: var(--paper); }
dialog h2 { margin: 0; font: 700 25px Georgia, serif; }
.dialog-tools { padding: 14px 6px 0; }
.catalog-list, .admin-section { min-height: 280px; padding: 0 18px 24px; overflow: auto; }
.catalog-card, .admin-row { display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; align-items: center; padding: 14px 4px; border-bottom: 1px solid var(--line); }
.catalog-card h3, .admin-row strong { margin: 0; font: 700 17px Georgia, serif; }
.catalog-card p, .admin-row p { margin: 0; color: var(--muted); font-size: 13px; }
.catalog-card small { color: var(--muted); }
.catalog-card .primary { grid-row: 1 / 4; grid-column: 2; }
.stack-form { padding: 20px; margin: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-note { padding: 12px; border-left: 3px solid var(--gold); color: var(--muted); background: var(--sand); font-size: 13px; line-height: 1.45; }
.compact-dialog > p, .compact-dialog > .text-button { margin-inline: 20px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 18px; }
.stat-card { padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--sand); }
.stat-card strong { display: block; font: 700 28px Georgia, serif; }
.stat-card span { color: var(--muted); font-size: 12px; }
.admin-tabs { margin: 0 18px 14px; }
.row-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.row-actions button { min-height: 34px; padding: 0 9px; border: 1px solid var(--line); border-radius: 6px; background: white; cursor: pointer; font-size: 12px; }
.toast { position: fixed; z-index: 1200; left: 50%; bottom: 24px; max-width: min(440px, calc(100% - 28px)); padding: 11px 16px; border-radius: 8px; color: white; background: #263d35; box-shadow: var(--shadow); opacity: 0; transform: translate(-50%, 20px); pointer-events: none; transition: .25s; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.mobile-nav, .mobile-only, .scrim { display: none; }

@media (max-width: 760px) {
  body { overflow: hidden; }
  .mobile-only { display: grid; }
  .app-shell { grid-template: 58px 1fr 66px / 1fr; grid-template-areas: "top" "reader" "nav"; }
  .topbar { padding: 0 10px; }
  .wordmark strong { display: none; }
  .top-action { display: none; }
  .library-panel { position: fixed; inset: 0 auto 0 0; width: min(88vw, 340px); transform: translateX(-105%); transition: transform .25s ease; box-shadow: var(--shadow); }
  .library-panel.open { transform: translateX(0); }
  .scrim { position: fixed; inset: 0; z-index: 12; display: block; background: rgba(18,31,27,.42); }
  .reader-toolbar { min-height: 52px; padding: 6px 10px; gap: 5px; }
  .reader-toolbar .icon-button { min-width: 36px; height: 36px; }
  .font-control input { width: 68px; }
  .switch b { display: none; }
  .song-heading, .lyrics, .video-wrap { width: calc(100% - 28px); }
  .song-heading { padding-top: 28px; }
  .song-heading h1 { font-size: 38px; }
  .song-actions { align-items: flex-start; flex-direction: column; gap: 0; }
  .lyrics { padding-top: 26px; padding-bottom: 50px; }
  .mobile-nav { grid-area: nav; z-index: 11; display: grid; grid-template-columns: 1fr 1fr 1fr; padding: 6px 8px max(6px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--paper); }
  .mobile-nav button { border: 0; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; }
.mobile-nav span { display: block; color: var(--forest); font-size: 22px; line-height: 24px; }
  .mobile-nav .ui-icon { display: block; width: 21px; height: 21px; margin: 1px auto 2px; }
  .mobile-nav .nav-add span { width: 38px; height: 30px; display: grid; place-items: center; margin: -10px auto 4px; border-radius: 16px; color: white; background: var(--gold); }
  .auth-screen { padding-inline: 10px; }
  .auth-card { padding: 22px 18px; border-radius: 16px 16px 36px 16px; }
  .workspace-dialog, .form-dialog { width: 100%; max-width: none; max-height: calc(100dvh - 12px); margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .form-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .catalog-card { grid-template-columns: 1fr; }
  .catalog-card .primary { grid-area: auto; margin-top: 7px; }
  .admin-row { grid-template-columns: 1fr; }
  .row-actions { justify-content: flex-start; }
  .empty-reader h1 { font-size: 29px; }
}
