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

:root {
  --yellow: #ffde36;
  --yellow-light: #fff6cf;
  --orange: #ff8500;
  --black: #000000;
  --gray-900: #222222;
  --gray-800: #333333;
  --gray-700: #464646;
  --gray-500: #777777;
  --gray-400: #848484;
  --gray-300: #999999;
  --gray-200: #cecece;
  --gray-150: #ededed;
  --gray-100: #f7f7f7;
  --gray-50: #fafafa;
  --white: #ffffff;
  --bg: #f2f2f2;
  --sidebar-w: 280px;
}

html, body {
  height: 100%;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', sans-serif;
  background: var(--bg);
  color: var(--black);
  -webkit-font-smoothing: antialiased;
}

body.viewer-body {
  overflow: hidden;
  display: flex;
}

/* =========================================================
 * Sidebar — floating style for viewer
 * ========================================================= */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--white);
  border-right: 1px solid var(--gray-150);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.25s ease;
}

.sidebar.floating {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  box-shadow: 4px 0 32px rgba(0, 0, 0, 0.1);
  transform: translateX(calc(var(--sidebar-w) * -1));
}

.sidebar.floating.show {
  transform: translateX(0);
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-dot {
  width: 36px;
  height: 36px;
  background: var(--yellow);
  border-radius: 10px;
}

.brand h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.brand p {
  font-size: 11px;
  font-weight: 500;
  color: var(--gray-500);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.sidebar-toggle {
  background: var(--gray-100);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  color: var(--gray-700);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

.sidebar-toggle:hover {
  background: var(--gray-150);
  color: var(--black);
}

/* Mode switch inside sidebar */
.sidebar .mode-switch {
  margin: 12px 16px;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--gray-100);
  border-radius: 100px;
}

.sidebar .mode-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: 100px;
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  text-align: center;
  transition: all 0.2s;
}

.sidebar .mode-btn:hover {
  color: var(--black);
}

.sidebar .mode-btn.active {
  background: var(--black);
  color: var(--white);
}

.screen-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-section {
  margin-bottom: 8px;
}

.nav-section-title {
  display: block;
  padding: 10px 20px 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-500);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 20px;
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--gray-100);
  color: var(--black);
}

.nav-item.active {
  background: var(--yellow-light);
  color: var(--black);
  font-weight: 600;
  border-left: 3px solid var(--yellow);
  padding-left: 17px;
}

.nav-item .idx {
  font-size: 10px;
  color: var(--gray-400);
  font-weight: 500;
  min-width: 18px;
}

.nav-item.active .idx {
  color: var(--orange);
  font-weight: 700;
}

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--gray-150);
  font-size: 11px;
  color: var(--gray-500);
}

.sidebar-footer .keys {
  margin-top: 4px;
  color: var(--gray-400);
}

/* =========================================================
 * Viewer — full-height mode with floating UI
 * ========================================================= */
.viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.viewer-full {
  position: relative;
  height: 100vh;
  width: 100%;
}

/* Floating meta (top-left) */
.floating-meta {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 10px 10px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 16px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  max-width: calc(100% - 200px);
}

.menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--black);
  border: none;
  color: var(--white);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
}

.menu-btn:hover {
  background: var(--yellow);
  color: var(--black);
}

.meta-text {
  min-width: 0;
  flex: 1;
}

.section-label {
  display: inline-block;
  padding: 2px 8px;
  background: var(--yellow-light);
  color: var(--orange);
  border-radius: 100px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-bottom: 3px;
}

.floating-meta h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--black);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

/* Floating counter (top-right) */
.floating-counter {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 50;
  padding: 12px 18px;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 100px;
  font-size: 13px;
  font-weight: 700;
  color: var(--white);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}

/* Floating hints (bottom-center) */
.floating-hints {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 100px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  font-size: 11px;
  font-weight: 500;
  color: var(--gray-500);
  white-space: nowrap;
}

.floating-hints .hint-sep {
  color: var(--gray-300);
}

.floating-hints kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  color: var(--gray-700);
  min-width: 18px;
  text-align: center;
}

