/* ==========================================================
   Design tokens — neutral grayscale, light/dark adaptive
   ========================================================== */
:root {
  --bg: #ffffff;
  --surface: #f6f6f6;
  --border: #e4e4e4;
  --text: #141414;
  --text-muted: #6f6f6f;
  --overlay: rgba(0, 0, 0, 0.5);

  --font-body: "Pretendard", "Noto Sans KR", sans-serif;
  --font-display: "GeneralKimJwajin", "Pretendard", "Noto Sans KR", sans-serif;
  --radius: 2px;
}

@font-face {
  font-family: "GeneralKimJwajin";
  src: url("../fonts/GeneralKimJwajin_Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101010;
    --surface: #1a1a1a;
    --border: #2c2c2c;
    --text: #f2f2f2;
    --text-muted: #9a9a9a;
    --overlay: rgba(0, 0, 0, 0.7);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ---------------- Nav ---------------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 20px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.nav-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.nav-links { display: flex; gap: 22px; }

.nav-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 14px;
  cursor: pointer;
  transition: color 0.15s ease;
}

.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--text); }

.nav-right {
  display: flex;
  align-items: center;
  gap: 22px;
  margin-left: auto;
}

.nav-icon-link {
  align-items: center;
  color: var(--text-muted);
  transition: color 0.15s ease;
}

.nav-icon-link:not([hidden]) { display: flex; }

.nav-icon-link:hover { color: var(--text); }
.nav-icon-link svg { width: 17px; height: 17px; }

.signup-badge {
  background: #f5c518;
  color: #000;
  font-weight: 700;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
}

.signup-badge:not([hidden]) { display: inline-block; }
.signup-badge:hover { color: #000; opacity: 0.85; }

#new-signups-note:not([hidden]) { display: inline-block; margin-bottom: 16px; }

/* ---------------- Hero ---------------- */
.hero {
  padding: 120px 24px 96px;
  max-width: 720px;
  margin: 0 auto;
  text-align: center;
}

.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(48px, 9vw, 84px);
  font-weight: 700;
  margin: 0 0 28px;
  letter-spacing: -0.01em;
}

.hero-icons {
  display: flex;
  justify-content: center;
  gap: 14px;
}

.hero-icons a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 45px;
  height: 45px;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  transition: border-color 0.15s ease, opacity 0.15s ease;
}

.hero-icons a:hover { border-color: var(--text); }

.hero-icons svg { width: 19px; height: 19px; }

/* ---------------- Departments (sections) ---------------- */
main { max-width: 960px; margin: 0 auto; padding: 0 24px 96px; }

.dept {
  padding: 56px 0;
  border-top: 1px solid var(--border);
  scroll-margin-top: 72px;
}

.dept h2 {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 28px;
}

.card-grid:not([hidden]) {
  display: grid;
  grid-template-columns: repeat(auto-fill, 220px);
  justify-content: start;
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 128px;
  text-align: center;
  transition: border-color 0.15s ease;
}

.card:hover { border-color: var(--text-muted); }

.card-tag {
  font-size: 11px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: var(--radius);
}

.card h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.card-link {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-muted);
}

.card-link:hover { color: var(--text); }

.card-placeholder {
  border-style: dashed;
  opacity: 0.55;
}

.text-block { margin-bottom: 8px; }

.text-line {
  margin: 0 0 6px;
  font-size: 15px;
  color: var(--text);
}

.text-line:last-child { margin-bottom: 0; }

.subnav {
  gap: 18px;
  margin-bottom: 20px;
}

.subnav:not([hidden]) { display: flex; }

.subnav-link {
  background: none;
  border: none;
  padding: 0 0 4px;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease;
}

.subnav-link:hover { color: var(--text); }
.subnav-link.active { color: var(--text); border-bottom-color: var(--text); }

.account-help-row {
  margin-top: 14px;
  gap: 16px;
}

.account-help-row:not([hidden]) { display: flex; flex-wrap: wrap; }

.account-help-row .subnav-link,
.account-help-row a.subnav-link {
  border-bottom: none;
}

