/* ===================================================================
   Hillper — styles
   Warm, calm, family-friendly. Comfortaa + soft pastel palette.
   =================================================================== */

:root {
  /* Palette */
  --off-white: #faf7f2;
  --beige: #efe5d5;
  --beige-deep: #e7dac6;
  --card: #ffffff;
  --ink: #2e2a26;
  --ink-soft: #6f665d;
  --blue: #a8d8ea;
  --blue-deep: #7cc0da;
  --red: #f2a9a0;
  --red-deep: #e88d82;

  /* Shape */
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 8px 24px rgba(46, 42, 38, 0.08);
  --shadow-lg: 0 20px 50px rgba(46, 42, 38, 0.22);
  --header-h: 68px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Comfortaa", system-ui, sans-serif;
  background: var(--off-white);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

button {
  font-family: inherit;
  cursor: pointer;
}

::selection {
  background: var(--blue);
  color: var(--ink);
}

.hidden {
  display: none !important;
}

/* Wordmark ---------------------------------------------------------- */
.wordmark {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 2.6rem;
  color: var(--ink);
}
.wordmark.small {
  font-size: 1.5rem;
}

/* Shared button ----------------------------------------------------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  background: var(--blue);
  color: var(--ink);
  transition: background 0.2s, transform 0.05s;
}
.btn:hover {
  background: var(--blue-deep);
}
.btn:active {
  transform: translateY(1px);
}

/* ===================================================================
   GATE
   =================================================================== */
.gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(
      1100px 520px at 50% -8%,
      rgba(168, 216, 234, 0.5),
      transparent 62%
    ),
    radial-gradient(
      900px 500px at 100% 110%,
      rgba(242, 169, 160, 0.35),
      transparent 60%
    ),
    var(--off-white);
}
.gate-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 24px;
  padding: 2.6rem 2.2rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.gate-sub {
  margin: 0.6rem 0 1.6rem;
  color: var(--ink-soft);
}
#gate-form {
  display: grid;
  gap: 0.7rem;
}
#gate-input {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 2px solid var(--beige-deep);
  border-radius: var(--radius-sm);
  background: var(--off-white);
  color: var(--ink);
  font-size: 1rem;
  font-family: inherit;
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#gate-input:focus {
  outline: none;
  border-color: var(--blue-deep);
  box-shadow: 0 0 0 4px rgba(168, 216, 234, 0.4);
}
.gate-error {
  margin: 1rem 0 0;
  color: var(--red-deep);
  font-size: 0.92rem;
  visibility: hidden;
}
.gate-error.show {
  visibility: visible;
}
.gate-foot {
  margin-top: 1.6rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
}
.shake {
  animation: shake 0.35s;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

/* ===================================================================
   HEADER
   =================================================================== */
.header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.2rem;
  background: rgba(250, 247, 242, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--beige-deep);
}
.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 10px;
  background: var(--beige);
  padding: 0 11px;
}
.menu-toggle span {
  display: block;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
}
.search-wrap {
  position: relative;
  margin-left: auto;
  width: min(360px, 46vw);
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--ink-soft);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 0.6rem 0.9rem 0.6rem 2.4rem;
  border: 2px solid var(--beige-deep);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#search:focus {
  outline: none;
  border-color: var(--blue-deep);
  box-shadow: 0 0 0 4px rgba(168, 216, 234, 0.35);
}

/* ===================================================================
   LAYOUT
   =================================================================== */