/* =========================================================
 * Stage — full height phone display
 * ========================================================= */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 32px;
  overflow: auto;
  background:
    radial-gradient(circle at 25% 25%, rgba(255, 222, 54, 0.08), transparent 50%),
    radial-gradient(circle at 75% 75%, rgba(255, 133, 0, 0.05), transparent 50%),
    var(--bg);
}

.stage-full {
  height: 100vh;
  padding: 40px 80px;
}

.arrow {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: 50%;
  background: var(--white);
  border: 1px solid var(--gray-150);
  color: var(--gray-700);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  flex-shrink: 0;
}

.arrow:hover {
  background: var(--yellow);
  color: var(--black);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.arrow:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.arrow:disabled:hover {
  background: var(--white);
  color: var(--gray-700);
}

/* =========================================================
 * iPhone mock — large variant for full viewer
 * ========================================================= */
.phone {
  flex-shrink: 0;
  padding: 12px;
  background: #1a1a1a;
  border-radius: 48px;
  box-shadow:
    0 0 0 2px #3a3a3a,
    0 25px 50px rgba(0, 0, 0, 0.18),
    0 12px 24px rgba(0, 0, 0, 0.12);
  position: relative;
}

.phone-frame {
  position: relative;
  width: 390px;
  height: 844px;
  max-height: calc(100vh - 120px);
  background: var(--white);
  border-radius: 36px;
  overflow: hidden;
}

.phone-large .phone-frame {
  max-height: calc(100vh - 80px);
}

.phone-notch {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 30px;
  background: #1a1a1a;
  border-radius: 100px;
  z-index: 10;
}

.phone-screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--gray-200) transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.phone-screen::-webkit-scrollbar {
  width: 6px;
}
.phone-screen::-webkit-scrollbar-thumb {
  background: var(--gray-200);
  border-radius: 3px;
}
.phone-screen::-webkit-scrollbar-track {
  background: transparent;
}

.phone-screen img {
  display: block;
  width: 390px;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

/* Popup / bottom sheet variant — render at natural size, vertically centered
   on a dimmed "phone background" to simulate in-app overlay */
.phone-screen.is-popup {
  justify-content: center;
  background:
    linear-gradient(rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.45)),
    repeating-linear-gradient(
      45deg,
      #2a2a2a 0 6px,
      #1f1f1f 6px 12px
    );
}

.phone-screen.is-popup img {
  width: auto;             /* overridden inline via JS to naturalWidth/2 */
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  margin: auto 0;          /* auto-margins center when fits, clamp when overflow */
}

.phone-indicator {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 139px;
  height: 5px;
  background: #1a1a1a;
  border-radius: 100px;
  z-index: 10;
  pointer-events: none;
}

/* =========================================================
 * Fade animation on screen change
 * ========================================================= */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.phone-screen img.entering {
  animation: fadeIn 0.25s ease both;
}

/* =========================================================
 * Responsive
 * ========================================================= */
@media (max-width: 900px) {
  .floating-meta {
    top: 12px;
    left: 12px;
    padding: 8px 12px 8px 8px;
    max-width: calc(100% - 140px);
  }

  .floating-meta h2 {
    font-size: 13px;
    max-width: 180px;
  }

  .section-label {
    font-size: 9px;
  }

  .menu-btn {
    width: 32px;
    height: 32px;
  }

  .floating-counter {
    top: 12px;
    right: 12px;
    padding: 10px 14px;
    font-size: 11px;
  }

  .floating-hints {
    display: none;
  }

  .stage-full {
    padding: 20px 60px;
  }

  .arrow {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  .phone {
    padding: 8px;
    border-radius: 36px;
  }

  .phone-frame {
    width: 320px;
    height: 692px;
    max-height: calc(100vh - 60px);
    border-radius: 28px;
  }

  .phone-notch {
    width: 100px;
    height: 24px;
  }

  .phone-screen img {
    width: 320px;
  }
}

@media (max-width: 520px) {
  .stage-full {
    padding: 12px 12px;
    gap: 8px;
  }

  .arrow {
    position: fixed;
    bottom: 20px;
    z-index: 60;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
  }

  .arrow-prev {
    left: 20px;
  }

  .arrow-next {
    right: 20px;
  }

  .phone-frame {
    width: 280px;
    height: 605px;
  }

  .phone-screen img {
    width: 280px;
  }
}