#account-back-link {
  display: block;
  margin-top: 14px;
  border-bottom: none;
}

.consent-row {
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}

.consent-row:not([hidden]) { display: flex; }

.consent-row input { width: auto; margin-top: 2px; }
.consent-row a { color: var(--text); }

.remember-row {
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.remember-row:not([hidden]) { display: flex; }

.remember-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.remember-row input { width: auto; }

#account-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 16px;
  font-size: 13px;
  cursor: pointer;
  margin-top: 8px;
}

#account-logout:hover { border-color: var(--text); }

.gallery-item.placeholder figcaption {
  position: static;
  opacity: 1;
  background: none;
  color: var(--text-muted);
  font-weight: 400;
}

.gallery-item.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16 / 7;
}

.gallery-item.placeholder .gallery-img { display: none; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.gallery-item {
  position: relative;
  margin: 0;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.gallery-img { width: 100%; height: 100%; background: var(--surface); object-fit: cover; display: block; }

.gallery-item figcaption {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.gallery-item:hover figcaption,
.gallery-item:focus-within figcaption { opacity: 1; }

body.editing-mode .gallery-item:not(.placeholder) figcaption { opacity: 1; }

.sub-dept {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px dashed var(--border);
}

.sub-dept-label {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 14px;
}

.sub-dept-label.admin-section-label { margin-top: 48px; }

/* ---------------- Contact (modal, opened via nav button) ---------------- */
.hardware-detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  justify-content: flex-end;
  background: var(--overlay);
}

.hardware-detail-overlay[hidden] { display: none; }

.hardware-detail-panel {
  width: 560px;
  max-width: 100%;
  height: 100%;
  overflow-y: auto;
  background: var(--bg);
  border-left: 1px solid var(--border);
  padding: 48px 40px;
}

.hardware-detail-panel .hardware-img { width: 100%; max-width: 480px; }

.hardware-detail-field {
  margin: 22px 0;
}

.hardware-detail-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.hardware-detail-panel h2 { font-size: 26px; font-weight: 700; margin: 20px 0 12px; }

@media (max-width: 900px) {
  .hardware-detail-panel { width: 100%; }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--overlay);
}

.modal-overlay[hidden] { display: none; }

.modal {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 28px 28px;
}

.modal h2 {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 20px;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 6px 10px;
}

.modal-close:hover { color: var(--text); }

.contact-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-row {
  display: flex;
  gap: 12px;
}

.field-row .admin-btn { align-self: flex-start; }

.field-row input,
.field-row select {
  flex: 1;
  min-width: 0;
}

input, textarea, select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 12px 14px;
  resize: vertical;
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }

input:focus, textarea:focus, select:focus, button:focus, a:focus {
  outline: 2px solid var(--text-muted);
  outline-offset: 2px;
}

