:root {
  --ink: #14201c;
  --fog: #d8e2dc;
  --paper: #f3f6f4;
  --panel: rgba(20, 32, 28, 0.92);
  --accent: #c4f061;
  --accent-ink: #1a2a12;
  --line: rgba(216, 226, 220, 0.14);
  --shadow: 0 24px 60px rgba(8, 16, 12, 0.35);
  --radius: 18px;
  --sidebar: 340px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Manrope", sans-serif;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--paper);
  background:
    radial-gradient(1200px 700px at 10% -10%, rgba(196, 240, 97, 0.18), transparent 55%),
    radial-gradient(900px 600px at 100% 0%, rgba(88, 140, 120, 0.28), transparent 50%),
    linear-gradient(160deg, #0d1613 0%, #1a2b24 45%, #101a16 100%);
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Login */
.login-body {
  overflow: auto;
}

.login-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-card {
  width: min(100%, 420px);
  padding: 2.2rem 1.8rem 1.9rem;
  border-radius: 28px;
  border: 1px solid var(--line);
  background: rgba(16, 26, 22, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  animation: rise 0.5s ease both;
}

.login-card .brand-mark {
  font-size: clamp(2.6rem, 8vw, 3.4rem);
}

.login-lead {
  margin: 0.55rem 0 1.6rem;
  color: rgba(216, 226, 220, 0.75);
}

.login-form {
  display: grid;
  gap: 0.55rem;
}

.login-form label {
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(216, 226, 220, 0.6);
}

.login-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--paper);
  padding: 0.9rem 1rem;
  font: inherit;
  outline: none;
}

.login-form input:focus {
  border-color: rgba(196, 240, 97, 0.55);
}

.login-error {
  margin: 0.2rem 0 0;
  color: #ffb4a8;
  font-size: 0.9rem;
}

.btn-block {
  width: 100%;
  margin-top: 0.55rem;
  border: 0;
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.25rem 1rem 1rem;
  background: var(--panel);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(16px);
  z-index: 3;
  min-height: 0;
}

.brand {
  padding: 0.25rem 0.45rem 0.1rem;
}

.brand-mark {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.1rem, 3vw, 2.7rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--accent);
}

.brand-tag {
  margin: 0.4rem 0 0;
  color: var(--fog);
  font-size: 0.9rem;
  opacity: 0.78;
}

.categories {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 0.25rem;
}

.cat {
  display: inline-flex;
  align-items: center;
  padding: 0.42rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: rgba(243, 246, 244, 0.82);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.cat:hover {
  background: rgba(255, 255, 255, 0.05);
}

.cat.is-active {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}

.toolbar {
  display: grid;
  gap: 0.45rem;
  padding: 0 0.25rem;
}

.search input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--paper);
  padding: 0.72rem 1rem;
  font: inherit;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.search input::placeholder {
  color: rgba(216, 226, 220, 0.55);
}

.search input:focus {
  border-color: rgba(196, 240, 97, 0.55);
  background: rgba(255, 255, 255, 0.07);
}

.count {
  margin: 0;
  padding: 0 0.35rem;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(216, 226, 220, 0.55);
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  overflow: auto;
  padding: 0.15rem;
  margin: 0 -0.15rem;
  flex: 1;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(196, 240, 97, 0.35) transparent;
}

