/*
 * Page-level styles for birta viewer.
 * Theme colors are inherited from github-markdown-css which defines
 * --bgColor-default, --fgColor-default, etc. via [data-theme] and
 * @media (prefers-color-scheme) selectors on .markdown-body.
 *
 * For the header and status bar (outside .markdown-body), we define
 * our own variables that mirror the github-markdown-css palette.
 */

:root {
  --birta-fg: #1f2328;
  --birta-bg: #ffffff;
  --birta-bg-secondary: #f6f8fa;
  --birta-border: #d1d9e0;
}

[data-theme="dark"] {
  --birta-fg: #e6edf3;
  --birta-bg: #0d1117;
  --birta-bg-secondary: #161b22;
  --birta-border: #30363d;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --birta-fg: #e6edf3;
    --birta-bg: #0d1117;
    --birta-bg-secondary: #161b22;
    --birta-border: #30363d;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--birta-bg);
  color: var(--birta-fg);
  transition: background-color 0.2s, color 0.2s;
}

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 8px 24px;
  background-color: var(--birta-bg-secondary);
  border-bottom: 1px solid var(--birta-border);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--birta-fg);
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.header.header-hidden {
  display: none;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.theme-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-dropdown {
  position: relative;
}

.theme-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--birta-bg-secondary);
  border: 1px solid var(--birta-border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--birta-fg);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  transition: border-color 0.2s;
  white-space: nowrap;
}

.theme-dropdown-btn:hover {
  border-color: var(--birta-fg);
}

.theme-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 160px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--birta-bg);
  border: 1px solid var(--birta-border);
  border-radius: 6px;
  padding: 4px 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 200;
}

.theme-dropdown.open .theme-dropdown-menu {
  display: block;
}

.theme-dropdown-item {
  display: block;
  width: 100%;
  padding: 6px 16px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--birta-fg);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  text-align: left;
  transition: background-color 0.1s;
}

.theme-dropdown-item:hover {
  background-color: var(--birta-bg-secondary);
}

.theme-dropdown-item.active {
  font-weight: 600;
  background-color: var(--birta-bg-secondary);
}

.reading-toggle,
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--birta-border);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--birta-fg);
  font-size: 14px;
  line-height: 1;
  transition: border-color 0.2s;
}

.reading-toggle:hover,
.theme-toggle:hover {
  border-color: var(--birta-fg);
}

.theme-toggle.disabled {
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
}

.theme-toggle svg {
  display: none;
}

.container {
  max-width: 1012px;
  margin: 24px auto;
  padding: 0;
  border: 1px solid var(--birta-border);
  border-radius: 6px;
}

.container .markdown-body {
  padding: 40px;
}

/* File header bar — GitHub-style */
.file-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background-color: var(--birta-bg-secondary);
  border-bottom: 1px solid var(--birta-border);
  border-radius: 6px 6px 0 0;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 32px;
}

/* View toggle (Preview / Raw) — segmented control in file header */
.view-toggle {
  display: flex;
  margin-left: auto;
  border: 1px solid var(--birta-border);
  border-radius: 6px;
  overflow: hidden;
}

.view-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  background: none;
  border: none;
  border-right: 1px solid var(--birta-border);
  cursor: pointer;
  color: var(--birta-fg);
  opacity: 0.6;
  transition: background-color 0.15s, opacity 0.15s;
  line-height: 1;
}

.view-btn:last-child {
  border-right: none;
}

.view-btn:hover {
  opacity: 0.9;
  background-color: var(--birta-bg);
}

.view-btn.active {
  background-color: var(--birta-bg);
  opacity: 1;
}

.file-header-icon {
  flex-shrink: 0;
  opacity: 0.6;
}

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

@media (max-width: 767px) {
  .container .markdown-body {
    padding: 16px;
  }

  .header {
    padding: 8px 16px;
  }
}

.status {
  position: fixed;
  bottom: 12px;
  right: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
  background-color: var(--birta-bg-secondary);
  border: 1px solid var(--birta-border);
  color: var(--birta-fg);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.status.visible {
  opacity: 1;
}

/* --- Reading mode --- */
body.reading-mode .header {
  transform: translateY(-100%);
  pointer-events: none;
  opacity: 0;
}

body.reading-mode .file-header {
  display: none;
}

body.reading-mode .source-container {
  display: none;
}

body.reading-mode .container {
  border-color: transparent;
  margin-top: 0;
}

.reading-progress {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background-color: var(--birta-fg);
  opacity: 0.25;
  z-index: 200;
  pointer-events: none;
  transition: width 80ms linear;
}

.reading-exit-zone {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  z-index: 300;
}

.reading-exit-bar {
  position: fixed;
  top: 8px;
  right: 16px;
  z-index: 301;
  transform: translateY(-48px);
  transition: transform 0.2s ease, opacity 0.2s ease;
  transition-delay: 0.3s;
  opacity: 0;
  pointer-events: none;
}

.reading-exit-zone:hover ~ .reading-exit-bar,
.reading-exit-bar:hover {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
  transition-delay: 0s;
}

.reading-exit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background-color: var(--birta-bg-secondary);
  border: 1px solid var(--birta-border);
  border-radius: 6px;
  color: var(--birta-fg);
  cursor: pointer;
  transition: border-color 0.2s;
}

.reading-exit-btn:hover {
  border-color: var(--birta-fg);
}

/* --- Source / Raw view --- */
.source-container {
  display: flex;
  overflow-x: auto;
}

.source-lines {
  flex-shrink: 0;
  padding: 16px 0;
  user-select: none;
  text-align: right;
  background-color: var(--birta-bg);
}

.source-lines span {
  display: block;
  padding: 0 12px 0 16px;
  color: var(--birta-fg);
  opacity: 0.35;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 20px;
  white-space: nowrap;
}

.source-code {
  flex: 1;
  margin: 0;
  padding: 16px 16px 16px 12px;
  overflow-x: auto;
  background-color: var(--birta-bg) !important;
  color: var(--birta-fg);
  tab-size: 4;
}

.source-code code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 20px;
}

/* Prevent page CSS (e.g. .header) from affecting syntect scope class names */
.source-code span {
  display: inline;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  position: static;
  float: none;
}

/* Override inline background-color from syntect on themed code blocks */
.markdown-body .highlight pre[style],
.markdown-body pre[style] {
  background-color: var(--bgColor-muted) !important;
}

/* Heading anchor links — GitHub-style hover-reveal */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  position: relative;
}

.markdown-body .anchor {
  float: left;
  padding-right: 4px;
  margin-left: -20px;
  line-height: 1;
}

.markdown-body .anchor::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 16px;
  vertical-align: middle;
  background-color: var(--birta-fg);
  opacity: 0;
  transition: opacity 0.15s;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a2.002 2.002 0 0 0 0 2.83Z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a2.002 2.002 0 0 0 0 2.83Z'/%3E%3C/svg%3E");
  -webkit-mask-size: 16px 16px;
  mask-size: 16px 16px;
}

.markdown-body h1:hover .anchor::before,
.markdown-body h2:hover .anchor::before,
.markdown-body h3:hover .anchor::before,
.markdown-body h4:hover .anchor::before,
.markdown-body h5:hover .anchor::before,
.markdown-body h6:hover .anchor::before,
.markdown-body .anchor:focus::before {
  opacity: 0.5;
}

.markdown-body h1:hover .anchor::before:hover,
.markdown-body .anchor:focus::before {
  opacity: 1;
}