.layout {
  display: grid;
  grid-template-columns: 268px 1fr;
  align-items: start;
}
.sidebar {
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 1.4rem 1rem;
  border-right: 1px solid var(--beige-deep);
}
.sidebar-title {
  margin: 0 0 0.8rem;
  padding-left: 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* Category tree ----------------------------------------------------- */
.cat-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.cat-list.depth-1 {
  margin-left: 0.55rem;
  padding-left: 0.55rem;
  border-left: 2px solid var(--beige-deep);
}
.cat-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 0.98rem;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  margin-bottom: 2px;
  transition: background 0.15s, color 0.15s;
}
.cat-btn:hover {
  background: var(--beige);
}
.cat-btn.active {
  background: var(--blue);
  color: var(--ink);
  font-weight: 600;
}
.cat-btn.is-parent {
  color: var(--ink-soft);
  font-weight: 600;
  cursor: default;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.cat-btn.is-parent:hover {
  background: transparent;
}
.cat-count {
  flex: none;
  min-width: 1.4rem;
  text-align: center;
  font-size: 0.72rem;
  color: var(--ink-soft);
  background: var(--beige);
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
}
.cat-btn.active .cat-count {
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink);
}
.nav-note {
  padding: 0.8rem 0.7rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.nav-note.error {
  color: var(--red-deep);
}

/* ===================================================================
   CONTENT
   =================================================================== */
.content {
  padding: 1.8rem 1.8rem 4rem;
  min-height: calc(100vh - var(--header-h));
}
.view-head {
  margin-bottom: 1.4rem;
}
.view-title {
  margin: 0;
  font-size: 1.9rem;
  font-weight: 700;
}
.view-sub {
  margin: 0.2rem 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

/* Grid -------------------------------------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}
.tile {
  position: relative;
  border: none;
  padding: 0;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--beige);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  animation: rise 0.45s forwards;
}
@keyframes rise {
  to { opacity: 1; transform: translateY(0); }
}
.tile .thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s ease;
}
.tile:hover .thumb {
  transform: scale(1.06);
}
.thumb-fallback {
  background: linear-gradient(135deg, var(--beige), var(--beige-deep));
}
/* Play badge for video tiles */
.play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(46, 42, 38, 0.55);
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.play::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 54%;
  transform: translate(-50%, -50%);
  border-style: solid;
  border-width: 10px 0 10px 17px;
  border-color: transparent transparent transparent #fff;
}

/* ===================================================================
   STATES (loading / empty / error)
   =================================================================== */
.state {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 2.5rem 0.5rem;
  color: var(--ink-soft);
  font-size: 1rem;
}
.state.empty,
.state.error {
  justify-content: flex-start;
}
.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid var(--beige-deep);
  border-top-color: var(--blue-deep);
  animation: spin 0.8s linear infinite;
  flex: none;
}
.spinner.small {
  width: 15px;
  height: 15px;
  border-width: 2px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===================================================================
   LIGHTBOX
   =================================================================== */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(30, 27, 24, 0.9);
  padding: 3.2rem 1rem 4rem;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox.open {
  display: flex;
}
.lb-body {
  max-width: 94vw;
  max-height: 82vh;
  display: flex;
  cursor: auto;
}
.lb-media {
  max-width: 94vw;
  max-height: 82vh;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  background: #000;
}
.lb-caption {
  position: absolute;
  bottom: 1.1rem;
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.9rem;
  padding: 0 1rem;
  pointer-events: none;
}
.lb-close,
.lb-nav {
  position: absolute;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: background 0.2s;
}
.lb-close {
  top: 1rem;
  right: 1.1rem;
  width: 44px;
  height: 44px;
  font-size: 1.9rem;
  line-height: 1;
}
.lb-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 50px;
  font-size: 2rem;
  line-height: 1;
}
.lb-prev { left: 1rem; }
.lb-next { right: 1rem; }
.lb-close:hover,
.lb-nav:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* ===================================================================
   MOBILE
   =================================================================== */
.backdrop {
  display: none;
  position: fixed;
  inset: var(--header-h) 0 0;
  z-index: 20;
  background: rgba(46, 42, 38, 0.4);
}
.backdrop.show {
  display: block;
}

@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .menu-toggle {
    display: flex;
  }
  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    height: auto;
    width: 82%;
    max-width: 320px;
    z-index: 25;
    background: var(--off-white);
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform 0.28s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .content {
    padding: 1.3rem 1.1rem 4rem;
  }
  .view-title {
    font-size: 1.5rem;
  }
  .wordmark.small {
    font-size: 1.3rem;
  }
  .search-wrap {
    width: auto;
    flex: 1;
  }
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }
  .lb-nav {
    width: 42px;
    height: 42px;
    font-size: 1.6rem;
  }
}

@media (max-width: 480px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ===================================================================
   UPLOAD LINK (in the main app header)
   =================================================================== */
.upload-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex: none;
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--red);
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  transition: background 0.2s;
}
.upload-link:hover {
  background: var(--red-deep);
}
.upload-link svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.4;
  stroke-linecap: round;
}

/* ===================================================================
   UPLOAD DASHBOARD (upload.html)
   =================================================================== */
