:root {
  --bg: #0c0d10;
  --bg-elev: #15171c;
  --bg-hover: #1c1f26;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f3f4f6;
  --muted: #8b8f9a;
  --accent: #e8943a;
  --accent-hover: #f3a84f;
  --accent-ink: #1a1208;
  --paper: #ffffff;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.38);
  --radius-sm: 10px;
  --thumbs-w: 5.25rem;
  --gap: 0.85rem;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html {
  color-scheme: dark;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  height: 100dvh;
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  color: inherit;
}

.app {
  height: 100%;
  display: grid;
  grid-template-columns: var(--thumbs-w) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "header header"
    "thumbs viewer"
    "footer footer";
}

.site-header,
.site-footer {
  display: flex;
  align-items: center;
  gap: 0.75rem 1rem;
  padding-left: max(1rem, var(--safe-l));
  padding-right: max(1rem, var(--safe-r));
  background: var(--bg);
  z-index: 20;
}

.site-header {
  grid-area: header;
  position: relative;
  min-height: 3.5rem;
  padding-top: var(--safe-t);
  border-bottom: 1px solid var(--line);
  justify-content: space-between;
  overflow: visible;
  z-index: 30;
}

.site-footer {
  grid-area: footer;
  min-height: 2.35rem;
  padding-bottom: var(--safe-b);
  border-top: 1px solid var(--line);
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.01em;
}

.brand-wrap {
  position: relative;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  margin: 0;
  padding: 0.2rem 0.35rem 0.2rem 0.2rem;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.brand:hover,
.brand:focus-visible,
.brand-wrap.is-open .brand {
  background: var(--bg-elev);
}

.brand:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.brand-mark {
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
  background: var(--accent);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3.5px;
}

.brand-mark span {
  display: block;
  width: 1.05rem;
  height: 2px;
  border-radius: 1px;
  background: var(--accent-ink);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand-name {
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-tag {
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: lowercase;
}

.project-menu {
  position: absolute;
  top: calc(100% + 0.45rem);
  left: 0;
  width: min(22.5rem, calc(100vw - 1.5rem));
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  box-shadow: var(--shadow);
  z-index: 40;
}

.project-item {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  padding: 0.7rem 0.75rem;
  border-radius: 8px;
  color: var(--text);
}

.project-item:hover,
.project-item:focus-visible {
  background: var(--bg-hover);
}

.project-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.project-title {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
}

.project-meta {
  font-size: 0.68rem;
  color: var(--muted);
}

.now-playing {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.now-meta {
  text-align: center;
  min-width: 7.5rem;
}

.doc-title {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-counter {
  font-size: 0.68rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.icon-btn,
.btn-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  flex: 0 0 auto;
}

.btn-download {
  height: 2.25rem;
  padding: 0 0.85rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  background: var(--bg-hover);
  border-color: rgba(255, 255, 255, 0.16);
}

.btn-download:hover,
.btn-download:focus-visible {
  background: var(--accent-hover);
}

.icon-btn:active,
.btn-download:active {
  transform: scale(0.96);
}

.icon-btn:focus-visible,
.btn-download:focus-visible,
.doc-thumb:focus-visible,
.pdf-page-wrap:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.thumbs {
  grid-area: thumbs;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: var(--gap) 0.65rem;
  overflow: auto;
  scrollbar-width: thin;
  border-right: 1px solid var(--line);
}

.doc-thumb {
  width: 100%;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--bg-elev);
  cursor: pointer;
  overflow: hidden;
  touch-action: manipulation;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.doc-thumb canvas,
.doc-thumb img {
  display: block;
  width: 100%;
  height: auto;
}

.doc-thumb.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.doc-thumb:hover {
  transform: translateY(-1px);
}

.viewer {
  grid-area: viewer;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  padding: 0.85rem 1.1rem 1.5rem;
}

.status {
  margin: 18vh auto 0;
  max-width: 28rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.status.is-error {
  color: #f0b4b4;
}

[hidden] {
  display: none !important;
}

.pdf-page-wrap {
  position: relative;
  display: block;
  width: min(100%, 920px);
  margin: 0 auto 1rem;
  cursor: pointer;
  scroll-margin-top: 0.6rem;
}

.pdf-page-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  background: var(--paper);
  box-shadow: var(--shadow);
  user-select: none;
}

.page-action {
  position: absolute;
  right: 0.7rem;
  top: 0.7rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  background: rgba(12, 13, 16, 0.78);
  color: var(--text);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0.82;
  pointer-events: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(2.6rem + var(--safe-b));
  transform: translateX(-50%);
  z-index: 40;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  font-size: 0.8rem;
  box-shadow: var(--shadow);
}

.footer-hint {
  color: var(--muted);
}

@media (hover: none) {
  .doc-thumb:hover {
    transform: none;
  }
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "header"
      "thumbs"
      "viewer"
      "footer";
  }

  .thumbs {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.55rem 0.85rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .doc-thumb {
    flex: 0 0 3.1rem;
    width: 3.1rem;
  }

  .viewer {
    padding: 0.75rem 0.75rem 1.25rem;
  }
}

@media (max-width: 640px) {
  .site-header {
    flex-wrap: wrap;
    min-height: 0;
    padding-top: calc(0.45rem + var(--safe-t));
    padding-bottom: 0.45rem;
    gap: 0.45rem 0.6rem;
  }

  .brand-wrap {
    flex: 1 1 auto;
  }

  .now-playing {
    flex: 1 1 100%;
    justify-content: center;
    order: 3;
  }

  .now-meta {
    min-width: 0;
    flex: 1 1 auto;
  }

  .btn-download-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .btn-download {
    width: 2.25rem;
    padding: 0;
  }

  .footer-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .viewer {
    scroll-behavior: auto;
  }

  .icon-btn,
  .btn-download,
  .doc-thumb,
  .page-action {
    transition: none;
  }
}