button[type="submit"] {
  align-self: flex-start;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  padding: 11px 20px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

button[type="submit"]:hover { opacity: 0.8; }
button[type="submit"]:disabled { opacity: 0.5; cursor: not-allowed; }

.form-status {
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
  margin: 0;
}

main.contact-main { max-width: 1100px; }

h1.contact-title { font-size: 40px; }

.contact-split {
  display: flex;
}

.contact-column {
  flex: 1;
  min-width: 0;
}

.contact-column:first-child { padding-right: 40px; }

.contact-column:last-child {
  padding-left: 40px;
  border-left: 1px solid var(--border);
}

.contact-column-title {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 14px;
}

.contact-x-link {
  display: inline-block;
  margin-top: 28px;
  font-size: 28px;
  font-weight: 700;
  color: #f5c518;
}

.contact-x-link:hover { opacity: 0.8; }

#contact-submit { align-self: flex-end; }

/* ---------------- Admin page ---------------- */
.admin-main { max-width: clamp(1560px, 90vw, 2000px); margin: 0 auto; padding: 56px 24px 96px; }

@media (max-width: 1560px) {
  .admin-main { max-width: 100%; }
}

.admin-title { font-size: 28px; font-weight: 700; margin: 0 0 32px; }

.admin-table-wrap { overflow-x: auto; }

#note-list-table-wrap .admin-table { font-size: 16px; }

.note-list-title-link {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
}

.note-list-title-link:hover { color: var(--text-muted); }

.note-list-title-link-row {
  display: flex;
  margin: 14px 0;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

#studydb-results .note-list-title-link-row { min-height: calc(18px * 1.6 * 4); align-items: center; }

.studydb-list-index {
  flex-shrink: 0;
  align-self: center;
  width: 5ch;
  text-align: center;
  color: var(--text);
  font-size: 14px;
  margin-right: 8px;
}

.studydb-list-date {
  flex-shrink: 0;
  align-self: center;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 13px;
}

.studydb-list-sep {
  flex-shrink: 0;
  align-self: stretch;
  border-left: 1px solid var(--text-muted);
  margin-right: 14px;
}

.note-list-title-link + .studydb-list-sep { margin-left: 14px; }

#studydb-count { margin-top: 20px; }

#studydb-page-size, #studydb-region-filter { flex: none; width: auto; }

#link-table input { width: 100%; }

#studydb-pagination {
  justify-content: center;
  align-items: center;
  margin-top: 32px;
  gap: 10px;
}

#studydb-page-numbers { display: flex; gap: 10px; }

#studydb-pagination > button,
#studydb-page-numbers button {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 16px;
  font-size: 16px;
  cursor: pointer;
  margin: 0;
}

#studydb-pagination > button:disabled { opacity: 0.35; cursor: default; }

#studydb-page-numbers button:disabled {
  color: var(--text);
  border: 2px solid var(--text);
  font-weight: 700;
  cursor: default;
}

.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }

.admin-table th, .admin-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: normal;
  word-break: break-word;
}

.admin-table th { color: var(--text-muted); font-weight: 500; }

.admin-sort-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  padding: 0;
  cursor: pointer;
}

.admin-sort-btn:hover { color: var(--text); }
.admin-sort-btn.active { color: var(--text); }

.admin-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  margin-right: 6px;
  white-space: nowrap;
}

.admin-btn:hover, .admin-btn:focus { border-color: var(--text); outline: none; }
.admin-btn-danger { color: #c0392b; border-color: #c0392b; }

/* ---------------- Privacy page ---------------- */
.doc-main { max-width: 640px; margin: 0 auto; padding: 56px 24px 96px; }
.doc-main h1 { font-size: 26px; font-weight: 700; margin: 0 0 28px; }
.doc-main h2 { font-size: 16px; font-weight: 700; margin: 28px 0 8px; }
.doc-main p, .doc-main li { font-size: 14px; color: var(--text-muted); line-height: 1.7; }

/* ---------------- Inline admin editing ---------------- */
[contenteditable="true"] {
  cursor: text;
  border-radius: var(--radius);
  outline: 1px dashed transparent;
}

[contenteditable="true"]:hover,
[contenteditable="true"]:focus {
  outline-color: var(--text-muted);
}

.edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.edit-row [contenteditable="true"] {
  flex: 1;
}

.edit-remove-btn {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.edit-remove-btn:hover { color: var(--text); border-color: var(--text); }

.card .edit-remove-btn { margin-top: 8px; }

.card-url-input {
  width: 100%;
  margin-top: 8px;
  padding: 6px 8px;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
}

.card-url-input::placeholder { color: var(--text-muted); }

.edit-add-btn {
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  padding: 8px 14px;
  font-size: 12px;
  font-family: var(--font-body);
  cursor: pointer;
  margin-top: 8px;
}

.edit-add-btn:hover { color: var(--text); border-color: var(--text-muted); }

.edit-add-card {
  display: flex;
  align-items: center;
  justify-content: center;
}

.edit-add-card .edit-add-btn { margin-top: 0; }

#edit-status {
  font-size: 12px;
  color: var(--text-muted);
}

.hardware-form:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.hardware-image-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.hardware-rating {
  font-size: 13px;
  letter-spacing: 1px;
  color: #f5c518;
}

#hardware-list table { table-layout: fixed; }
#hardware-list .hw-col-thumb { width: 6%; }
#hardware-list .hw-col-name { width: 15%; }
#hardware-list .hw-col-category { width: 12%; }
#hardware-list .hw-col-narrow { width: 7%; }
#hardware-list .hw-col-comment { width: 17%; }
#hardware-list .hw-col-wide { width: 27%; }
#hardware-list .hw-col-actions { width: 2%; }

.hardware-owner {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.hardware-img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--bg);
}