.ghost-link {
  margin-left: auto;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.5rem 0.9rem;
  border-radius: 10px;
  transition: color 0.2s, background 0.2s;
}
.ghost-link:hover {
  color: var(--ink);
  background: var(--beige);
}
.upload-page {
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem 1.4rem 5rem;
}
.upload-head {
  margin-bottom: 1.6rem;
}
.upload-head h1 {
  margin: 0;
  font-size: 1.9rem;
}
.upload-intro {
  margin: 0.3rem 0 0;
  color: var(--ink-soft);
}
.panel {
  background: var(--card);
  border: 1px solid var(--beige-deep);
  border-radius: var(--radius);
  padding: 1.4rem;
  margin-bottom: 1.2rem;
  box-shadow: var(--shadow);
}
.panel.actions {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}
.panel-title {
  margin: 0 0 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* Form fields */
.field-select,
.field-text {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 2px solid var(--beige-deep);
  border-radius: var(--radius-sm);
  background: var(--off-white);
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field-select:focus,
.field-text:focus {
  outline: none;
  border-color: var(--blue-deep);
  box-shadow: 0 0 0 4px rgba(168, 216, 234, 0.35);
}
.new-cat {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.6rem;
  margin-top: 0.8rem;
  align-items: start;
}
.new-cat .field-select {
  width: auto;
  min-width: 160px;
}
.new-cat .inline-error {
  grid-column: 1 / -1;
}
.inline-error {
  margin: 0.2rem 0 0;
  color: var(--red-deep);
  font-size: 0.85rem;
  min-height: 1em;
}

/* Buttons */
.btn-primary {
  background: var(--blue);
}
.btn-primary:hover {
  background: var(--blue-deep);
}
.btn-primary:disabled {
  background: var(--beige-deep);
  color: var(--ink-soft);
  cursor: not-allowed;
}
.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 2px solid var(--beige-deep);
}
.btn-ghost:hover {
  background: var(--beige);
}

/* Visually hidden but still rendered/interactive — used for the file input.
   iOS opens programmatically-triggered file inputs more reliably when they
   are present in layout rather than display:none / [hidden]. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Drop zone */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 2.4rem 1rem;
  border: 2px dashed var(--blue-deep);
  border-radius: var(--radius);
  background: rgba(168, 216, 234, 0.12);
  text-align: center;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-drag {
  background: rgba(168, 216, 234, 0.28);
  border-color: var(--blue);
  outline: none;
}
.dz-icon {
  width: 34px;
  height: 34px;
  fill: none;
  stroke: var(--blue-deep);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.dz-text {
  margin: 0.4rem 0 0;
  font-weight: 600;
}
.dz-sub {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}
.dz-browse {
  color: var(--blue-deep);
  text-decoration: underline;
}

/* File list */
.file-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem;
  border: 1px solid var(--beige-deep);
  border-radius: var(--radius-sm);
  background: var(--off-white);
}
.fi-thumb {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background-color: var(--beige);
  background-size: cover;
  background-position: center;
}
.fi-thumb-video {
  position: relative;
  background: linear-gradient(135deg, var(--beige), var(--beige-deep));
}
.fi-thumb-video::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 8px 0 8px 13px;
  border-color: transparent transparent transparent var(--ink-soft);
}
.fi-main {
  flex: 1;
  min-width: 0;
}
.fi-row {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
}
.fi-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.92rem;
}
.fi-size {
  flex: none;
  color: var(--ink-soft);
  font-size: 0.82rem;
}
.fi-bar {
  height: 6px;
  margin: 0.4rem 0 0.3rem;
  background: var(--beige);
  border-radius: 999px;
  overflow: hidden;
}
.fi-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--blue-deep);
  border-radius: 999px;
  transition: width 0.15s;
}
.fi-status {
  font-size: 0.8rem;
  color: var(--ink-soft);
}
.status-done .fi-fill {
  background: #7bbf8e;
}
.status-done .fi-status {
  color: #5a9c6d;
}
.status-failed .fi-fill,
.status-toolarge .fi-fill {
  background: var(--red-deep);
}
.status-failed .fi-status,
.status-toolarge .fi-status {
  color: var(--red-deep);
}
.status-toolarge {
  border-color: var(--red);
}
.fi-remove {
  flex: none;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: var(--beige);
  color: var(--ink-soft);
  font-size: 1.2rem;
  line-height: 1;
}
.fi-remove:hover {
  background: var(--red);
  color: var(--ink);
}

/* Result banner */
.result {
  margin-top: 0.5rem;
  padding: 1rem 1.2rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.result.ok {
  background: #e6f4ea;
  color: #3f7a54;
}
.result.mixed {
  background: #fdf1e3;
  color: #9a6a2f;
}
.result.error {
  background: #fbe9e7;
  color: var(--red-deep);
}

@media (max-width: 560px) {
  .new-cat {
    grid-template-columns: 1fr;
  }
  .new-cat .field-select {
    width: 100%;
  }
  .upload-link span {
    display: none;
  }
}
