/* NAS 플레이어 — 다크 단일 테마. 외부 CDN 없이 전부 로컬. */

:root {
  --bg: #14161a;
  --bg-elevated: #1c1f26;
  --bg-hover: #262a33;
  --border: #2c303a;
  --text: #e8e9ec;
  --text-dim: #9aa0ab;
  --accent: #4f8cff;
  --accent-hover: #6ea0ff;
  --error: #ff6b6b;
  --danger: #e05252;
  --radius: 0.5rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 1rem;
  line-height: 1.5;
}

h1,
h2,
h3 {
  margin: 0 0 1rem;
  font-weight: 600;
}

.view {
  min-height: 100vh;
  padding: 1.25rem;
  max-width: 56rem;
  margin: 0 auto;
}

.hidden {
  display: none !important;
}

/* ── 공통 폼 요소 ─────────────────────────────────── */
input,
select,
button {
  font: inherit;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
}

input:focus,
select:focus,
button:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  cursor: pointer;
  background: var(--bg-hover);
}

button:hover {
  background: #30343f;
}

form button[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0d10;
  font-weight: 600;
}

form button[type="submit"]:hover {
  background: var(--accent-hover);
}

.error {
  color: var(--error);
  min-height: 1.2em;
  margin: 0.5rem 0 0;
  word-break: break-word;
}

.notice {
  background: #2a2410;
  border: 1px solid #5a4a12;
  color: #e8c96a;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
}

/* ── 로그인 화면 ──────────────────────────────────── */
#login-view {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  text-align: center;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 20rem;
}

#login-form label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}

/* ── 탐색 화면 ────────────────────────────────────── */
#browse-view header,
#settings-view header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

#browse-view header div {
  display: flex;
  gap: 0.5rem;
}

#crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.95rem;
}

#crumbs button {
  background: none;
  border: none;
  padding: 0.2rem 0.3rem;
  color: var(--text-dim);
}

#crumbs button:hover {
  color: var(--accent-hover);
  background: none;
}

#crumbs button:first-child {
  color: var(--text);
  font-weight: 600;
}

.crumb-sep {
  color: var(--text-dim);
}

#entries {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 0.6rem;
}

#entries li.entry {
  display: flex;
  flex-direction: column;
  overflow: hidden; /* 썸네일 모서리를 카드 radius에 맞춰 자름 */
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

#entries li.entry:hover {
  background: var(--bg-hover);
}

/* 카드 상단 썸네일 영역 — 16:9 고정 비율 */
#entries .thumb-box {
  aspect-ratio: 16 / 9;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

#entries img.thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 썸네일 없음(폴더·생성 실패) 대체 아이콘 */
#entries .thumb-placeholder {
  font-size: 2rem;
  color: var(--text-dim);
}

#entries li.dir .thumb-placeholder {
  color: var(--accent); /* ▸ 폴더 표시 */
}

#entries .meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.5rem 0.65rem;
}

#entries .name {
  overflow-wrap: anywhere;
  font-size: 0.9rem;
  display: -webkit-box; /* 긴 이름은 2줄 클램프 */
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#entries .size {
  color: var(--text-dim);
  font-size: 0.8rem;
}

#entries li.empty,
#entries li.error {
  grid-column: 1 / -1; /* 그리드에서 전체 폭 차지 */
  list-style: none;
  padding: 1rem;
  color: var(--text-dim);
  text-align: center;
  cursor: default;
}

#entries li.error {
  color: var(--error);
}

/* ── 플레이어 ─────────────────────────────────────── */
#player-wrap {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  z-index: 10;
}

#btn-close-player {
  align-self: flex-end;
  margin-right: 1vw;
}

#player {
  width: 100%;
  max-width: 64rem;
  max-height: 80vh;
  background: #000;
  border-radius: var(--radius);
}

/* ── 이미지 뷰어(#player-wrap 오버레이 패턴 준용) ─── */
#viewer-wrap {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  z-index: 10;
}

/* 상단 바: 위치 표시("3 / 27") + 닫기 버튼 — 기존 닫기 버튼 자리(우상단) 유지 */
.viewer-topbar {
  align-self: flex-end;
  margin-right: 1vw;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

#viewer-pos {
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* 이전/다음 — 화면 좌우 중앙 오버레이(모바일 엄지가 닿는 위치),
   반투명 배경, 터치 타겟 최소 2.75rem */
#btn-prev-image,
#btn-next-image {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0.4rem;
  background: rgba(20, 22, 26, 0.55);
  border-radius: 50%;
  z-index: 11;
}

#btn-prev-image {
  left: 0.75rem;
}

#btn-next-image {
  right: 0.75rem;
}

#btn-prev-image:not(:disabled):hover,
#btn-next-image:not(:disabled):hover {
  background: rgba(38, 42, 51, 0.85);
}

/* 끝단에서는 숨김이 아니라 비활성 — 버튼 위치 예측 가능성 유지 */
#btn-prev-image:disabled,
#btn-next-image:disabled {
  opacity: 0.35;
  cursor: default;
  background: rgba(20, 22, 26, 0.55);
}

#viewer-img {
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius);
}

/* ── 설정 화면 ────────────────────────────────────── */
#settings-view section {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

#settings-view form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: 28rem;
}

#folder-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#folder-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

#folder-list li.empty {
  color: var(--text-dim);
  justify-content: center;
}

#folder-list button {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}

#folder-list button:hover {
  background: #f06565;
}

#settings-msg {
  min-height: 1.2em;
  color: var(--text-dim);
}

/* ── 모바일 대응 ──────────────────────────────────── */
@media (max-width: 40rem) {
  .view {
    padding: 0.85rem;
  }

  #browse-view header {
    flex-direction: column;
    align-items: stretch;
  }

  #browse-view header div {
    justify-content: flex-end;
  }

  #entries {
    /* 좁은 화면에서도 2칸 이상 유지 */
    grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  }

  input,
  select,
  button {
    font-size: 1rem;
    padding: 0.65rem 0.8rem;
  }

  #settings-view form {
    max-width: 100%;
  }

  #player {
    max-height: 60vh;
  }

  #viewer-img {
    max-height: 75vh; /* 모바일 — 닫기 버튼·주소창 공간 확보 */
  }

  /* 좁은 화면 — 이전/다음 버튼을 가장자리에 붙여 사진 가림 최소화 */
  #btn-prev-image {
    left: 0.4rem;
  }

  #btn-next-image {
    right: 0.4rem;
  }
}
