:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #2e2e2e;
  --accent: #4f8ef7;
  --accent-hover: #3a76e0;
  --danger: #e05252;
  --danger-hover: #c93f3f;
  --text: #f0f0f0;
  --muted: #888;
  --radius: 12px;
  --radius-sm: 8px;
}

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

button, a, label, input { touch-action: manipulation; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15,15,15,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.site-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.dot { color: var(--accent); }
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-badge {
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 20px;
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: border-color 0.15s;
}
.user-badge:hover { border-color: var(--accent); color: var(--text); }

/* ── Buttons ── */
.btn-primary, .btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 18px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.97); }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-danger:disabled { background: #3a2020; color: #666; cursor: not-allowed; }
.full-width { width: 100%; margin-top: 12px; }

.btn-upload-trigger {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 700;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-upload-trigger:hover { background: var(--accent-hover); }

/* ── Main ── */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}
.subtitle {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 20px;
}

/* ── Semester Grid ── */
#semester-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.semester-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s, background 0.15s;
  user-select: none;
}
.semester-card:hover {
  border-color: var(--accent);
  background: var(--surface2);
}
.semester-card:active { transform: scale(0.97); }
.semester-label {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 6px;
}
.semester-meta {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.semester-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 5px;
  background: var(--accent);
}
.sem-no-klausur .semester-dot { background: var(--muted); }

/* ── Detail View ── */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0;
  margin-bottom: 16px;
  font-weight: 600;
}
.back-btn:hover { text-decoration: underline; }
#detail-title {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 24px;
}
.section-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 10px;
  font-weight: 600;
}
#klausur-section, #loesungen-section {
  margin-bottom: 32px;
}

/* ── File Cards ── */
.file-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.file-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}
.file-info {
  flex: 1;
  min-width: 0;
}
.file-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}
.file-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.btn-icon {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.8rem;
  padding: 6px 10px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}
.btn-icon:hover { background: var(--border); }
.btn-icon.danger { color: var(--danger); }
.btn-icon.danger:hover { background: #2a1515; border-color: var(--danger); }

.empty-hint {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 12px 0;
  font-style: italic;
}

/* ── Modals ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  backdrop-filter: blur(4px);
}
@media (min-width: 640px) {
  .modal { align-items: center; }
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 28px 24px 32px;
  width: 100%;
  max-width: 540px;
  position: relative;
  max-height: 92vh;
  overflow-y: auto;
}
@media (min-width: 640px) {
  .modal-box {
    border-radius: var(--radius);
    padding: 32px 28px;
  }
}
.modal-box h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 10px;
}
.modal-box p {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 16px;
  line-height: 1.5;
}
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--surface2);
  border: none;
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { color: var(--text); background: var(--border); }
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.modal-actions .btn-secondary,
.modal-actions .btn-primary,
.modal-actions .btn-danger { flex: 1; padding: 12px; }

input[type="text"], input[type="tel"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  padding: 12px 14px;
  margin-bottom: 14px;
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus { border-color: var(--accent); }
#name-confirm { width: 100%; padding: 13px; }

/* ── Upload Steps ── */
.upload-modal-box { padding-bottom: 40px; }
.upload-step { display: flex; flex-direction: column; }
.step-hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 14px !important;
}
.capture-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
}
.btn-camera {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  font-size: 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 700;
}
.camera-icon { font-size: 1.4rem; }
.hidden { display: none !important; }

/* Photo preview row (step 1 mini thumbnails) */
#photo-preview-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  min-height: 0;
}
.thumb-mini {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid var(--border);
  position: relative;
}
.thumb-count {
  background: var(--accent);
  color: #fff;
  width: 56px;
  height: 56px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
}

/* Review grid */
#review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
  max-height: 45vh;
  overflow-y: auto;
}
.review-thumb {
  position: relative;
  aspect-ratio: 3/4;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid var(--border);
}
.review-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.review-thumb .remove-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  font-size: 1.4rem;
}
.review-thumb:hover .remove-overlay,
.review-thumb:active .remove-overlay { opacity: 1; }
.review-thumb.pdf-placeholder {
  background: var(--surface2);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}

/* Semester Picker */
.semester-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 24px 0 8px;
}
.type-toggle {
  display: flex;
  background: var(--surface2);
  border-radius: 30px;
  padding: 3px;
  gap: 3px;
}
.toggle-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
  padding: 9px 28px;
  border-radius: 30px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.toggle-btn.active {
  background: var(--accent);
  color: #fff;
}
.year-picker {
  display: flex;
  align-items: center;
  gap: 20px;
}
.year-arrow {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  line-height: 1;
}
.year-arrow:hover { background: var(--border); }
#year-display {
  font-size: 2rem;
  font-weight: 800;
  min-width: 80px;
  text-align: center;
}
.year-label {
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 20px;
}
#upload-status {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  text-align: center;
}
#upload-status.success { background: #0f2a1a; color: #4caf82; border: 1px solid #1e4a30; }
#upload-status.error { background: #2a0f0f; color: #e05252; border: 1px solid #4a1e1e; }
#upload-status.loading { background: var(--surface2); color: var(--muted); }

/* ── Sort / List Header ── */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.list-header .subtitle { margin-bottom: 0; }
.sort-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.sort-btn:hover { color: var(--text); border-color: var(--accent); }

/* ── Comments ── */
.loesung-block {
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.loesung-block .file-card {
  border: none;
  border-radius: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}
.comment-section {
  padding: 12px 14px;
  background: var(--surface2);
}
.comments-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.comment-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.comment-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.comment-author {
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--accent);
}
.comment-time {
  font-size: 0.75rem;
  color: var(--muted);
  flex: 1;
}
.comment-delete {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}
.comment-delete:hover { color: var(--danger); background: #2a0f0f; }
.comment-text {
  font-size: 0.87rem;
  line-height: 1.45;
  word-break: break-word;
}
.no-comments {
  color: var(--muted);
  font-size: 0.8rem;
  font-style: italic;
}
.comment-form {
  display: flex;
  gap: 8px;
  align-items: center;
}
.comment-input {
  flex: 1;
  margin-bottom: 0 !important;
  font-size: 0.88rem;
  padding: 9px 12px;
}
.comment-submit {
  padding: 9px 14px;
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* ── Utilities ── */
.skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius-sm);
  height: 80px;
  margin-bottom: 8px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
