/* base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --text-primary: #c9d1d9;
  --text-secondary: #8b949e;
  --border: #30363d;
  --accent: #238636;
  --accent-hover: #2ea043;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color 0.2s, color 0.2s;
}

body.light-theme {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #eaeef2;
  --text-primary: #24292f;
  --text-secondary: #57606a;
  --border: #d0d7de;
}

/* container */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
}

/* header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
}

.controls {
  display: flex;
  gap: 10px;
}

.btn {
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn-icon {
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 60px 20px;
  text-align: center;
  background: var(--bg-secondary);
  transition: all 0.2s;
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--bg-tertiary);
}

.drop-zone-content svg {
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.drop-zone-content p {
  color: var(--text-secondary);
  font-size: 16px;
  margin-bottom: 8px;
}

.drop-zone-content .hint {
  font-size: 13px;
  color: var(--text-secondary);
  opacity: 0.7;
}

.error-message {
  color: #f85149;
  font-size: 14px;
  margin-top: 8px;
}

/* kbd */
kbd {
  display: inline-block;
  padding: 2px 6px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-primary);
}

/* file info */
.file-info {
  display: none;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-radius: 6px;
  margin-bottom: 20px;
  font-size: 14px;
  color: var(--text-secondary);
}

#fileName {
  font-weight: 500;
  color: var(--text-primary);
}

.file-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-info .separator {
  color: var(--border);
}

/* markdown body - github style */
.markdown-body {
  padding: 20px;
  background: var(--bg-secondary);
  border-radius: 6px;
}

.markdown-body h1,
.markdown-body h2 {
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border);
  margin-top: 24px;
  margin-bottom: 16px;
  font-weight: 600;
  line-height: 1.25;
}

.markdown-body h1 {
  font-size: 2em;
}

.markdown-body h2 {
  font-size: 1.5em;
}

.markdown-body h3 {
  font-size: 1.25em;
  margin-top: 24px;
  margin-bottom: 16px;
  font-weight: 600;
}

.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  font-size: 1em;
  margin-top: 24px;
  margin-bottom: 16px;
  font-weight: 600;
}

.markdown-body p {
  margin-bottom: 16px;
}

.markdown-body a {
  color: #58a6ff;
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

body.light-theme .markdown-body a {
  color: #0969da;
}

.markdown-body ul,
.markdown-body ol {
  margin-bottom: 16px;
  padding-left: 2em;
}

.markdown-body li {
  margin-bottom: 4px;
}

.markdown-body blockquote {
  padding: 0 1em;
  color: var(--text-secondary);
  border-left: 0.25em solid var(--border);
  margin-bottom: 16px;
}

.markdown-body pre {
  padding: 16px;
  overflow: auto;
  font-size: 85%;
  line-height: 1.45;
  background: var(--bg-tertiary);
  border-radius: 6px;
  margin-bottom: 16px;
}

.markdown-body code {
  padding: 0.2em 0.4em;
  margin: 0;
  font-size: 85%;
  background: var(--bg-tertiary);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
  border-radius: 0;
}

.markdown-body table {
  border-collapse: collapse;
  margin-bottom: 16px;
  width: 100%;
  overflow: auto;
}

.markdown-body table th,
.markdown-body table td {
  padding: 6px 13px;
  border: 1px solid var(--border);
}

.markdown-body table th {
  font-weight: 600;
  background: var(--bg-tertiary);
}

.markdown-body table tr:nth-child(2n) {
  background: var(--bg-tertiary);
}

.markdown-body img {
  max-width: 100%;
  border-radius: 6px;
  margin: 16px 0;
}

.markdown-body hr {
  height: 0.25em;
  padding: 0;
  margin: 24px 0;
  background: var(--border);
  border: 0;
}

.markdown-body input[type="checkbox"] {
  margin-right: 8px;
}

/* mermaid diagrams with panzoom */
.diagram-wrapper {
  position: relative;
  margin: 16px 0;
  background: var(--bg-tertiary);
  border-radius: 6px;
  overflow: hidden;
}

.diagram-container {
  overflow: hidden;
  min-height: 200px;
  padding: 16px;
  cursor: grab;
}

.diagram-container:active {
  cursor: grabbing;
}

.diagram-container .mermaid {
  text-align: center;
}

.zoom-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.2s;
}

.diagram-wrapper:hover .zoom-controls {
  opacity: 1;
}

.zoom-controls button {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.zoom-controls button:hover {
  background: var(--bg-tertiary);
}

.zoom-hint {
  display: flex;
  align-items: center;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 0 6px;
  opacity: 0.8;
}

/* fullscreen diagram modal */
.fullscreen-diagram {
  width: 95vw;
  height: 95vh;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fullscreen-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.fullscreen-title {
  font-weight: 500;
  font-size: 14px;
  color: var(--text-secondary);
}

.fullscreen-container {
  flex: 1;
  overflow: hidden;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fullscreen-container:active {
  cursor: grabbing;
}

.fullscreen-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.fullscreen-controls button {
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.fullscreen-controls button:hover {
  background: var(--bg-secondary);
}

.fullscreen-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 8px;
}

@media (hover: none) {
  .zoom-controls {
    opacity: 1;
  }
}

/* scroll to top button */
.scroll-top-btn {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: background 0.2s, opacity 0.2s, transform 0.2s;
  z-index: 100;
  opacity: 0.9;
}

.scroll-top-btn:hover {
  background: var(--accent-hover);
  opacity: 1;
  transform: translateY(-2px);
}

/* shortcuts modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
}

.modal h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

.shortcut-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.shortcut {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.shortcut span {
  color: var(--text-secondary);
}

/* responsive */
@media (max-width: 768px) {
  .container {
    padding: 15px;
  }

  header {
    flex-direction: column;
    gap: 15px;
    align-items: flex-start;
  }

  .controls {
    width: 100%;
  }

  .btn {
    flex: 1;
  }

  .markdown-body {
    padding: 15px;
  }

  .file-info {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }
}

/* scrollbar */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* print styles */
@media print {
  body {
    background: white;
    color: black;
  }

  header,
  .file-info,
  .drop-zone,
  .scroll-top-btn,
  .modal-overlay,
  .zoom-controls,
  #fileInput {
    display: none !important;
  }

  .diagram-container {
    overflow: visible;
    cursor: default;
  }

  .diagram-container .mermaid svg {
    max-width: 100%;
  }

  .container {
    max-width: 100%;
    padding: 0;
  }

  .markdown-body {
    display: block !important;
    background: white;
    padding: 0;
    border-radius: 0;
    color: black;
  }

  .markdown-body a {
    color: #0969da;
    text-decoration: underline;
  }

  .markdown-body a::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }

  .markdown-body pre {
    background: #f6f8fa;
    border: 1px solid #d0d7de;
    white-space: pre-wrap;
    word-wrap: break-word;
  }

  .markdown-body table th,
  .markdown-body table td {
    border-color: #d0d7de;
  }

  .markdown-body img {
    max-width: 100%;
  }

  .diagram-wrapper .mermaid svg {
    max-width: 100%;
  }
}