.file {
  display: grid;
  grid-template-columns: 2rem 1fr;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem 0.8rem;
  border-radius: 14px;
  color: inherit;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.file:hover {
  background: rgba(255, 255, 255, 0.05);
  transform: translateX(2px);
}

.file.is-active {
  background: rgba(196, 240, 97, 0.12);
  border-color: rgba(196, 240, 97, 0.28);
}

.file.is-hidden {
  display: none;
}

.file-icon {
  width: 2rem;
  height: 2.35rem;
  border-radius: 6px;
  background: linear-gradient(145deg, rgba(243, 246, 244, 0.95), rgba(216, 226, 220, 0.7));
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(20, 32, 28, 0.08);
}

.file-icon::after {
  content: "PDF";
  position: absolute;
  left: 50%;
  bottom: 0.28rem;
  transform: translateX(-50%);
  font-size: 0.52rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.file-icon-epub {
  background: linear-gradient(145deg, #ffe7b8, #f0c36a);
}

.file-icon-epub::after {
  content: "EPUB";
  font-size: 0.45rem;
}

.file-meta {
  min-width: 0;
  display: grid;
  gap: 0.18rem;
}

.file-name {
  font-weight: 600;
  font-size: 0.93rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-sub {
  font-size: 0.76rem;
  color: rgba(216, 226, 220, 0.58);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty {
  margin: 1rem 0.5rem;
  color: rgba(216, 226, 220, 0.72);
  line-height: 1.5;
}

.empty code,
.placeholder code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  color: var(--accent);
}

.sidebar-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.45rem 0.15rem;
  border-top: 1px solid var(--line);
  color: rgba(216, 226, 220, 0.55);
  font-size: 0.8rem;
}

.sidebar-foot a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.viewer {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
}

.viewer-bar {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.9rem 1.15rem;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 22, 19, 0.55);
  backdrop-filter: blur(10px);
}

.viewer-title {
  min-width: 0;
  flex: 1;
}

.viewer-title h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 2vw, 1.4rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-title p {
  margin: 0.2rem 0 0;
  color: rgba(216, 226, 220, 0.58);
  font-size: 0.82rem;
}

.viewer-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 0.95rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.88rem;
  border: 1px solid transparent;
  transition: transform 0.18s ease, filter 0.18s ease;
}

.btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--paper);
  border-color: var(--line);
  cursor: pointer;
  font: inherit;
}

.icon-btn {
  display: none;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  padding: 0.55rem;
  cursor: pointer;
}

.icon-btn span {
  display: block;
  height: 2px;
  margin: 4px 0;
  background: var(--paper);
  border-radius: 999px;
}

.stage {
  position: relative;
  min-height: 0;
  padding: 1rem;
  display: flex;
}

.stage iframe,
.epub-shell {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  animation: rise 0.45s ease both;
}

.epub-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background:
    linear-gradient(180deg, #f7f3ea 0%, #efe7d8 100%);
}

.epub-shell:fullscreen,
.epub-shell.is-fullscreen,
.epub-shell.is-fullscreen-fallback {
  width: 100vw;
  height: 100vh;
  max-width: none;
  border-radius: 0;
  box-shadow: none;
  z-index: 50;
}

.epub-shell.is-fullscreen-fallback {
  position: fixed;
  inset: 0;
}

.epub-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.8rem;
  border-bottom: 1px solid rgba(20, 32, 28, 0.08);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(8px);
}

.epub-toolbar-right {
  display: flex;
  gap: 0.45rem;
  flex-shrink: 0;
}

.epub-toolbar .btn-ghost {
  color: var(--ink);
  border-color: rgba(20, 32, 28, 0.14);
}

.epub-status {
  margin: 0;
  color: rgba(20, 32, 28, 0.62);
  font-size: 0.85rem;
  text-align: center;
  flex: 1;
  min-width: 0;
}

.epub-area {
  position: relative;
  min-height: 60vh;
  height: 100%;
  width: 100%;
  overflow: auto;
  background: #f7f3ea;
}

.epub-area .epub-container {
  width: 100% !important;
  height: 100% !important;
}

.epub-area iframe {
  border: 0 !important;
  background: transparent !important;
}

.placeholder {
  height: 100%;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 0.75rem;
  padding: 2rem;
  border: 1px dashed rgba(216, 226, 220, 0.25);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.03);
  animation: rise 0.5s ease both;
}

.placeholder-brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: 3rem;
  color: var(--accent);
  letter-spacing: -0.03em;
}

.placeholder p {
  margin: 0;
  max-width: 28rem;
  color: rgba(216, 226, 220, 0.78);
  line-height: 1.55;
}