#hardware-edit-toggle:not([hidden]) {
  display: block;
  margin-bottom: 20px;
}

.hardware-disclaimer {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 640px;
  margin-bottom: 12px;
}

.hardware-disclaimer-textarea {
  width: 100%;
  max-width: 640px;
  margin-bottom: 8px;
  font-size: 12px;
}

.hardware-rating-legend {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  font-size: 12px;
  color: var(--text-muted);
}

.hardware-rating-legend li {
  margin-bottom: 4px;
}

.hardware-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 24px 0 20px;
}

.hardware-view-toggle {
  display: flex;
  gap: 6px;
}

.hardware-view-toggle .admin-btn.active {
  border-color: var(--text);
  color: var(--text);
  background: var(--surface);
}

.hardware-controls select {
  padding: 8px 12px;
  font-size: 13px;
}

.hardware-list-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--bg);
  display: block;
}

/* ---------------- Note pages (토글 블록) ---------------- */
.note-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 10px;
}

.note-block summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 19px;
}

.note-block-body {
  margin-top: 14px;
  margin-bottom: 4px;
  padding-left: 20px;
  font-size: 17px;
  line-height: 1.7;
  color: var(--text);
}

.note-block-edit-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 10px;
}

.note-block-child {
  margin: 10px 0 0 16px;
  font-size: 17px;
}

.note-block-children-editor {
  margin: 4px 0 0 16px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

.note-block-child-edit-row {
  padding: 10px 12px;
}

#privacy-body-view {
  font-size: 16px;
  line-height: 1.8;
  color: var(--text);
  margin-top: 8px;
}

#privacy-detail-body-input {
  width: 100%;
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 16px;
}

.note-block-open-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------------- Motion / accessibility ---------------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .card { transition: none; }
}

/* ---------------- Responsive ---------------- */
@media (max-width: 560px) {
  .nav { padding: 14px 16px; gap: 10px 14px; flex-wrap: wrap; }
  .nav-name { font-size: 14px; white-space: nowrap; }
  .nav-links { gap: 12px; flex-wrap: wrap; }
  .nav-right { gap: 12px; margin-left: 0; flex: 1 0 100%; flex-wrap: wrap; justify-content: flex-end; }
  .nav-link { font-size: 13px; white-space: nowrap; }
  .card-grid:not([hidden]) { grid-template-columns: 1fr; }
  .hero:not([hidden]) {
    padding: 40px 16px;
    min-height: 70vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  main { padding: 0 16px 64px; }
  .field-row { flex-direction: column; }
  .contact-split { flex-direction: column; }
  .contact-column:first-child { padding-right: 0; }
  .contact-column:last-child {
    padding-left: 0;
    padding-top: 32px;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  #note-list-table-wrap .admin-table thead { display: none; }
  #note-list-table-wrap .admin-table,
  #note-list-table-wrap .admin-table tbody { display: block; width: 100%; }
  #note-list-table-wrap .admin-table tr {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
  }
  #note-list-table-wrap .admin-table td { padding: 0; border: none; }
  #note-list-table-wrap .admin-table td:nth-child(1) { grid-column: 1 / -1; }
  #note-list-table-wrap .admin-table td:nth-child(1) .note-list-title-link { font-size: 20px; }
  #note-list-table-wrap .admin-table td:nth-child(2) { font-size: 12px; color: var(--text-muted); }
  #note-list-table-wrap .admin-table td:nth-child(3) { font-size: 12px; color: var(--text-muted); text-align: right; }
  #note-list-table-wrap .admin-table td:nth-child(4) { grid-column: 1 / -1; }
  #note-list-table-wrap .admin-table td:nth-child(4):empty { display: none; }
}