.backdrop {
  display: none;
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0 0.25rem;
}

.nav-link {
  text-decoration: none;
  color: rgba(243, 246, 244, 0.78);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
}

.nav-link.is-active,
.nav-link:hover {
  background: rgba(196, 240, 97, 0.14);
  color: var(--paper);
  border-color: rgba(196, 240, 97, 0.3);
}

.flash {
  margin: 0 0.25rem;
  padding: 0.65rem 0.8rem;
  border-radius: 12px;
  font-size: 0.9rem;
}

.flash-ok {
  background: rgba(196, 240, 97, 0.16);
  color: var(--accent);
}

.flash-error {
  background: rgba(255, 120, 100, 0.14);
  color: #ffb4a8;
}

.file-icon-note {
  background: linear-gradient(145deg, #d9f1ff, #8ec8e8);
}

.file-icon-note::after {
  content: "NOTE";
  font-size: 0.42rem;
}

.stage-panel {
  overflow: auto;
}

.note-form,
.stack-form {
  display: grid;
  gap: 0.55rem;
  max-width: 760px;
  margin: 0 auto;
  padding: 1.2rem;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  color: var(--paper);
}

.note-form label,
.stack-form label,
.stack-form legend {
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(216, 226, 220, 0.62);
}

.note-form input,
.note-form textarea,
.note-form select,
.stack-form input,
.stack-form select,
.stack-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--paper);
  padding: 0.8rem 0.95rem;
  font: inherit;
}

.note-form textarea {
  min-height: 280px;
  resize: vertical;
  line-height: 1.55;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.4rem;
}

.note-view {
  max-width: 760px;
  margin: 0 auto;
  padding: 1.4rem 1.5rem 1.2rem;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #f7f3ea 0%, #efe7d8 100%);
  color: #1d221c;
  box-shadow: var(--shadow);
  min-height: 60%;
}

.note-body {
  font-size: 1.05rem;
  line-height: 1.7;
  white-space: normal;
}

.note-delete {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(20, 32, 28, 0.1);
}

.btn-danger {
  background: #c45545;
  color: #fff;
  border: 0;
  cursor: pointer;
}

.admin-body {
  overflow: auto;
}

.admin-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.4rem 1.2rem 2.5rem;
}

.admin-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.2rem;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 1rem;
}

.panel {
  padding: 1.2rem;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(16, 26, 22, 0.78);
  box-shadow: var(--shadow);
}

.panel-wide {
  grid-column: 1 / -1;
}

.panel h2 {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.35rem;
}

.panel h2.spaced {
  margin-top: 1.6rem;
}

.muted {
  color: rgba(216, 226, 220, 0.65);
  font-size: 0.92rem;
}

.check-set {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.8rem 0.9rem;
  display: grid;
  gap: 0.45rem;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.95rem;
  color: var(--paper);
  cursor: pointer;
}

.check input {
  width: auto;
}

.plain-list {
  margin: 0;
  padding-left: 1.1rem;
  color: rgba(243, 246, 244, 0.85);
  line-height: 1.7;
}

.table-wrap {
  overflow: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 0.7rem 0.45rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.admin-table th {
  color: rgba(216, 226, 220, 0.6);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
}

.table-actions a,
.linkish {
  color: var(--accent);
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

@media (max-width: 900px) {
  .admin-grid {
    grid-template-columns: 1fr;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 900px) {
  body:not(.login-body) {
    overflow: auto;
  }

  .app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, 340px);
    transform: translateX(-105%);
    transition: transform 0.28s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .viewer {
    min-height: 100vh;
    min-height: 100dvh;
  }

  .stage {
    height: calc(100vh - 5.2rem);
    height: calc(100dvh - 5.2rem);
  }

  .icon-btn {
    display: inline-block;
  }

  .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(5, 10, 8, 0.55);
    z-index: 2;
  }

  .backdrop[hidden] {
    display: none;
  }
}
